1 | /* xajax Javascript library :: version 0.2.4 */ |
---|
2 | |
---|
3 | Array.prototype.containsValue = function(valueToCheck) |
---|
4 | { |
---|
5 | for (var i=0;i<this.length;i++) { |
---|
6 | if (this[i] == valueToCheck) return true; |
---|
7 | } |
---|
8 | return false; |
---|
9 | } |
---|
10 | |
---|
11 | function Xajax() |
---|
12 | { |
---|
13 | this.DebugMessage = function(text) |
---|
14 | { |
---|
15 | if (text.length > 1000) text = text.substr(0,1000)+"...\n[long response]\n..."; |
---|
16 | try { |
---|
17 | if (this.debugWindow == undefined || this.debugWindow.closed == true) { |
---|
18 | this.debugWindow = window.open('about:blank', 'xajax-debug', 'width=800,height=600,scrollbars=1,resizable,status'); |
---|
19 | this.debugWindow.document.write('<html><head><title>Xajax debug output</title></head><body><h2>Xajax debug output</h2><div id="debugTag"></div></body></html>'); |
---|
20 | } |
---|
21 | text = text.replace(/&/g, "&") |
---|
22 | text = text.replace(/</g, "<") |
---|
23 | text = text.replace(/>/g, ">") |
---|
24 | debugTag = this.debugWindow.document.getElementById('debugTag'); |
---|
25 | debugTag.innerHTML = ('<b>'+(new Date()).toString()+'</b>: ' + text + '<hr/>') + debugTag.innerHTML; |
---|
26 | } catch (e) { |
---|
27 | alert("Xajax Debug:\n " + text); |
---|
28 | } |
---|
29 | }; |
---|
30 | |
---|
31 | this.workId = 'xajaxWork'+ new Date().getTime(); |
---|
32 | this.depth = 0; |
---|
33 | this.responseErrorsForAlert = ["400","401","402","403","404","500","501","502","503"]; |
---|
34 | |
---|
35 | //Get the XMLHttpRequest Object |
---|
36 | this.getRequestObject = function() |
---|
37 | { |
---|
38 | if (xajaxDebug) this.DebugMessage("Initializing Request Object.."); |
---|
39 | var req = null; |
---|
40 | if (typeof XMLHttpRequest != "undefined") |
---|
41 | req = new XMLHttpRequest(); |
---|
42 | if (!req && typeof ActiveXObject != "undefined") |
---|
43 | { |
---|
44 | try |
---|
45 | { |
---|
46 | req=new ActiveXObject("Msxml2.XMLHTTP"); |
---|
47 | } |
---|
48 | catch (e) |
---|
49 | { |
---|
50 | try |
---|
51 | { |
---|
52 | req=new ActiveXObject("Microsoft.XMLHTTP"); |
---|
53 | } |
---|
54 | catch (e2) |
---|
55 | { |
---|
56 | try { |
---|
57 | req=new ActiveXObject("Msxml2.XMLHTTP.4.0"); |
---|
58 | } |
---|
59 | catch (e3) |
---|
60 | { |
---|
61 | req=null; |
---|
62 | } |
---|
63 | } |
---|
64 | } |
---|
65 | } |
---|
66 | if(!req && window.createRequest) |
---|
67 | req = window.createRequest(); |
---|
68 | |
---|
69 | if (!req) this.DebugMessage("Request Object Instantiation failed."); |
---|
70 | |
---|
71 | return req; |
---|
72 | } |
---|
73 | |
---|
74 | // xajax.$() is shorthand for document.getElementById() |
---|
75 | this.$ = function(sId) |
---|
76 | { |
---|
77 | if (!sId) { |
---|
78 | return null; |
---|
79 | } |
---|
80 | var returnObj = document.getElementById(sId); |
---|
81 | if (!returnObj && document.all) { |
---|
82 | returnObj = document.all[sId]; |
---|
83 | } |
---|
84 | if (xajaxDebug && !returnObj && sId != this.workId) { |
---|
85 | this.DebugMessage("Element with the id \"" + sId + "\" not found."); |
---|
86 | } |
---|
87 | return returnObj; |
---|
88 | } |
---|
89 | |
---|
90 | // xajax.include(sFileName) dynamically includes an external javascript file |
---|
91 | this.include = function(sFileName) |
---|
92 | { |
---|
93 | var objHead = document.getElementsByTagName('head'); |
---|
94 | var objScript = document.createElement('script'); |
---|
95 | objScript.type = 'text/javascript'; |
---|
96 | objScript.src = sFileName; |
---|
97 | objHead[0].appendChild(objScript); |
---|
98 | } |
---|
99 | |
---|
100 | this.stripOnPrefix = function(sEventName) |
---|
101 | { |
---|
102 | sEventName = sEventName.toLowerCase(); |
---|
103 | if (sEventName.indexOf('on') == 0) |
---|
104 | { |
---|
105 | sEventName = sEventName.replace(/on/,''); |
---|
106 | } |
---|
107 | |
---|
108 | return sEventName; |
---|
109 | } |
---|
110 | |
---|
111 | this.addOnPrefix = function(sEventName) |
---|
112 | { |
---|
113 | sEventName = sEventName.toLowerCase(); |
---|
114 | if (sEventName.indexOf('on') != 0) |
---|
115 | { |
---|
116 | sEventName = 'on' + sEventName; |
---|
117 | } |
---|
118 | |
---|
119 | return sEventName; |
---|
120 | } |
---|
121 | |
---|
122 | // xajax.addHandler adds an event handler to an element |
---|
123 | this.addHandler = function(sElementId, sEvent, sFunctionName) |
---|
124 | { |
---|
125 | if (window.addEventListener) |
---|
126 | { |
---|
127 | sEvent = this.stripOnPrefix(sEvent); |
---|
128 | eval("this.$('"+sElementId+"').addEventListener('"+sEvent+"',"+sFunctionName+",false);"); |
---|
129 | } |
---|
130 | else |
---|
131 | { |
---|
132 | sAltEvent = this.addOnPrefix(sEvent); |
---|
133 | eval("this.$('"+sElementId+"').attachEvent('"+sAltEvent+"',"+sFunctionName+",false);"); |
---|
134 | } |
---|
135 | } |
---|
136 | |
---|
137 | // xajax.removeHandler removes an event handler from an element |
---|
138 | this.removeHandler = function(sElementId, sEvent, sFunctionName) |
---|
139 | { |
---|
140 | if (window.addEventListener) |
---|
141 | { |
---|
142 | sEvent = this.stripOnPrefix(sEvent); |
---|
143 | eval("this.$('"+sElementId+"').removeEventListener('"+sEvent+"',"+sFunctionName+",false);"); |
---|
144 | } |
---|
145 | else |
---|
146 | { |
---|
147 | sAltEvent = this.addOnPrefix(sEvent); |
---|
148 | eval("this.$('"+sElementId+"').detachEvent('"+sAltEvent+"',"+sFunctionName+",false);"); |
---|
149 | } |
---|
150 | } |
---|
151 | |
---|
152 | // xajax.create creates a new child node under a parent |
---|
153 | this.create = function(sParentId, sTag, sId) |
---|
154 | { |
---|
155 | var objParent = this.$(sParentId); |
---|
156 | objElement = document.createElement(sTag); |
---|
157 | objElement.setAttribute('id',sId); |
---|
158 | if (objParent) |
---|
159 | objParent.appendChild(objElement); |
---|
160 | } |
---|
161 | |
---|
162 | // xajax.insert inserts a new node before another node |
---|
163 | this.insert = function(sBeforeId, sTag, sId) |
---|
164 | { |
---|
165 | var objSibling = this.$(sBeforeId); |
---|
166 | objElement = document.createElement(sTag); |
---|
167 | objElement.setAttribute('id',sId); |
---|
168 | objSibling.parentNode.insertBefore(objElement, objSibling); |
---|
169 | } |
---|
170 | |
---|
171 | // xajax.insertAfter inserts a new node after another node |
---|
172 | this.insertAfter = function(sAfterId, sTag, sId) |
---|
173 | { |
---|
174 | var objSibling = this.$(sAfterId); |
---|
175 | objElement = document.createElement(sTag); |
---|
176 | objElement.setAttribute('id',sId); |
---|
177 | objSibling.parentNode.insertBefore(objElement, objSibling.nextSibling); |
---|
178 | } |
---|
179 | |
---|
180 | this.getInput = function(sType, sName, sId) |
---|
181 | { |
---|
182 | var Obj; |
---|
183 | if (!window.addEventListener) |
---|
184 | { |
---|
185 | Obj = document.createElement('<input type="'+sType+'" id="'+sId+'" name="'+sName+'">'); |
---|
186 | } |
---|
187 | else |
---|
188 | { |
---|
189 | Obj = document.createElement('input'); |
---|
190 | Obj.setAttribute('type',sType); |
---|
191 | Obj.setAttribute('name',sName); |
---|
192 | Obj.setAttribute('id',sId); |
---|
193 | } |
---|
194 | return Obj; |
---|
195 | } |
---|
196 | |
---|
197 | // xajax.createInput creates a new input node under a parent |
---|
198 | this.createInput = function(sParentId, sType, sName, sId) |
---|
199 | { |
---|
200 | var objParent = this.$(sParentId); |
---|
201 | var objElement = this.getInput(sType, sName, sId); |
---|
202 | if (objParent && objElement) |
---|
203 | objParent.appendChild(objElement); |
---|
204 | } |
---|
205 | |
---|
206 | // xajax.insertInput creates a new input node before another node |
---|
207 | this.insertInput = function(sBeforeId, sType, sName, sId) |
---|
208 | { |
---|
209 | var objSibling = this.$(sBeforeId); |
---|
210 | var objElement = this.getInput(sType, sName, sId); |
---|
211 | if (objElement && objSibling && objSibling.parentNode) |
---|
212 | objSibling.parentNode.insertBefore(objElement, objSibling); |
---|
213 | } |
---|
214 | |
---|
215 | // xajax.insertInputAfter creates a new input node after another node |
---|
216 | this.insertInputAfter = function(sAfterId, sType, sName, sId) |
---|
217 | { |
---|
218 | var objSibling = this.$(sAfterId); |
---|
219 | var objElement = this.getInput(sType, sName, sId); |
---|
220 | if (objElement && objSibling && objSibling.parentNode) { |
---|
221 | objSibling.parentNode.insertBefore(objElement, objSibling.nextSibling); |
---|
222 | } |
---|
223 | } |
---|
224 | |
---|
225 | // xajax.remove deletes an element |
---|
226 | this.remove = function(sId) |
---|
227 | { |
---|
228 | objElement = this.$(sId); |
---|
229 | if (objElement && objElement.parentNode && objElement.parentNode.removeChild) |
---|
230 | { |
---|
231 | objElement.parentNode.removeChild(objElement); |
---|
232 | } |
---|
233 | } |
---|
234 | |
---|
235 | //xajax.replace searches for text in an attribute of an element and replaces it |
---|
236 | //with a different text |
---|
237 | this.replace = function(sId,sAttribute,sSearch,sReplace) |
---|
238 | { |
---|
239 | var bFunction = false; |
---|
240 | |
---|
241 | if (sAttribute == "innerHTML") |
---|
242 | sSearch = this.getBrowserHTML(sSearch); |
---|
243 | |
---|
244 | eval("var txt=this.$('"+sId+"')."+sAttribute); |
---|
245 | if (typeof txt == "function") |
---|
246 | { |
---|
247 | txt = txt.toString(); |
---|
248 | bFunction = true; |
---|
249 | } |
---|
250 | if (txt.indexOf(sSearch)>-1) |
---|
251 | { |
---|
252 | var newTxt = ''; |
---|
253 | while (txt.indexOf(sSearch) > -1) |
---|
254 | { |
---|
255 | x = txt.indexOf(sSearch)+sSearch.length+1; |
---|
256 | newTxt += txt.substr(0,x).replace(sSearch,sReplace); |
---|
257 | txt = txt.substr(x,txt.length-x); |
---|
258 | } |
---|
259 | newTxt += txt; |
---|
260 | if (bFunction) |
---|
261 | { |
---|
262 | eval('this.$("'+sId+'").'+sAttribute+'=newTxt;'); |
---|
263 | } |
---|
264 | else if (this.willChange(sId,sAttribute,newTxt)) |
---|
265 | { |
---|
266 | eval('this.$("'+sId+'").'+sAttribute+'=newTxt;'); |
---|
267 | } |
---|
268 | } |
---|
269 | } |
---|
270 | |
---|
271 | // xajax.getFormValues() builds a query string XML message from the elements of a form object |
---|
272 | // * The first argument is the id of the form |
---|
273 | // * The second argument (optional) can be set to true if you want to submit disabled elements |
---|
274 | // * The third argument (optional) allows you to specify a string prefix that a form element |
---|
275 | // name must contain if you want that element to be submitted |
---|
276 | this.getFormValues = function(frm) |
---|
277 | { |
---|
278 | var objForm; |
---|
279 | var submitDisabledElements = false; |
---|
280 | if (arguments.length > 1 && arguments[1] == true) |
---|
281 | submitDisabledElements = true; |
---|
282 | var prefix=""; |
---|
283 | if(arguments.length > 2) |
---|
284 | prefix = arguments[2]; |
---|
285 | |
---|
286 | if (typeof(frm) == "string") |
---|
287 | objForm = this.$(frm); |
---|
288 | else |
---|
289 | objForm = frm; |
---|
290 | var sXml = "<xjxquery><q>"; |
---|
291 | if (objForm && objForm.tagName == 'FORM') |
---|
292 | { |
---|
293 | var formElements = objForm.elements; |
---|
294 | for( var i=0; i < formElements.length; i++) |
---|
295 | { |
---|
296 | if (!formElements[i].name) |
---|
297 | continue; |
---|
298 | if (formElements[i].name.substring(0, prefix.length) != prefix) |
---|
299 | continue; |
---|
300 | if (formElements[i].type && (formElements[i].type == 'radio' || formElements[i].type == 'checkbox') && formElements[i].checked == false) |
---|
301 | continue; |
---|
302 | if (formElements[i].disabled && formElements[i].disabled == true && submitDisabledElements == false) |
---|
303 | continue; |
---|
304 | var name = formElements[i].name; |
---|
305 | if (name) |
---|
306 | { |
---|
307 | if (sXml != '<xjxquery><q>') |
---|
308 | sXml += '&'; |
---|
309 | if(formElements[i].type=='select-multiple') |
---|
310 | { |
---|
311 | for (var j = 0; j < formElements[i].length; j++) |
---|
312 | { |
---|
313 | if (formElements[i].options[j].selected == true) |
---|
314 | sXml += name+"="+encodeURIComponent(formElements[i].options[j].value)+"&"; |
---|
315 | } |
---|
316 | } |
---|
317 | else |
---|
318 | { |
---|
319 | sXml += name+"="+encodeURIComponent(formElements[i].value); |
---|
320 | } |
---|
321 | } |
---|
322 | } |
---|
323 | } |
---|
324 | |
---|
325 | sXml +="</q></xjxquery>"; |
---|
326 | |
---|
327 | return sXml; |
---|
328 | } |
---|
329 | |
---|
330 | // Generates an XML message that xajax can understand from a javascript object |
---|
331 | this.objectToXML = function(obj) |
---|
332 | { |
---|
333 | var sXml = "<xjxobj>"; |
---|
334 | for (i in obj) |
---|
335 | { |
---|
336 | try |
---|
337 | { |
---|
338 | if (i == 'constructor') |
---|
339 | continue; |
---|
340 | if (obj[i] && typeof(obj[i]) == 'function') |
---|
341 | continue; |
---|
342 | |
---|
343 | var key = i; |
---|
344 | var value = obj[i]; |
---|
345 | if (value && typeof(value)=="object" && this.depth <= 50) |
---|
346 | { |
---|
347 | this.depth++; |
---|
348 | value = this.objectToXML(value); |
---|
349 | this.depth--; |
---|
350 | } |
---|
351 | |
---|
352 | sXml += "<e><k>"+key+"</k><v>"+value+"</v></e>"; |
---|
353 | |
---|
354 | } |
---|
355 | catch(e) |
---|
356 | { |
---|
357 | if (xajaxDebug) this.DebugMessage(e.name+": "+e.message); |
---|
358 | } |
---|
359 | } |
---|
360 | sXml += "</xjxobj>"; |
---|
361 | |
---|
362 | return sXml; |
---|
363 | } |
---|
364 | |
---|
365 | // unserializes data structure from xajaxResponse::_buildObjXml() |
---|
366 | this._nodeToObject = function(node) { |
---|
367 | // parentNode here is weird, have to tune |
---|
368 | if (node.nodeName == '#cdata-section') { |
---|
369 | var data = ""; |
---|
370 | for (var j=0; j<node.parentNode.childNodes.length; j++) { |
---|
371 | data += node.parentNode.childNodes[j].data; |
---|
372 | } |
---|
373 | return data; |
---|
374 | } |
---|
375 | else if (node.nodeName == 'xjxobj') { |
---|
376 | var data = new Array(); |
---|
377 | for (var j=0; j<node.childNodes.length; j++) { |
---|
378 | var child = node.childNodes[j]; |
---|
379 | var key; |
---|
380 | var value; |
---|
381 | if (child.nodeName == 'e') { |
---|
382 | for (var k=0; k<child.childNodes.length; k++) { |
---|
383 | if (child.childNodes[k].nodeName == 'k') { |
---|
384 | key = child.childNodes[k].firstChild.data; |
---|
385 | } |
---|
386 | else if (child.childNodes[k].nodeName == 'v') { |
---|
387 | value = this._nodeToObject(child.childNodes[k].firstChild); |
---|
388 | } |
---|
389 | } |
---|
390 | if (key != null && value != null) { |
---|
391 | data[key] = value; |
---|
392 | key = value = null; |
---|
393 | } |
---|
394 | } |
---|
395 | } |
---|
396 | return data; |
---|
397 | } |
---|
398 | } |
---|
399 | |
---|
400 | this.loadingFunction = function(){}; |
---|
401 | this.doneLoadingFunction = function(){}; |
---|
402 | var loadingTimeout; |
---|
403 | |
---|
404 | // Sends a XMLHttpRequest to call the specified PHP function on the server |
---|
405 | // * sRequestType is optional -- defaults to POST |
---|
406 | this.call = function(sFunction, aArgs, sRequestType) |
---|
407 | { |
---|
408 | var i,r,postData; |
---|
409 | if (document.body && xajaxWaitCursor) |
---|
410 | document.body.style.cursor = 'wait'; |
---|
411 | if (xajaxStatusMessages == true) window.status = 'Sending Request...'; |
---|
412 | clearTimeout(loadingTimeout); |
---|
413 | loadingTimeout = setTimeout("xajax.loadingFunction();",400); |
---|
414 | if (xajaxDebug) this.DebugMessage("Starting xajax..."); |
---|
415 | if (sRequestType == null) { |
---|
416 | var xajaxRequestType = xajaxDefinedPost; |
---|
417 | } |
---|
418 | else { |
---|
419 | var xajaxRequestType = sRequestType; |
---|
420 | } |
---|
421 | var uri = xajaxRequestUri; |
---|
422 | var value; |
---|
423 | switch(xajaxRequestType) |
---|
424 | { |
---|
425 | case xajaxDefinedGet:{ |
---|
426 | var uriGet = uri.indexOf("?")==-1?"?xajax="+encodeURIComponent(sFunction):"&xajax="+encodeURIComponent(sFunction); |
---|
427 | if (aArgs) { |
---|
428 | for (i = 0; i<aArgs.length; i++) |
---|
429 | { |
---|
430 | value = aArgs[i]; |
---|
431 | if (typeof(value)=="object") |
---|
432 | value = this.objectToXML(value); |
---|
433 | uriGet += "&xajaxargs[]="+encodeURIComponent(value); |
---|
434 | } |
---|
435 | } |
---|
436 | uriGet += "&xajaxr=" + new Date().getTime(); |
---|
437 | uri += uriGet; |
---|
438 | postData = null; |
---|
439 | } break; |
---|
440 | case xajaxDefinedPost:{ |
---|
441 | postData = "xajax="+encodeURIComponent(sFunction); |
---|
442 | postData += "&xajaxr="+new Date().getTime(); |
---|
443 | if (aArgs) { |
---|
444 | for (i = 0; i <aArgs.length; i++) |
---|
445 | { |
---|
446 | value = aArgs[i]; |
---|
447 | if (typeof(value)=="object") |
---|
448 | value = this.objectToXML(value); |
---|
449 | postData = postData+"&xajaxargs[]="+encodeURIComponent(value); |
---|
450 | } |
---|
451 | } |
---|
452 | } break; |
---|
453 | default: |
---|
454 | alert("Illegal request type: " + xajaxRequestType); return false; break; |
---|
455 | } |
---|
456 | r = this.getRequestObject(); |
---|
457 | if (!r) return false; |
---|
458 | r.open(xajaxRequestType==xajaxDefinedGet?"GET":"POST", uri, true); |
---|
459 | if (xajaxRequestType == xajaxDefinedPost) |
---|
460 | { |
---|
461 | try |
---|
462 | { |
---|
463 | r.setRequestHeader("Method", "POST " + uri + " HTTP/1.1"); |
---|
464 | r.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); |
---|
465 | } |
---|
466 | catch(e) |
---|
467 | { |
---|
468 | alert("Your browser does not appear to support asynchronous requests using POST."); |
---|
469 | return false; |
---|
470 | } |
---|
471 | } |
---|
472 | r.onreadystatechange = function() |
---|
473 | { |
---|
474 | if (r.readyState != 4) |
---|
475 | return; |
---|
476 | |
---|
477 | if (r.status==200) |
---|
478 | { |
---|
479 | if (xajaxDebug) xajax.DebugMessage("Received:\n" + r.responseText); |
---|
480 | if (r.responseXML && r.responseXML.documentElement) |
---|
481 | xajax.processResponse(r.responseXML); |
---|
482 | else { |
---|
483 | var errorString = "Error: the XML response that was returned from the server is invalid."; |
---|
484 | errorString += "\nReceived:\n" + r.responseText; |
---|
485 | trimmedResponseText = r.responseText.replace( /^\s+/g, "" );// strip leading space
|
---|
486 | trimmedResponseText = trimmedResponseText.replace( /\s+$/g, "" );// strip trailing |
---|
487 | if (trimmedResponseText != r.responseText) |
---|
488 | errorString += "\nYou have whitespace in your response."; |
---|
489 | alert(errorString); |
---|
490 | document.body.style.cursor = 'default'; |
---|
491 | if (xajaxStatusMessages == true) window.status = 'Invalid XML response error'; |
---|
492 | } |
---|
493 | } |
---|
494 | else { |
---|
495 | if (xajax.responseErrorsForAlert.containsValue(r.status)) { |
---|
496 | var errorString = "Error: the server returned the following HTTP status: " + r.status; |
---|
497 | errorString += "\nReceived:\n" + r.responseText; |
---|
498 | alert(errorString); |
---|
499 | } |
---|
500 | document.body.style.cursor = 'default'; |
---|
501 | if (xajaxStatusMessages == true) window.status = 'Invalid XML response error'; |
---|
502 | } |
---|
503 | |
---|
504 | delete r; |
---|
505 | r = null; |
---|
506 | } |
---|
507 | if (xajaxDebug) this.DebugMessage("Calling "+sFunction +" uri="+uri+" (post:"+ postData +")"); |
---|
508 | r.send(postData); |
---|
509 | if (xajaxStatusMessages == true) window.status = 'Waiting for data...'; |
---|
510 | delete r; |
---|
511 | return true; |
---|
512 | } |
---|
513 | |
---|
514 | //Gets the text as it would be if it were being retrieved from |
---|
515 | //the innerHTML property in the current browser |
---|
516 | this.getBrowserHTML = function(html) |
---|
517 | { |
---|
518 | tmpXajax = this.$(this.workId); |
---|
519 | if (!tmpXajax) |
---|
520 | { |
---|
521 | tmpXajax = document.createElement("div"); |
---|
522 | tmpXajax.setAttribute('id',this.workId); |
---|
523 | tmpXajax.style.display = "none"; |
---|
524 | tmpXajax.style.visibility = "hidden"; |
---|
525 | document.body.appendChild(tmpXajax); |
---|
526 | } |
---|
527 | tmpXajax.innerHTML = html; |
---|
528 | var browserHTML = tmpXajax.innerHTML; |
---|
529 | tmpXajax.innerHTML = ''; |
---|
530 | |
---|
531 | return browserHTML; |
---|
532 | } |
---|
533 | |
---|
534 | // Tests if the new Data is the same as the extant data |
---|
535 | this.willChange = function(element, attribute, newData) |
---|
536 | { |
---|
537 | if (!document.body) |
---|
538 | { |
---|
539 | return true; |
---|
540 | } |
---|
541 | if (attribute == "innerHTML") |
---|
542 | { |
---|
543 | newData = this.getBrowserHTML(newData); |
---|
544 | } |
---|
545 | elementObject = this.$(element); |
---|
546 | if (elementObject) { |
---|
547 | var oldData; |
---|
548 | eval("oldData=this.$('"+element+"')."+attribute); |
---|
549 | if (newData !== oldData) |
---|
550 | return true; |
---|
551 | } |
---|
552 | |
---|
553 | return false; |
---|
554 | } |
---|
555 | |
---|
556 | //Returns the source code of the page after it's been modified by xajax |
---|
557 | this.viewSource = function() |
---|
558 | { |
---|
559 | return "<html>"+document.getElementsByTagName("HTML")[0].innerHTML+"</html>"; |
---|
560 | } |
---|
561 | |
---|
562 | //Process XML xajaxResponses returned from the request |
---|
563 | this.processResponse = function(xml) |
---|
564 | { |
---|
565 | clearTimeout(loadingTimeout); |
---|
566 | this.doneLoadingFunction(); |
---|
567 | if (xajaxStatusMessages == true) window.status = 'Processing...'; |
---|
568 | var tmpXajax = null; |
---|
569 | xml = xml.documentElement; |
---|
570 | if (xml == null) |
---|
571 | return; |
---|
572 | |
---|
573 | var skipCommands = 0; |
---|
574 | for (var i=0; i<xml.childNodes.length; i++) |
---|
575 | { |
---|
576 | if (skipCommands > 0) { |
---|
577 | skipCommands--; |
---|
578 | continue; |
---|
579 | } |
---|
580 | if (xml.childNodes[i].nodeName == "cmd") |
---|
581 | { |
---|
582 | var cmd; |
---|
583 | var id; |
---|
584 | var property; |
---|
585 | var data; |
---|
586 | var search; |
---|
587 | var type; |
---|
588 | var before; |
---|
589 | var objElement = null; |
---|
590 | |
---|
591 | for (var j=0; j<xml.childNodes[i].attributes.length; j++) |
---|
592 | { |
---|
593 | if (xml.childNodes[i].attributes[j].name == "n") |
---|
594 | { |
---|
595 | cmd = xml.childNodes[i].attributes[j].value; |
---|
596 | } |
---|
597 | else if (xml.childNodes[i].attributes[j].name == "t") |
---|
598 | { |
---|
599 | id = xml.childNodes[i].attributes[j].value; |
---|
600 | } |
---|
601 | else if (xml.childNodes[i].attributes[j].name == "p") |
---|
602 | { |
---|
603 | property = xml.childNodes[i].attributes[j].value; |
---|
604 | } |
---|
605 | else if (xml.childNodes[i].attributes[j].name == "c") |
---|
606 | { |
---|
607 | type = xml.childNodes[i].attributes[j].value; |
---|
608 | } |
---|
609 | } |
---|
610 | if (xml.childNodes[i].childNodes.length > 1 && xml.childNodes[i].firstChild.nodeName == "#cdata-section") |
---|
611 | { |
---|
612 | data = ""; |
---|
613 | for (var j=0; j<xml.childNodes[i].childNodes.length; j++) |
---|
614 | { |
---|
615 | data += xml.childNodes[i].childNodes[j].data; |
---|
616 | } |
---|
617 | } |
---|
618 | else if (xml.childNodes[i].firstChild && xml.childNodes[i].firstChild.nodeName == 'xjxobj') { |
---|
619 | data = this._nodeToObject(xml.childNodes[i].firstChild); |
---|
620 | objElement = "XJX_SKIP"; |
---|
621 | } |
---|
622 | else if (xml.childNodes[i].childNodes.length > 1) |
---|
623 | { |
---|
624 | for (var j=0; j<xml.childNodes[i].childNodes.length; j++) |
---|
625 | { |
---|
626 | if (xml.childNodes[i].childNodes[j].childNodes.length > 1 && xml.childNodes[i].childNodes[j].firstChild.nodeName == "#cdata-section") |
---|
627 | { |
---|
628 | var internalData = ""; |
---|
629 | for (var k=0; k<xml.childNodes[i].childNodes[j].childNodes.length;k++) |
---|
630 | { |
---|
631 | internalData+=xml.childNodes[i].childNodes[j].childNodes[k].nodeValue; |
---|
632 | } |
---|
633 | } else { |
---|
634 | var internalData = xml.childNodes[i].childNodes[j].firstChild.nodeValue; |
---|
635 | } |
---|
636 | |
---|
637 | if (xml.childNodes[i].childNodes[j].nodeName == "s") |
---|
638 | { |
---|
639 | search = internalData; |
---|
640 | } |
---|
641 | if (xml.childNodes[i].childNodes[j].nodeName == "r") |
---|
642 | { |
---|
643 | data = internalData; |
---|
644 | } |
---|
645 | } |
---|
646 | } |
---|
647 | else if (xml.childNodes[i].firstChild) |
---|
648 | data = xml.childNodes[i].firstChild.nodeValue; |
---|
649 | else |
---|
650 | data = ""; |
---|
651 | |
---|
652 | if (objElement != "XJX_SKIP") objElement = this.$(id); |
---|
653 | var cmdFullname; |
---|
654 | try |
---|
655 | { |
---|
656 | if (cmd=="cc") { |
---|
657 | cmdFullname = "addConfirmCommands"; |
---|
658 | var confirmResult = confirm(data); |
---|
659 | if (!confirmResult) { |
---|
660 | skipCommands = id; |
---|
661 | } |
---|
662 | } |
---|
663 | if (cmd=="al") |
---|
664 | { |
---|
665 | cmdFullname = "addAlert"; |
---|
666 | alert(data); |
---|
667 | } |
---|
668 | else if (cmd=="js") |
---|
669 | { |
---|
670 | cmdFullname = "addScript/addRedirect"; |
---|
671 | eval(data); |
---|
672 | } |
---|
673 | else if (cmd=="jc") |
---|
674 | { |
---|
675 | cmdFullname = "addScriptCall"; |
---|
676 | var scr = id + '('; |
---|
677 | if (data[0] != null) { |
---|
678 | scr += 'data[0]'; |
---|
679 | for (var l=1; l<data.length; l++) { |
---|
680 | scr += ',data['+l+']'; |
---|
681 | } |
---|
682 | } |
---|
683 | scr += ');'; |
---|
684 | eval(scr); |
---|
685 | } |
---|
686 | else if (cmd=="in") |
---|
687 | { |
---|
688 | cmdFullname = "addIncludeScript"; |
---|
689 | this.include(data); |
---|
690 | } |
---|
691 | else if (cmd=="as") |
---|
692 | { |
---|
693 | cmdFullname = "addAssign/addClear"; |
---|
694 | if (this.willChange(id,property,data)) |
---|
695 | { |
---|
696 | eval("objElement."+property+"=data;"); |
---|
697 | } |
---|
698 | } |
---|
699 | else if (cmd=="ap") |
---|
700 | { |
---|
701 | cmdFullname = "addAppend"; |
---|
702 | eval("objElement."+property+"+=data;"); |
---|
703 | } |
---|
704 | else if (cmd=="pp") |
---|
705 | { |
---|
706 | cmdFullname = "addPrepend"; |
---|
707 | eval("objElement."+property+"=data+objElement."+property); |
---|
708 | } |
---|
709 | else if (cmd=="rp") |
---|
710 | { |
---|
711 | cmdFullname = "addReplace"; |
---|
712 | this.replace(id,property,search,data) |
---|
713 | } |
---|
714 | else if (cmd=="rm") |
---|
715 | { |
---|
716 | cmdFullname = "addRemove"; |
---|
717 | this.remove(id); |
---|
718 | } |
---|
719 | else if (cmd=="ce") |
---|
720 | { |
---|
721 | cmdFullname = "addCreate"; |
---|
722 | this.create(id,data,property); |
---|
723 | } |
---|
724 | else if (cmd=="ie") |
---|
725 | { |
---|
726 | cmdFullname = "addInsert"; |
---|
727 | this.insert(id,data,property); |
---|
728 | } |
---|
729 | else if (cmd=="ia") |
---|
730 | { |
---|
731 | cmdFullname = "addInsertAfter"; |
---|
732 | this.insertAfter(id,data,property); |
---|
733 | } |
---|
734 | else if (cmd=="ci") |
---|
735 | { |
---|
736 | cmdFullname = "addCreateInput"; |
---|
737 | this.createInput(id,type,data,property); |
---|
738 | } |
---|
739 | else if (cmd=="ii") |
---|
740 | { |
---|
741 | cmdFullname = "addInsertInput"; |
---|
742 | this.insertInput(id,type,data,property); |
---|
743 | } |
---|
744 | else if (cmd=="iia") |
---|
745 | { |
---|
746 | cmdFullname = "addInsertInputAfter"; |
---|
747 | this.insertInputAfter(id,type,data,property); |
---|
748 | } |
---|
749 | else if (cmd=="ev") |
---|
750 | { |
---|
751 | cmdFullname = "addEvent"; |
---|
752 | property = this.addOnPrefix(property); |
---|
753 | eval("this.$('"+id+"')."+property+"= function(){"+data+";}"); |
---|
754 | } |
---|
755 | else if (cmd=="ah") |
---|
756 | { |
---|
757 | cmdFullname = "addHandler"; |
---|
758 | this.addHandler(id, property, data); |
---|
759 | } |
---|
760 | else if (cmd=="rh") |
---|
761 | { |
---|
762 | cmdFullname = "addRemoveHandler"; |
---|
763 | this.removeHandler(id, property, data); |
---|
764 | } |
---|
765 | } |
---|
766 | catch(e) |
---|
767 | { |
---|
768 | if (xajaxDebug) |
---|
769 | alert("While trying to '"+cmdFullname+"' (command number "+i+"), the following error occured:\n" |
---|
770 | + e.name+": "+e.message+"\n" |
---|
771 | + (id&&!objElement?"Object with id='"+id+"' wasn't found.\n":"")); |
---|
772 | } |
---|
773 | delete objElement; |
---|
774 | delete cmd; |
---|
775 | delete cmdFullname; |
---|
776 | delete id; |
---|
777 | delete property; |
---|
778 | delete search; |
---|
779 | delete data; |
---|
780 | delete type; |
---|
781 | delete before; |
---|
782 | delete internalData; |
---|
783 | delete j; |
---|
784 | delete k; |
---|
785 | } |
---|
786 | } |
---|
787 | delete xml; |
---|
788 | delete i; |
---|
789 | document.body.style.cursor = 'default'; |
---|
790 | if (xajaxStatusMessages == true) window.status = 'Done'; |
---|
791 | } |
---|
792 | } |
---|
793 | |
---|
794 | var xajax = new Xajax(); |
---|
795 | xajaxLoaded = true; |
---|