dom-zindex
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -19,5 +19,24 @@ "use strict"; | ||
}; | ||
function isDocument() { | ||
return typeof document !== 'undefined'; | ||
} | ||
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)); | ||
} | ||
} | ||
} | ||
} | ||
return max; | ||
} | ||
function getDom() { | ||
if (!storeEl) { | ||
if (typeof document !== 'undefined') { | ||
if (isDocument()) { | ||
storeEl = document.getElementById(storeId); | ||
@@ -53,4 +72,3 @@ if (!storeEl) { | ||
} | ||
var setCurrent = createSetHandle(storeMainKey); | ||
exports.setCurrent = setCurrent; | ||
var setCurrent = exports.setCurrent = createSetHandle(storeMainKey); | ||
function createGetHandle(key, nextMethod) { | ||
@@ -78,9 +96,7 @@ return function getCurrent(currZindex) { | ||
} | ||
var getCurrent = createGetHandle(storeMainKey, getNext); | ||
exports.getCurrent = getCurrent; | ||
var getCurrent = exports.getCurrent = createGetHandle(storeMainKey, getNext); | ||
function getNext() { | ||
return setCurrent(getCurrent() + 1); | ||
} | ||
var setSubCurrent = createSetHandle(storeSubKey); | ||
exports.setSubCurrent = setSubCurrent; | ||
var setSubCurrent = exports.setSubCurrent = createSetHandle(storeSubKey); | ||
var _getSubCurrent = createGetHandle(storeSubKey, getSubNext); | ||
@@ -103,5 +119,5 @@ function getSubCurrent() { | ||
getSubCurrent: getSubCurrent, | ||
getSubNext: getSubNext | ||
getSubNext: getSubNext, | ||
getMax: getDomMaxZIndex | ||
}; | ||
var _default = DomZIndex; | ||
exports["default"] = _default; | ||
var _default = exports["default"] = DomZIndex; |
@@ -32,5 +32,24 @@ (function (global, factory) { | ||
}; | ||
function isDocument() { | ||
return typeof document !== 'undefined'; | ||
} | ||
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)); | ||
} | ||
} | ||
} | ||
} | ||
return max; | ||
} | ||
function getDom() { | ||
if (!storeEl) { | ||
if (typeof document !== 'undefined') { | ||
if (isDocument()) { | ||
storeEl = document.getElementById(storeId); | ||
@@ -66,4 +85,3 @@ if (!storeEl) { | ||
} | ||
var setCurrent = createSetHandle(storeMainKey); | ||
_exports.setCurrent = setCurrent; | ||
var setCurrent = _exports.setCurrent = createSetHandle(storeMainKey); | ||
function createGetHandle(key, nextMethod) { | ||
@@ -91,9 +109,7 @@ return function getCurrent(currZindex) { | ||
} | ||
var getCurrent = createGetHandle(storeMainKey, getNext); | ||
_exports.getCurrent = getCurrent; | ||
var getCurrent = _exports.getCurrent = createGetHandle(storeMainKey, getNext); | ||
function getNext() { | ||
return setCurrent(getCurrent() + 1); | ||
} | ||
var setSubCurrent = createSetHandle(storeSubKey); | ||
_exports.setSubCurrent = setSubCurrent; | ||
var setSubCurrent = _exports.setSubCurrent = createSetHandle(storeSubKey); | ||
var _getSubCurrent = createGetHandle(storeSubKey, getSubNext); | ||
@@ -116,6 +132,6 @@ function getSubCurrent() { | ||
getSubCurrent: getSubCurrent, | ||
getSubNext: getSubNext | ||
getSubNext: getSubNext, | ||
getMax: getDomMaxZIndex | ||
}; | ||
var _default = DomZIndex; | ||
_exports["default"] = _default; | ||
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=f,e.getSubCurrent=l,e.getSubNext=m,e.setSubCurrent=e.setCurrent=void 0;var t=null,n="z-index-manage",d={m:1e3,s:1e3};function i(){return t||"undefined"==typeof document||(t=document.getElementById(n))||((t=document.createElement("div")).id=n,t.style.display="none",document.body.appendChild(t),u(d.m),s(d.s)),t}function r(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+"")),d[n]}}var u=r("m");function o(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}}e.setCurrent=u;var a=o("m",f);function f(){return u(a()+1)}e.getCurrent=a;var s=r("s"),c=(e.setSubCurrent=s,o("s",m));function l(){return a()+c()}function m(){return s(c()+1),l()}e.default={setCurrent:u,getCurrent:a,getNext:f,setSubCurrent:s,getSubCurrent:l,getSubNext:m}}); | ||
!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}}}); |
@@ -9,5 +9,24 @@ var storeEl = null; | ||
}; | ||
function isDocument() { | ||
return typeof document !== 'undefined'; | ||
} | ||
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)); | ||
} | ||
} | ||
} | ||
} | ||
return max; | ||
} | ||
function getDom() { | ||
if (!storeEl) { | ||
if (typeof document !== 'undefined') { | ||
if (isDocument()) { | ||
storeEl = document.getElementById(storeId); | ||
@@ -89,4 +108,5 @@ if (!storeEl) { | ||
getSubCurrent: getSubCurrent, | ||
getSubNext: getSubNext | ||
getSubNext: getSubNext, | ||
getMax: getDomMaxZIndex | ||
}; | ||
export default DomZIndex; |
{ | ||
"name": "dom-zindex", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Web common z-index style management", | ||
@@ -5,0 +5,0 @@ "files": [ |
@@ -38,9 +38,12 @@ # z-index Manager | ||
// Set main current z-index | ||
// Gets the largest z-index on the page. | ||
domZindex.getMax() | ||
// Set main current z-index. | ||
domZindex.setCurrent(1000) | ||
// Get main current z-index | ||
// Get main current z-index. | ||
domZindex.getCurrent() // 1000 | ||
// Get main next z-index | ||
// Get main next z-index. | ||
domZindex.getNext() // 1001 | ||
@@ -51,3 +54,3 @@ | ||
// Get subordinate next z-index | ||
// Get subordinate next z-index. | ||
domZindex.getSubNext() // 2002 | ||
@@ -54,0 +57,0 @@ ``` |
@@ -38,2 +38,5 @@ # z-index 管理器 | ||
// 获取页面中最大的 z-index | ||
domZindex.getMax() | ||
// 设置当前 z-index | ||
@@ -40,0 +43,0 @@ domZindex.setCurrent(1000) |
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
20358
392
74