Skip to content

Commit d1b6565

Browse files
committed
- add toggler function
- useful if we want to chain toggling to other object such as ldcover. - bump version
1 parent f753671 commit d1b6565

File tree

9 files changed

+33
-10
lines changed

9 files changed

+33
-10
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
## v2.1.0
4+
5+
- add `toggler` function
6+
- useful if we want to chain toggling to other object such as ldcover.
7+
8+
39
## v2.0.1
410

511
- remove deprecated `ldLoader`

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ config includes following options:
3333
* ctrl: custom animation control unit. should at least contains a member function "step(t)".
3434
- step(t): will be invoked repeatedly by requestAnimationFrame during loading period. context (aka this) will be root.
3535
* atomic: default true. when atomic is false, you will need N ldloader.off() call to dismiss ldloader if there was already N ldloader.on() call.
36+
* toggler(v): optional toggler triggered when `on/off` status changed. useful for chaining toggling events.
37+
- `v`: on/off status.
3638

3739
Methods:
40+
3841
* on(delay): toggle loader on. return promise. (if delay is provided, wait delay(ms) before on )
3942
* off(delay): toggle loader off. (if delay is provided, wait delay(ms) before off )
4043
* cancel(v): cancel delayed action. force state to `v` if v is defined.

dist/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
className: '',
1111
atomic: true
1212
}, opt);
13+
this._toggler = typeof opt.toggler === 'function'
14+
? opt.toggler
15+
: function(){};
1316
if (opt.zmgr) {
1417
this.zmgr(opt.zmgr);
1518
}
@@ -127,7 +130,7 @@
127130
});
128131
},
129132
toggle: function(v, delay, force){
130-
var d, this$ = this;
133+
var d, ret, this$ = this;
131134
delay == null && (delay = 0);
132135
force == null && (force = false);
133136
d = !(v != null)
@@ -147,7 +150,7 @@
147150
}, delay);
148151
});
149152
}
150-
return new Promise(function(res, rej){
153+
ret = new Promise(function(res, rej){
151154
var ref$, running, zmgr;
152155
this$.count = (ref$ = this$.count + d) > 0 ? ref$ : 0;
153156
if (!force && !this$.opt.atomic && (this$.count >= 2 || (this$.count === 1 && d < 0))) {
@@ -180,6 +183,9 @@
180183
}
181184
return res();
182185
});
186+
return ret.then(function(){
187+
return this$._toggler(d > 0 ? true : false);
188+
});
183189
}
184190
});
185191
import$(ldloader, {

dist/index.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"name": "ldloader",
44
"license": "MIT",
55
"description": "loader manipulation library",
6-
"version": "2.0.1",
6+
"version": "2.1.0",
77
"files": [
88
"dist/**/*"
99
],

src/ldld.ls

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
ldloader = (opt={}) ->
22
@opt = {active-class: \running, base-z: 4000, auto-z: false, class-name: '', atomic: true} <<< opt
3+
@_toggler = if typeof(opt.toggler) == \function => opt.toggler else (->)
34
if opt.zmgr => @zmgr opt.zmgr
45
<[root container]>.map (n) ~> if opt[n] =>
56
list = if Array.isArray(opt[n]) => opt[n]
@@ -51,7 +52,7 @@ ldloader.prototype = Object.create(Object.prototype) <<< do
5152
#if d > 0 => @toggle(v)then ~> setTimeout (~> res!), delay
5253
# if is off: off after resolve
5354
#else => setTimeout (~> @toggle(v)then ~> res!), delay
54-
new Promise (res, rej) ~>
55+
ret = new Promise (res, rej) ~>
5556
@count = (@count + d >? 0)
5657
if !force and !@opt.atomic and ( @count >= 2 or (@count == 1 and d < 0)) => return res!
5758
@root.map ~>
@@ -68,6 +69,7 @@ ldloader.prototype = Object.create(Object.prototype) <<< do
6869
zmgr.remove @z
6970
@root.map ~> it.style.zIndex = ""
7071
res!
72+
ret.then ~> @_toggler(if d > 0 => true else false)
7173

7274
ldloader <<< do
7375
_zmgr: do

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
className: '',
1111
atomic: true
1212
}, opt);
13+
this._toggler = typeof opt.toggler === 'function'
14+
? opt.toggler
15+
: function(){};
1316
if (opt.zmgr) {
1417
this.zmgr(opt.zmgr);
1518
}
@@ -127,7 +130,7 @@
127130
});
128131
},
129132
toggle: function(v, delay, force){
130-
var d, this$ = this;
133+
var d, ret, this$ = this;
131134
delay == null && (delay = 0);
132135
force == null && (force = false);
133136
d = !(v != null)
@@ -147,7 +150,7 @@
147150
}, delay);
148151
});
149152
}
150-
return new Promise(function(res, rej){
153+
ret = new Promise(function(res, rej){
151154
var ref$, running, zmgr;
152155
this$.count = (ref$ = this$.count + d) > 0 ? ref$ : 0;
153156
if (!force && !this$.opt.atomic && (this$.count >= 2 || (this$.count === 1 && d < 0))) {
@@ -180,6 +183,9 @@
180183
}
181184
return res();
182185
});
186+
return ret.then(function(){
187+
return this$._toggler(d > 0 ? true : false);
188+
});
183189
}
184190
});
185191
import$(ldloader, {

0 commit comments

Comments
 (0)