Download da versão 0.95 jquery.include.js 1.2 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}, options);
if(typeof url=='object') {
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) {
$.include(url.shift()+'', null, options);
}
} else {
$.each(url, function(){$.include.count.i++});
$.each(url, function(index, element) {
$.include(index, element, options);
});
}
} else {
if($.inArray(url, $.include.past)<0){
$.include.past.push(url);
if (/.js$/.test(url)) {
$.ajax({
type: 'get',
url: url+'',
dataType: 'script',
cache: true,
success: function() { $.include.callback(callback, this, $(this), options.count) }
});
} else if (/.css$/.test(url)) {
var link = document.createElement('link');
$(link)
.attr({'href':url+'','rel':'stylesheet','type':'text/css'})
.ready(function() { $.include.callback(callback, this, $(this), options.count) });
document.body.appendChild(link);
} else {
var img = $.include.img.length;
$.include.img.push({ img : $('
').attr('src',url+'').bind('load readystatechange', function() { $.include.callback(callback, this, $(this), options.count) }) });
}
} else {
callback(callback, options.target, options.elements, options.count);
}
}
};
$.extend(
$.include,{
past:[],
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});
return false;
});
return false;
} else {
$.include(eventType.url, eventType.success, { target: this, elements: selectors });
}
};
})(jQuery);
// Loader Plugin
(function($) {
$.fn.isIE6 = function(callback) {
($.browser.msie && $.browser.version.substr(0,1) == 6 && typeof callback == "function")
?callback($(this))
:null;
try{document.execCommand("BackgroundImageCache", false, true)}catch(err){};
return this;
};
$.extend($.include, {
loadingBG : 'include-loader.gif',
loading : function(type) {
if($('#jquery-include-loader').size()<1) {
$.include($.include.loadingBG);
$('
')
.attr('id','jquery-include-loader')
.css({
'-moz-border-radius':'10px',
'-webkit-border-radius':'10px',
'background':'url('+$.include.loadingBG+') no-repeat 50% 50% #333',
'border':'2px solid #666',
'float':'left',
'font-size':'0',
'left':'50%',
'padding':'25px',
'position':'fixed',
'top':'50%'
})
.isIE6(function(obj){
$(obj).css({'position':'absolute'});
$(window).scroll(function(){
$('#jquery-include-loader').css({'margin': $('html').scrollTop()+'px 0 0 '+$('html').scrollLeft()+'px'});
});
})
.hide()
.appendTo('body');
}
if (type=='show') {
$('#jquery-include-loader').show();
} else if (type=='hide') {
$('#jquery-include-loader').fadeOut();
}
}
}
);
})(jQuery);