﻿jQuery.preloadCssImages = function(c) { c = jQuery.extend({ statusTextEl: null, statusBarEl: null, errorDelay: 999, simultaneousCacheLoading: 2 }, c); var a = [], f = 0, d = [], g, e; function i() { clearTimeout(e); if (d && d.length && d[f]) { f++; if (c.statusTextEl) { var j = (d[f]) ? "Now Loading: <span>" + d[f].split("/")[d[f].split("/").length - 1] : "Loading complete"; jQuery(c.statusTextEl).html('<span class="numLoaded">' + f + '</span> of <span class="numTotal">' + d.length + '</span> loaded (<span class="percentLoaded">' + (f / d.length * 100).toFixed(0) + '%</span>) <span class="currentImg">' + j + "</span></span>"); } if (c.statusBarEl) { var k = jQuery(c.statusBarEl).width(); jQuery(c.statusBarEl).css("background-position", -(k - (k * f / d.length).toFixed(0)) + "px 50%"); } h(); } } function h() { if (d && d.length && d[f]) { var j = new Image(); j.src = d[f]; if (!j.complete) { jQuery(j).bind("error load onreadystatechange", i); } else { i(); } e = setTimeout(i, c.errorDelay); } } function b(n, z) { var w = false, r = [], p = [], C; var o = n.length; while (o--) { var y = ""; if (z && z[o]) { C = z[o]; } else { var E = (n[o].href) ? n[o].href : "window.location.href"; var D = E.split("/"); D.pop(); C = D.join("/"); if (C) { C += "/"; } } var t = false; try { if (n[o].cssRules) { t = true; } } catch (B) { var A = B; } if (!t) { continue; } if (n[o].cssRules || n[o].rules) { g = (n[o].cssRules) ? n[o].cssRules : n[o].rules; var s = g.length; while (s--) { if (g[s].style && g[s].style.cssText) { var q = g[s].style.cssText; if (q.toLowerCase().indexOf("url") != -1) { y += q; } } else { if (g[s].styleSheet) { r.push(g[s].styleSheet); w = true; } } } } var F = y.match(/[^\("]+\.(gif|jpg|jpeg|png)/g); if (F) { var v = F.length; while (v--) { var k = (F[v].charAt(0) == "/" || F[v].match("://")) ? F[v] : C + F[v]; if (jQuery.inArray(k, d) == -1) { d.push(k); } } } if (!w && n[o].imports && n[o].imports.length) { for (var l = 0, j = n[o].imports.length; l < j; l++) { var x = n[o].imports[l].href; x = x.split("/"); x.pop(); x = x.join("/"); if (x) { x += "/"; } var m = (x.charAt(0) == "/" || x.match("://")) ? x : C + x; p.push(m); r.push(n[o].imports[l]); } } } if (r.length) { b(r, p); return false; } var u = c.simultaneousCacheLoading; while (u--) { setTimeout(h, u); } } b(document.styleSheets); return d; };
