UNPKG

6.22 kBJavaScriptView Raw
1"use strict";
2/**
3 * Document 对象扩展
4 */
5var SameSite;
6(function (SameSite) {
7 SameSite["NONE"] = "None";
8 SameSite["LAX"] = "Lax";
9 SameSite["STRICT"] = "Strict";
10})(SameSite || (SameSite = {}));
11var CookieInstance = /** @class */ (function () {
12 function CookieInstance() {
13 }
14 CookieInstance.prototype.set = function (name, value, options) {
15 var $name = name = encodeURIComponent(name)
16 .replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent);
17 var $value = value ? encodeURIComponent(value)
18 .replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g, decodeURIComponent) : '';
19 var stringifiedAttributes = '';
20 if (options) {
21 stringifiedAttributes += options.domain ? '; domain=' + options.domain : '';
22 stringifiedAttributes += options.path ? '; path=' + options.path : '';
23 if (options.expires) {
24 var $expiresDate = options.expires instanceof Date ? options.expires : new Date(Date.now() + options.expires * 864e5);
25 stringifiedAttributes += options.expires ? '; expires=' + $expiresDate.toUTCString() : '';
26 }
27 stringifiedAttributes += options.sameSite ? '; sameSite=' + options.sameSite : '';
28 if (Object.isBoolean(options.secure) && options.secure) {
29 stringifiedAttributes += options.expires ? '; secure' : '';
30 }
31 if (Object.isBoolean(options.httpOnly) && options.httpOnly) {
32 stringifiedAttributes += options.httpOnly ? '; httpOnly' : '';
33 }
34 }
35 return document.cookie = $name + '=' + $value + stringifiedAttributes;
36 };
37 CookieInstance.prototype.get = function (name) {
38 var cookies = document.cookie ? document.cookie.split('; ') : [];
39 for (var i = 0; i < cookies.length; i++) {
40 var parts = cookies[i].split('=');
41 var $name = decodeURIComponent(parts[0]);
42 var $value = parts.slice(1).join('=');
43 if ($name === name) {
44 if ($value[0] === '"') {
45 $value = $value.slice(1, -1);
46 }
47 return $value.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent);
48 }
49 }
50 return null;
51 };
52 CookieInstance.prototype.delete = function (name, options) {
53 var $options = options ? options : {};
54 $options.expires = -1;
55 this.set(name, '', $options);
56 };
57 return CookieInstance;
58}());
59/**
60 * 检测当前浏览器是否为全屏
61 *
62 * @return 当前浏览器是否为全屏
63 */
64Object.defineProperty(document, "fullScreen", {
65 value: Object.isUndefined(document.fullscreen) === false ? document.fullscreen : (Object.isUndefined(document.mozFullScreen) === false ? document.mozFullScreen : (Object.isUndefined(document.webkitIsFullScreen) === false ? document.webkitIsFullScreen : (Object.isUndefined(document.msFullScreen) === false ? document.msFullScreen : (Object.isUndefined(document.fullscreenElement) === false ? document.fullscreenElement !== null : (Object.isUndefined(document.mozFullScreenElement) === false ? document.mozFullScreenElement !== null : (Object.isUndefined(document.webkitFullscreenElement) === false ? document.webkitFullscreenElement !== null : (Object.isUndefined(document.msFullscreenElement) === false ? document.msFullscreenElement !== null : false))))))),
66 configurable: true,
67 writable: false
68});
69/**
70 * 检测当前浏览器是否支持全屏模式
71 *
72 * @return 当前浏览器是否支持全屏模式
73 */
74Object.defineProperty(document, "fullScreenEnabled", {
75 value: Object.isUndefined(document.mozFullScreenEnabled) === false ? document.mozFullScreenEnabled : (Object.isUndefined(document.webkitFullscreenEnabled) === false ? document.webkitFullscreenEnabled : (Object.isUndefined(document.msFullscreenEnabled) === false ? document.msFullscreenEnabled : (Object.isUndefined(document.fullscreenEnabled) === false ? document.fullscreenEnabled : false))),
76 configurable: true,
77 writable: false
78});
79/**
80 * 返回当前文档中正在以全屏模式显示的 Element 节点
81 *
82 * @return 当前文档中正在以全屏模式显示的 Element 节点
83 */
84Object.defineProperty(document, "fullScreenElement", {
85 value: Object.isUndefined(document.mozFullScreenElement) === false ? document.mozFullScreenElement : (Object.isUndefined(document.webkitFullscreenElement) === false ? document.webkitFullscreenElement : (Object.isUndefined(document.msFullscreenElement) === false ? document.msFullscreenElement : (Object.isUndefined(document.fullscreenElement) === false ? document.fullscreenElement : null))),
86 configurable: true,
87 writable: false
88});
89/**
90 * 返回 Cookie 对象
91 *
92 * @return Cookie 对象
93 */
94Object.defineProperty(document, "httpCookie", {
95 value: new CookieInstance(),
96 configurable: true,
97 writable: false
98});
99/**
100 * 请求进入全屏模式
101 *
102 * @return Promise
103 */
104Document.prototype.requestFullscreen = function () {
105 var doc = document.documentElement;
106 if (Object.isFunction(doc.mozRequestFullScreen)) {
107 return doc.mozRequestFullScreen();
108 }
109 else if (Object.isFunction(doc.webkitRequestFullscreen)) {
110 return doc.webkitRequestFullscreen();
111 }
112 else if (Object.isFunction(doc.msRequestFullscreen)) {
113 return doc.msRequestFullscreen();
114 }
115 else {
116 return doc.requestFullscreen();
117 }
118};
119/**
120 * 退出全屏模式
121 *
122 * @return Promise
123 */
124Document.prototype.exitFullscreen = function () {
125 if (Object.isFunction(document.mozCancelFullScreen)) {
126 return document.mozCancelFullScreen();
127 }
128 else if (Object.isFunction(document.mozExitFullScreen)) {
129 return document.mozExitFullScreen();
130 }
131 else if (Object.isFunction(document.webkitCancelFullScreen)) {
132 return document.webkitCancelFullScreen();
133 }
134 else if (Object.isFunction(document.webkitExitFullscreen)) {
135 return document.webkitExitFullscreen();
136 }
137 else if (Object.isFunction(document.msExitFullscreen)) {
138 return document.msExitFullscreen();
139 }
140 else {
141 return document.exitFullscreen();
142 }
143};
144//# sourceMappingURL=document.js.map
\No newline at end of file