Skip to content

Commit 2c10057

Browse files
Adding VSDoc file
1 parent da6c878 commit 2c10057

File tree

3 files changed

+342
-5
lines changed

3 files changed

+342
-5
lines changed

lib/rx.jquery-vsdoc.js

Lines changed: 339 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,339 @@
1+
/**
2+
* Copyright 2011 Microsoft Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
(function(global, $) {
17+
var root = global.Rx,
18+
observable = root.Observable,
19+
observableProto = observable.prototype,
20+
asyncSubject = root.AsyncSubject,
21+
observableCreate = observable.create,
22+
observableCreateWithDisposable = observable.createWithDisposable,
23+
disposableEmpty = root.Disposable.empty,
24+
slice = Array.prototype.slice,
25+
proto = $.fn;
26+
27+
$.Deferred.prototype.toObservable = function () {
28+
var subject = new asyncSubject();
29+
parent.done(function () {
30+
subject.onNext(slice.call(arguments));
31+
subject.onCompleted();
32+
}).fail(function () {
33+
subject.onError(slice.call(arguments));
34+
});
35+
return subject;
36+
};
37+
38+
observableProto.toDeferred = function () {
39+
var deferred = $.Deferred();
40+
this.subscribe(function (value) {
41+
deferred.resolve(value);
42+
}, function (e) {
43+
deferred.reject(e);
44+
});
45+
return deferred;
46+
};
47+
48+
$.Callbacks.prototype.toObservable = function () {
49+
var parent = this;
50+
return observableCreate(function (observer) {
51+
var handler = function(values) {
52+
observer.onNext(values);
53+
};
54+
parent.add(handler);
55+
return function () {
56+
parent.remove(handler);
57+
};
58+
});
59+
};
60+
61+
proto.onAsObservable = function (events, selector, data) {
62+
var parent = this;
63+
return observableCreate(function(observer) {
64+
var handler = function(eventObject) {
65+
observer.onNext(eventObject);
66+
};
67+
parent.on(events, selector, data, handler);
68+
return function() {
69+
parent.off(events, selector, handler);
70+
};
71+
});
72+
};
73+
74+
proto.bindAsObservable = function(eventType, eventData) {
75+
var parent = this;
76+
return observableCreate(function(observer) {
77+
var handler = function(eventObject) {
78+
observer.onNext(eventObject);
79+
};
80+
parent.bind(eventType, eventData, handler);
81+
return function() {
82+
parent.unbind(eventType, handler);
83+
};
84+
});
85+
};
86+
proto.delegateAsObservable = function(selector, eventType, eventData) {
87+
var parent = this;
88+
return observableCreate(function(observer) {
89+
var handler = function(eventObject) {
90+
observer.onNext(eventObject);
91+
};
92+
parent.delegate(selector, eventType, eventData, handler);
93+
return function() {
94+
parent.undelegate(selector, eventType, handler);
95+
};
96+
});
97+
};
98+
proto.liveAsObservable = function(eventType, eventData) {
99+
var parent = this;
100+
return observableCreate(function(observer) {
101+
var handler = function(eventObject) {
102+
observer.onNext(eventObject);
103+
};
104+
parent.live(eventType, eventData, handler);
105+
return function() {
106+
parent.die(eventType, handler);
107+
};
108+
});
109+
};
110+
proto.changeAsObservable = function (eventData) {
111+
return this.bindAsObservable('change', eventData);
112+
};
113+
proto.clickAsObservable = function (eventData) {
114+
return this.bindAsObservable('click', eventData);
115+
};
116+
proto.dblclickAsObservable = function (eventData) {
117+
return this.bindAsObservable('dblclick', eventData);
118+
};
119+
proto.focusAsObservable = function(eventData) {
120+
return this.bindAsObservable('focus', eventData);
121+
};
122+
proto.focusinAsObservable = function(eventData) {
123+
return this.bindAsObservable('focusin', eventData);
124+
};
125+
proto.focusoutAsObservable = function(eventData) {
126+
return this.bindAsObservable('focusout', eventData);
127+
};
128+
proto.keydownAsObservable = function(eventData) {
129+
return this.bindAsObservable('keydown', eventData);
130+
};
131+
proto.keyupAsObservable = function(eventData) {
132+
return this.bindAsObservable('keyup', eventData);
133+
};
134+
proto.loadAsObservable = function(eventData) {
135+
return this.bindAsObservable('load', eventData);
136+
};
137+
proto.mousedownAsObservable = function(eventData) {
138+
return this.bindAsObservable('mousedown', eventData);
139+
};
140+
proto.mouseenterAsObservable = function(eventData) {
141+
return this.bindAsObservable('mouseenter', eventData);
142+
};
143+
proto.mouseleaveAsObservable = function(eventData) {
144+
return this.bindAsObservable('mouseleave', eventData);
145+
};
146+
proto.mousemoveAsObservable = function(eventData) {
147+
return this.bindAsObservable('mousemove', eventData);
148+
};
149+
proto.mouseoverAsObservable = function(eventData) {
150+
return this.bindAsObservable('mouseover', eventData);
151+
};
152+
proto.mouseupAsObservable = function(eventData) {
153+
return this.bindAsObservable('mouseup', eventData);
154+
};
155+
proto.resizeAsObservable = function(eventData) {
156+
return this.bindAsObservable('resize', eventData);
157+
};
158+
proto.scrollAsObservable = function(eventData) {
159+
return this.bindAsObservable('scroll', eventData);
160+
};
161+
proto.selectAsObservable = function(eventData) {
162+
return this.bindAsObservable('select', eventData);
163+
};
164+
proto.submitAsObservable = function(eventData) {
165+
return this.bindAsObservable('submit', eventData);
166+
};
167+
proto.unloadAsObservable = function(eventData) {
168+
return this.bindAsObservable('unload', eventData);
169+
};
170+
proto.oneAsObservable = function(eventType, eventData) {
171+
var parent = this;
172+
return observableCreateWithDisposable(function(observer) {
173+
var handler = function(eventObject) {
174+
parent.unbind(eventType, handler);
175+
observer.onNext(eventObject);
176+
observer.onCompleted();
177+
};
178+
parent.bind(eventType, eventData, handler);
179+
return dispoableEmpty;
180+
});
181+
};
182+
proto.readyAsObservable = function() {
183+
var parent = this;
184+
return observableCreateWithDisposable(function(observer) {
185+
var handler = function(eventObject) {
186+
observer.onNext(eventObject);
187+
};
188+
parent.ready(handler);
189+
return dispoableEmpty;
190+
});
191+
};
192+
proto.hideAsObservable = function(duration) {
193+
var subject = new asyncSubject();
194+
this.hide(duration, function() {
195+
subject.onNext(this);
196+
subject.onCompleted();
197+
});
198+
return subject;
199+
};
200+
proto.showAsObservable = function(duration) {
201+
var subject = new asyncSubject();
202+
this.show(duration, function() {
203+
subject.onNext(this);
204+
subject.onCompleted();
205+
});
206+
return subject;
207+
};
208+
proto.animateAsObservable = function(properties, duration, easing) {
209+
var subject = new asyncSubject();
210+
this.animate(properties, duration, easing, function() {
211+
subject.onNext(this);
212+
subject.onCompleted();
213+
});
214+
return subject;
215+
};
216+
proto.fadeInAsObservable = function(duration) {
217+
var subject = new asyncSubject();
218+
this.fadeIn(duration, function() {
219+
subject.onNext(this);
220+
subject.onCompleted();
221+
});
222+
return subject;
223+
};
224+
proto.fadeToAsObservable = function(duration, opacity) {
225+
var subject = new asyncSubject();
226+
this.fadeTo(duration, opacity, function() {
227+
subject.onNext(this);
228+
subject.onCompleted();
229+
});
230+
return subject;
231+
};
232+
proto.fadeOutAsObservable = function(duration) {
233+
var subject = new asyncSubject();
234+
this.fadeOut(duration, function() {
235+
subject.onNext(this);
236+
subject.onCompleted();
237+
});
238+
return subject;
239+
};
240+
proto.fadeToggleAsObservable = function(duration, easing) {
241+
var subject = new asyncSubject();
242+
this.fadeToggle(duration, easing, function() {
243+
subject.onNext(this);
244+
subject.onCompleted();
245+
});
246+
return subject;
247+
};
248+
proto.slideDownAsObservable = function(duration) {
249+
var subject = new asyncSubject();
250+
this.slideDown(duration, function() {
251+
subject.onNext(this);
252+
subject.onCompleted();
253+
});
254+
return subject;
255+
};
256+
proto.slideUpAsObservable = function(duration) {
257+
var subject = new asyncSubject();
258+
this.slideUp(duration, function() {
259+
subject.onNext(this);
260+
subject.onCompleted();
261+
});
262+
return subject;
263+
};
264+
proto.slideToggleAsObservable = function(duration) {
265+
var subject = new asyncSubject();
266+
this.slideToggle(duration, function() {
267+
subject.onNext(this);
268+
subject.onCompleted();
269+
});
270+
return subject;
271+
};
272+
proto.toggleAsObservable = function(duration, easing) {
273+
var subject = new asyncSubject();
274+
this.toggle(duration, easing, function() {
275+
subject.onNext(this);
276+
subject.onCompleted();
277+
});
278+
return subject;
279+
};
280+
var ajaxAsObservable = $.ajaxAsObservable = function(settings) {
281+
/// <summary>
282+
/// Perform an asynchronous HTTP (Ajax) request wrapping the jQuery ajax method in an Rx.AsyncSubject.
283+
/// &#10;2 - jQuery.ajaxAsObservable(settings)
284+
/// </summary>
285+
/// <param name="options" type="Object">
286+
/// A set of key/value pairs that configure the Ajax request. All settings are optional. A default can be set for any option with $.ajaxSetup(). See jQuery.ajax( settings ) below for a complete list of all settings.
287+
/// </param>
288+
var subject = new asyncSubject(), internalSettings = {};
289+
internalSettings.success = function(data, textStatus, jqXHR) {
290+
subject.onNext({ data: data, textStatus: textStatus, jqXHR: jqXHR });
291+
subject.onCompleted();
292+
};
293+
internalSettings.error = function(jqXHR, textStatus, errorThrown) {
294+
subject.onError({ jqXHR: jqXHR, textStatus: textStatus, errorThrown: errorThrown });
295+
};
296+
$.extend(true, internalSettings, settings);
297+
$.ajax(internalSettings);
298+
return subject;
299+
};
300+
$.getAsObservable = function(url, data, dataType) {
301+
return ajaxAsObservable({ url: url, dataType: dataType, data: data });
302+
};
303+
$.getJSONAsObservable = function(url, data) {
304+
/// <summary>
305+
/// Load JSON-encoded data from the server using a GET HTTP request.
306+
/// </summary>
307+
/// <param name="url" type="String">
308+
/// A string containing the URL to which the request is sent.
309+
/// </param>
310+
/// <param name="data" type="Object">
311+
/// A map or string that is sent to the server with the request.
312+
/// </param>
313+
return ajaxAsObservable({ url: url, dataType: 'json', data: data });
314+
};
315+
$.getScriptAsObservable = function(url) {
316+
/// <summary>
317+
/// Load a JavaScript file from the server using a GET HTTP request, then execute it. This wraps the existing jQuery.getScript method in an Rx.AsyncSubject.
318+
/// </summary>
319+
/// <param name="url" type="String">
320+
/// A string containing the URL to which the request is sent.
321+
/// </param>
322+
return ajaxAsObservable({ url: url, dataType: 'script'});
323+
};
324+
$.postAsObservable = function(url, data, dataType) {
325+
/// <summary>
326+
/// Load data from the server using a HTTP POST request, wrapping the jQuery.post request in an Rx.AsyncSubject.
327+
/// </summary>
328+
/// <param name="url" type="String">
329+
/// A string containing the URL to which the request is sent.
330+
/// </param>
331+
/// <param name="data" type="String">
332+
/// A map or string that is sent to the server with the request.
333+
/// </param>
334+
/// <param name="dataType" type="String">
335+
/// The type of data expected from the server. Default: Intelligent Guess (xml, json, script, or html).
336+
/// </param>
337+
return ajaxAsObservable({ url: url, dataType: dataType, data: data, type: 'POST'});
338+
};
339+
})(this, jQuery);

lib/rx.jquery.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,18 +277,16 @@
277277
});
278278
return subject;
279279
};
280-
var ajaxAsObservable = $.ajaxAsObservable = function(settings) {
280+
var ajaxAsObservable = $.ajaxAsObservable = function(settings) {
281281
var subject = new asyncSubject(), internalSettings = {};
282-
for (var k in settings) {
283-
internalSettings[k] = settings[k];
284-
}
285282
internalSettings.success = function(data, textStatus, jqXHR) {
286283
subject.onNext({ data: data, textStatus: textStatus, jqXHR: jqXHR });
287284
subject.onCompleted();
288285
};
289286
internalSettings.error = function(jqXHR, textStatus, errorThrown) {
290287
subject.onError({ jqXHR: jqXHR, textStatus: textStatus, errorThrown: errorThrown });
291288
};
289+
$.extend(true, internalSettings, settings);
292290
$.ajax(internalSettings);
293291
return subject;
294292
};

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This project provides Reactive Extensions for JavaScript (RxJS) bindings for jQu
66

77
## GETTING STARTED
88

9-
There are a number of ways to get started with L2O.js depending on your environment.
9+
There are a number of ways to get started with the jQuery Bindings for RxJS.
1010

1111
### Download the Source
1212

0 commit comments

Comments
 (0)