-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjquery.fxqueues-2.0.3.js
executable file
·225 lines (186 loc) · 6.29 KB
/
jquery.fxqueues-2.0.3.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/*
* jQuery FxQueues 2.0.3
* Copyright 2009 Luciano German Panaro <[email protected]>
* Released under the MIT and GPL licenses.
*/
(function($){
var fxQueue = function(queueName) {
return {
name: queueName,
isFxQueue: true,
paused: false,
playing: null,
shouldStart: function() {
return (this.playing == null || !this.paused);
},
pause: function() {
if (!this.playing) { return false; }
((this.playing.isScope)? this.playing: this.playing.elem).stop();
this.paused = true;
return true;
},
stop: function() {
if (!this.playing) { return false; }
((this.playing.isScope)? this.playing: this.playing.elem).stop();
this.playing = null;
this.paused = false;
this.length = 0;
return true;
},
start: function() {
// if a dequeued fn was paused
if (this.playing && this.paused) {
this.playing();
this.paused = false;
return true;
// or if the queue has not started
} else if (this.length && !this.playing) {
this.playing = this[0];
$(document).dequeue(this.name);
return true;
}
return false;
},
getScope: function( scopeName ) {
if (this.playing && this.playing.isScope && this.playing.called == scopeName) {
return this.playing;
}
for (var i = 0; i < this.length; i++) {
if (this[i].isScope && this[i].called == scopeName) {
return this[i];
}
}
return false;
},
dequeue: function( caller ) {
// Do nothing if queue is not playing anything
if (!this.playing) {
return false;
}
if (this.playing.isScope) {
var queueItems = this.playing.items;
// Find the actual element in scope's items
for ( var i=0; i < queueItems.length; i++) {
if ( caller == queueItems[i].elem[0] && !queueItems[i].finished ) {
queueItems[i].finished = true;
this.playing.finishedItems++;
}
}
// Do not dequeue if scope is not finished
if (this.playing.finishedItems < queueItems.length) {
return false;
}
// Dequeue just once for every selection
} else if (this.playing.elem && this.playing.elem[0] != caller) {
return false;
}
var queue = this;
setTimeout(function() {
queue.playing = queue[0];
$(document).dequeue(queue.name);
}, this.playing.postDelay);
return true;
}
};
};
var fxScope = function ( scopeName ) {
var newScope = function() {
for (var i=0; i < newScope.items.length; i++) {
newScope.items[i]();
}
};
newScope.called = scopeName;
newScope.isScope = true;
newScope.finishedItems = 0;
newScope.stop = function() {
for (var i=0; i < newScope.items.length; i++) {
newScope.items[i].elem.stop();
}
};
newScope.items = [];
return newScope;
};
// We need to overload the default animate method
var _animate = $.fn.animate;
$.fn.animate = function( props, speed, easing, callback ) {
if (!this.length) {
return this;
}
var options = (typeof speed == "object")? speed: $.speed(speed, easing, callback);
// Load in the default options
var opts = $.extend({
queue: "fx",
position: "end",
limit: -1,
preDelay: 0,
postDelay: 0,
complete: null
}, options );
// Let normal animations just pass through
if ( !opts.queue || opts.queue == "fx" ) {
return _animate.apply( this, arguments );
}
// Get the name of the queue
var queueName = opts.queue;
// Get the effect queue (A global queue is centered on 'document')
var queue = $(document).queue( opts.queue );
// Extend the queue object if it's new.
if ( !queue.isFxQueue ) {
$.extend(queue, fxQueue(queueName));
}
// We're overriding the default queueing behavior
opts.queue = false;
// The animation to queue
var fn = function() {
opts.complete = function() {
queue.dequeue(this);
if ( $.isFunction(fn.users_complete) ) {
return fn.users_complete.apply(this, arguments);
}
};
setTimeout(function() {
fn.elem.animate( props, opts );
}, fn.preDelay);
};
fn.elem = this;
fn.preDelay = opts.preDelay || 0;
fn.postDelay = opts.postDelay || 0;
fn.users_complete = speed.complete || callback; //Do not use the one generated by $.speed
// If scope exists, just add the animation and return
var scope = queue.getScope( opts.scope );
if ( scope ) {
scope.items.push( fn );
// Start the animation if the scope is already being played
if (queue.playing == scope) {
fn();
}
return this;
}
// Restrict the animation to a specifically sized queue
if ( opts.limit < 0 || queue.length < opts.limit) {
var add = null; //What we are going to add into the queue
if ( opts.scope ) {
add = fxScope( opts.scope );
add.items.push(fn);
} else {
add = fn;
}
if ( opts.position == "end" ) {
queue.push( add );
} else if ( opts.position == "front" ) {
queue.splice( 1, 0, add );
}
if ( queue.shouldStart() ) {
queue.start();
}
return this;
}
};
// A simple global fx queue getter
$.extend({
fxqueue: function(queueName) {
return $(document).queue( queueName );
}
});
$.fxqueue.version = "2.0.3";
})(jQuery);