-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.multipleload.js
executable file
·68 lines (66 loc) · 2.5 KB
/
jquery.multipleload.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
/**
* Copyright (c) 2011 - 2012, Stephen Lee <[email protected]>
* All rights reserved.
* @link https://lightworx.io
*
* Licensed under the BSD and MIT Licenses:
* The plugin multipleload get one or more DOM node(s) from specified url,
* to replace the specified container objects.
*
* The first step, multipleload will to set a hidden div as a temporary container, if it does not exist.
* and the temporary container id defaults to '#filter_temp_container', just like the following:
* <div id="filter_temp_container" style="display:none;"></div>
* as you can see, the attribute style value is "display:none;", means that's a hidden container,
* and you may need to redefine the container id,(e.g. may current id have naming conflicts with others).
* you should specify in the $.multipleLoad.load(), just like the following:
*
* @example:
* $.multipleLoad.load({container:'#another_filter_temp_container'}); // redefine a new temporary container.
*
* And the second step, we should to define the selector, the selector defined which nodes is we needed.
* you can specify one or more node(s), when you set multiple nodes, then it should use the separator ',' comma to separate every node.
*
* @example:
* $.multipleLoad.load({selector:"#main,#header"});
*
* And the next, to set the web page url.
*
* @example:
* $.multipleLoad.load({url:"/"});
*
* The final step, to set the replaceObjects, if the replaceObjects have no defined,
* that will be replace the default selector, if it is exist.
*
* The following code is a complete example:
* @example:
* var replaceObjects = Array("#main","#header");
* $.multipleLoad.load({url:'/the_page_url',container:'#another_filter_temp_container',replaceObjects:replaceObjects,selector:"#main,#header"});
*/
;(function($){
jQuery.multipleLoad = {
load : function(parameters)
{
defaults = {
container:'#filter_temp_container',
url:'/',
selector:'#header,#main',
replaceObjects:null
};
jQuery.extend(defaults,parameters);
if($(defaults.container).length==0)
{
$('body').append('<div id="'+defaults.container.replace('#','')+'" style="display:none;"></div>');
}
if(defaults.replaceObjects!=null)
{
var selector = defaults.selector.split(',');
$(defaults.container).load(defaults.url+" "+defaults.selector,function(){
$.each(defaults.replaceObjects,function(i,n){
$(n).html($(defaults.container+' > '+selector.shift()).html());
});
$(defaults.container).html('');
});
}
}
};
})(jQuery);