PageRenderTime 43ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/part2/view/common/js/aa.js

http://part2web.googlecode.com/
JavaScript | 893 lines | 532 code | 124 blank | 237 comment | 257 complexity | a609a8f8dbca26a1c31c103f0d5b393d MD5 | raw file
  1. /*
  2. Copyright 2005 Vitaliy Shevchuk (shevit@users.sourceforge.net)
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. // constructor;
  14. function AjaxAnywhere() {
  15. this.id = AjaxAnywhere.defaultInstanceName;
  16. this.formName = null;
  17. this.formId = null;
  18. this.notSupported = false;
  19. this.delayBeforeContentUpdate = true;
  20. this.delayInMillis = 100;
  21. this.callbackExecuted = true;
  22. if (window.XMLHttpRequest) {
  23. this.req = new XMLHttpRequest();
  24. if (this.req.overrideMimeType) {
  25. this.req.overrideMimeType("text/xml;charset=utf-8");
  26. }
  27. } else if (window.ActiveXObject) {
  28. try {
  29. this.req = new ActiveXObject("Msxml2.XMLHTTP");
  30. } catch(e) {
  31. try {
  32. this.req = new ActiveXObject("Microsoft.XMLHTTP");
  33. } catch(e1) {
  34. this.notSupported = true;
  35. /* XMLHTTPRequest not supported */
  36. }
  37. }
  38. }
  39. if (this.req == null || typeof this.req == "undefined")
  40. this.notSupported = true;
  41. }
  42. AjaxAnywhere.defaultInstanceName = "default";
  43. AjaxAnywhere.ASYNCH_KEY = "automated.test.session=false";
  44. AjaxAnywhere.SYNCH_KEY = "automated.test.session=true";
  45. /**
  46. * this features are added for better support of in-browser automated test frameworks like Selenium
  47. * if URL or query string contains "automated.test.sessionh=false" this method sets a session cookie to indicate that
  48. * for this session XmlHttpRequest must operate in synchronous mode.
  49. * click() method of in-browser test framework must not return untill page zones are correctly updated
  50. */
  51. AjaxAnywhere.parseQueryString = function(){
  52. if (location.href.indexOf(AjaxAnywhere.ASYNCH_KEY)!=-1)
  53. document.cookie = AjaxAnywhere.ASYNCH_KEY;
  54. else if (location.href.indexOf(AjaxAnywhere.SYNCH_KEY)!=-1)
  55. document.cookie = AjaxAnywhere.SYNCH_KEY;
  56. }
  57. AjaxAnywhere.parseQueryString();
  58. /**
  59. * returns true if curreny session is markes to work in synchronous mode for better compatibility with in-browser test,
  60. * like Selenium
  61. */
  62. AjaxAnywhere.prototype.isAsynch = function (){
  63. return document.cookie.indexOf(AjaxAnywhere.SYNCH_KEY)==-1;
  64. }
  65. /**
  66. * Stores substitutes SubmitButton names in to redo sustitution if a button was eventually inside a refresh zone.
  67. */
  68. AjaxAnywhere.prototype.substitutedSubmitButtons = new Array();
  69. AjaxAnywhere.prototype.substitutedSubmitButtonsInfo = new Object();
  70. /**
  71. * Returns a Form object that corresponds to formName property of this AjaxAnywhere class instance.
  72. */
  73. AjaxAnywhere.prototype.findForm = function () {
  74. var form;
  75. if (this.formId != null){
  76. //alert();
  77. form = document.getElementById(this.formId);
  78. //alert(form.action);
  79. }else{
  80. if (this.formName != null)
  81. form = document.forms[this.formName];
  82. else if (document.forms.length > 0)
  83. form = document.forms[0];
  84. }
  85. if (typeof form != "object")
  86. alert("AjaxAnywhere error: Form with name [" + this.formName + "] not found");
  87. return form;
  88. }
  89. /**
  90. * Binds this instance to window object using "AjaxAnywhere."+this.id as a key.
  91. */
  92. AjaxAnywhere.prototype.bindById = function () {
  93. var key = "AjaxAnywhere." + this.id;
  94. window[key] = this;
  95. }
  96. /**
  97. * Finds an instance by id.
  98. */
  99. AjaxAnywhere.findInstance = function(id) {
  100. var key = "AjaxAnywhere." + id;
  101. return window[key];
  102. }
  103. /**
  104. * This function is used to submit all form fields by AJAX request to the server.
  105. * If the form is submited with <input type=submit|image>, submitButton should be a reference to the DHTML object. Otherwise - undefined.
  106. */
  107. AjaxAnywhere.prototype.submitAJAX = function(additionalPostData, submitButton) {
  108. if (this.notSupported)
  109. return this.onSubmitAjaxNotSupported(additionalPostData, submitButton);
  110. if (additionalPostData == null || typeof additionalPostData == "undefined")
  111. additionalPostData = "";
  112. this.bindById();
  113. //??by honghao 20070726
  114. //???additionalPostData????form
  115. /*var form ;
  116. if(additionalPostData == null || additionalPostData == ""){
  117. form = this.findForm();
  118. }else{
  119. form = additionalPostData;
  120. if(typeof form != "object"){//?????????form
  121. form=this.findForm();
  122. }
  123. }
  124. alert(form.id);*/
  125. var form = this.findForm();
  126. var actionAttrNode = form.attributes["action"];
  127. var url = actionAttrNode == null?null:actionAttrNode.nodeValue;
  128. if ((url == null) || (url == ""))
  129. url = location.href;
  130. var pos = url.indexOf("#");
  131. if (pos!=-1)
  132. url = url.substring(0,pos);
  133. if ((url == null) || (url == ""))
  134. url = location.href;
  135. pos = url.indexOf("#");
  136. if (pos!=-1)
  137. url = url.substring(0,pos);
  138. var zones = this.getZonesToReload(url, submitButton);
  139. if (zones == null) {
  140. // submit in tradiditional way :
  141. this.submitOld(form,submitButton)
  142. return;
  143. }
  144. this.dropPreviousRequest();
  145. this.req.open("POST", url, this.isAsynch());
  146. this.req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
  147. this.req.setRequestHeader("Accept", "text/xml");
  148. var postData = this.preparePostData(submitButton);
  149. if (zones != "")
  150. postData = '&aazones=' + encodeURIComponent(zones) + "&" + postData + "&" + additionalPostData;
  151. else
  152. postData += "&" + additionalPostData;
  153. this.sendPreparedRequest(postData);
  154. }
  155. /**
  156. * sends a GET request to the server.
  157. */
  158. AjaxAnywhere.prototype.getAJAX = function(url, zonesToRefresh) {
  159. if (this.notSupported)
  160. return this.onGetAjaxNotSupported(url);
  161. this.bindById();
  162. if (zonesToRefresh == null || typeof zonesToRefresh == "undefined")
  163. zonesToRefresh = "";
  164. var urlDependentZones = this.getZonesToReload(url);
  165. if (urlDependentZones == null) {
  166. location.href = url;
  167. return;
  168. }
  169. if (urlDependentZones.length != 0)
  170. zonesToRefresh += "," + urlDependentZones;
  171. this.dropPreviousRequest();
  172. var newUrl;
  173. if(url.indexOf("?")!=-1){
  174. newUrl=url.substring(0,url.indexOf("?")+1);
  175. var urlStr=url.substring(url.indexOf("?")+1);
  176. if(urlStr!=""){
  177. var urlStrs = urlStr.split("&");
  178. if(urlStrs.length>0){
  179. newUrl+=urlStrs[0].split("=")[0]+"="+encodeURIComponent(urlStrs[0].split("=")[1]);
  180. for(var i=1;i<urlStrs.length;i++){
  181. newUrl+="&"+urlStrs[i].split("=")[0]+"="+encodeURIComponent(urlStrs[i].split("=")[1]);
  182. }
  183. }
  184. }
  185. }else{
  186. newUrl=url;
  187. }
  188. url=newUrl;
  189. url += (url.indexOf("?") != -1) ? "&" : "?";
  190. url += "aaxmlrequest=true&aa_rand=" + Math.random();
  191. // avoid caching
  192. if (zonesToRefresh != null && zonesToRefresh != "")
  193. url += '&aazones=' + encodeURIComponent(zonesToRefresh);
  194. this.req.open("GET", url, this.isAsynch());
  195. this.req.setRequestHeader("Content-Type", "text/html;charset=utf-8");
  196. this.req.setRequestHeader("Accept", "text/xml");
  197. this.sendPreparedRequest("");
  198. }
  199. /**
  200. * @private
  201. */
  202. AjaxAnywhere.prototype.sendPreparedRequest = function (postData) {
  203. this.req.setRequestHeader("Accept", "text/xml");
  204. var callbackKey = this.id + "_callbackFunction";
  205. if (typeof window[callbackKey] == "undefined")
  206. window[callbackKey] = new Function("AjaxAnywhere.findInstance(\"" + this.id + "\").callback(); ");
  207. this.req.onreadystatechange = window[callbackKey];
  208. this.showLoadingMessage();
  209. this.callbackExecuted = false;
  210. this.req.send(postData);
  211. this.onRequestSent();
  212. if ((!this.isAsynch()) && (!this.callbackExecuted )){
  213. window[callbackKey](); // look like firefox does not execute the callback for synch xmlhttprequest call.
  214. }
  215. }
  216. /**
  217. * Used internally by AjaxAnywhere. Aborts previous request if not completed.
  218. */
  219. AjaxAnywhere.prototype.dropPreviousRequest = function() {
  220. if (this.req.readyState != 0 && this.req.readyState != 4) {
  221. // abort previous request if not completed
  222. this.req.abort();
  223. this.handlePrevousRequestAborted();
  224. }
  225. }
  226. /**
  227. * Internally used to prepare Post data.
  228. * If the form is submited with &lt;input type=submit|image&gt;, submitButton is a reference to the DHTML object. Otherwise - undefined.
  229. */
  230. AjaxAnywhere.prototype.preparePostData = function(submitButton) {
  231. var form = this.findForm();
  232. var result = "&aaxmlrequest=true";
  233. for (var i = 0; i < form.elements.length; i++) {
  234. var el = form.elements[i];
  235. if (el.tagName.toLowerCase() == "select") {
  236. for (var j = 0; j < el.options.length; j++) {
  237. var op = el.options[j];
  238. if (op.selected)
  239. //result += "&" + encodeURIComponent(el.name) + "=" + encodeURIComponent(op.value);
  240. result += "&" + el.name+ "="+encodeURIComponent(op.value);
  241. }
  242. } else if (el.tagName.toLowerCase() == "textarea") {
  243. //result += "&" + encodeURIComponent(el.name) + "=" + encodeURIComponent(el.value);
  244. result += "&" +el.name+ "="+encodeURIComponent(el.value);
  245. } else if (el.tagName.toLowerCase() == "input") {
  246. if (el.type.toLowerCase() == "checkbox" || el.type.toLowerCase() == "radio") {
  247. if (el.checked)
  248. //result += "&" + encodeURIComponent(el.name) + "=" + encodeURIComponent(el.value);
  249. result += "&" +el.name+ "=" + encodeURIComponent(el.value);
  250. } else if (el.type.toLowerCase() == "submit") {
  251. if (el == submitButton) // is "el" the submit button that fired the form submit?
  252. //result += "&" + encodeURIComponent(el.name) + "=" + encodeURIComponent(el.value);
  253. result += "&" +el.name+"="+encodeURIComponent(el.value);
  254. } else if (el.type.toLowerCase() != "button") {
  255. //result += "&" + encodeURIComponent(el.name) + "=" + encodeURIComponent(el.value);
  256. result += "&" +el.name + "=" + encodeURIComponent(el.value);
  257. }
  258. }
  259. }
  260. if (typeof submitButton != 'undefined' && submitButton != null && submitButton.type.toLowerCase() == "image") {
  261. if (submitButton.name == null || submitButton.name == "" || typeof submitButton.name == "undefined")
  262. result += "&x=1&y=1"; // .x and .y coordinates calculation is not supported.
  263. else
  264. //result += "&" + encodeURIComponent(submitButton.name) + ".x=1&" +
  265. result += "&" + submitButton.name+ ".x=1&" +encodeURIComponent(submitButton.name) + ".y=1";
  266. }
  267. return result;
  268. }
  269. /**
  270. * Pauses the thread of execution for the specified number of milliseconds
  271. * @private
  272. */
  273. function delay(millis) {
  274. date = new Date();
  275. var curDate = null;
  276. do {
  277. curDate = new Date();
  278. }
  279. while (curDate - date < millis);
  280. }
  281. /**
  282. * Handle wrong content type.
  283. */
  284. AjaxAnywhere.prototype.handleWrongContentType = function()
  285. {
  286. alert("AjaxAnywhere error : content-type in not text/xml : [" + this.req.getResponseHeader('content-type') + "]");
  287. }
  288. /**
  289. * A callback. internally used
  290. */
  291. AjaxAnywhere.prototype.callback = function() {
  292. if (this.req.readyState == 4) {
  293. this.callbackExecuted = true;
  294. this.onBeforeResponseProcessing();
  295. this.hideLoadingMessage();
  296. if (this.req.status == 200) {
  297. if (this.req.getResponseHeader('content-type').toLowerCase().substring(0, 8) != 'text/xml') {
  298. this.handleWrongContentType();
  299. return;
  300. }
  301. var docs = this.req.responseXML.getElementsByTagName("document");
  302. var redirects = this.req.responseXML.getElementsByTagName("redirect");
  303. var zones = this.req.responseXML.getElementsByTagName("zone");
  304. var exceptions = this.req.responseXML.getElementsByTagName("exception");
  305. var scripts = this.req.responseXML.getElementsByTagName("script");
  306. var images = this.req.responseXML.getElementsByTagName("image");
  307. if (redirects.length != 0) {
  308. var newURL = redirects[0].firstChild.data;
  309. location.href = newURL;
  310. }
  311. if (docs.length != 0) {
  312. var newContent = docs[0].firstChild.data;
  313. //cleanup ressources
  314. delete this.req;
  315. document.close();
  316. document.write(newContent);
  317. document.close();
  318. }
  319. if (images.length != 0) {
  320. var preLoad = new Array(images.length);
  321. for (var i = 0; i < images.length; i++) {
  322. var img = images[i].firstChild;
  323. if (img != null) {
  324. preLoad[i] = new Image();
  325. preLoad[i].src = img.data;
  326. }
  327. }
  328. if (this.delayBeforeContentUpdate) {
  329. delay(this.delayInMillis);
  330. }
  331. }
  332. if (zones.length != 0) {
  333. for (var i = 0; i < zones.length; i++) {
  334. var zoneNode = zones[i];
  335. var name = zoneNode.getAttribute("name");
  336. var id = zoneNode.getAttribute("id");
  337. var html = "";
  338. for (var childIndex = 0; childIndex < zoneNode.childNodes.length; childIndex++) {
  339. html += zoneNode.childNodes[childIndex].data
  340. }
  341. var zoneHolder = name!=null?
  342. document.getElementById("aazone." + name):
  343. document.getElementById(id);
  344. if (zoneHolder != null && typeof(zoneHolder) != "undefined") {
  345. zoneHolder.innerHTML = html;
  346. }
  347. }
  348. }
  349. if (exceptions.length != 0) {
  350. var e = exceptions[0];
  351. var type = e.getAttribute("type");
  352. var stackTrace = e.firstChild.data;
  353. this.handleException(type, stackTrace);
  354. }
  355. if (scripts.length != 0) {
  356. for (var $$$$i = 0; $$$$i < scripts.length; $$$$i++) {
  357. // use $$$$i variable to avoid collision with "i" inside user script
  358. var script = scripts[$$$$i].firstChild;
  359. if (script != null) {
  360. script = script.data;
  361. if (script.indexOf("document.write") != -1) {
  362. this.handleException("document.write", "This script contains document.write(), which is not compatible with AjaxAnywhere : \n\n" + script);
  363. } else {
  364. eval("var aaInstanceId = \""+this.id+"\"; \n"+script);
  365. }
  366. }
  367. }
  368. var globals = this.getGlobalScriptsDeclarationsList(script);
  369. if (globals != null)
  370. for (var i in globals) {
  371. var objName = globals[i];
  372. try {
  373. window[objName] = eval(objName);
  374. } catch(e) {
  375. }
  376. }
  377. }
  378. } else {
  379. if (this.req.status != 0)
  380. this.handleHttpErrorCode(this.req.status);
  381. }
  382. this.restoreSubstitutedSubmitButtons();
  383. this.onAfterResponseProcessing();
  384. }
  385. }
  386. /**
  387. * Default sample loading message show function. Overrride it if you like.
  388. */
  389. /**
  390. AjaxAnywhere.prototype.showLoadingMessage = function() {
  391. var div = document.getElementById("AA_" + this.id + "_loading_div");
  392. if (div == null) {
  393. div = document.createElement("DIV");
  394. document.body.appendChild(div);
  395. div.id = "AA_" + this.id + "_loading_div";
  396. div.innerHTML = "&nbsp;Loading...";
  397. div.style.position = "absolute";
  398. div.style.border = "1 solid black";
  399. div.style.color = "white";
  400. div.style.backgroundColor = "blue";
  401. div.style.width = "100px";
  402. div.style.heigth = "50px";
  403. div.style.fontFamily = "Arial, Helvetica, sans-serif";
  404. div.style.fontWeight = "bold";
  405. div.style.fontSize = "11px";
  406. }
  407. div.style.top = document.body.scrollTop + "px";
  408. div.style.left = (document.body.offsetWidth - 100 - (document.all?20:0)) + "px";
  409. div.style.display = "";
  410. }
  411. */
  412. AjaxAnywhere.prototype.showLoadingMessage = function() {
  413. var div = document.getElementById("AA_" + this.id + "_loading_div");
  414. if (div == null) {
  415. div = document.createElement("DIV");
  416. document.body.appendChild(div);
  417. div.id = "AA_" + this.id + "_loading_div";
  418. // div.innerHTML = "<img src=\"/part2/jsp/images/loading.gif\" /><br/>loading...";
  419. div.style.textAlign= "center";
  420. div.style.padding="30px, 40px";
  421. div.style.position = "absolute";
  422. div.style.border = "0px solid #369";
  423. div.style.color = "#369";
  424. div.style.backgroundColor = "#fff";
  425. div.style.fontFamily = "Arial";
  426. div.style.fontWeight = "bold";
  427. div.style.fontSize = "1em";
  428. }
  429. div.style.top = ((document.body.offsetHeight)/2 - 30) + "px";
  430. div.style.left = ((document.body.offsetWidth)/2 - 40) + "px";
  431. div.style.display = "";
  432. }
  433. /**
  434. * Default sample loading message hide function. Overrride it if you like.
  435. */
  436. AjaxAnywhere.prototype.hideLoadingMessage = function() {
  437. var div = document.getElementById("AA_" + this.id + "_loading_div");
  438. var load = document.getElementById("load");
  439. if (div != null){
  440. div.style.display = "none";
  441. if(load != null)
  442. load.style.display = "none";
  443. }
  444. }
  445. /**
  446. * This function is used to facilitatte AjaxAnywhere integration with existing projects/frameworks.
  447. * It substitutes default Form.sumbit().
  448. * The new implementation calls AjaxAnywhere.isFormSubmitByAjax() function to find out if the form
  449. * should be submitted in traditional way or by AjaxAnywhere.
  450. */
  451. AjaxAnywhere.prototype.substituteFormSubmitFunction = function() {
  452. if (this.notSupported)
  453. return;
  454. this.bindById();
  455. var form = this.findForm();
  456. form.submit_old = form.submit;
  457. var code = "var ajax = AjaxAnywhere.findInstance(\"" + this.id + "\"); " +
  458. "if (typeof ajax !='object' || ! ajax.isFormSubmitByAjax() ) " +
  459. "ajax.findForm().submit_old();" +
  460. " else " +
  461. "ajax.submitAJAX();"
  462. form.submit = new Function(code);
  463. }
  464. /**
  465. * Substitutes the default behavior of &lt;input type=submit|image&gt; to submit the form via AjaxAnywhere.
  466. *
  467. * @param {boolean} indicates if existing onClick handlers should be preserved.
  468. * If keepExistingOnClickHandler==true,
  469. * Existing handler will be called first if it returns false, or if event.returnValue==false, AjaxAnywhere will not
  470. * continue form submission.
  471. * If keepExistingOnClickHandler==false or undefines, existing onClick event handlers will be replaced.
  472. *
  473. * @param {Array} list of submitButtons and submitImages names. If the parameter is omitted or undefined,
  474. * all elements will be processed
  475. */
  476. AjaxAnywhere.prototype.substituteSubmitButtonsBehavior = function (keepExistingOnClickHandler, elements) {
  477. if (this.notSupported)
  478. return;
  479. var form = this.findForm();
  480. if (elements == null || typeof elements == "undefined") { // process all elements
  481. elements = new Array();
  482. for (var i = 0; i < form.elements.length; i++) {
  483. elements.push(form.elements[i]);
  484. }
  485. var inputs = document.getElementsByTagName("input");
  486. for (var i = 0; i < inputs.length; i++) {
  487. var input = inputs[i];
  488. if (input.type != null && typeof input.type != "undefined" &&
  489. input.type.toLowerCase() == "image" && input.form == form) {
  490. elements.push(input);
  491. }
  492. }
  493. for (var i = 0; i < elements.length; i++) {
  494. var el = elements[i];
  495. if (el.tagName.toLowerCase() == "input" && (el.type.toLowerCase() == "submit"
  496. || el.type.toLowerCase() == "image")) {
  497. this.substituteSubmitBehavior(el, keepExistingOnClickHandler);
  498. }
  499. }
  500. } else { //process only specified elements
  501. for (var i = 0; i < elements.length; i++) {
  502. var el = elements[i];
  503. if (el == null)
  504. continue;
  505. if (typeof el != "object")
  506. el = form.elements[el];
  507. if (typeof el != "undefined") {
  508. if (el.tagName.toLowerCase() == "input" && (el.type.toLowerCase() == "submit"
  509. || el.type.toLowerCase() == "image"))
  510. this.substituteSubmitBehavior(el, keepExistingOnClickHandler);
  511. }
  512. }
  513. }
  514. }
  515. /**
  516. * Performs a single element behavior substitution
  517. *
  518. * @private
  519. */
  520. AjaxAnywhere.prototype.substituteSubmitBehavior = function (el, keepExistingOnClickHandler) {
  521. var inList = false;
  522. for (var i = 0; i < this.substitutedSubmitButtons.length; i++) {
  523. var btnName = this.substitutedSubmitButtons[i];
  524. if (btnName == el.name) {
  525. inList = true;
  526. break;
  527. }
  528. }
  529. if (!inList)
  530. this.substitutedSubmitButtons.push(el.name);
  531. this.substitutedSubmitButtonsInfo[el.name] = keepExistingOnClickHandler;
  532. if (keepExistingOnClickHandler && (typeof el.onclick != "undefined") && ( el.onclick != null) && ( el.onclick != "")) {
  533. el.AA_old_onclick = el.onclick;
  534. }
  535. el.onclick = handleSubmitButtonClick;
  536. el.ajaxAnywhereId = this.id;
  537. }
  538. /**
  539. *
  540. * @private
  541. */
  542. AjaxAnywhere.prototype.restoreSubstitutedSubmitButtons = function() {
  543. if (this.substitutedSubmitButtons.length == 0)
  544. return;
  545. var form = this.findForm();
  546. for (var i = 0; i < this.substitutedSubmitButtons.length; i++) {
  547. var name = this.substitutedSubmitButtons[i];
  548. var el = form.elements[name];
  549. if (el != null && typeof el != "undefined") {
  550. if (el.onclick != handleSubmitButtonClick) {
  551. var keepExistingOnClickHandler = this.substitutedSubmitButtonsInfo[el.name];
  552. this.substituteSubmitBehavior(el, keepExistingOnClickHandler);
  553. }
  554. } else {
  555. //input type=image
  556. if (name != null && typeof name != "undefined" && name.length != 0) {
  557. var elements = document.getElementsByName(name);
  558. if (elements != null)
  559. for (var j = 0; j < elements.length; j++) {
  560. el = elements[j];
  561. if (el != null && typeof el != "undefined"
  562. && el.tagName.toLowerCase() == "input"
  563. && typeof el.type != "undefined" && el.type.toLowerCase() == "image") {
  564. if (el.onclick != handleSubmitButtonClick) {
  565. var keepExistingOnClickHandler = this.substitutedSubmitButtonsInfo[el.name];
  566. this.substituteSubmitBehavior(el, keepExistingOnClickHandler);
  567. }
  568. }
  569. }
  570. }
  571. }
  572. }
  573. }
  574. /**
  575. * @private
  576. */
  577. function handleSubmitButtonClick(_event) {
  578. if (typeof this.AA_old_onclick != "undefined") {
  579. if (false == this.AA_old_onclick(_event))
  580. return false;
  581. if (typeof window.event != "undefined")
  582. if (window.event.returnValue == false)
  583. return false;
  584. }
  585. var onsubmit = this.form.onsubmit;
  586. if (typeof onsubmit == "function") {
  587. if (false == onsubmit(_event))
  588. return false;
  589. if (typeof window.event != "undefined")
  590. if (window.event.returnValue == false)
  591. return false;
  592. }
  593. AjaxAnywhere.findInstance(this.ajaxAnywhereId).submitAJAX('', this);
  594. return false;
  595. }
  596. /**
  597. * Override this function if you use AjaxAnywhere.substituteFormSubmitFunction() to
  598. * dynamically inform AjaxAnywhere of the method you want to use for the form submission.
  599. */
  600. AjaxAnywhere.prototype.isFormSubmitByAjax = function () {
  601. return true;
  602. }
  603. /**
  604. * Some browsers (notably IE) do not load images from thier cache when content is updated using
  605. * innerHTML. As a result, each image is re-requested from the server even though the image exists
  606. * in the cache. To work around this issue, AjaxAnywhere preloads images present in the new content
  607. * and intrduces a brief dely (default of 100 milleseconds) before calling innerHTML.
  608. * See http://support.microsoft.com/default.aspx?scid=kb;en-us;319546 for further details.
  609. * This function can be used to change this behaviour.
  610. * @param (boolean) isDelay
  611. */
  612. AjaxAnywhere.prototype.setDelayBeforeLoad = function (isDelay) {
  613. this.delayBeforeContentUpdate = isDelay;
  614. }
  615. /**
  616. * Returns the current delay behavior.
  617. */
  618. AjaxAnywhere.prototype.isDelayBeforeLoad = function () {
  619. return this.delayBeforeContentUpdate;
  620. }
  621. /**
  622. * Sets the delay period in milliseconds. The default delay is 100 milliseconds.
  623. * @param (int) delayMillis
  624. */
  625. AjaxAnywhere.prototype.setDelayTime = function (delayMillis) {
  626. this.delayInMillis = delayMillis;
  627. }
  628. /**
  629. * Returns the delay period in milliseconds.
  630. */
  631. AjaxAnywhere.prototype.getDelayTime = function () {
  632. return this.delayInMillis;
  633. }
  634. /**
  635. * If an exception is throws on the server-side during AJAX request, it will be processed
  636. * by this function. The default implementation is alert(stackTrace);
  637. * Override it if you need.
  638. */
  639. AjaxAnywhere.prototype.handleException = function(type, details) {
  640. alert(details);
  641. }
  642. /**
  643. * If an HTTP Error code returned during AJAX request, it will be processed
  644. * by this function. The default implementation is alert(code);
  645. * Override it if you need.
  646. */
  647. AjaxAnywhere.prototype.handleHttpErrorCode = function(code) {
  648. var details = confirm("AjaxAnywhere default error handler. XMLHttpRequest HTTP Error code:" + code + " \n\n Would you like to view the response content in a new window?");
  649. if (details) {
  650. var win = window.open("", this.id + "_debug_window");
  651. if (win != null) {
  652. win.document.write("<html><body><xmp>" + this.req.responseText);
  653. win.document.close();
  654. win.focus();
  655. } else {
  656. alert("Please, disable your pop-up blocker for this site first.");
  657. }
  658. }
  659. }
  660. /**
  661. * Override it if you need.
  662. */
  663. AjaxAnywhere.prototype.handlePrevousRequestAborted = function() {
  664. //alert("AjaxAnywhere default error handler. INFO: previous AJAX request dropped")
  665. }
  666. /**
  667. * If the HTML received in responce to AJAX request contains JavaScript that defines new
  668. * functions/variables, they must be propagated to the proper context. Override this method
  669. * to return the Array of function/variable names.
  670. */
  671. AjaxAnywhere.prototype.getGlobalScriptsDeclarationsList = function(script) {
  672. return null;
  673. }
  674. /**
  675. * This function should be overridden by AjaxAnywhere user to implement client-side
  676. * determination of zones to reload.
  677. *
  678. * If the form is submited with &lt;input type=submit|image&gt;, submitButton is a reference to the DHTML object. Otherwise - undefined.
  679. *
  680. * @Returns a comma separated list of zones to reload, or "document.all" to reload
  681. * the whole page. Returns null if the request must be sent in traditional way
  682. *
  683. */
  684. AjaxAnywhere.prototype.getZonesToReload = function(url, submitButton) {
  685. return this.getZonesToReaload();
  686. // backward compatibility only
  687. }
  688. /**
  689. * depreceted : wrond spelling : Reaload will be removed in later versions
  690. */
  691. AjaxAnywhere.prototype.getZonesToReaload = function(url, submitButton) {
  692. return "";
  693. }
  694. /**
  695. * Override this method to implement a custom action
  696. */
  697. AjaxAnywhere.prototype.onRequestSent = function () {
  698. };
  699. /**
  700. * Override this method to implement a custom action
  701. */
  702. AjaxAnywhere.prototype.onBeforeResponseProcessing = function () {
  703. };
  704. /**
  705. * Override this method to implement a custom action
  706. */
  707. AjaxAnywhere.prototype.onAfterResponseProcessing = function () {
  708. };
  709. /**
  710. * Provides a default implementation from graceful degradation for getAJAX()
  711. * calls location.href=url if XMLHttpRequest is unavailable, reloading the entire page .
  712. */
  713. AjaxAnywhere.prototype.onGetAjaxNotSupported = function (url) {
  714. location.href = url;
  715. return false;
  716. };
  717. /**
  718. * Provides a default implementation from graceful degradation for submitAJAX()
  719. * calls form.submit() if XMLHttpRequest is unavailable, reloading the entire page
  720. */
  721. AjaxAnywhere.prototype.onSubmitAjaxNotSupported = function (additionalPostData, submitButton) {
  722. var form = this.findForm();
  723. var actionAttrNode = form.attributes["action"];
  724. var url = actionAttrNode == null?null:actionAttrNode.nodeValue;
  725. var url_backup = url;
  726. if (typeof additionalPostData != 'undefined' && additionalPostData != null) {
  727. url += (url.indexOf("?") != -1) ? "&" : "?";
  728. url += additionalPostData;
  729. form.attributes["action"].nodeValue= url;
  730. // only POST method allows sending additional
  731. // date by altering form action URL.
  732. form.setAttribute("method", "post");
  733. }
  734. this.submitOld(form,submitButton);
  735. form.attributes["action"].nodeValue= url_backup;
  736. return false;
  737. };
  738. /**
  739. * submit the form in tradiditional way :
  740. * @private
  741. */
  742. AjaxAnywhere.prototype.submitOld = function (form,submitButton){
  743. var submitHolder = null;
  744. if (submitButton!=null && typeof submitButton!="undefined"){
  745. submitHolder = document.createElement("input");
  746. submitHolder.setAttribute("type","hidden");
  747. submitHolder.setAttribute("name",submitButton.name);
  748. submitHolder.setAttribute("value",submitButton.value);
  749. form.appendChild(submitHolder);
  750. }
  751. if (typeof form.submit_old == "undefined")
  752. form.submit();
  753. else
  754. form.submit_old();
  755. if (submitButton!=null ){
  756. form.removeChild(submitHolder);
  757. }
  758. }
  759. // default instance.
  760. ajaxAnywhere = new AjaxAnywhere();
  761. ajaxAnywhere.bindById();