pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

Javascript pastebin - collaborative debugging tool View Help


Posted by Greg-J on Sun 20 Jul 09:10
report abuse | download | new post

  1. jQuery.preloadCssImages = function(settings){
  2.         var settings = jQuery.extend({
  3.                 statusTextEl: null,
  4.                 statusBarEl: null
  5.         }, settings);
  6.        
  7.         var allImgs = [];
  8.         var k = 0;
  9.         var sheets = document.styleSheets;
  10.        
  11.         for(var i = 0; i<sheets.length; i++){
  12.                 var cssPile = '';
  13.                 var csshref = sheets[ i ].href ? sheets[ i ].href : 'window.location.href';
  14.                 var baseURLarr = csshref.split('/');
  15.                 baseURLarr.pop();
  16.                 var baseURL = baseURLarr.join('/');
  17.                 if(baseURL!==""){
  18.                                 baseURL+='/';
  19.                 }
  20.                 if(document.styleSheets[ i ].cssRules){
  21.                         var thisSheetRules = document.styleSheets[ i ].cssRules;
  22.                         for(var j = 0; j<thisSheetRules.length; j++){
  23.                                 cssPile+= thisSheetRules[j].cssText;
  24.                         }
  25.                 }
  26.                 else {
  27.                         cssPile+= document.styleSheets[ i ].cssText;
  28.                 }
  29.                
  30.                 var imgUrls = cssPile.match(/[^\(]+\.(gif|jpg|jpeg|png)/g);
  31.                 var loaded = 0;
  32.                 if(imgUrls !== null && imgUrls.length>0 && imgUrls !== ''){
  33.                         var arr = jQuery.makeArray(imgUrls);
  34.                         jQuery(arr).each(function(){
  35.                                 allImgs[ k ] = new Image();
  36.                                 allImgs[ k ].src = (this.charAt(0) == '/' || this.match('http://')) ? this : baseURL + this;
  37.                                
  38.                                 $(allImgs[ k ]).load(function(){
  39.                                                 loaded++;
  40.                                                 if(settings.statusTextEl) {$(settings.statusTextEl).html('<span class="numLoaded">'+loaded+'</span> of <span class="numTotal">'+allImgs.length+'</span> loaded (<span class="percentLoaded">'+(loaded/allImgs.length*100).toFixed(0)+'%</span>) <span class="currentImg">Now Loading: <span>'+allImgs[loaded-1].src.split('/')[allImgs[loaded-1].src.split('/').length-1]+'</span></span>');
  41.                                         }
  42.                                         if(settings.statusBarEl) {
  43.                                                 var barWidth = $(settings.statusBarEl).width();
  44.                                                 $(settings.statusBarEl).css('background-position', -(barWidth-(barWidth*loaded/allImgs.length).toFixed(0))+'px 50%');
  45.                                         }
  46.                                 });
  47.                                 k++;
  48.                         });
  49.                 }
  50.         }
  51.         return allImgs;
  52. };

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me so that I can delete my post