Download da versão 0.98 jquery.include.js 1.4 KB (gzip)
Aplicando:
Demo Dialog (dialog ui)
Demo FancyBox
Segue o plugin descompactado em versão de testes:
; jQuery.include || (function($) {
$.include = function(url,callback,options){
var options = $.extend({ target: null, elements: null, eventType: '', count: 0, dataType: [], extension: ''}, options);
if(typeof url=='object') {
if ( typeof(url[0].url) != 'undefined' ) {
while (url.length) {
var objUrl = url.shift();
$.include(objUrl.url, objUrl.success);
}
return false;
}
var dataType = $.extend([], options.dataType);
options.count = 1;
if ($.isFunction(callback))
$.include.call.push({success:callback, target:options.target, elements:options.elements, eventType:options.eventType});
if (typeof url.length != 'undefined') {
$.include.count.i+=url.length;
while (url.length) {
options.dataType = dataType.shift();
$.include(url.shift()+'', null, options);
}
} else {
$.each(url, function(){$.include.count.i++});
$.each(url, function(index, element) {
options.dataType = dataType.shift();
$.include(index, element, options);
});
}
} else {
if($.inArray(url, $.include.past)<0){
$.include.past.push(url);
if ((/.js$/.test(url) && options.dataType == '') || (options.dataType == 'js')) {
$.ajax({
type: 'GET',
url: ((/http$/.test(url))?'':$.include.path.js)+url+'',
dataType: 'script',
cache: true,
async: false,
success: function() {
$.include.callback(callback, this, $(this), options.count)
}
});
} else if ((/.css$/.test(url) && options.dataType == '') || (options.dataType == 'css')) {
var link = document.createElement('link'),
url = ((/http$/.test(url))?'':$.include.path.css)+url+'';
$(link)
.attr({'href':url,'rel':'stylesheet','type':'text/css'});
document.body.appendChild(link);
$(document).ready(function() {
$.include.callback(callback, $('link[href="'+url+'"]'), null, options.count)
});
} else {
var img = $.include.img.length;
$.include.img.push({
img :
$('
')
.attr('src',((/http$/.test(url))?'':$.include.path.img)+url+'')
.bind('load readystatechange', function() {
$(this).unbind('load readystatechange');
$.include.callback(callback, this, $(this), options.count) })
});
}
} else {
callback(callback, options.target, options.elements, options.count);
}
}
};
$.extend(
$.include,{
past:[],
path:{js:'',css:'',img:''},
count:{'i':0,'o':0},
call:[],
callback: function (callback, target, elements, count) {
$.include.count.o += count;
if (typeof callback=='function')
callback(target, elements);
if ($.include.count.o==$.include.count.i) {
while($.include.call.length) {
var exe = $.include.call.shift();
$(exe.elements).unbind(exe.eventType);
exe.success(exe.target, exe.elements, exe.eventType);
}
}
},
img:[]
}
);
$.fn.include = function(eventType, options) {
var selectors = $(this);
if (typeof options != 'undefined') {
$(this).one(eventType+'', function() {
if ($.isFunction(options.complete))
options.complete(this, selectors);
$.include(options.url, options.success, { target: this, elements: selectors, eventType: options.eventType, dataType: options.dataType});
return false;
});
return false;
} else {
$.include(eventType.url, eventType.success, { target: this, elements: selectors });
}
};
})(jQuery);


