dom-zindex
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -13,2 +13,4 @@ "use strict"; | ||
var storeId = 'z-index-manage'; | ||
var styleEl = null; | ||
var styleId = 'z-index-style'; | ||
var storeMainKey = 'm'; | ||
@@ -39,2 +41,23 @@ var storeSubKey = 's'; | ||
} | ||
function getStyle() { | ||
if (!styleEl) { | ||
if (isDocument()) { | ||
styleEl = document.getElementById(styleId); | ||
if (!styleEl) { | ||
styleEl = document.createElement('style'); | ||
styleEl.id = styleId; | ||
document.getElementsByTagName('head')[0].appendChild(styleEl); | ||
} | ||
} | ||
} | ||
return styleEl; | ||
} | ||
function updateVar() { | ||
var styEl = getStyle(); | ||
if (styEl) { | ||
var prefixes = '--dom-'; | ||
var propKey = '-z-index'; | ||
styEl.innerHTML = ':root{' + prefixes + 'main' + propKey + ':' + getCurrent() + ';' + prefixes + 'sub' + propKey + ':' + getSubCurrent() + '}'; | ||
} | ||
} | ||
function getDom() { | ||
@@ -70,2 +93,3 @@ if (!storeEl) { | ||
} | ||
updateVar(); | ||
return storeData[key]; | ||
@@ -122,2 +146,3 @@ }; | ||
}; | ||
updateVar(); | ||
var _default = exports["default"] = DomZIndex; |
@@ -26,2 +26,4 @@ (function (global, factory) { | ||
var storeId = 'z-index-manage'; | ||
var styleEl = null; | ||
var styleId = 'z-index-style'; | ||
var storeMainKey = 'm'; | ||
@@ -52,2 +54,23 @@ var storeSubKey = 's'; | ||
} | ||
function getStyle() { | ||
if (!styleEl) { | ||
if (isDocument()) { | ||
styleEl = document.getElementById(styleId); | ||
if (!styleEl) { | ||
styleEl = document.createElement('style'); | ||
styleEl.id = styleId; | ||
document.getElementsByTagName('head')[0].appendChild(styleEl); | ||
} | ||
} | ||
} | ||
return styleEl; | ||
} | ||
function updateVar() { | ||
var styEl = getStyle(); | ||
if (styEl) { | ||
var prefixes = '--dom-'; | ||
var propKey = '-z-index'; | ||
styEl.innerHTML = ':root{' + prefixes + 'main' + propKey + ':' + getCurrent() + ';' + prefixes + 'sub' + propKey + ':' + getSubCurrent() + '}'; | ||
} | ||
} | ||
function getDom() { | ||
@@ -83,2 +106,3 @@ if (!storeEl) { | ||
} | ||
updateVar(); | ||
return storeData[key]; | ||
@@ -135,3 +159,4 @@ }; | ||
}; | ||
updateVar(); | ||
var _default = _exports["default"] = DomZIndex; | ||
}); |
@@ -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=s,e.getSubCurrent=l,e.getSubNext=b,e.setSubCurrent=e.setCurrent=void 0;var t=null,n="z-index-manage",d={m:1e3,s:1e3};function u(){return"undefined"!=typeof document}function o(){return t||!u()||(t=document.getElementById(n))||((t=document.createElement("div")).id=n,t.style.display="none",document.body.appendChild(t),a(d.m),m(d.s)),t}function r(n){return function(e){var t;return e&&(e=Number(e),d[n]=e,t=o())&&(t.dataset?t.dataset[n]=e+"":t.setAttribute("data-"+n,e+"")),d[n]}}var a=e.setCurrent=r("m");function i(r,u){return function(e){var t=o(),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 f=e.getCurrent=i("m",s);function s(){return a(f()+1)}var m=e.setSubCurrent=r("s"),c=i("s",b);function l(){return f()+c()}function b(){return m(c()+1),l()}e.default={setCurrent:a,getCurrent:f,getNext:s,setSubCurrent:m,getSubCurrent:l,getSubNext:b,getMax:function(){var e=0;if(u())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}}}); | ||
!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}); |
var storeEl = null; | ||
var storeId = 'z-index-manage'; | ||
var styleEl = null; | ||
var styleId = 'z-index-style'; | ||
var storeMainKey = 'm'; | ||
@@ -28,2 +30,23 @@ var storeSubKey = 's'; | ||
} | ||
function getStyle() { | ||
if (!styleEl) { | ||
if (isDocument()) { | ||
styleEl = document.getElementById(styleId); | ||
if (!styleEl) { | ||
styleEl = document.createElement('style'); | ||
styleEl.id = styleId; | ||
document.getElementsByTagName('head')[0].appendChild(styleEl); | ||
} | ||
} | ||
} | ||
return styleEl; | ||
} | ||
function updateVar() { | ||
var styEl = getStyle(); | ||
if (styEl) { | ||
var prefixes = '--dom-'; | ||
var propKey = '-z-index'; | ||
styEl.innerHTML = ':root{' + prefixes + 'main' + propKey + ':' + getCurrent() + ';' + prefixes + 'sub' + propKey + ':' + getSubCurrent() + '}'; | ||
} | ||
} | ||
function getDom() { | ||
@@ -60,2 +83,3 @@ if (!storeEl) { | ||
} | ||
updateVar(); | ||
return storeData[key]; | ||
@@ -112,2 +136,3 @@ }; | ||
}; | ||
updateVar(); | ||
export default DomZIndex; |
{ | ||
"name": "dom-zindex", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "Web common z-index style management", | ||
@@ -5,0 +5,0 @@ "files": [ |
@@ -71,2 +71,18 @@ # z-index Manager | ||
## Css var | ||
Using css variables. | ||
* ```--dom-main-z-index``` be equivalent to ```getCurrent()``` | ||
* ```--dom-sub-z-index``` be equivalent to ```getSubCurrent()``` | ||
```css | ||
.my-popup { | ||
z-index: var(--dom-main-z-index); | ||
} | ||
.my-msg { | ||
z-index: var(--dom-sub-z-index); | ||
} | ||
``` | ||
## Contributors | ||
@@ -73,0 +89,0 @@ |
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
23440
470
96