Last change
on this file since 59329aa was 59329aa, checked in by Ema <ema_spirova@…>, 3 years ago |
adding photos
|
-
Property mode
set to
100644
|
File size:
4.8 KB
|
Line | |
---|
1 | function ZIndexUtils() {
|
---|
2 | let zIndexes = [];
|
---|
3 | const generateZIndex = (key, baseZIndex) => {
|
---|
4 | let lastZIndex = zIndexes.length > 0 ? zIndexes[zIndexes.length - 1] : { key, value: baseZIndex };
|
---|
5 | let newZIndex = lastZIndex.value + (lastZIndex.key === key ? 0 : baseZIndex) + 1;
|
---|
6 | zIndexes.push({ key, value: newZIndex });
|
---|
7 | return newZIndex;
|
---|
8 | };
|
---|
9 | const revertZIndex = (zIndex) => {
|
---|
10 | zIndexes = zIndexes.filter(obj => obj.value !== zIndex);
|
---|
11 | };
|
---|
12 | const getCurrentZIndex = () => {
|
---|
13 | return zIndexes.length > 0 ? zIndexes[zIndexes.length - 1].value : 0;
|
---|
14 | };
|
---|
15 | const getZIndex = (el) => {
|
---|
16 | return el ? parseInt(el.style.zIndex, 10) || 0 : 0;
|
---|
17 | };
|
---|
18 | return {
|
---|
19 | get: getZIndex,
|
---|
20 | set: (key, el, baseZIndex) => {
|
---|
21 | if (el) {
|
---|
22 | el.style.zIndex = String(generateZIndex(key, baseZIndex));
|
---|
23 | }
|
---|
24 | },
|
---|
25 | clear: (el) => {
|
---|
26 | if (el) {
|
---|
27 | revertZIndex(getZIndex(el));
|
---|
28 | el.style.zIndex = '';
|
---|
29 | }
|
---|
30 | },
|
---|
31 | getCurrent: () => getCurrentZIndex()
|
---|
32 | };
|
---|
33 | }
|
---|
34 | export default ZIndexUtils();
|
---|
35 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiemluZGV4dXRpbHMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvYXBwL2NvbXBvbmVudHMvdXRpbHMvemluZGV4dXRpbHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ik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gICAgICAgIH0sXG4gICAgICAgIGNsZWFyOiAoZWwpID0+IHtcbiAgICAgICAgICAgIGlmIChlbCkge1xuICAgICAgICAgICAgICAgIHJldmVydFpJbmRleChnZXRaSW5kZXgoZWwpKTtcbiAgICAgICAgICAgICAgICBlbC5zdHlsZS56SW5kZXggPSAnJztcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSxcbiAgICAgICAgZ2V0Q3VycmVudDogKCkgPT4gZ2V0Q3VycmVudFpJbmRleCgpXG4gICAgfTtcbn1cblxuZXhwb3J0IGRlZmF1bHQgWkluZGV4VXRpbHMoKTtcbiJdfQ== |
---|
Note:
See
TracBrowser
for help on using the repository browser.