Heuristic ranking analysis
[contractdashboard.git] / lib / pChart2.1.0 / examples / delayedLoader / delayedLoading.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
 /*
     delayedLoader - JS to delay out of sight pictures rendering
 
     Version     : 2.0.2
     Made by     : Jean-Damien POGOLOTTI
     Last Update : 10/12/10
 
     This file can be distributed under the license you can find at :
 
                       http://www.pchart.net/license
 
     You can find the whole class documentation on the pChart web site.
 */
 
 var PictureCache  = new Array();
 var PictureCount  = 0;
 var WaitPicture   = "wait.gif";
 var DivClassName  = "pChart";
 var DefaultWidth  = 70;
 var DefaultHeight = 230;
 var DefaultAlt    = "pChart rendered picture";
 
 
 /* Do the DOM document processing */
 function loaderInit()
  {
   WindowSize   = getWindowSize();
   WindowHeight = WindowSize[1];
   Offset       = getScrollXY();
   HeightOffset = Offset[1];
 
   /* Enumerate the tags */
   Links = document.getElementsByTagName("a");   
   for (i = 0; i < Links.length; i++)   
    {   
     className = Links[i].className;   
 
     if ( className == DivClassName )   
      {   
       ObjectWidth  = Links[i].getAttribute("data-pchart-width");
       ObjectHeight = Links[i].getAttribute("data-pchart-height");
       ObjectID     = Links[i].id;
       ObjectTop    = Links[i].offsetTop;
       ObjectURL    = Links[i].href;
       ObjectAlt    = Links[i].getAttribute("data-pchart-alt");
 
       if ( ObjectWidth == null )  { ObjectWidth  = DefaultWidth; }
       if ( ObjectHeight == null ) { ObjectHeight = DefaultHeight; }
       if ( ObjectAlt == null )    { ObjectAlt    = DefaultAlt; }
 
       if (ObjectID == "") { ObjectID = "pChart-"+i; Links[i].id = ObjectID; }
 
       PictureCache[PictureCount]    = new Array();
       PictureCache[PictureCount][0] = ObjectID;
       PictureCache[PictureCount][1] = ObjectTop;
       PictureCache[PictureCount][2] = ObjectURL;
       PictureCache[PictureCount][3] = ObjectAlt;
       PictureCache[PictureCount][4] = ObjectWidth;
       PictureCache[PictureCount][5] = ObjectHeight;
 
       PictureCount++;
      }   
    }   
 
   /* Replace the <A> tags by <DIV> ones and attach the loader */
   for(i=0;i<PictureCount;i++)
    {
     ATag    = document.getElementById(PictureCache[i][0]);
     DivTag  = document.createElement("div");
     DivID   = "pChart-Div"+i; PictureCache[i][0] = DivID;
 
     DivTag.setAttribute("id", DivID);
     DivTag.style.width  = PictureCache[i][4];
     DivTag.style.height = PictureCache[i][5];
     DivTag.style.backgroundColor = "#E0E0E0";
 
     DivTag2  = ATag.parentNode.replaceChild(DivTag, ATag);
 
     DivTop = DivTag.offsetTop;
     PictureCache[i][1] = DivTop;
 
     changeOpac(50, i);
     changeContent("<img src='"+WaitPicture+"' width=24 height=24 alt=''/>",i);
 
     if ( HeightOffset + WindowHeight > PictureCache[i][1] ) { triggerVisible(i); }
    }
  }
 
 /* Replace the contents of the delayed loading DIV */
 function changeContent(html, id)
  { DivID = PictureCache[id][0]; document.getElementById(DivID).innerHTML = html; }
 
 /* Trigger the picture rendering when the pChart DIV became visible */
 function triggerVisible(PictureID)
  {
   if ( !PictureCache[PictureID][6] == true )
    {
     PictureCache[PictureID][6] = true;
     ajaxRender(PictureCache[PictureID][2],PictureID);
    }
  }
 
 /* Catch the navigator window scrolling event */
 function scrollEvent()
  {
   WindowSize   = getWindowSize();
   WindowHeight = WindowSize[1];
   Offset       = getScrollXY();
   HeightOffset = Offset[1];
 
   for(i=0;i<=PictureCount-1;i++) { if ( HeightOffset + WindowHeight > PictureCache[i][1] ) { triggerVisible(i); } }
  }
 
 /* Cross browser X/Y window offset gatherer */
 function getScrollXY()
  {
   var scrOfX = 0, scrOfY = 0;
 
   if( typeof( window.pageYOffset ) == 'number' )
    { scrOfY = window.pageYOffset; scrOfX = window.pageXOffset; }
   else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) )
    { scrOfY = document.body.scrollTop; scrOfX = document.body.scrollLeft; }
   else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) )
    { scrOfY = document.documentElement.scrollTop; scrOfX = document.documentElement.scrollLeft; }
 
   return [ scrOfX, scrOfY ];
  }
 
 /* Cross browser X/Y window size gatherer */
 function getWindowSize()
  {
   var myWidth = 0, myHeight = 0;
 
   if( typeof( window.innerWidth ) == 'number' )
    { myWidth = window.innerWidth; myHeight = window.innerHeight; }
   else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
    { myWidth = document.documentElement.clientWidth; myHeight = document.documentElement.clientHeight; }
   else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
    { myWidth = document.body.clientWidth; myHeight = document.body.clientHeight; }
 
   return [ myWidth, myHeight ];
  }
 
 /* Cross browser alpha transparency changer */
 function changeOpac(opacity, id)   
  {
   DivID = PictureCache[id][0];
 
   var object = document.getElementById(DivID).style;   
   object.opacity = (opacity / 100);   
   object.MozOpacity = (opacity / 100);   
   object.KhtmlOpacity = (opacity / 100);   
   object.filter = "alpha(opacity=" + opacity + ")";   
  }   
 
 /* Shade in-out function */
 function opacity(id, opacStart, opacEnd, millisec)
  {
   var speed = Math.round(millisec / 100);
   var timer = 0;
 
   if(opacStart > opacEnd)
    {
     for(i = opacStart; i >= opacEnd; i--)
      {
       setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
       timer++;
      }
    }
   else if(opacStart < opacEnd)
    {
     for(i = opacStart; i <= opacEnd; i++)
      {
       setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
       timer++;
      }
    }
  }
 
 /* Start the loader */
 function StartFade(PictureID)
  {
   Loader     = new Image();
   URL        = PictureCache[PictureID][2];
   Loader.src = URL;   
   setTimeout("CheckLoadingStatus("+PictureID+")", 200);   
  }
 
 /* check the picture loading status */
 function CheckLoadingStatus(PictureID)   
  {
   DivID = PictureCache[PictureID][0];
   URL   = PictureCache[PictureID][2];
   Alt   = PictureCache[PictureID][3];
 
   if ( Loader.complete == true )   
    {
     changeOpac(0, PictureID);
     HTMLResult = "<center><img src='" + URL + "' alt='"+Alt+"'/></center>";
     document.getElementById(DivID).innerHTML = HTMLResult;
 
     opacity(PictureID,0,100,100);
    }
   else  
    setTimeout("CheckLoadingStatus("+PictureID+")", 200);   
  }   
 
 /* Compute the pChart picture in background */
 function ajaxRender(URL,PictureID)
  {
   var xmlhttp=false;   
   /*@cc_on @*/  
   /*@if (@_jscript_version >= 5)  
    try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { xmlhttp = false; } }  
   @end @*/  
  
   if (!xmlhttp && typeof XMLHttpRequest!='undefined')   
    { try { xmlhttp = new XMLHttpRequest(); } catch (e) { xmlhttp=false; } }   
  
   if (!xmlhttp && window.createRequest)   
    { try { xmlhttp = window.createRequest(); } catch (e) { xmlhttp=false; } }   
  
   xmlhttp.open("GET", URL,true);
 
   xmlhttp.onreadystatechange=function()
    { if (xmlhttp.readyState==4) { StartFade(PictureID); } }   
   xmlhttp.send(null)   
  }