This repository has been archived by the owner on Apr 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathrx.jquery.js
749 lines (668 loc) · 40.2 KB
/
rx.jquery.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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
(function (root, factory) {
var freeExports = typeof exports == 'object' && exports &&
(typeof root == 'object' && root && root == root.global && (window = root), exports);
// Because of build optimizers
if (typeof define === 'function' && define.amd) {
define(['rx', 'jquery', 'exports'], function (Rx, jQuery, exports) {
root.Rx = factory(root, exports, Rx, jQuery);
return root.Rx;
});
} else if (typeof module == 'object' && module && module.exports == freeExports) {
module.exports = factory(root, module.exports, require('rx'), require('jquery'));
} else {
root.Rx = factory(root, {}, root.Rx, jQuery);
}
}(this, function (global, exp, Rx, $, undefined) {
// Headers
var observable = Rx.Observable,
observableProto = observable.prototype,
AsyncSubject = Rx.AsyncSubject,
observableCreate = observable.create,
observableCreateWithDisposable = observable.createWithDisposable,
disposableEmpty = Rx.Disposable.empty,
slice = Array.prototype.slice,
proto = $.fn;
function observableCreateRefCount(subscribe) {
return observableCreate(subscribe).publish().refCount();
}
// Check for deferred as of jQuery 1.5
if ($.Deferred) {
/**
* Converts the jQuery Deferred to an Observable sequence
* @returns {Observable} An Observable sequence created from a jQuery Deferred object.
*/
$.Deferred.toObservable = function (deferred) {
var subject = new AsyncSubject();
deferred.done(function () {
subject.onNext(slice.call(arguments));
subject.onCompleted();
}).fail(function () {
subject.onError(slice.call(arguments));
});
return subject;
};
/**
* Converts an existing Observable sequence to a jQuery Deferred object.
* @returns {Deferred} A jQuery Deferred object wrapping the Observable sequence.
*/
observableProto.toDeferred = function () {
var deferred = $.Deferred();
this.subscribe(function (value) {
deferred.resolve(value);
}, function (e) {
deferred.reject(e);
});
return deferred;
};
}
//in order to support jQuery 1.6.*
if ($.Callbacks) {
/**
* Converts an existing Callbacks object to an Observable sequence
* @returns {Observable} An Observable sequence created from a jQuery Callbacks object.
*/
$.Callbacks.prototype.toObservable = function () {
var parent = this;
return observableCreate(function (observer) {
function handler(values) {
observer.onNext(values);
}
parent.add(handler);
return function () {
parent.remove(handler);
};
});
};
} if (!!proto.on) {
/**
* Attach an event handler function for one or more events to the selected elements as an Observable sequence.
*
* @param {String} events One or more space-separated event types and optional namespaces, such as "click" or "keydown.myPlugin".
* @param {String} [selector] A selector string to filter the descendants of the selected elements that trigger the event. If the selector is null or omitted, the event is always triggered when it reaches the selected element.
* @param {Any} [data] Data to be passed to the handler in event.data when an event is triggered.
* @returns {Observable} An Observable sequence which wraps the jQuery on method.
*/
proto.onAsObservable = function () {
var parent = this, oargs = slice.call(arguments, 0), args;
return observableCreateRefCount(function(observer) {
function handler(eventObject) {
eventObject.additionalArguments = slice.call(arguments, 1);
observer.onNext(eventObject);
}
args = oargs.slice();
args.push(handler);
parent.on.apply(parent, args);
return function() {
parent.off.apply(parent, args);
};
});
};
}
/**
* Attach a handler to an event for the elements as an Observable sequence.
*
* @param {String} eventType A string containing one or more DOM event types, such as "click" or "submit," or custom event names.
* @param {Object} eventData An object containing data that will be passed to the event handler.
* @returns {Observable} An Observable sequence which wraps the jQuery bind method.
*/
proto.bindAsObservable = function(eventType, eventData) {
var parent = this;
return observableCreateRefCount(function(observer) {
function handler(eventObject) {
eventObject.additionalArguments = slice.call(arguments, 1);
observer.onNext(eventObject);
}
parent.bind(eventType, eventData, handler);
return function() {
parent.unbind(eventType, eventData, handler);
};
});
};
/**
* Attach a handler to one or more events for all elements that match the selector, now or in the future, based on a specific set of root elements as an Observable sequence
*
* @param {String} selector A selector to filter the elements that trigger the event.
* @param {String} eventType A string containing one or more space-separated JavaScript event types, such as "click" or "keydown," or custom event names.
* @param {Object} eventData An object containing data that will be passed to the event handler.
* @returns {Observable} An Observable sequence which wraps the jQuery delegate method
*/
proto.delegateAsObservable = function(selector, eventType, eventData) {
var parent = this;
return observableCreateRefCount(function(observer) {
function handler(eventObject) {
eventObject.additionalArguments = slice.call(arguments, 1);
observer.onNext(eventObject);
}
parent.delegate(selector, eventType, eventData, handler);
return function() {
parent.undelegate(selector, eventType, handler);
};
});
};
// Removed as of 1.9
if (!!proto.live) {
/**
* Attach an event handler for all elements which match the current selector, now and in the future as an Observable sequence
*
* @param {String} eventType A string containing a JavaScript event type, such as "click" or "keydown." As of jQuery 1.4 the string can contain multiple, space-separated event types or custom event names.
* @param {Object} data An object containing data that will be passed to the event handler.
* @returns {Observable} An Observable sequence which wraps the jQuery live method
*/
proto.liveAsObservable = function(eventType, data) {
var parent = this;
return observableCreateRefCount(function(observer) {
function handler(eventObject) {
eventObject.additionalArguments = slice.call(arguments, 1);
observer.onNext(eventObject);
}
parent.live(eventType, data, handler);
return function() {
parent.die(eventType, data, handler);
};
});
};
}
/**
* Bind an event handler to the “change” JavaScript event, or trigger that event on an element as an Observable sequence.
*
* @param {Object} [eventData] An object containing data that will be passed to the event handler.
* @returns {Observable} An Observable sequence which wraps the jQuery “change” event.
*/
proto.changeAsObservable = function (eventData) {
return this.bindAsObservable('change', eventData);
};
/**
* Bind an event handler to the “click” JavaScript event, or trigger that event on an element as an Observable sequence.
*
* @param {Object} [eventData] An object containing data that will be passed to the event handler.
* @returns {Observable} An Observable sequence which wraps the jQuery “click” event.
*/
proto.clickAsObservable = function (eventData) {
return this.bindAsObservable('click', eventData);
};
/**
* Bind an event handler to the “dblclick” JavaScript event, or trigger that event on an element as an Observable sequence.
*
* @param {Object} [eventData] An object containing data that will be passed to the event handler.
* @returns {Observable} An Observable sequence which wraps the jQuery "“dblclick”" event.
*/
proto.dblclickAsObservable = function (eventData) {
return this.bindAsObservable('dblclick', eventData);
};
/**
* Bind an event handler to the “focus” JavaScript event, or trigger that event on an element as an Observable sequence.
*
* @param {Object} [eventData] An object containing data that will be passed to the event handler.
* @returns {Observable} An Observable sequence which wraps the jQuery "“focus”" event.
*/
proto.focusAsObservable = function(eventData) {
return this.bindAsObservable('focus', eventData);
};
/**
* Bind an event handler to the “focusin” event as an Observable sequence.
*
* @param {Object} [eventData] An object containing data that will be passed to the event handler.
* @returns {Observable} An Observable sequence which wraps the jQuery “focusin” event.
*/
proto.focusinAsObservable = function(eventData) {
return this.bindAsObservable('focusin', eventData);
};
/**
* Bind an event handler to the “focusin” event as an Observable sequence.
*
* @param {Object} [eventData] An object containing data that will be passed to the event handler.
* @returns {Observable} An Observable sequence which wraps the jQuery “focusin” event.
*/
proto.focusoutAsObservable = function(eventData) {
return this.bindAsObservable('focusout', eventData);
};
/**
* Bind an event handler to the "keypress" JavaScript event, or trigger that event on an element as an Observable sequence.
*
* @param {Object} [eventData] An object containing data that will be passed to the event handler.
* @returns {Observable} An Observable sequence which wraps the jQuery “keypress” event.
*/
proto.keypressAsObservable = function(eventData) {
return this.bindAsObservable('keypress', eventData);
};
/**
* Bind an event handler to the “keydown” JavaScript event, or trigger that event on an element as an Observable sequence.
*
* @param {Object} [eventData] An object containing data that will be passed to the event handler.
* @returns {Observable} An Observable sequence which wraps the jQuery “keydown” event.
*/
proto.keydownAsObservable = function(eventData) {
return this.bindAsObservable('keydown', eventData);
};
/**
* Bind an event handler to the “keyup” JavaScript event, or trigger that event on an element as an Observable sequence.
*
* @param {Object} [eventData] An object containing data that will be passed to the event handler.
* @returns {Observable} An Observable sequence which wraps the jQuery “keyup” event.
*/
proto.keyupAsObservable = function(eventData) {
return this.bindAsObservable('keyup', eventData);
};
/**
* Bind an event handler to the “load” JavaScript event as an Observable sequence.
*
* @param {Object} [eventData] An object containing data that will be passed to the event handler.
* @returns {Observable} An Observable sequence which wraps the jQuery “load” event.
*/
proto.loadAsObservable = function(eventData) {
return this.bindAsObservable('load', eventData);
};
/**
* Bind an event handler to the “mousedown” JavaScript event, or trigger that event on an element as an Observable sequence.
*
* @param {Object} [eventData] An object containing data that will be passed to the event handler.
* @returns {Observable} An Observable sequence which wraps the jQuery “mousedown” event.
*/
proto.mousedownAsObservable = function(eventData) {
return this.bindAsObservable('mousedown', eventData);
};
/**
* Bind an event handler to be fired when the mouse enters an element, or trigger that handler on an element as an Observable sequence.
*
* @param {Object} [eventData] An object containing data that will be passed to the event handler.
* @returns {Observable} An Observable sequence which wraps the jQuery “mouseenter” event.
*/
proto.mouseenterAsObservable = function(eventData) {
return this.bindAsObservable('mouseenter', eventData);
};
/**
* Bind an event handler to be fired when the mouse leaves an element, or trigger that handler on an element as an Observable sequence.
*
* @param {Object} [eventData] An object containing data that will be passed to the event handler.
* @returns {Observable} An Observable sequence which wraps the jQuery “mouseleave” event.
*/
proto.mouseleaveAsObservable = function(eventData) {
return this.bindAsObservable('mouseleave', eventData);
};
/**
* Bind an event handler to the “mousemove” JavaScript event, or trigger that event on an element as an Observable sequence.
*
* @param {Object} [eventData] An object containing data that will be passed to the event handler.
* @returns {Observable} An Observable sequence which wraps the jQuery “mousemove” event.
*/
proto.mousemoveAsObservable = function(eventData) {
return this.bindAsObservable('mousemove', eventData);
};
/**
* Bind an event handler to the “mouseout” JavaScript event, or trigger that event on an element as an Observable sequence.
*
* @param {Object} [eventData] An object containing data that will be passed to the event handler.
* @returns {Observable} An Observable sequence which wraps the jQuery “mouseout” event.
*/
proto.mouseoutAsObservable = function(eventData) {
return this.bindAsObservable('mouseout', eventData);
};
/**
* Bind an event handler to the “mouseover” JavaScript event, or trigger that event on an element as an Observable sequence.
*
* @param {Object} [eventData] An object containing data that will be passed to the event handler.
* @returns {Observable} An Observable sequence which wraps the jQuery “mouseover” event.
*/
proto.mouseoverAsObservable = function(eventData) {
return this.bindAsObservable('mouseover', eventData);
};
/**
* Bind an event handler to the “mouseup” JavaScript event, or trigger that event on an element as an Observable sequence.
*
* @param {Object} [eventData] An object containing data that will be passed to the event handler.
* @returns {Observable} An Observable sequence which wraps the jQuery “mouseup” event.
*/
proto.mouseupAsObservable = function(eventData) {
return this.bindAsObservable('mouseup', eventData);
};
/**
* Bind an event handler to the “resize” JavaScript event, or trigger that event on an element as an Observable sequence.
*
* @param {Object} [eventData] An object containing data that will be passed to the event handler.
* @returns {Observable} An Observable sequence which wraps the jQuery “resize” event.
*/
proto.resizeAsObservable = function(eventData) {
return this.bindAsObservable('resize', eventData);
};
/**
* Bind an event handler to the “scroll” JavaScript event, or trigger that event on an element as an Observable sequence.
*
* @param {Object} [eventData] An object containing data that will be passed to the event handler.
* @returns {Observable} An Observable sequence which wraps the jQuery “scroll” event.
*/
proto.scrollAsObservable = function(eventData) {
return this.bindAsObservable('scroll', eventData);
};
/**
* Bind an event handler to the “select” JavaScript event, or trigger that event on an element as an Observable sequence.
*
* @param {Object} [eventData] An object containing data that will be passed to the event handler.
* @returns {Observable} An Observable sequence which wraps the jQuery “select” event.
*/
proto.selectAsObservable = function(eventData) {
return this.bindAsObservable('select', eventData);
};
/**
* Bind an event handler to the “select” JavaScript event, or trigger that event on an element as an Observable sequence.
*
* @param {Object} [eventData] An object containing data that will be passed to the event handler.
* @returns {Observable} An Observable sequence which wraps the jQuery “select” event.
*/
proto.submitAsObservable = function(eventData) {
return this.bindAsObservable('submit', eventData);
};
/**
* Bind an event handler to the “unload” JavaScript event as an Observable sequence. This is deprecated as of jQuery 1.8.
*
* @param {Object} [eventData] An object containing data that will be passed to the event handler.
* @returns {Observable} An Observable sequence which wraps the jQuery “unload” event.
*/
proto.unloadAsObservable = function(eventData) {
return this.bindAsObservable('unload', eventData);
};
/**
* Attach a handler to an event for the elements as an Observable sequence. The handler is executed at most once per element.
*
* @param {String} events A string containing one or more JavaScript event types, such as "click" or "submit," or custom event names.
* @param {String} [selector] A selector string to filter the descendants of the selected elements that trigger the event. If the selector is null or omitted, the event is always triggered when it reaches the selected element.
* @param {Object} [data] An object containing data that will be passed to the event handler.
* @returns {Observable} An Observable sequence which wraps the jQuery one method.
*/
proto.oneAsObservable = function(events) {
var parent = this, oargs = slice.call(arguments, 0), args;
return observableCreateRefCount(function(observer) {
function handler (eventObject) {
eventObject.additionalArguments = slice.call(arguments, 1);
observer.onNext(eventObject);
}
args = oargs.slice();
args.push(handler);
parent.one.apply(parent, args);
});
};
/**
* Specify a function to execute when the DOM is fully loaded as an Observable sequence.
*
* @returns {Observable} An Observable sequence which wraps the jQuery ready method.
*/
proto.readyAsObservable = function() {
var parent = this;
return observableCreateRefCount(function(observer) {
function handler(eventObject) {
observer.onNext(eventObject);
}
parent.ready(handler);
});
};
function handleAnimation(jQueryProto, method, args) {
var options = args[0];
// Check for duration
if (typeof options === 'number' || typeof options === 'string') {
options = { duration: options };
} else if (!options) {
options = {};
}
// Check for easing
if (args.length === 2) {
options.easing = args[1];
}
var subject = new AsyncSubject();
options.complete = function() {
subject.onNext(jQueryProto);
subject.onCompleted();
};
jQueryProto[method](options);
return subject.asObservable();
}
/**
* Hide the matched elements as an Observable sequence.
*
* @param {String|Number} [duration] A string or number determining how long the animation will run. If not specified, defaults to 400.
* @param {String} [easing] A string indicating which easing function to use for the transition.
* @param {Object} [options] A map of additional options to pass to the method.
* @param {String|Number} [options.duration] A string or number determining how long the animation will run.
* @param {String} [options.easing] A string indicating which easing function to use for the transition.
* @param {String|Boolean} [options.queue] A Boolean indicating whether to place the animation in the effects queue. If false, the animation will begin immediately. As of jQuery 1.7, the queue option can also accept a string, in which case the animation is added to the queue represented by that string. When a custom queue name is used the animation does not automatically start; you must call .dequeue("queuename") to start it.
* @param {Object} [options.specialEasing] A map of one or more of the CSS properties defined by the properties argument and their corresponding easing functions.
* @param {Number} [options.step] A function to be called for each animated property of each animated element. This function provides an opportunity to modify the Tween object to change the value of the property before it is set.
* @returns {Observable} An Observable sequence which wraps the jQuery hide method.
*/
proto.hideAsObservable = function (options) {
return handleAnimation(this, 'hide', arguments);
};
/**
* Display the matched elements as an Observable sequence.
*
* @param {String|Number} [duration] A string or number determining how long the animation will run. If not specified, defaults to 400.
* @param {String} [easing] A string indicating which easing function to use for the transition.
* @param {Object} [options] A map of additional options to pass to the method.
* @param {String|Number} [options.duration] A string or number determining how long the animation will run.
* @param {String} [options.easing] A string indicating which easing function to use for the transition.
* @param {String|Boolean} [options.queue] A Boolean indicating whether to place the animation in the effects queue. If false, the animation will begin immediately. As of jQuery 1.7, the queue option can also accept a string, in which case the animation is added to the queue represented by that string. When a custom queue name is used the animation does not automatically start; you must call .dequeue("queuename") to start it.
* @param {Object} [options.specialEasing] A map of one or more of the CSS properties defined by the properties argument and their corresponding easing functions.
* @param {Number} [options.step] A function to be called for each animated property of each animated element. This function provides an opportunity to modify the Tween object to change the value of the property before it is set.
* @returns {Observable} An Observable sequence which wraps the jQuery show method.
*/
proto.showAsObservable = function(options) {
return handleAnimation(this, 'show', arguments);
};
/**
* Display the matched elements as an Observable sequence.
*
* @param {Object} properties An object of CSS properties and values that the animation will move toward.
* @param {String|Number} [duration] A string or number determining how long the animation will run. If not specified, defaults to 400.
* @param {String} [easing] A string indicating which easing function to use for the transition.
* @param {Object} [options] A map of additional options to pass to the method.
* @param {String|Number} [options.duration] A string or number determining how long the animation will run.
* @param {String} [options.easing] A string indicating which easing function to use for the transition.
* @param {String|Boolean} [options.queue] A Boolean indicating whether to place the animation in the effects queue. If false, the animation will begin immediately. As of jQuery 1.7, the queue option can also accept a string, in which case the animation is added to the queue represented by that string. When a custom queue name is used the animation does not automatically start; you must call .dequeue("queuename") to start it.
* @param {Object} [options.specialEasing] A map of one or more of the CSS properties defined by the properties argument and their corresponding easing functions.
* @param {Number} [options.step] A function to be called for each animated property of each animated element. This function provides an opportunity to modify the Tween object to change the value of the property before it is set.
* @returns {Observable} An Observable sequence which wraps the jQuery show method.
*/
proto.animateAsObservable = function(properties, options) {
// Check for duration
if (typeof options === 'number' || typeof options === 'string') {
options = { duration: options };
} else if (!options) {
options = {};
}
// Check for easing
if (arguments.length === 3) {
options.easing = arguments[2];
}
var subject = new AsyncSubject();
options.complete = function() {
subject.onNext(this);
subject.onCompleted();
};
this.animate(properties, options);
return subject.asObservable();
};
/**
* Display the matched elements as an Observable sequence.
*
* @param {String|Number} [duration] A string or number determining how long the animation will run. If not specified, defaults to 400.
* @param {String} [easing] A string indicating which easing function to use for the transition.
* @param {Object} [options] A map of additional options to pass to the method.
* @param {String|Number} [options.duration] A string or number determining how long the animation will run.
* @param {String} [options.easing] A string indicating which easing function to use for the transition.
* @param {String|Boolean} [options.queue] A Boolean indicating whether to place the animation in the effects queue. If false, the animation will begin immediately. As of jQuery 1.7, the queue option can also accept a string, in which case the animation is added to the queue represented by that string. When a custom queue name is used the animation does not automatically start; you must call .dequeue("queuename") to start it.
* @param {Object} [options.specialEasing] A map of one or more of the CSS properties defined by the properties argument and their corresponding easing functions.
* @param {Number} [options.step] A function to be called for each animated property of each animated element. This function provides an opportunity to modify the Tween object to change the value of the property before it is set.
* @returns {Observable} An Observable sequence which wraps the jQuery fadeIn method.
*/
proto.fadeInAsObservable = function(options) {
return handleAnimation(this, 'fadeIn', arguments);
};
/**
* Adjust the opacity of the matched elements as an Observable sequence
*
* @param {String|Number} duration A string or number determining how long the animation will run.
* @param {Number} opacity A number between 0 and 1 denoting the target opacity.
* @param {String} [easing] A string indicating which easing function to use for the transition.
* @returns {Observable} An Observable sequence which wraps the jQuery fadeTo method.
*/
proto.fadeToAsObservable = function(duration, opacity, easing) {
var subject = new AsyncSubject();
this.fadeTo(duration, opacity, easing, function() {
subject.onNext(proto);
subject.onCompleted();
});
return subject.asObservable();
};
/**
* Hide the matched elements by fading them to transparent as an Observable sequence.
*
* @param {String|Number} [duration] A string or number determining how long the animation will run. If not specified, defaults to 400.
* @param {String} [easing] A string indicating which easing function to use for the transition.
* @param {Object} [options] A map of additional options to pass to the method.
* @param {String|Number} [options.duration] A string or number determining how long the animation will run.
* @param {String} [options.easing] A string indicating which easing function to use for the transition.
* @param {String|Boolean} [options.queue] A Boolean indicating whether to place the animation in the effects queue. If false, the animation will begin immediately. As of jQuery 1.7, the queue option can also accept a string, in which case the animation is added to the queue represented by that string. When a custom queue name is used the animation does not automatically start; you must call .dequeue("queuename") to start it.
* @param {Object} [options.specialEasing] A map of one or more of the CSS properties defined by the properties argument and their corresponding easing functions.
* @param {Number} [options.step] A function to be called for each animated property of each animated element. This function provides an opportunity to modify the Tween object to change the value of the property before it is set.
* @returns {Observable} An Observable sequence which wraps the jQuery fadeOut method.
*/
proto.fadeOutAsObservable = function(options) {
return handleAnimation(this, 'fadeOut', arguments);
};
/**
* Display or hide the matched elements by animating their opacity as an Observable sequence.
*
* @param {String|Number} [duration] A string or number determining how long the animation will run. If not specified, defaults to 400.
* @param {String} [easing] A string indicating which easing function to use for the transition.
* @param {Object} [options] A map of additional options to pass to the method.
* @param {String|Number} [options.duration] A string or number determining how long the animation will run.
* @param {String} [options.easing] A string indicating which easing function to use for the transition.
* @param {String|Boolean} [options.queue] A Boolean indicating whether to place the animation in the effects queue. If false, the animation will begin immediately. As of jQuery 1.7, the queue option can also accept a string, in which case the animation is added to the queue represented by that string. When a custom queue name is used the animation does not automatically start; you must call .dequeue("queuename") to start it.
* @param {Object} [options.specialEasing] A map of one or more of the CSS properties defined by the properties argument and their corresponding easing functions.
* @param {Number} [options.step] A function to be called for each animated property of each animated element. This function provides an opportunity to modify the Tween object to change the value of the property before it is set.
* @returns {Observable} An Observable sequence which wraps the jQuery fadeToggle method.
*/
proto.fadeToggleAsObservable = function(options) {
return handleAnimation(this, 'fadeToggle', arguments);
};
/**
* Display the matched elements with a sliding motion as an Observable sequence.
*
* @param {String|Number} [duration] A string or number determining how long the animation will run. If not specified, defaults to 400.
* @param {String} [easing] A string indicating which easing function to use for the transition.
* @param {Object} [options] A map of additional options to pass to the method.
* @param {String|Number} [options.duration] A string or number determining how long the animation will run.
* @param {String} [options.easing] A string indicating which easing function to use for the transition.
* @param {String|Boolean} [options.queue] A Boolean indicating whether to place the animation in the effects queue. If false, the animation will begin immediately. As of jQuery 1.7, the queue option can also accept a string, in which case the animation is added to the queue represented by that string. When a custom queue name is used the animation does not automatically start; you must call .dequeue("queuename") to start it.
* @param {Object} [options.specialEasing] A map of one or more of the CSS properties defined by the properties argument and their corresponding easing functions.
* @param {Number} [options.step] A function to be called for each animated property of each animated element. This function provides an opportunity to modify the Tween object to change the value of the property before it is set.
* @returns {Observable} An Observable sequence which wraps the jQuery slideDown method.
*/
proto.slideDownAsObservable = function(options) {
return handleAnimation(this, 'slideDown', arguments);
};
/**
* Hide the matched elements with a sliding motion as an Observable sequence.
*
* @param {String|Number} [duration] A string or number determining how long the animation will run. If not specified, defaults to 400.
* @param {String} [easing] A string indicating which easing function to use for the transition.
* @param {Object} [options] A map of additional options to pass to the method.
* @param {String|Number} [options.duration] A string or number determining how long the animation will run.
* @param {String} [options.easing] A string indicating which easing function to use for the transition.
* @param {String|Boolean} [options.queue] A Boolean indicating whether to place the animation in the effects queue. If false, the animation will begin immediately. As of jQuery 1.7, the queue option can also accept a string, in which case the animation is added to the queue represented by that string. When a custom queue name is used the animation does not automatically start; you must call .dequeue("queuename") to start it.
* @param {Object} [options.specialEasing] A map of one or more of the CSS properties defined by the properties argument and their corresponding easing functions.
* @param {Number} [options.step] A function to be called for each animated property of each animated element. This function provides an opportunity to modify the Tween object to change the value of the property before it is set.
* @returns {Observable} An Observable sequence which wraps the jQuery slideUp method.
*/
proto.slideUpAsObservable = function(options) {
return handleAnimation(this, 'slideUp', arguments);
};
/**
* Hide the matched elements with a sliding motion as an Observable sequence.
*
* @param {String|Number} [duration] A string or number determining how long the animation will run. If not specified, defaults to 400.
* @param {String} [easing] A string indicating which easing function to use for the transition.
* @param {Object} [options] A map of additional options to pass to the method.
* @param {String|Number} [options.duration] A string or number determining how long the animation will run.
* @param {String} [options.easing] A string indicating which easing function to use for the transition.
* @param {String|Boolean} [options.queue] A Boolean indicating whether to place the animation in the effects queue. If false, the animation will begin immediately. As of jQuery 1.7, the queue option can also accept a string, in which case the animation is added to the queue represented by that string. When a custom queue name is used the animation does not automatically start; you must call .dequeue("queuename") to start it.
* @param {Object} [options.specialEasing] A map of one or more of the CSS properties defined by the properties argument and their corresponding easing functions.
* @param {Number} [options.step] A function to be called for each animated property of each animated element. This function provides an opportunity to modify the Tween object to change the value of the property before it is set.
* @returns {Observable} An Observable sequence which wraps the jQuery slideToggle method.
*/
proto.slideToggleAsObservable = function(options) {
return handleAnimation(this, 'slideToggle', arguments);
};
/**
* Display or hide the matched elements as an Observable sequence.
*
* @param {String|Number} [duration] A string or number determining how long the animation will run. If not specified, defaults to 400.
* @param {String} [easing] A string indicating which easing function to use for the transition.
* @param {Object} [options] A map of additional options to pass to the method.
* @param {String|Number} [options.duration] A string or number determining how long the animation will run.
* @param {String} [options.easing] A string indicating which easing function to use for the transition.
* @param {String|Boolean} [options.queue] A Boolean indicating whether to place the animation in the effects queue. If false, the animation will begin immediately. As of jQuery 1.7, the queue option can also accept a string, in which case the animation is added to the queue represented by that string. When a custom queue name is used the animation does not automatically start; you must call .dequeue("queuename") to start it.
* @param {Object} [options.specialEasing] A map of one or more of the CSS properties defined by the properties argument and their corresponding easing functions.
* @param {Number} [options.step] A function to be called for each animated property of each animated element. This function provides an opportunity to modify the Tween object to change the value of the property before it is set.
* @returns {Observable} An Observable sequence which wraps the jQuery slideToggle method.
*/
proto.toggleAsObservable = function(duration, easing) {
return handleAnimation(this, 'toggle', arguments);
};
var ajaxAsObservable = $.ajaxAsObservable = function(settings) {
var subject = new AsyncSubject();
var internalSettings = {
success: function(data, textStatus, jqXHR) {
subject.onNext({ data: data, textStatus: textStatus, jqXHR: jqXHR });
subject.onCompleted();
},
error: function(jqXHR, textStatus, errorThrown) {
subject.onError({ jqXHR: jqXHR, textStatus: textStatus, errorThrown: errorThrown });
}
};
$.extend(true, internalSettings, settings);
$.ajax(internalSettings);
return subject;
};
/**
* Load data from the server using a HTTP GET request as an Observable sequence.
*
* @param {String} url A string containing the URL to which the request is sent.
* @param {Object} [data] A plain object or string that is sent to the server with the request.
* @param {String} [dataType] The type of data expected from the server. Default: Intelligent Guess (xml, json, script, or html).
* @returns {Observable} An Observable sequence which wraps the jQuery get method.
*/
$.getAsObservable = function(url, data, dataType) {
return ajaxAsObservable({ url: url, dataType: dataType, data: data });
};
/**
* Load JSON-encoded data from the server using a GET HTTP request as an Observable sequence.
*
* @param {String} url A string containing the URL to which the request is sent.
* @param {Object} [data] A plain object or string that is sent to the server with the request.
* @returns {Observable} An Observable sequence which wraps the jQuery getJSON method.
*/
$.getJSONAsObservable = function(url, data) {
return ajaxAsObservable({ url: url, dataType: 'json', data: data });
};
/**
* Load a JavaScript file from the server using a GET HTTP request, then execute it as an Observable sequence.
*
* @param {String} url A string containing the URL to which the request is sent.
* @returns {Observable} An Observable sequence which wraps the jQuery getJSON method.
*/
$.getScriptAsObservable = function(url) {
return ajaxAsObservable({ url: url, dataType: 'script'});
};
/**
* Load data from the server using a HTTP POST request as an Observable sequence.
*
* @param {String} url A string containing the URL to which the request is sent.
* @param {Object} [data] A plain object or string that is sent to the server with the request.
* @param {String} [dataType] The type of data expected from the server. Default: Intelligent Guess (xml, json, script, or html).
* @returns {Observable} An Observable sequence which wraps the jQuery get method.
*/
$.postAsObservable = function(url, data, dataType) {
return ajaxAsObservable({ url: url, dataType: dataType, data: data, type: 'POST'});
};
return Rx;
}));