1/* 2 * jPreLoader - jQuery plugin 3 * Create a Loading Screen to preload images and content for you website 4 * 5 * Name: jPreLoader.js 6 * Author: Kenny Ooi - http://www.inwebson.com 7 * Date: July 11, 2012 8 * Version: 2.1 9 * Example: http://www.inwebson.com/demo/jpreloader-v2/ 10 * 11 */ 12 13(function ($) { 14 var items = new Array(), 15 errors = new Array(), 16 onComplete = function () { 17 }, 18 current = -1; 19 20 var jpreOptions = { 21 splashVPos: '35%', 22 loaderVPos: '75%', 23 splashID: '#jpreContent', 24 showSplash: true, 25 showPercentage: true, 26 autoClose: true, 27 closeBtnText: 'Start!', 28 onetimeLoad: false, 29 debugMode: false, 30 splashFunction: function () { 31 } 32 } 33 34 //cookie 35 var getCookie = function () { 36 if (jpreOptions.onetimeLoad) { 37 var cookies = document.cookie.split('; '); 38 for (var i = 0, parts; (parts = cookies[i] && cookies[i].split('=')); i++) { 39 if ((parts.shift()) === "jpreLoader") { 40 return (parts.join('=')); 41 } 42 } 43 return false; 44 } else { 45 return false; 46 } 47 48 } 49 var setCookie = function (expires) { 50 if (jpreOptions.onetimeLoad) { 51 var exdate = new Date(); 52 exdate.setDate(exdate.getDate() + expires); 53 var c_value = ((expires == null) ? "" : "expires=" + exdate.toUTCString()); 54 document.cookie = "jpreLoader=loaded; " + c_value; 55 } 56 } 57 58 //get all images from css and <img> tag 59 var getImages = function (element) { 60 $(element).find('*:not(script)').each(function () { 61 var url = ""; 62 63 if ($(this).css('background-image').indexOf('none') == -1 && $(this).css('background-image').indexOf('-gradient') == -1) { 64 url = $(this).css('background-image'); 65 if (url.indexOf('url') != -1) { 66 var temp = url.match(/url\((.*?)\)/); 67 url = temp[1].replace(/\"/g, ''); 68 } 69 } else if ($(this).get(0).nodeName.toLowerCase() == 'img' && typeof($(this).attr('src')) != 'undefined') { 70 url = $(this).attr('src'); 71 } 72 73 if (url.length > 0) { 74 items.push(url); 75 } 76 }); 77 } 78 79 var getVideos = function (element) { 80 $(element).find('video').each(function (num, el) { 81 el.load(); 82 el.onloadeddata = function () { 83 completeLoading(); 84 }; 85 }); 86 }; 87 88 var getIframes = function (element) { 89 $(element).find('iframe').each(function (num, el) { 90 $(el).ready(function () { 91 completeLoading(); 92 }); 93 }); 94 }; 95 96 var per = 0, curPer = 0, 97 ticks = 5; 98 99 var changePercentage = function () { 100 if (curPer < per) { 101 curPer += parseInt((per - curPer) / ticks); 102 curPer = Math.min(curPer, 100); 103 ticks--; 104 } 105 $('.preloader .percentage').text(curPer); 106 $('#circle').circleProgress('value', curPer / 100); 107 if (curPer < 100) { 108 setTimeout(function () { 109 changePercentage(); 110 }, 100); 111 } 112 }; 113 114 //create preloaded image 115 var preloading = function () { 116 completeLoading(); 117 for (var i = 0; i < items.length; i++) { 118 if (loadImg(items[i])); 119 } 120 changePercentage(); 121 } 122 var loadImg = function (url) { 123 var imgLoad = new Image(); 124 $(imgLoad) 125 .load(function () { 126 completeLoading(); 127 }) 128 .error(function () { 129 errors.push($(this).attr('src')); 130 completeLoading(); 131 }) 132 .attr('src', url); 133 }; 134 135 //update progress bar once image loaded 136 var completeLoading = function () { 137 current++; 138 // var length = items.length + $('video').length + $('iframe').length; 139 var length = items.length; 140 if (length == 0) { 141 current++; 142 } 143 144 per = Math.round((current / length) * 100); 145 // $('.preloader .line .inner').stop().animate({ 146 // width: per + '%' 147 // }, 500, 'linear'); 148 149 if (jpreOptions.showPercentage) { 150 // $('.preloader .percentage').text(per); 151 ticks = 7; 152 } 153 154 //if all images loaded 155 if (current >= length) { 156 current = length;
157 setCookie(); //create cookie 158 159 if (jpreOptions.showPercentage) { 160 per = 100; 161 // $('.preloader .percentage').text("100"); 162 } 163 164 //fire debug mode 165 if (jpreOptions.debugMode) { 166 var error = debug(); 167 } 168 169 //max progress bar 170 // $(jBar).stop().animate({ 171 // width: '100%' 172 // }, 500, 'linear', function() { 173 // }); 174 loadComplete(); 175 176 } 177 } 178 179 var loadComplete = function () { 180 onComplete(); //callback function 181 }; 182 183 //debug mode 184 var debug = function () { 185 if (errors.length > 0) { 186 var str = 'ERROR - IMAGE FILES MISSING!!!\n\r' 187 str += errors.length + ' image files cound not be found. \n\r'; 188 str += 'Please check your image paths and filenames:\n\r'; 189 for (var i = 0; i < errors.length; i++) { 190 str += '- ' + errors[i] + '\n\r'; 191 } 192 return true; 193 } else { 194 return false; 195 } 196 } 197 198 $.fn.jpreLoader = function (options, callback) { 199 if (options) { 200 $.extend(jpreOptions, options); 201 } 202 if (typeof callback == 'function') { 203 onComplete = callback; 204 } 205 206 //show preloader once JS loaded 207 $('body').css({ 208 'display': 'block' 209 }); 210 211 return this.each(function () { 212 if (!(getCookie())) { 213 getImages(this); 214 // getVideos(this); 215 // getIframes(this); 216 217 preloading(); 218 } 219 else { //onetime load / cookie is set 220 $(jpreOptions.splashID).remove(); 221 onComplete(); 222 } 223 }); 224 }; 225 226})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.