dom-zindex
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -54,16 +54,25 @@ "use strict"; | ||
exports.setCurrent = setCurrent; | ||
function createGetHandle(key) { | ||
return function getCurrent() { | ||
function createGetHandle(key, nextMethod) { | ||
return function getCurrent(currZindex) { | ||
var zIndex; | ||
var doc = getDom(); | ||
if (doc) { | ||
zIndex = doc.dataset ? doc.dataset[key] : doc.getAttribute('data-' + key); | ||
var domVal = doc.dataset ? doc.dataset[key] : doc.getAttribute('data-' + key); | ||
if (domVal) { | ||
zIndex = Number(domVal); | ||
} | ||
} | ||
if (zIndex) { | ||
return Number(zIndex); | ||
if (!zIndex) { | ||
zIndex = storeData[key]; | ||
} | ||
return storeData[key]; | ||
if (currZindex) { | ||
if (Number(currZindex) < zIndex) { | ||
return nextMethod(); | ||
} | ||
return currZindex; | ||
} | ||
return zIndex; | ||
}; | ||
} | ||
var getCurrent = createGetHandle(storeMainKey); | ||
var getCurrent = createGetHandle(storeMainKey, getNext); | ||
exports.getCurrent = getCurrent; | ||
@@ -75,3 +84,3 @@ function getNext() { | ||
exports.setSubCurrent = setSubCurrent; | ||
var _getSubCurrent = createGetHandle(storeSubKey); | ||
var _getSubCurrent = createGetHandle(storeSubKey, getSubNext); | ||
function getSubCurrent() { | ||
@@ -78,0 +87,0 @@ return getCurrent() + _getSubCurrent(); |
@@ -67,16 +67,25 @@ (function (global, factory) { | ||
_exports.setCurrent = setCurrent; | ||
function createGetHandle(key) { | ||
return function getCurrent() { | ||
function createGetHandle(key, nextMethod) { | ||
return function getCurrent(currZindex) { | ||
var zIndex; | ||
var doc = getDom(); | ||
if (doc) { | ||
zIndex = doc.dataset ? doc.dataset[key] : doc.getAttribute('data-' + key); | ||
var domVal = doc.dataset ? doc.dataset[key] : doc.getAttribute('data-' + key); | ||
if (domVal) { | ||
zIndex = Number(domVal); | ||
} | ||
} | ||
if (zIndex) { | ||
return Number(zIndex); | ||
if (!zIndex) { | ||
zIndex = storeData[key]; | ||
} | ||
return storeData[key]; | ||
if (currZindex) { | ||
if (Number(currZindex) < zIndex) { | ||
return nextMethod(); | ||
} | ||
return currZindex; | ||
} | ||
return zIndex; | ||
}; | ||
} | ||
var getCurrent = createGetHandle(storeMainKey); | ||
var getCurrent = createGetHandle(storeMainKey, getNext); | ||
_exports.getCurrent = getCurrent; | ||
@@ -88,3 +97,3 @@ function getNext() { | ||
_exports.setSubCurrent = setSubCurrent; | ||
var _getSubCurrent = createGetHandle(storeSubKey); | ||
var _getSubCurrent = createGetHandle(storeSubKey, getSubNext); | ||
function getSubCurrent() { | ||
@@ -91,0 +100,0 @@ return getCurrent() + _getSubCurrent(); |
@@ -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",r={m:1e3,s:1e3};function u(){return t||"undefined"==typeof document||(t=document.getElementById(n))||((t=document.createElement("div")).id=n,t.style.display="none",document.body.appendChild(t),i(r.m),s(r.s)),t}function d(n){return function(e){var t;return e&&(e=Number(e),r[n]=e,t=u())&&(t.dataset?t.dataset[n]=e+"":t.setAttribute("data-"+n,e+"")),r[n]}}var i=d("m");function o(n){return function(){var e,t=u();return(e=t?t.dataset?t.dataset[n]:t.getAttribute("data-"+n):e)?Number(e):r[n]}}e.setCurrent=i;var a=o("m");function f(){return i(a()+1)}e.getCurrent=a;var s=d("s"),c=(e.setSubCurrent=s,o("s"));function l(){return a()+c()}function m(){return s(c()+1),l()}e.default={setCurrent:i,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=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}}); |
@@ -44,16 +44,25 @@ var storeEl = null; | ||
export var setCurrent = createSetHandle(storeMainKey); | ||
function createGetHandle(key) { | ||
return function getCurrent() { | ||
function createGetHandle(key, nextMethod) { | ||
return function getCurrent(currZindex) { | ||
var zIndex; | ||
var doc = getDom(); | ||
if (doc) { | ||
zIndex = doc.dataset ? doc.dataset[key] : doc.getAttribute('data-' + key); | ||
var domVal = doc.dataset ? doc.dataset[key] : doc.getAttribute('data-' + key); | ||
if (domVal) { | ||
zIndex = Number(domVal); | ||
} | ||
} | ||
if (zIndex) { | ||
return Number(zIndex); | ||
if (!zIndex) { | ||
zIndex = storeData[key]; | ||
} | ||
return storeData[key]; | ||
if (currZindex) { | ||
if (Number(currZindex) < zIndex) { | ||
return nextMethod(); | ||
} | ||
return currZindex; | ||
} | ||
return zIndex; | ||
}; | ||
} | ||
export var getCurrent = createGetHandle(storeMainKey); | ||
export var getCurrent = createGetHandle(storeMainKey, getNext); | ||
export function getNext() { | ||
@@ -63,3 +72,3 @@ return setCurrent(getCurrent() + 1); | ||
export var setSubCurrent = createSetHandle(storeSubKey); | ||
var _getSubCurrent = createGetHandle(storeSubKey); | ||
var _getSubCurrent = createGetHandle(storeSubKey, getSubNext); | ||
export function getSubCurrent() { | ||
@@ -66,0 +75,0 @@ return getCurrent() + _getSubCurrent(); |
{ | ||
"name": "dom-zindex", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Web common z-index style management", | ||
@@ -5,0 +5,0 @@ "files": [ |
@@ -33,3 +33,3 @@ # z-index Manager | ||
## Example | ||
## Example 1 | ||
@@ -39,2 +39,5 @@ ```javascript | ||
// Set main current z-index | ||
domZindex.setCurrent(1000) | ||
// Get main current z-index | ||
@@ -53,4 +56,18 @@ domZindex.getCurrent() // 1000 | ||
## Example 2 | ||
```javascript | ||
import domZindex from 'dom-zindex' | ||
// If the incoming z-index is less than global, the next one is automatically fetched. | ||
let currZindex1 = 888 | ||
currZindex1 = domZindex.getCurrent(currZindex1) // 1000 | ||
// If the z-index is greater than the global value, the value is returned. | ||
let currZindex2 = 2000 | ||
currZindex2 = domZindex.getCurrent(currZindex2) // 1500 | ||
``` | ||
## License | ||
[MIT](LICENSE) © 2019-present, Xu Liangzhan |
@@ -33,3 +33,3 @@ # z-index 管理器 | ||
## Example | ||
## 示例 1 | ||
@@ -39,2 +39,5 @@ ```javascript | ||
// 设置当前 z-index | ||
domZindex.setCurrent(1000) | ||
// 获取当前 z-index | ||
@@ -53,4 +56,18 @@ domZindex.getCurrent() // 1000 | ||
## 示例 2 | ||
```javascript | ||
import domZindex from 'dom-zindex' | ||
// 如果传入 z-index 小于全局,则自动获取下一个 | ||
let currZindex1 = 999 | ||
currZindex1 = domZindex.getCurrent(currZindex1) // 1000 | ||
// 如果传入 z-index 大于全局,则返回传入值 | ||
let currZindex2 = 1500 | ||
currZindex2 = domZindex.getCurrent(currZindex2) // 1500 | ||
``` | ||
## 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
18463
340
71