BVB Source Codes

Easy website system v2.0 Show ImageLoader.js Source code

Return Download Easy website system v2.0: download ImageLoader.js Source code - Download Easy website system v2.0 Source code - Type:.js
  1. //*+----------------------------------------------
  2. //* ImageLoader.js
  3. //* To load outside images.
  4. //* Copyright(C) By Michael Chen(www.jzchen.net)
  5. //*-----------------------------------------------
  6.  
  7. /****************************************************************************
  8.  * ImageLoader, v1.2
  9.  * To load outside images.
  10.  * I design this Class for preloading the images. Initially, I use 'this' but
  11.  *   faild. So I rewrite it as a static class. any body can give some help in
  12.  *   setTimeout("this.somefunc()") please mail me at [email]jzchen@jzchen.net[/email]
  13.  *
  14.  * Usage:     ImageLoader.add("a.gif", "b.gif", "c.jpg", ...); // add others..
  15.  *            ImageLoader.onProgressChange = function() {...}
  16.  *            ImageLoader.onLoadFinish = function() {...}
  17.  *            ImageLoader.onTimeOut = somefunction;
  18.  *            ImageLoader.startLoad();
  19.  ****************************************************************************/
  20.  
  21. function ImageLoader() {}
  22.  
  23. // Internal varibles definition
  24. ImageLoader._preImages = new Array();
  25. ImageLoader._imageUrlBuffer = new Array();
  26. ImageLoader._currentID = 0;
  27. ImageLoader._loaded = new Array();
  28. ImageLoader._loadedNum = 0;
  29. ImageLoader._currentLoading = "";
  30. ImageLoader._timeOut = 30 * 1000;
  31. ImageLoader._timeElapsed = 0;
  32. ImageLoader._checkInterval = 50;
  33.  
  34. // Event simulation
  35. ImageLoader.onProgressChange = new Function();
  36. ImageLoader.onLoadFinish = new Function();
  37. ImageLoader.onTimeOut = new Function();
  38.  
  39. /**
  40. * Add images to the image array
  41. * @param image1, image2, ...
  42. * @return none
  43. */
  44. ImageLoader.add = function() {
  45.     for (var i = ImageLoader._currentID; i < arguments.length; ImageLoader._currentID++,i++) {
  46.         if (arguments[i] != null || arguments[i] != "") {
  47.             ImageLoader._imageUrlBuffer[i] = arguments[i];
  48.         }
  49.     }
  50. }
  51.    
  52. /**
  53. * Get the Resouces count to be loaded
  54. * @param none
  55. * @return the number of resources to load.
  56. */
  57. ImageLoader.getResourceCount = function() {
  58.     return ImageLoader._imageUrlBuffer.length;
  59. }
  60.  
  61. /**
  62. * Get the  count of current loaded.
  63. * @param none
  64. * @return long the number of images that current loaded
  65. */
  66. ImageLoader.getLoadedCount = function() {
  67.     return ImageLoader._loadedNum;
  68. }
  69.  
  70. /**
  71. * Get the current loading image url
  72. * @param none
  73. * @return string the url of the current loading image.
  74. */
  75. ImageLoader.getCurrentLoading = function() {
  76.     return ImageLoader._currentLoading;
  77. }
  78.  
  79. /**
  80. * Set the timeout value. initial is 30 seconds.
  81. * @param long millisecond time
  82. * @return none
  83. */
  84. ImageLoader.setTimeOut = function(ts) {
  85.     ImageLoader._timeOut = ts;
  86. }
  87.  
  88. /**
  89. * Get the timeout value
  90. * @param none
  91. * @return int the timeout value
  92. */
  93. ImageLoader.getTimeOut = function() {
  94.     return ImageLoader._timeOut;
  95. }
  96.  
  97. /**
  98. * Start to load the images.
  99. * @param none
  100. * @return none
  101. */
  102. ImageLoader.startLoad = function() {
  103.     for (var i = 0; i < ImageLoader._imageUrlBuffer.length; i++) {
  104.         ImageLoader._preImages[i] = new Image();
  105.         ImageLoader._preImages[i].src = ImageLoader._imageUrlBuffer[i];
  106.         ImageLoader._loaded[i] = false;
  107.     }
  108.     ImageLoader.checkLoad();
  109. }
  110.  
  111. /*-
  112. * checkLoad
  113. * Internal use only.
  114. * Do not use it directly. otherwise will encount an error.
  115. */
  116. ImageLoader.checkLoad = function() {
  117.     if (ImageLoader._loadedNum == ImageLoader._preImages.length) {
  118.         ImageLoader.onLoadFinish();
  119.         return;
  120.     }
  121.  
  122.     if (ImageLoader._timeElapsed >= ImageLoader._timeOut) {
  123.         ImageLoader.onTimeOut();
  124.         return;
  125.     }
  126.  
  127.     for (i = 0; i < ImageLoader._preImages.length; i++) {
  128.         if (ImageLoader._loaded[i] == false && ImageLoader._preImages[i].complete) {
  129.             ImageLoader._loaded[i] = true;
  130.             ImageLoader._currentLoading = ImageLoader._imageUrlBuffer[i];
  131.             ImageLoader._loadedNum++;
  132.             ImageLoader.onProgressChange();
  133.         }
  134.     }
  135.    
  136.     ImageLoader._timeElapsed += ImageLoader._checkInterval;
  137.  
  138.     setTimeout("ImageLoader.checkLoad()", ImageLoader._checkInterval);
  139. }
downloadImageLoader.js Source code - Download Easy website system v2.0 Source code
Related Source Codes/Software:
Good business mall v2.0 open source edition - Good business, open source shopping mall, which is... 2016-10-23
Desert arashi v0.1.2 file operations procedures - Desert arashi file operations procedures is a simp... 2016-10-23
Ali cloud storage v1.1 PHP file upload system root directory - Aliyun stored SWFUPLOAD a simple file upload syste... 2016-10-23
Qr code generation V1.1 online - Directions for use: 2016-10-23
Short url program V1.2 (with black and white list function) - This short url program has three features: 2016-10-22
Emlog for SAE v4.2.1 - Emlog for SAE is suitable for SAE emlog used modif... 2016-10-23
Food science and technology chain edition v1.1 online reservation system - Treat chain version of the main functions of the o... 2016-10-23
MyProber PHP 0.26 a probe - MyProber v0.26 2016-10-23
Project management software KisProject v1.0.3 - Kis (Keep it simple) is a free WEB-based team coll... 2016-10-23
HP fetion automatic daily weather forecast v1.0 - HP fetion daily automated weather main uses 1. ac... 2016-10-23
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top