-
Notifications
You must be signed in to change notification settings - Fork 1
/
jquery.remote-selector.js
30 lines (30 loc) · 1022 Bytes
/
jquery.remote-selector.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
(function ( $ ) {
$.remote = function(selectors) {
var deffereds = [];
selectors = selectors.split(',');
$.each(selectors, function(index, selector){
var deffered = new jQuery.Deferred();
deffereds.push(deffered);
var match = selector.match('(https?://[^ ]+)(?: ?(.*))?');
if (match.length)
{
var url = match[1];
var selector = match[2];
$.ajax({
url: 'http://dom-perignon.appspot.com/get?url=' + url,
dataType: 'jsonp'
}).then(function(response){
if (selector)
{
deffered.resolve($(response).find(selector));
}
else
{
deffered.resolve(response);
}
});
}
});
return $.when.apply(null, deffereds);
};
}( jQuery ));