-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathloader.jquery.min.js
9 lines (9 loc) · 4.22 KB
/
loader.jquery.min.js
1
2
3
4
5
6
7
8
9
//
// loader.jquery.js
// Loader Plugin Version 1.0
// Loader Plugin for preloading images and background images
//
// Created by Robbie Bardijn on 2012-05-22.
// Copyright 2012 Robbie Bardijn. All rights reserved.
//
(function(e){e.fn.preload=function(t,n){if(n===undefined&&t===undefined)throw"ERROR : preload function must be given at least one parrameter";if(typeof t!="string"){n=t;t=undefined}if(typeof n=="object"){if(n.completeCallBack===undefined||n.completeCallBack instanceof Function==0)throw"you must specify a completeCallBack key in a callBackObj object, the value of this key Must be a function";if(n.startCallBack instanceof Function==0&&n.startCallBack!==undefined)throw"If you specify a startCallBack key, the value of this key Must be a function";n.startCallBack===undefined&&(n.startCallBack=function(){});if(n.endCallBack instanceof Function==0&&n.endCallBack!==undefined)throw"If you specify a endCallBack key, the value of this key Must be a function";n.endCallBack===undefined&&(n.endCallBack=function(){})}n instanceof Function&&(n={completeCallBack:n,startCallBack:function(){},endCallBack:function(){}});if(this.children().length===0){n.startCallBack(this);if(t==="image"&&this.get(0).nodeName.toLowerCase()==="img"){var r=this,i=new Image;i.addEventListener?i.addEventListener("load",function(){n.completeCallBack(r);n.endCallBack(r)},!1):i.attachEvent&&i.attachEvent("onload",function(){n.completeCallBack(r);n.endCallBack(r)});i.src=this[0].src}if(t==="background-image")if(this.css("background-image")!=="none"&&this.css("background-image").indexOf("url")!==-1){var r=this,i=new Image;i.addEventListener?i.addEventListener("load",function(){n.completeCallBack(r);n.endCallBack(r)},!1):i.attachEvent&&i.attachEvent("onload",function(){n.completeCallBack(r);n.endCallBack(r)});var s=r.css("background-image").replace(/(\"|\'|\ )/g,""),o=s.split(",");for(var u=0;u<o.length;u++)i.src=o[u].substring(4,o[u].length-1)}else{n.completeCallBack(this);n.endCallBack(this)}if(t===undefined){if(this.get(0).nodeName.toLowerCase()==="img"){var r=this,i=new Image;i.addEventListener?i.addEventListener("load",function(){n.completeCallBack(r);n.endCallBack(r)},!1):i.attachEvent&&i.attachEvent("onload",function(){n.completeCallBack(r);n.endCallBack(r)});i.src=this[0].src}if(this.css("background-image")!=="none"&&this.css("background-image").indexOf("url")!==-1){var r=this,i=new Image;i.addEventListener?i.addEventListener("load",function(){n.completeCallBack(r);n.endCallBack(r)},!1):i.attachEvent&&i.attachEvent("onload",function(){n.completeCallBack(r);n.endCallBack(r)});var s=r.css("background-image").replace(/(\"|\'|\ )/g,""),o=s.split(",");for(var u=0;u<o.length;u++)i.src=o[u].substring(4,o[u].length-1)}else{n.completeCallBack(this);n.endCallBack(this)}}}else{if(t==="image"){var a=this.find("img");n.startCallBack(a);var f=0;a.each(function(t){function s(){f+=1;n.completeCallBack(r);a.length===f&&n.endCallBack(a)}var r=e(this),i=new Image;i.addEventListener?i.addEventListener("load",s,!1):i.attachEvent&&i.attachEvent("onload",s);i.src=r.context.src})}if(t==="background-image"){var a=this.find("*").filter(function(){var t;e(this).css("background-image")!=="none"&&e(this).css("background-image").indexOf("url")!==-1?t=!0:t=!1;return t});n.startCallBack(a);var f=0;a.each(function(t){function s(){f+=1;n.completeCallBack(r);a.length===f&&n.endCallBack(a)}var r=e(this),i=new Image;i.addEventListener?i.addEventListener("load",s,!1):i.attachEvent&&i.attachEvent("onload",s);var o=r.css("background-image").replace(/(\"|\'|\ )/g,""),u=o.split(",");for(var l=0;l<u.length;l++)i.src=u[l].substring(4,u[l].length-1)})}if(t===undefined){var l=this.find("img"),c=this.find("*").filter(function(){var t;e(this).css("background-image")!=="none"&&e(this).css("background-image").indexOf("url")!==-1?t=!0:t=!1;return t}),a=l.add(c);n.startCallBack(a);var f=0;a.each(function(t){function s(){f+=1;n.completeCallBack(r);a.length===f&&n.endCallBack(a)}var r=e(this),i=new Image;i.addEventListener?i.addEventListener("load",s,!1):i.attachEvent&&i.attachEvent("onload",s);if(r.get(0).nodeName.toLowerCase()==="img")i.src=r.context.src;else{var o=r.css("background-image").replace(/(\"|\'|\ )/g,""),u=o.split(",");for(var l=0;l<u.length;l++)i.src=u[l].substring(4,u[l].length-1)}})}}}})(jQuery);