/[webpac2]/trunk/web/iwf/iwfajax.js
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /trunk/web/iwf/iwfajax.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 66 - (hide annotations)
Wed Nov 16 15:33:08 2005 UTC (18 years, 6 months ago) by dpavlin
File MIME type: text/cpp
File size: 22858 byte(s)
 r8899@llin:  dpavlin | 2005-11-16 16:32:37 +0100
 I have doubts about this fix -- elParent.tagName

1 dpavlin 55 // =========================================================================
2     /// IWF - Interactive Website Framework. Javascript library for creating
3     /// responsive thin client interfaces.
4     ///
5     /// Copyright (C) 2005 Brock Weaver brockweaver@users.sourceforge.net
6     ///
7     /// This library is free software; you can redistribute it and/or modify
8     /// it under the terms of the GNU Lesser General Public License as published
9     /// by the Free Software Foundation; either version 2.1 of the License, or
10     /// (at your option) any later version.
11     ///
12     /// This library is distributed in the hope that it will be useful, but
13     /// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14     /// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15     /// License for more details.
16     ///
17     /// You should have received a copy of the GNU Lesser General Public License
18     /// along with this library; if not, write to the Free Software Foundation,
19     /// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20     ///
21     /// Brock Weaver
22     /// brockweaver@users.sourceforge.net
23     /// 1605 NW Maple Pl
24     /// Ankeny, IA 50021
25     ///
26     //! http://iwf.sourceforge.net/
27     // --------------------------------------------------------------------------
28     //! NOTE: To minimize file size, strip all fluffy comments (except the LGPL, of course!)
29     //! using the following regex (global flag and multiline on):
30     //! ^\t*//([^/!].*|$)
31 dpavlin 46 //
32 dpavlin 55 // This reduces file size by about 30%, give or take.
33 dpavlin 46 //
34 dpavlin 55 //! To rip out only logging statements (commented or uncommented):
35     //! ^/{0,2}iwfLog.*
36     // --------------------------------------------------------------------------
37 dpavlin 46
38 dpavlin 55
39 dpavlin 46 // --------------------------------------------------------------------------
40     //
41 dpavlin 55 //! iwfajax.js
42     //
43 dpavlin 46 // Thread-safe background xml request via XmlHttpRequest object
44     //
45 dpavlin 55 //! Dependencies:
46     //! iwfxml.js
47     //! iwfcore.js
48     //! iwfgui.js (optional -- pretty progress bar)
49 dpavlin 46 //
50 dpavlin 55 //! Brock Weaver - brockweaver@users.sourceforge.net
51     //! v 0.2 - 2005-11-14
52     //! core bug patch
53 dpavlin 46 // --------------------------------------------------------------------------
54 dpavlin 55 //! v 0.1 - 2005-06-05
55     //! Initial release.
56     //
57     //! Known Issues:
58     //! AddToHistory does not work
59     //! Iframe not implemented
60     //
61     // =========================================================================
62 dpavlin 46
63 dpavlin 55
64    
65    
66     // show progress bar if they included iwfgui.js, window.status otherwise.
67     var _iwfShowGuiProgress = iwfExists(window.iwfShow);
68    
69    
70    
71    
72    
73    
74     // -----------------------------------
75     // Begin: Dependency Check
76     // -----------------------------------
77    
78 dpavlin 46 if (!window.iwfGetById || !window.iwfXmlDoc){
79     iwfLog("IWF Dependency Error: iwfajax.js is dependent upon both iwfcore.js and iwfxml.js, so you *must* reference those files first.\n\nExample:\n\n<script type='text/javascript' src='iwfcore.js'></script>\n<script type='text/javascript' src='iwfxml.js'></script>\n<script type='text/javascript' src='iwfajax.js'></script>", true);
80     }
81    
82     // -----------------------------------
83 dpavlin 55 // End: Dependency Check
84     // -----------------------------------
85    
86     // -----------------------------------
87 dpavlin 46 // Begin: AJAX Request and Response
88     // -----------------------------------
89    
90     function iwfRequest(urlOrForm, targetElementOnResponse, addToHistory, callback){
91    
92     // we use a javascript feature here called "inner functions"
93     // using these means the local variables retain their values after the outer function
94     // has returned. this is useful for thread safety, so
95     // reassigning the onreadystatechange function doesn't stomp over earlier requests.
96    
97     function iwfBindCallback(){
98     if (req.readyState == 4) {
99     _iwfOnRequestEnd();
100     if (req.status == 200 || req.status == 0) {
101 dpavlin 55 //iwfLog('exact response from server:\n\n' + req.responseText);
102 dpavlin 46 _iwfResponseHandler(req.responseText, localCallback, localTarget);
103     } else {
104     _iwfOnRequestError(req.status, req.statusText, req.responseText);
105     }
106     return;
107     }
108     }
109    
110     // determine how to hit the server...
111     var url = null;
112     var method = 'GET';
113     var postdata = null;
114     var isFromForm = true;
115     var contentType = 'application/x-www-form-urlencoded';
116    
117     if (iwfIsString(urlOrForm)){
118    
119     // if we get here, they either specified the url or the name of the form.
120     // either way, flag so we return nothing.
121     isFromForm = false;
122    
123     var frm = iwfGetForm(urlOrForm);
124     if (!frm){
125     // is a url.
126     url = urlOrForm;
127     method = 'GET';
128     postdata = null;
129     } else {
130     // is name of a form.
131     // fill with the form object.
132     urlOrForm = frm;
133     }
134    
135     }
136    
137     // use a local variable to hold our callback and target until the inner function is called...
138     var localCallback = callback;
139     var localTarget = targetElementOnResponse;
140    
141     if (!iwfIsString(urlOrForm)){
142    
143     var ctl = null;
144    
145    
146     // is a form or a control in the form.
147     if (iwfExists(urlOrForm.form)){
148     // is a control in the form. jump up to the form.
149     ctl = urlOrForm;
150     urlOrForm = urlOrForm.form;
151     }
152    
153    
154     // if they passed a form and no local target, lookup the form.iwfTarget attribute and use it if possible
155     if (!localTarget){
156     localTarget = iwfAttribute(urlOrForm, 'iwfTarget');
157     }
158    
159     if (localTarget){
160 dpavlin 55 var elTgt = iwfGetOrCreateByNameWithinForm(urlOrForm, 'iwfTarget', 'input', 'hidden');
161 dpavlin 46 if (elTgt){
162     iwfAttribute(elTgt, 'value', localTarget);
163     iwfRemoveAttribute(elTgt, 'disabled');
164     }
165     }
166    
167    
168     url = urlOrForm.action;
169     method = urlOrForm.method.toUpperCase();
170     switch(method){
171     case "POST":
172     postdata = _iwfGetFormData(urlOrForm, url, ctl);
173    
174     // we also need to properly set the content-type header...
175     var frm = iwfGetForm(urlOrForm);
176     if (frm){
177     var enc = iwfAttribute(frm, 'encoding');
178     if (!enc){
179     enc = iwfAttribute(frm, 'enctype');
180     }
181     if (enc){
182     contentType = enc;
183     }
184     }
185    
186     break;
187     case "GET":
188     default:
189     url = _iwfGetFormData(urlOrForm, url, ctl);
190     break;
191     }
192     }
193    
194     // prevent any browser caching of our url by requesting a unique url everytime...
195     url += ((url.indexOf('?') > -1) ? '&' : '?') + 'iwfRequestId=' + new Date().valueOf();
196    
197 dpavlin 55 //iwfLog("url = " + url);
198     //iwfLog("method = " + method);
199     //iwfLog("postdata = " + postdata);
200     //iwfLog("contenttype = " + contentType);
201 dpavlin 46
202    
203     var req = null;
204     if (!addToHistory){
205 dpavlin 55 //iwfLog("using XHR to perform request...");
206 dpavlin 46 // use XHR to perform the request, as this will
207     // prevent the browser from adding it to history.
208     req = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
209    
210     // bind our callback
211     req.onreadystatechange = iwfBindCallback;
212    
213     // show progress if it's not already visible...
214     _iwfOnRequestStart();
215    
216     // hit the server
217     req.open(method, url, true);
218     req.setRequestHeader('Content-Type', contentType);
219     req.send(postdata);
220     } else {
221     // use an IFRAME element to perform the request,
222     // as this will cause the browser to add it to history.
223     // TODO: make this work!!!
224     iwfLog("using IFRAME to perform request...");
225     iwfLog('request and add to history not implemented yet!!!', true);
226     return;
227    
228     var el = iwfGetById("iwfHistoryFrame");
229     if (!el){
230     iwfLog("To enable history tracking in IWF, you must add an invisible IFRAME element to your page:\n<IFRAME id='iwfHistoryFrame' style='display:none'></IFRAME>", true);
231     }
232    
233     el.src = url;
234    
235     // show progress if it's not already visible...
236     _iwfOnRequestStart();
237    
238    
239     }
240    
241     // if this is called from the form.onsubmit event, make sure the form doesn't submit...
242    
243     if (isFromForm){
244     return false;
245     } else {
246     // return absolutely nothing so anchor tags don't hork the current page
247     }
248    
249     }
250    
251     function _iwfGetFormData(form, url, ctl){
252    
253     var method = form.method;
254     if (!method) method = "get";
255    
256     var output = null;
257    
258     if (method == 'get'){
259     output = url + ((url.indexOf('?') > -1) ? '&' : '?');
260     } else {
261     output = '';
262     }
263    
264    
265     // if there is a target specified in the <form> tag,
266     // copy its contents to a hidden <input type='hidden'> tag.
267    
268 dpavlin 55 //iwfLog("total elements in form named '" + form.name + "': " + form.elements.length);
269 dpavlin 46 for(var i=0;i<form.elements.length;i++){
270     var el = form.elements[i];
271     var nm = iwfAttribute(el, 'name');
272     var val = null;
273     if (!iwfAttribute(el, 'disabled') && nm){
274     switch (el.tagName.toLowerCase()){
275     case 'input':
276     switch(iwfAttribute(el, 'type')){
277     case 'checkbox':
278     case 'radio':
279 dpavlin 56 if (iwfAttribute(el, 'checked') || el.checked){
280     val = iwfAttribute(el, 'value') || el.value;
281 dpavlin 46 }
282     break;
283     case 'button':
284     if (el == ctl){
285     val = iwfAttribute(el, 'value');
286     }
287     break;
288     case 'submit':
289     if (el == ctl){
290     val = iwfAttribute(el, 'value');
291     }
292     break;
293     case 'text':
294     default:
295     val = iwfAttribute(el, 'value');
296     break;
297     case 'file':
298     iwfLog('TODO: implement <input type="file"> in _iwfGetFormData', true);
299     val = iwfAttribute(el, 'value');
300     break;
301     case 'image':
302     iwfLog('TODO: implement <input type="image"> in _iwfGetFormData', true);
303     val = iwfAttribute(el, 'value');
304     break;
305     case 'reset':
306     iwfLog('TODO: implement <input type="reset"> in _iwfGetFormData', true);
307     break;
308     case 'hidden':
309     val = iwfAttribute(el, 'value');
310     break;
311     }
312     break;
313     case 'textarea':
314 dpavlin 56 val = iwfAttribute(el, 'innerText') || el.value;
315 dpavlin 46 break;
316     case 'button':
317     if (el == ctl){
318 dpavlin 56 val = iwfAttribute(el, 'innerText') || el.value;
319 dpavlin 46 }
320     break;
321     case 'select':
322     for(var j=0;j<el.options.length;j++){
323     if (iwfAttribute(el.options[j], 'selected') == 'true'){
324     if (!val){
325     val = iwfAttribute(el.options[j], 'value');
326     } else {
327     val += '+' + iwfAttribute(el.options[j], 'value');
328     }
329     }
330     }
331     }
332    
333     if (val){
334     if (output.length > 0){
335     output += '&';
336     }
337     output += escape(nm) + '=' + escape(val);
338     }
339     }
340     }
341     if (output.length == 0){
342     return null;
343     } else {
344     return output;
345     }
346     }
347    
348     function _iwfResponseReceived(doc){
349 dpavlin 55 iwfLog('iframeloaded');
350 dpavlin 46 var xmlDoc = new iwfXmlDoc(doc.innerHTML);
351     }
352    
353     function _iwfResponseHandler(origText, callback, tgt){
354     var doc = new iwfXmlDoc(origText);
355     if (!doc.response){
356     // not in our default xml format.
357     // just throw out the xml to the callback, if any
358     if (callback){
359     callback(doc);
360     } else {
361     iwfLog("IWF Ajax Error: No callback defined for non-standard response:\n" + origText, true);
362     }
363     } else {
364     if (doc.response.debugging == 'true'){
365     iwfLoggingEnabled = true;
366     iwfLog("IWF Ajax Debugging:\nParsed response:\n\n" + doc.response.outerXml(true), true);
367     iwfShowLog();
368     }
369     for(var i=0; i< doc.response.childNodes.length; i++){
370     var node = doc.response.childNodes[i];
371     if (node.nodeName.indexOf("#") != 0){
372 dpavlin 55 //iwfLog('node.target=' + node.target + '\ntgt=' + tgt);
373 dpavlin 46 if (!tgt) {
374     // server target is ignored if a client target exists.
375     tgt = node.target;
376     }
377     if (node.errorCode && iwfToInt(node.errorCode, true) != 0){
378     // an error occurred.
379     _iwfOnRequestError(node.errorCode, node.errorMessage);
380     } else {
381     if (!node.type){
382     node.type = "";
383     }
384     switch(node.type.toLowerCase()){
385     case "html":
386     case "xhtml":
387     var innerHtml = node.innerHtml();
388     //iwfLog('parsed html response:\n\n' + innerHtml);
389     _iwfInsertHtml(innerHtml, tgt);
390     break;
391     case "javascript":
392     case "js":
393     var bomb = true;
394     if (node.childNodes.length == 1){
395     var js = node.childNodes[0];
396     if (js.nodeName == '#cdata' || js.nodeName == '#comment'){
397     bomb = false;
398     var code = js.getText();
399     eval(code);
400     }
401     }
402     if (bomb){
403     iwfLog("IWF Ajax Error: When an <action> is defined of type javascript, it content must be contained by either a Comment (<!-- -->) or CDATA (<![CDATA[ ]]>).\nCDATA is the more appropriate manner, as this is the xml-compliant one.\nHowever, COMMENT is also allowed as this is html-compliant, such as within a <script> element.\n\n<action> xml returned:\n\n" + node.outerXml(), true);
404     }
405     break;
406     case "xml":
407     if (callback){
408     callback(node);
409     }
410     break;
411     case "debug":
412     iwfLog("IWF Debug: <action> type identified as 'debug'.\nXml received for current action:\n\n" + node.outerXml(), true);
413     break;
414     default:
415     iwfLog('IWF Ajax Error: <action> type of "' + node.type + '" is not a valid option.\n\nValid options:\n\'html\' or \'xhtml\' = parse as html and inject into element with the id specified by the target attribute\n\'javascript\' or \'js\' = parse as javascript and execute\n\'xml\' = parse as xml and call the callback specified when iwfRequest() was called\n\'debug\' = parse as xml and log/alert the result\n\n<action> xml returned:\n\n' + node.outerXml(), true);
416     break;
417     }
418     }
419     }
420     }
421     }
422    
423     }
424    
425     function _iwfInsertHtml(html, parentNodeId){
426     if(!parentNodeId){
427     parentNodeId = 'iwfContent';
428     iwfLog("IWF Ajax Warning: <action> with a type of 'html' does not have its target attribute specified, so using the default of 'iwfContent'.");
429     }
430    
431     if(!parentNodeId){
432     iwfLog("IWF Ajax Error: <action> node with a type of 'html' does not have its target attribute specified to a valid element.\nPlease specify the id of the element into which the contents of the <action> node should be placed.\nTo fill the entire page, simply specify 'body'.", true);
433     } else {
434     var el = iwfGetById(parentNodeId);
435     if (!el){
436     if (parentNodeId == 'body'){
437     el = iwfGetByTagName('body');
438     if (!el || el.length == 0){
439     iwfLog("IWF Ajax Error: Could not locate the tag named 'body'", true);
440     return;
441     } else {
442     el = el[0];
443     }
444     } else {
445     iwfLog('IWF Ajax Error: Could not locate element with id of ' + parentNodeId + ' into which the following html should be placed:\n\n' + html, true);
446     return;
447     }
448     }
449    
450     //iwfLog(iwfElementToString(el));
451     //iwfLog(html);
452    
453     // trying to shove a <form> node inside another <form> node is a bad thing.
454     // make sure we don't do that here.
455     var re = /<form/i;
456     var match = re.exec(html);
457     if (match && document.forms.length > 0){
458     // our html to inject contains a form node.
459     // bubble up the chain until we find a <form> node, or we have no parents
460     var elParent = el;
461 dpavlin 66 // I have doubts about adding elParent.tagName here
462     // but I don't have better idea. -dpavlin
463     while (elParent && elParent.tagName && elParent.tagName.toLowerCase() != 'form'){
464 dpavlin 46 elParent = iwfGetParent(elParent);
465     }
466    
467 dpavlin 66 if (elParent && elParent.tagName && elParent.tagName.toLowerCase() == 'form'){
468 dpavlin 46 iwfLog('IWF Ajax Error: Attempting to inject html which contains a <form> node into a target element which is itself a <form> node, or is already contained by a <form> node.\nThis is bad html, and will not work appropriately on some major browsers.', true);
469     }
470     }
471    
472    
473     el.innerHTML = html;
474    
475    
476     // if there is a script element, we have to explicitly add it to the body element,
477     // as IE and firefox just don't like it when you try to add it as part of the innerHTML
478     // property. Go figure.
479    
480     var i = 0;
481     // don't stomp on any existing scripts...
482     while (iwfGetById('iwfScript' + i)){
483     i++;
484     }
485    
486     var scriptStart = html.indexOf("<script");
487     while(scriptStart > -1){
488     scriptStart = html.indexOf(">", scriptStart) + 1;
489    
490     // copy contents of script into a default holder
491     var scriptEnd = html.indexOf("</script>", scriptStart);
492     var scriptHtml = html.substr(scriptStart, scriptEnd - scriptStart);
493    
494     var re = /^\s*<!--/;
495     var match = re.exec(scriptHtml);
496     if (!match){
497     iwfLog("IWF Ajax Error: Developer, you *must* put the <!-- and //--> 'safety net' around your script within all <script> tags.\nThe offending <script> tag contains the following code:\n\n" + scriptHtml + "\n\nThis requirement is due to how IWF injects the html so the browser is able to actually parse the script and make its contents available for execution.", true);
498     }
499    
500     // this code is the worst hack in this entire framework.
501     // the code in the try portion should work anywhere -- but
502 dpavlin 55 // IE barfs when you try to set the innerHTML on a script element.
503     // not only that, but IE won't parse script unless a visible element
504     // is contained in the innerHTML when it is set, so we need the <code>IE hack here</code>
505 dpavlin 46 // and it cannot be removed.
506     // I don't understand why creating a new node and setting its innerHTML causes the browsers
507     // to parse and execute the script, but it does.
508     // Note there is a major leak here, as we do not try to reuse existing iwfScriptXXXX elements
509     // in case they are in use by other targets. To clean these up, simply call iwfCleanScripts
510     // periodically. This is so app-dependent, I didn't want to try to keep track of everything
511     // and possibly miss a case, causing really weird results that only show up occassionally.
512     //
513     // Plus I'm getting lazy. :)
514     //
515     try {
516 dpavlin 55 //! moz (DOM)
517     var elScript = iwfGetOrCreateById('iwfScript' + i, 'script');
518 dpavlin 46 elScript.type = 'text/javascript';
519     elScript.defer = 'true';
520     elScript.innerHTML = scriptHtml;
521    
522 dpavlin 55 iwfAppendChild('body', elScript);
523    
524 dpavlin 46 } catch(e){
525 dpavlin 56 //iwfLog("IE Hack for injecting script tag...", true);
526 dpavlin 55 //! IE hack
527     // IE needs a visible tag within a non-script element to have scripting apply... Don't ask me why, ask the IE team why.
528     // My guess is the visible element causes the page to at least partially re-render, which in turn kicks off any script parsing
529     // code in IE.
530 dpavlin 46 var elDiv = iwfGetOrCreateById('iwfScript' + i, '<div style="display:none"></div>', 'body');
531 dpavlin 55 elDiv.innerHTML = '<code>IE hack here</code><script id="iwfScript' + i + '" defer="true">' + scriptHtml + '</script' + '>';
532 dpavlin 46 }
533    
534     i++;
535    
536     scriptStart = html.indexOf("<script", scriptEnd+8);
537     }
538     }
539     }
540    
541     function iwfCleanScripts(){
542     var i = 0;
543 dpavlin 55 while(iwfRemoveNode('iwfScript' + (i++)));
544    
545 dpavlin 46 }
546    
547    
548    
549     var _iwfTotalRequests = 0;
550     var _iwfPendingRequests = 0;
551     var _iwfRequestTicker = null;
552     var _iwfRequestTickCount = 0;
553     var _iwfRequestTickDuration = 100;
554 dpavlin 55
555    
556     // TODO: make the styles applied be configurable variables at the top of this file.
557     function _iwfGetBusyBar(inner){
558     var b = iwfGetById('iwfBusy');
559     if (!b){
560     b = iwfGetOrCreateById('iwfBusy', 'div', 'body');
561     if(b.style){
562     b.style.position = 'absolute';
563     b.style.border = '1px solid black';
564     b.style.backgroundColor = '#efefef';
565     b.style.textAlign = 'center';
566     }
567     iwfWidth(b, 100);
568     iwfHeight(b, 20);
569     iwfZIndex(b, 9999);
570    
571     iwfX(b, 0);
572     iwfY(b, 0);
573    
574     // iwfX(b, iwfClientWidth() - iwfWidth(b)-5);
575     // iwfY(b, iwfClientHeight() - iwfHeight(b)-5);
576    
577     iwfHide(b);
578     }
579    
580    
581    
582     var bb = iwfGetById('iwfBusyBar');
583     if(!bb){
584     bb = iwfGetOrCreateById('iwfBusyBar', 'div', b);
585     bb.style.backgroundColor = 'navy';
586     bb.style.color = 'white';
587     bb.style.textAlign = 'center';
588     iwfWidth(bb, 1);
589     iwfHeight(bb, 20);
590     iwfX(bb, 0);
591     iwfY(bb, 0);
592     }
593    
594     if(inner){
595     return bb;
596     } else {
597     return b;
598     }
599    
600     }
601    
602 dpavlin 46 function _iwfOnRequestStart(){
603     _iwfPendingRequests++;
604     _iwfTotalRequests++;
605    
606     _iwfRequestTickDuration = 100;
607    
608     if (!_iwfRequestTicker){
609     _iwfRequestTickCount = 0;
610     if (window.iwfOnRequestStart){
611     _iwfRequestTickDuration = iwfOnRequestStart();
612 dpavlin 55 } else if (_iwfShowGuiProgress) {
613     // use gui busy implementation
614     var bb = _iwfGetBusyBar(true);
615     iwfWidth(bb, 1);
616     bb.innerHTML = '0%';
617     iwfShow(_iwfGetBusyBar(false));
618 dpavlin 46 } else {
619     // use default busy implementation...
620     window.status = 'busy.';
621     }
622     if (!_iwfRequestTickDuration){
623     _iwfRequestTickDuration = 100;
624     }
625     _iwfRequestTicker = setInterval(_iwfOnRequestTick, _iwfRequestTickDuration);
626     }
627     }
628    
629     function _iwfOnRequestTick(){
630     _iwfRequestTickCount++;
631     if (window.iwfOnRequestTick){
632     iwfOnRequestTick(_iwfRequestTickCount, _iwfRequestTickDuration, _iwfPendingRequests);
633     } else if (!window.iwfOnRequestStart) {
634 dpavlin 55 if (_iwfShowGuiProgress) {
635     // use gui busy implementation
636     var bar = _iwfGetBusyBar(true);
637     if(bar){
638     var w = iwfWidth(bar) + 1;
639     if (w > 95){
640     w = 95;
641     }
642     iwfWidth(bar, w);
643     bar.innerHTML = "loading " + iwfIntFormat(w) + "%";
644     }
645     } else {
646     // use default busy implementation...
647     window.status = 'busy...............................................'.substr(0, (_iwfRequestTickCount % 45) + 5);
648     }
649 dpavlin 46 } else {
650     // they didn't define a tick function,
651     // but they did define a start one, so do nothing.
652     }
653     }
654    
655     function _iwfOnRequestEnd(){
656     _iwfPendingRequests--;
657     if (_iwfPendingRequests < 1){
658     _iwfPendingRequests = 0;
659     _iwfTotalRequests = 0;
660     clearInterval(_iwfRequestTicker);
661     _iwfRequestTicker = null;
662     if (window.iwfOnRequestEnd){
663     iwfOnRequestEnd();
664     } else if (!window.iwfOnRequestStart) {
665 dpavlin 55 if (_iwfShowGuiProgress) {
666     // use gui busy implementation
667     var bar = _iwfGetBusyBar(true);
668     if(bar){
669     iwfWidth(bar, 100);
670     bar.innerHTML = "Done";
671     iwfHideGentlyDelay(_iwfGetBusyBar(false), 15, 500);
672     }
673     } else {
674     // use default busy implementation...
675     window.status = 'done.';
676     }
677 dpavlin 46 } else {
678     // they didn't define an end function,
679     // but they did define a start one, so do nothing.
680     }
681    
682     } else {
683     if (window.iwfOnRequestProgress){
684     iwfOnRequestProgress(_iwfPendingRequests, _iwfTotalRequests);
685     } else if (!window.iwfOnRequestStart) {
686 dpavlin 55 if (_iwfShowGuiProgress) {
687     // use gui busy implementation
688     var pct = (1 - (_iwfPendingRequests/_iwfTotalRequests)) * 100;
689     if (pct > 100){
690     pct = 100;
691     }
692     var bar = _iwfGetBusyBar(true);
693     if(bar){
694     iwfWidth(bar, pct);
695     bar.innerHTML = "loading " + iwfIntFormat(pct) + "%";
696     }
697     } else {
698     // use default busy implementation...
699 dpavlin 56 window.status = 'Remaining: ' + _iwfPendingRequests;
700 dpavlin 55 }
701 dpavlin 46 } else {
702     // they didn't define an end function,
703     // but they did define a start one, so do nothing.
704     }
705     }
706     }
707    
708     function _iwfOnRequestError(code, msg, text){
709     iwfLog("Error " + code + ": " + msg + ":\n\n" + text);
710     if (window.iwfOnRequestError){
711     iwfOnRequestError(code, msg, text);
712     } else {
713     alert("Error " + code + ": " + msg + ":\n\n" + text);
714     }
715     }
716    
717     // -----------------------------------
718     // End: AJAX Request and Response
719 dpavlin 48 // -----------------------------------

Properties

Name Value
svn:mime-type text/cpp

  ViewVC Help
Powered by ViewVC 1.1.26