Skip to content

Commit 7c1fcdb

Browse files
committed
add test case for zmgr
1 parent 2368930 commit 7c1fcdb

File tree

13 files changed

+370
-38
lines changed

13 files changed

+370
-38
lines changed

web/.view/index.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ pug_mixins["css"]("/assets/lib/ldloader/dev/ldld.css");
124124
;pug_debug_line = 11;pug_debug_filename = "src\u002Fpug\u002Findex.pug";
125125
pug_html = pug_html + "\u003Cstyle type=\"text\u002Fcss\"\u003E";
126126
;pug_debug_line = 11;pug_debug_filename = "src\u002Fpug\u002Findex.pug";
127-
pug_html = pug_html + ".btn-test {\n width: 300px;\n height: 300px;\n background: #ccc;\n margin: auto;\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n}\n.btn-test:hover {\n background: #f00;\n}\n\u003C\u002Fstyle\u003E\u003C\u002Fhead\u003E";
127+
pug_html = pug_html + ".btn-test {\n width: 100px;\n height: 100px;\n background: #ccc;\n margin: auto;\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n}\n.btn-test:hover {\n background: #f00;\n}\n#content {\n width: 100%;\n height: 3em;\n background: #e1e2e3;\n margin: 0.5em 0;\n position: relative;\n}\n#content div {\n position: absolute;\n top: 0;\n left: 0;\n height: 100%;\n opacity: 0;\n transition: all 0.35s linear;\n}\n#content div.running {\n opacity: 1;\n}\n.ldld-1 {\n width: 100%;\n background: #f00;\n}\n.ldld-2 {\n width: 80%;\n background: #f90;\n}\n.ldld-3 {\n width: 60%;\n background: #ff0;\n}\n.ldld-4 {\n width: 40%;\n background: #9f0;\n}\n\u003C\u002Fstyle\u003E\u003C\u002Fhead\u003E";
128128
;pug_debug_line = 12;pug_debug_filename = "src\u002Fpug\u002Findex.pug";
129129
pug_html = pug_html + "\u003Cbody\u003E";
130130
;pug_debug_line = 13;pug_debug_filename = "src\u002Fpug\u002Findex.pug";
@@ -202,15 +202,21 @@ pug_html = pug_html + "All 3 ";
202202
;pug_debug_line = 33;pug_debug_filename = "src\u002Fpug\u002Findex.pug";
203203
pug_html = pug_html + "\u003Cdiv class=\"ld ld-ring ld-spin\"\u003E\u003C\u002Fdiv\u003E";
204204
;pug_debug_line = 33;pug_debug_filename = "src\u002Fpug\u002Findex.pug";
205-
pug_html = pug_html + "\u003C\u002Fdiv\u003E\u003C\u002Fdiv\u003E";
206-
;pug_debug_line = 35;pug_debug_filename = "src\u002Fpug\u002Findex.pug";
207-
pug_mixins["script"]("/assets/lib/ldcover/main/ldcv.min.js");
205+
pug_html = pug_html + "\u003C\u002Fdiv\u003E";
206+
;pug_debug_line = 34;pug_debug_filename = "src\u002Fpug\u002Findex.pug";
207+
pug_html = pug_html + "\u003Cdiv id=\"content\"\u003E\u003C\u002Fdiv\u003E\u003C\u002Fdiv\u003E";
208208
;pug_debug_line = 36;pug_debug_filename = "src\u002Fpug\u002Findex.pug";
209-
pug_mixins["script"]("/assets/lib/ldloader/dev/ldld.js");
209+
pug_mixins["script"]("/assets/lib/@loadingio/debounce.js/main/debounce.min.js");
210210
;pug_debug_line = 37;pug_debug_filename = "src\u002Fpug\u002Findex.pug";
211+
pug_mixins["script"]("/assets/lib/ldcover/main/ldcv.min.js");
212+
;pug_debug_line = 38;pug_debug_filename = "src\u002Fpug\u002Findex.pug";
213+
pug_mixins["script"]("/assets/lib/zmgr/main/index.min.js");
214+
;pug_debug_line = 39;pug_debug_filename = "src\u002Fpug\u002Findex.pug";
215+
pug_mixins["script"]("/assets/lib/ldloader/dev/ldld.js");
216+
;pug_debug_line = 40;pug_debug_filename = "src\u002Fpug\u002Findex.pug";
211217
pug_html = pug_html + "\u003Cscript\u003E";
212-
;pug_debug_line = 37;pug_debug_filename = "src\u002Fpug\u002Findex.pug";
213-
pug_html = pug_html + "var ldld, show, btnTest, f;\nldld = {};\n['full', 'default', 'btn'].map(function(it){\n return ldld[it] = new ldLoader({\n root: \".test.\" + it\n });\n});\nldld.ctrl = new ldLoader({\n root: \".test.ctrl\",\n ctrl: {\n step: function(t){\n return this.innerText = Math.round(t \u002F 100) \u002F 10 + \"s passed.\";\n },\n done: function(t){\n return this.innerText = \"Finished.\";\n }\n }\n});\nldld.all = new ldLoader({\n root: Array.from(document.querySelectorAll(\".all\"))\n});\nshow = function(name){\n ldld[name].on();\n return ldld[name].off(2000);\n};\nbtnTest = document.querySelector('.btn-test');\nf = function(t){\n var x;\n requestAnimationFrame(f);\n x = Math.round(Math.sin(t * 0.001) * 300);\n return btnTest.style.left = x + \"px\";\n};\nrequestAnimationFrame(f);\u003C\u002Fscript\u003E\u003C\u002Fbody\u003E\u003C\u002Fhtml\u003E";
218+
;pug_debug_line = 40;pug_debug_filename = "src\u002Fpug\u002Findex.pug";
219+
pug_html = pug_html + "var ldld, show, btnTest, f, zmgr, content, ldldZ;\nldld = {};\n['full', 'default', 'btn'].map(function(it){\n return ldld[it] = new ldloader({\n root: \".test.\" + it\n });\n});\nldld.ctrl = new ldloader({\n root: \".test.ctrl\",\n ctrl: {\n step: function(t){\n return this.innerText = Math.round(t \u002F 100) \u002F 10 + \"s passed.\";\n },\n done: function(t){\n return this.innerText = \"Finished.\";\n }\n }\n});\nldld.all = new ldLoader({\n root: Array.from(document.querySelectorAll(\".all\"))\n});\nshow = function(name){\n ldld[name].on();\n return ldld[name].off(2000);\n};\nbtnTest = document.querySelector('.btn-test');\nf = function(t){\n var x;\n requestAnimationFrame(f);\n x = Math.round(Math.sin(t * 0.001) * 300);\n return btnTest.style.left = x + \"px\";\n};\nrequestAnimationFrame(f);\nzmgr = new zmgr();\ncontent = document.querySelectorAll('#content');\nldldZ = [\n new ldloader({\n container: content,\n className: 'ldld ldld-4',\n zmgr: zmgr,\n autoZ: true\n }), new ldloader({\n container: content,\n className: 'ldld ldld-3',\n zmgr: zmgr,\n autoZ: true\n }), new ldloader({\n container: content,\n className: 'ldld ldld-2',\n zmgr: zmgr,\n autoZ: true\n }), new ldloader({\n container: content,\n className: 'ldld ldld-1',\n zmgr: zmgr,\n autoZ: true\n })\n];\ndebounce(1000).then(function(){\n return ldldZ[3].on().then(function(){\n return debounce(1000);\n });\n}).then(function(){\n return ldldZ[2].on().then(function(){\n return debounce(1000);\n });\n}).then(function(){\n return ldldZ[1].on().then(function(){\n return debounce(1000);\n });\n}).then(function(){\n return ldldZ[0].on().then(function(){\n return debounce(1000);\n });\n}).then(function(){\n return ldldZ[3].off().then(function(){\n return debounce(1000);\n });\n}).then(function(){\n return ldldZ[2].off().then(function(){\n return debounce(1000);\n });\n}).then(function(){\n return ldldZ[1].off().then(function(){\n return debounce(1000);\n });\n}).then(function(){\n return ldldZ[0].off().then(function(){\n return debounce(1000);\n });\n});\u003C\u002Fscript\u003E\u003C\u002Fbody\u003E\u003C\u002Fhtml\u003E";
214220
}.call(this, "JSON" in locals_for_with ?
215221
locals_for_with.JSON :
216222
typeof JSON !== 'undefined' ? JSON : undefined, "b64img" in locals_for_with ?

web/src/pug/index.ls

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
ldld = {}
22
<[full default btn]>.map ->
3-
ldld[it] = new ldLoader root: ".test.#it"
4-
ldld.ctrl = new ldLoader root: ".test.ctrl", ctrl: do
3+
ldld[it] = new ldloader root: ".test.#it"
4+
ldld.ctrl = new ldloader root: ".test.ctrl", ctrl: do
55
step: (t) -> @innerText = "#{Math.round(t/100)/10}s passed."
66
done: (t) -> @innerText = "Finished."
77

@@ -16,3 +16,21 @@ f = (t) ->
1616
btn-test.style.left = "#{x}px"
1717

1818
requestAnimationFrame f
19+
20+
zmgr = new zmgr!
21+
content = document.querySelectorAll(\#content)
22+
ldld-z = [
23+
new ldloader container: content, class-name: 'ldld ldld-4', zmgr: zmgr, auto-z: true
24+
new ldloader container: content, class-name: 'ldld ldld-3', zmgr: zmgr, auto-z: true
25+
new ldloader container: content, class-name: 'ldld ldld-2', zmgr: zmgr, auto-z: true
26+
new ldloader container: content, class-name: 'ldld ldld-1', zmgr: zmgr, auto-z: true
27+
]
28+
debounce 1000
29+
.then -> ldld-z.3.on! .then -> debounce 1000
30+
.then -> ldld-z.2.on! .then -> debounce 1000
31+
.then -> ldld-z.1.on! .then -> debounce 1000
32+
.then -> ldld-z.0.on! .then -> debounce 1000
33+
.then -> ldld-z.3.off! .then -> debounce 1000
34+
.then -> ldld-z.2.off! .then -> debounce 1000
35+
.then -> ldld-z.1.off! .then -> debounce 1000
36+
.then -> ldld-z.0.off! .then -> debounce 1000

web/src/pug/index.pug

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ html
3131
.btn.btn-outline-secondary.mr-2.all.ld-ext-right All 1 #[.ld.ld-ring.ld-spin]
3232
.btn.btn-outline-secondary.mr-2.all.ld-ext-left All 2 #[.ld.ld-ring.ld-spin]
3333
.btn.btn-outline-secondary.mr-2.all.ld-ext-top All 3 #[.ld.ld-ring.ld-spin]
34+
#content
3435

36+
+script("/assets/lib/@loadingio/debounce.js/main/debounce.min.js")
3537
+script("/assets/lib/ldcover/main/ldcv.min.js")
38+
+script("/assets/lib/zmgr/main/index.min.js")
3639
+script("/assets/lib/ldloader/dev/ldld.js")
3740
script: include:lsc index.ls

web/src/pug/index.styl

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.btn-test
2-
width: 300px
3-
height: 300px
2+
width: 100px
3+
height: 100px
44
background: #ccc
55
margin: auto
66
position: absolute
@@ -11,3 +11,37 @@
1111
&:hover
1212
background: #f00
1313

14+
#content
15+
width: 100%
16+
height: 3em
17+
background: #e1e2e3
18+
margin: .5em 0
19+
position: relative
20+
div
21+
position: absolute
22+
top: 0
23+
left: 0
24+
height: 100%
25+
opacity: 0
26+
transition: all .35s linear
27+
div.running
28+
opacity: 1
29+
30+
31+
.ldld-1
32+
width: 100%
33+
background: #f00
34+
35+
.ldld-2
36+
width: 80%
37+
background: #f90
38+
39+
.ldld-3
40+
width: 60%
41+
background: #ff0
42+
43+
.ldld-4
44+
width: 40%
45+
background: #9f0
46+
47+

web/static/assets/lib/@loadingio/debounce.js/0.0.1/debounce.js

Lines changed: 87 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/static/assets/lib/@loadingio/debounce.js/0.0.1/debounce.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.0.1

web/static/assets/lib/ldloader/dev/ldld.js

Lines changed: 56 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,18 @@
1010
className: '',
1111
atomic: true
1212
}, opt);
13+
if (opt.zmgr) {
14+
this.zmgr(opt.zmgr);
15+
}
1316
['root', 'container'].map(function(n){
17+
var list;
1418
if (opt[n]) {
15-
return this$[n] = (Array.isArray(opt[n])
19+
list = Array.isArray(opt[n])
1620
? opt[n]
17-
: [opt[n]]).map(function(it){
21+
: opt[n] instanceof NodeList
22+
? Array.from(opt[n])
23+
: [opt[n]];
24+
return this$[n] = list.map(function(it){
1825
var ret;
1926
ret = typeof it === 'string' ? document.querySelector(it) : it;
2027
if (!ret) {
@@ -53,6 +60,13 @@
5360
return this;
5461
};
5562
ldloader.prototype = import$(Object.create(Object.prototype), {
63+
zmgr: function(it){
64+
if (it != null) {
65+
return this._zmgr = it;
66+
} else {
67+
return this._zmgr;
68+
}
69+
},
5670
isOn: function(){
5771
return this.running;
5872
},
@@ -134,7 +148,7 @@
134148
});
135149
}
136150
return new Promise(function(res, rej){
137-
var ref$, running, idx;
151+
var ref$, running, zmgr;
138152
this$.count = (ref$ = this$.count + d) > 0 ? ref$ : 0;
139153
if (!force && !this$.opt.atomic && (this$.count >= 2 || (this$.count === 1 && d < 0))) {
140154
return res();
@@ -152,25 +166,26 @@
152166
if (!this$.opt.autoZ) {
153167
return res();
154168
}
169+
zmgr = this$._zmgr || ldloader._zmgr;
155170
if (running) {
156-
if (ldloader.zmgr) {
157-
this$.z = ldloader.zmgr.add(this$.opt.baseZ);
158-
} else {
159-
this$.z = ((ref$ = ldloader.zstack)[ref$.length - 1] || this$.opt.baseZ) + 1;
160-
ldloader.zstack.push(z);
161-
}
171+
this$.z = zmgr.add(this$.opt.baseZ);
172+
/*
173+
if zmgr => @z = zmgr.add @opt.base-z
174+
else
175+
@z = (ldloader.zstack[* - 1] or @opt.base-z) + 1
176+
ldloader.zstack.push z
177+
*/
162178
this$.root.map(function(it){
163179
return it.style.zIndex = this$.z;
164180
});
165181
} else {
166-
if (ldloader.zmgr) {
167-
ldloader.zmgr.remove(this$.z);
168-
} else {
169-
if ((idx = ldloader.zstack.indexOf(this$.z)) < 0) {
170-
return res();
171-
}
172-
ldloader.zstack.splice(idx, 1);
173-
}
182+
zmgr.remove(this$.z);
183+
/*
184+
if zmgr => zmgr.remove @z
185+
else
186+
if (idx = ldloader.zstack.indexOf(@z)) < 0 => return res!
187+
ldloader.zstack.splice(idx, 1)
188+
*/
174189
this$.root.map(function(it){
175190
return it.style.zIndex = "";
176191
});
@@ -179,10 +194,31 @@
179194
});
180195
}
181196
});
197+
/*
198+
ldloader <<< do
199+
zstack: []
200+
zmgr: -> if it? => @_zmgr = it else @_zmgr
201+
*/
182202
import$(ldloader, {
183-
zstack: [],
184-
setZmgr: function(it){
185-
return this.zmgr = it;
203+
_zmgr: {
204+
add: function(v){
205+
var z, ref$;
206+
(this.s || (this.s = [])).push(z = Math.max(v || 0, ((ref$ = this.s)[ref$.length - 1] || 0) + 1));
207+
return z;
208+
},
209+
remove: function(v){
210+
var i;
211+
if ((i = (this.s || (this.s = [])).indexOf(v)) < 0) {} else {
212+
return this.s.splice(i, 1);
213+
}
214+
}
215+
},
216+
zmgr: function(it){
217+
if (it != null) {
218+
return this._zmgr = it;
219+
} else {
220+
return this._zmgr;
221+
}
186222
}
187223
});
188224
if (typeof module != 'undefined' && module !== null) {

0 commit comments

Comments
 (0)