dom-zindex
Advanced tools
Comparing version 1.0.5 to 1.0.6
@@ -11,2 +11,4 @@ "use strict"; | ||
exports.setSubCurrent = exports.setCurrent = void 0; | ||
var winDom = null; | ||
var bodyEl = null; | ||
var storeEl = null; | ||
@@ -22,15 +24,30 @@ var storeId = 'z-index-manage'; | ||
}; | ||
function isDocument() { | ||
return typeof document !== 'undefined'; | ||
function getDocument() { | ||
if (!winDom) { | ||
if (typeof document !== 'undefined') { | ||
winDom = document; | ||
} | ||
} | ||
return winDom; | ||
} | ||
function getBody() { | ||
if (winDom && !bodyEl) { | ||
bodyEl = winDom.body || winDom.getElementsByTagName('body')[0]; | ||
} | ||
return bodyEl; | ||
} | ||
function getDomMaxZIndex() { | ||
var max = 0; | ||
if (isDocument()) { | ||
var allElem = document.body.getElementsByTagName('*'); | ||
for (var i = 0; i < allElem.length; i++) { | ||
var elem = allElem[i]; | ||
if (elem && elem.style && elem.nodeType === 1) { | ||
var zIndex = elem.style.zIndex; | ||
if (zIndex && /^\d+$/.test(zIndex)) { | ||
max = Math.max(max, Number(zIndex)); | ||
var dom = getDocument(); | ||
if (dom) { | ||
var body = getBody(); | ||
if (body) { | ||
var allElem = body.getElementsByTagName('*'); | ||
for (var i = 0; i < allElem.length; i++) { | ||
var elem = allElem[i]; | ||
if (elem && elem.style && elem.nodeType === 1) { | ||
var zIndex = elem.style.zIndex; | ||
if (zIndex && /^\d+$/.test(zIndex)) { | ||
max = Math.max(max, Number(zIndex)); | ||
} | ||
} | ||
@@ -44,8 +61,9 @@ } | ||
if (!styleEl) { | ||
if (isDocument()) { | ||
styleEl = document.getElementById(styleId); | ||
var dom = getDocument(); | ||
if (dom) { | ||
styleEl = dom.getElementById(styleId); | ||
if (!styleEl) { | ||
styleEl = document.createElement('style'); | ||
styleEl = dom.createElement('style'); | ||
styleEl.id = styleId; | ||
document.getElementsByTagName('head')[0].appendChild(styleEl); | ||
dom.getElementsByTagName('head')[0].appendChild(styleEl); | ||
} | ||
@@ -64,13 +82,17 @@ } | ||
} | ||
function getDom() { | ||
function getStoreDom() { | ||
if (!storeEl) { | ||
if (isDocument()) { | ||
storeEl = document.getElementById(storeId); | ||
var dom = getDocument(); | ||
if (dom) { | ||
storeEl = dom.getElementById(storeId); | ||
if (!storeEl) { | ||
storeEl = document.createElement('div'); | ||
storeEl.id = storeId; | ||
storeEl.style.display = 'none'; | ||
document.body.appendChild(storeEl); | ||
setCurrent(storeData.m); | ||
setSubCurrent(storeData.s); | ||
var body = getBody(); | ||
if (body) { | ||
storeEl = dom.createElement('div'); | ||
storeEl.id = storeId; | ||
storeEl.style.display = 'none'; | ||
body.appendChild(storeEl); | ||
setCurrent(storeData.m); | ||
setSubCurrent(storeData.s); | ||
} | ||
} | ||
@@ -86,8 +108,8 @@ } | ||
storeData[key] = value; | ||
var doc = getDom(); | ||
if (doc) { | ||
if (doc.dataset) { | ||
doc.dataset[key] = value + ''; | ||
var el = getStoreDom(); | ||
if (el) { | ||
if (el.dataset) { | ||
el.dataset[key] = value + ''; | ||
} else { | ||
doc.setAttribute('data-' + key, value + ''); | ||
el.setAttribute('data-' + key, value + ''); | ||
} | ||
@@ -104,5 +126,5 @@ } | ||
var zIndex; | ||
var doc = getDom(); | ||
if (doc) { | ||
var domVal = doc.dataset ? doc.dataset[key] : doc.getAttribute('data-' + key); | ||
var el = getStoreDom(); | ||
if (el) { | ||
var domVal = el.dataset ? el.dataset[key] : el.getAttribute('data-' + key); | ||
if (domVal) { | ||
@@ -109,0 +131,0 @@ zIndex = Number(domVal); |
@@ -24,2 +24,4 @@ (function (global, factory) { | ||
_exports.setSubCurrent = _exports.setCurrent = void 0; | ||
var winDom = null; | ||
var bodyEl = null; | ||
var storeEl = null; | ||
@@ -35,15 +37,30 @@ var storeId = 'z-index-manage'; | ||
}; | ||
function isDocument() { | ||
return typeof document !== 'undefined'; | ||
function getDocument() { | ||
if (!winDom) { | ||
if (typeof document !== 'undefined') { | ||
winDom = document; | ||
} | ||
} | ||
return winDom; | ||
} | ||
function getBody() { | ||
if (winDom && !bodyEl) { | ||
bodyEl = winDom.body || winDom.getElementsByTagName('body')[0]; | ||
} | ||
return bodyEl; | ||
} | ||
function getDomMaxZIndex() { | ||
var max = 0; | ||
if (isDocument()) { | ||
var allElem = document.body.getElementsByTagName('*'); | ||
for (var i = 0; i < allElem.length; i++) { | ||
var elem = allElem[i]; | ||
if (elem && elem.style && elem.nodeType === 1) { | ||
var zIndex = elem.style.zIndex; | ||
if (zIndex && /^\d+$/.test(zIndex)) { | ||
max = Math.max(max, Number(zIndex)); | ||
var dom = getDocument(); | ||
if (dom) { | ||
var body = getBody(); | ||
if (body) { | ||
var allElem = body.getElementsByTagName('*'); | ||
for (var i = 0; i < allElem.length; i++) { | ||
var elem = allElem[i]; | ||
if (elem && elem.style && elem.nodeType === 1) { | ||
var zIndex = elem.style.zIndex; | ||
if (zIndex && /^\d+$/.test(zIndex)) { | ||
max = Math.max(max, Number(zIndex)); | ||
} | ||
} | ||
@@ -57,8 +74,9 @@ } | ||
if (!styleEl) { | ||
if (isDocument()) { | ||
styleEl = document.getElementById(styleId); | ||
var dom = getDocument(); | ||
if (dom) { | ||
styleEl = dom.getElementById(styleId); | ||
if (!styleEl) { | ||
styleEl = document.createElement('style'); | ||
styleEl = dom.createElement('style'); | ||
styleEl.id = styleId; | ||
document.getElementsByTagName('head')[0].appendChild(styleEl); | ||
dom.getElementsByTagName('head')[0].appendChild(styleEl); | ||
} | ||
@@ -77,13 +95,17 @@ } | ||
} | ||
function getDom() { | ||
function getStoreDom() { | ||
if (!storeEl) { | ||
if (isDocument()) { | ||
storeEl = document.getElementById(storeId); | ||
var dom = getDocument(); | ||
if (dom) { | ||
storeEl = dom.getElementById(storeId); | ||
if (!storeEl) { | ||
storeEl = document.createElement('div'); | ||
storeEl.id = storeId; | ||
storeEl.style.display = 'none'; | ||
document.body.appendChild(storeEl); | ||
setCurrent(storeData.m); | ||
setSubCurrent(storeData.s); | ||
var body = getBody(); | ||
if (body) { | ||
storeEl = dom.createElement('div'); | ||
storeEl.id = storeId; | ||
storeEl.style.display = 'none'; | ||
body.appendChild(storeEl); | ||
setCurrent(storeData.m); | ||
setSubCurrent(storeData.s); | ||
} | ||
} | ||
@@ -99,8 +121,8 @@ } | ||
storeData[key] = value; | ||
var doc = getDom(); | ||
if (doc) { | ||
if (doc.dataset) { | ||
doc.dataset[key] = value + ''; | ||
var el = getStoreDom(); | ||
if (el) { | ||
if (el.dataset) { | ||
el.dataset[key] = value + ''; | ||
} else { | ||
doc.setAttribute('data-' + key, value + ''); | ||
el.setAttribute('data-' + key, value + ''); | ||
} | ||
@@ -117,5 +139,5 @@ } | ||
var zIndex; | ||
var doc = getDom(); | ||
if (doc) { | ||
var domVal = doc.dataset ? doc.dataset[key] : doc.getAttribute('data-' + key); | ||
var el = getStoreDom(); | ||
if (el) { | ||
var domVal = el.dataset ? el.dataset[key] : el.getAttribute('data-' + key); | ||
if (domVal) { | ||
@@ -122,0 +144,0 @@ zIndex = Number(domVal); |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"function"==typeof define&&define.amd?define("dom-zindex",["exports"],t):"undefined"!=typeof exports?t(exports):(t(t={}),e.domZindex=t)}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,function(e){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.getCurrent=e.default=void 0,e.getNext=c,e.getSubCurrent=y,e.getSubNext=p,e.setSubCurrent=e.setCurrent=void 0;var t=null,n="z-index-manage",r=null,u="z-index-style",d={m:1e3,s:1e3};function o(){return"undefined"!=typeof document}function a(){var e,t;r||!o()||(r=document.getElementById(u))||((r=document.createElement("style")).id=u,document.getElementsByTagName("head")[0].appendChild(r)),r&&(r.innerHTML=":root{"+(e="--dom-")+"main"+(t="-z-index")+":"+l()+";"+e+"sub"+t+":"+y()+"}")}function i(){return t||!o()||(t=document.getElementById(n))||((t=document.createElement("div")).id=n,t.style.display="none",document.body.appendChild(t),f(d.m),g(d.s)),t}function s(n){return function(e){var t;return e&&(e=Number(e),d[n]=e,t=i())&&(t.dataset?t.dataset[n]=e+"":t.setAttribute("data-"+n,e+"")),a(),d[n]}}var f=e.setCurrent=s("m");function m(r,u){return function(e){var t=i(),n=(n=t&&(t=t.dataset?t.dataset[r]:t.getAttribute("data-"+r))?Number(t):n)||d[r];return e?Number(e)<n?u():e:n}}var l=e.getCurrent=m("m",c);function c(){return f(l()+1)}var g=e.setSubCurrent=s("s"),b=m("s",p);function y(){return l()+b()}function p(){return g(b()+1),y()}var v={setCurrent:f,getCurrent:l,getNext:c,setSubCurrent:g,getSubCurrent:y,getSubNext:p,getMax:function(){var e=0;if(o())for(var t=document.body.getElementsByTagName("*"),n=0;n<t.length;n++){var r=t[n];r&&r.style&&1===r.nodeType&&(r=r.style.zIndex)&&/^\d+$/.test(r)&&(e=Math.max(e,Number(r)))}return e}};a(),e.default=v}); | ||
!function(e,t){"function"==typeof define&&define.amd?define("dom-zindex",["exports"],t):"undefined"!=typeof exports?t(exports):(t(t={}),e.domZindex=t)}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,function(e){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.getCurrent=e.default=void 0,e.getNext=b,e.getSubCurrent=x,e.getSubNext=C,e.setSubCurrent=e.setCurrent=void 0;var t=null,n=null,r=null,u="z-index-manage",d=null,a="z-index-style",i={m:1e3,s:1e3};function o(){return t||"undefined"!=typeof document&&(t=document),t}function s(){return n=t&&!n?t.body||t.getElementsByTagName("body")[0]:n}function f(){var e,t;d||!(e=o())||(d=e.getElementById(a))||((d=e.createElement("style")).id=a,e.getElementsByTagName("head")[0].appendChild(d)),d&&(d.innerHTML=":root{"+(e="--dom-")+"main"+(t="-z-index")+":"+y()+";"+e+"sub"+t+":"+x()+"}")}function l(){var e,t;return r||(e=o())&&!(r=e.getElementById(u))&&(t=s())&&((r=e.createElement("div")).id=u,r.style.display="none",t.appendChild(r),g(i.m),v(i.s)),r}function m(n){return function(e){var t;return e&&(e=Number(e),i[n]=e,t=l())&&(t.dataset?t.dataset[n]=e+"":t.setAttribute("data-"+n,e+"")),f(),i[n]}}var g=e.setCurrent=m("m");function c(r,u){return function(e){var t=l(),n=(n=t&&(t=t.dataset?t.dataset[r]:t.getAttribute("data-"+r))?Number(t):n)||i[r];return e?Number(e)<n?u():e:n}}var y=e.getCurrent=c("m",b);function b(){return g(y()+1)}var v=e.setSubCurrent=m("s"),p=c("s",C);function x(){return y()+p()}function C(){return v(p()+1),x()}var N={setCurrent:g,getCurrent:y,getNext:b,setSubCurrent:v,getSubCurrent:x,getSubNext:C,getMax:function(){var e=0;if(o()){var t=s();if(t)for(var n=t.getElementsByTagName("*"),r=0;r<n.length;r++){var u=n[r];u&&u.style&&1===u.nodeType&&(u=u.style.zIndex)&&/^\d+$/.test(u)&&(e=Math.max(e,Number(u)))}}return e}};f(),e.default=N}); |
@@ -0,1 +1,3 @@ | ||
var winDom = null; | ||
var bodyEl = null; | ||
var storeEl = null; | ||
@@ -11,15 +13,30 @@ var storeId = 'z-index-manage'; | ||
}; | ||
function isDocument() { | ||
return typeof document !== 'undefined'; | ||
function getDocument() { | ||
if (!winDom) { | ||
if (typeof document !== 'undefined') { | ||
winDom = document; | ||
} | ||
} | ||
return winDom; | ||
} | ||
function getBody() { | ||
if (winDom && !bodyEl) { | ||
bodyEl = winDom.body || winDom.getElementsByTagName('body')[0]; | ||
} | ||
return bodyEl; | ||
} | ||
function getDomMaxZIndex() { | ||
var max = 0; | ||
if (isDocument()) { | ||
var allElem = document.body.getElementsByTagName('*'); | ||
for (var i = 0; i < allElem.length; i++) { | ||
var elem = allElem[i]; | ||
if (elem && elem.style && elem.nodeType === 1) { | ||
var zIndex = elem.style.zIndex; | ||
if (zIndex && /^\d+$/.test(zIndex)) { | ||
max = Math.max(max, Number(zIndex)); | ||
var dom = getDocument(); | ||
if (dom) { | ||
var body = getBody(); | ||
if (body) { | ||
var allElem = body.getElementsByTagName('*'); | ||
for (var i = 0; i < allElem.length; i++) { | ||
var elem = allElem[i]; | ||
if (elem && elem.style && elem.nodeType === 1) { | ||
var zIndex = elem.style.zIndex; | ||
if (zIndex && /^\d+$/.test(zIndex)) { | ||
max = Math.max(max, Number(zIndex)); | ||
} | ||
} | ||
@@ -33,8 +50,9 @@ } | ||
if (!styleEl) { | ||
if (isDocument()) { | ||
styleEl = document.getElementById(styleId); | ||
var dom = getDocument(); | ||
if (dom) { | ||
styleEl = dom.getElementById(styleId); | ||
if (!styleEl) { | ||
styleEl = document.createElement('style'); | ||
styleEl = dom.createElement('style'); | ||
styleEl.id = styleId; | ||
document.getElementsByTagName('head')[0].appendChild(styleEl); | ||
dom.getElementsByTagName('head')[0].appendChild(styleEl); | ||
} | ||
@@ -53,13 +71,17 @@ } | ||
} | ||
function getDom() { | ||
function getStoreDom() { | ||
if (!storeEl) { | ||
if (isDocument()) { | ||
storeEl = document.getElementById(storeId); | ||
var dom = getDocument(); | ||
if (dom) { | ||
storeEl = dom.getElementById(storeId); | ||
if (!storeEl) { | ||
storeEl = document.createElement('div'); | ||
storeEl.id = storeId; | ||
storeEl.style.display = 'none'; | ||
document.body.appendChild(storeEl); | ||
setCurrent(storeData.m); | ||
setSubCurrent(storeData.s); | ||
var body = getBody(); | ||
if (body) { | ||
storeEl = dom.createElement('div'); | ||
storeEl.id = storeId; | ||
storeEl.style.display = 'none'; | ||
body.appendChild(storeEl); | ||
setCurrent(storeData.m); | ||
setSubCurrent(storeData.s); | ||
} | ||
} | ||
@@ -75,9 +97,9 @@ } | ||
storeData[key] = value; | ||
var doc = getDom(); | ||
if (doc) { | ||
if (doc.dataset) { | ||
doc.dataset[key] = value + ''; | ||
var el = getStoreDom(); | ||
if (el) { | ||
if (el.dataset) { | ||
el.dataset[key] = value + ''; | ||
} | ||
else { | ||
doc.setAttribute('data-' + key, value + ''); | ||
el.setAttribute('data-' + key, value + ''); | ||
} | ||
@@ -94,5 +116,5 @@ } | ||
var zIndex; | ||
var doc = getDom(); | ||
if (doc) { | ||
var domVal = doc.dataset ? doc.dataset[key] : doc.getAttribute('data-' + key); | ||
var el = getStoreDom(); | ||
if (el) { | ||
var domVal = el.dataset ? el.dataset[key] : el.getAttribute('data-' + key); | ||
if (domVal) { | ||
@@ -99,0 +121,0 @@ zIndex = Number(domVal); |
{ | ||
"name": "dom-zindex", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "Web common z-index style management", | ||
@@ -5,0 +5,0 @@ "files": [ |
@@ -73,7 +73,6 @@ # z-index Manager | ||
Using css variables. | ||
* Built-in following variables | ||
* ```--dom-main-z-index``` 等于 ```getCurrent```() | ||
* ```--dom-sub-z-index``` 等于 ```getSubCurrent```() | ||
* ```--dom-main-z-index``` be equivalent to ```getCurrent()``` | ||
* ```--dom-sub-z-index``` be equivalent to ```getSubCurrent()``` | ||
```css | ||
@@ -80,0 +79,0 @@ .my-popup { |
@@ -71,4 +71,19 @@ # z-index 管理器 | ||
## 使用 CSS 变量 | ||
* 内置以下变量 | ||
* ```--dom-main-z-index``` 等于 ```getCurrent```() | ||
* ```--dom-sub-z-index``` 等于 ```getSubCurrent```() | ||
```css | ||
.my-popup { | ||
z-index: var(--dom-main-z-index); | ||
} | ||
.my-msg { | ||
z-index: var(--dom-sub-z-index); | ||
} | ||
``` | ||
## License | ||
[MIT](LICENSE) © 2019-present, Xu Liangzhan |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25173
536
95