/mojarra-2.1.7/jsf-ri/resources/mojarra.js

# · JavaScript · 191 lines · 56 code · 14 blank · 121 comment · 11 complexity · 5dd5ab940f0c5049ba09d80384eb42a2 MD5 · raw file

  1. /*
  2. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  3. *
  4. * Copyright 1997-2008 Sun Microsystems, Inc. All rights reserved.
  5. *
  6. * The contents of this file are subject to the terms of either the GNU
  7. * General Public License Version 2 only ("GPL") or the Common Development
  8. * and Distribution License("CDDL") (collectively, the "License"). You
  9. * may not use this file except in compliance with the License. You can obtain
  10. * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
  11. * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
  12. * language governing permissions and limitations under the License.
  13. *
  14. * When distributing the software, include this License Header Notice in each
  15. * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
  16. * Sun designates this particular file as subject to the "Classpath" exception
  17. * as provided by Sun in the GPL Version 2 section of the License file that
  18. * accompanied this code. If applicable, add the following below the License
  19. * Header, with the fields enclosed by brackets [] replaced by your own
  20. * identifying information: "Portions Copyrighted [year]
  21. * [name of copyright owner]"
  22. *
  23. * Contributor(s):
  24. *
  25. * If you wish your version of this file to be governed by only the CDDL or
  26. * only the GPL Version 2, indicate your decision by adding "[Contributor]
  27. * elects to include this software in this distribution under the [CDDL or GPL
  28. * Version 2] license." If you don't indicate a single choice of license, a
  29. * recipient has the option to distribute your version of this file under
  30. * either the CDDL, the GPL Version 2 or to extend the choice of license to
  31. * its licensees as provided above. However, if you add GPL Version 2 code
  32. * and therefore, elected the GPL Version 2 license, then the option applies
  33. * only if the new code is made subject to such option by the copyright
  34. * holder.
  35. *
  36. *
  37. * This file incorporates work covered by the following copyright and
  38. * permission notice:
  39. *
  40. * Copyright 2004 The Apache Software Foundation
  41. *
  42. * Licensed under the Apache License, Version 2.0 (the "License");
  43. * you may not use this file except in compliance with the License.
  44. * You may obtain a copy of the License at
  45. *
  46. * http://www.apache.org/licenses/LICENSE-2.0
  47. *
  48. * Unless required by applicable law or agreed to in writing, software
  49. * distributed under the License is distributed on an "AS IS" BASIS,
  50. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  51. * See the License for the specific language governing permissions and
  52. * limitations under the License.
  53. */
  54. /**
  55. @project JSF Ajax Library
  56. @version 2.0
  57. @description This is the standard implementation of the JSF Ajax Library.
  58. */
  59. /**
  60. * Register with OpenAjax
  61. */
  62. if (typeof OpenAjax !== "undefined" &&
  63. typeof OpenAjax.hub.registerLibrary !== "undefined") {
  64. OpenAjax.hub.registerLibrary("mojarra", "www.sun.com", "1.0", null);
  65. }
  66. /**
  67. * @name mojarra
  68. * @namespace
  69. */
  70. /*
  71. * Create our top level namespaces - mojarra
  72. */
  73. var mojarra = mojarra || {};
  74. /**
  75. * This function deletes any hidden parameters added
  76. * to the form by checking for a variable called 'adp'
  77. * defined on the form. If present, this variable will
  78. * contain all the params added by 'apf'.
  79. *
  80. * @param f - the target form
  81. */
  82. mojarra.dpf = function dpf(f) {
  83. var adp = f.adp;
  84. if (adp !== null) {
  85. for (var i = 0; i < adp.length; i++) {
  86. f.removeChild(adp[i]);
  87. }
  88. }
  89. };
  90. /*
  91. * This function adds any parameters specified by the
  92. * parameter 'pvp' to the form represented by param 'f'.
  93. * Any parameters added will be stored in a variable
  94. * called 'adp' and stored on the form.
  95. *
  96. * @param f - the target form
  97. * @param pvp - associative array of parameter
  98. * key/value pairs to be added to the form as hidden input
  99. * fields.
  100. */
  101. mojarra.apf = function apf(f, pvp) {
  102. var adp = new Array();
  103. f.adp = adp;
  104. var i = 0;
  105. for (var k in pvp) {
  106. if (pvp.hasOwnProperty(k)) {
  107. var p = document.createElement("input");
  108. p.type = "hidden";
  109. p.name = k;
  110. p.value = pvp[k];
  111. f.appendChild(p);
  112. adp[i++] = p;
  113. }
  114. }
  115. };
  116. /*
  117. * This is called by command link and command button. It provides
  118. * the form it is nested in, the parameters that need to be
  119. * added and finally, the target of the action. This function
  120. * will delete any parameters added <em>after</em> the form
  121. * has been submitted to handle DOM caching issues.
  122. *
  123. * @param f - the target form
  124. * @param pvp - associative array of parameter
  125. * key/value pairs to be added to the form as hidden input
  126. * fields.
  127. * @param t - the target of the form submission
  128. */
  129. mojarra.jsfcljs = function jsfcljs(f, pvp, t) {
  130. mojarra.apf(f, pvp);
  131. var ft = f.target;
  132. if (t) {
  133. f.target = t;
  134. }
  135. f.submit();
  136. f.target = ft;
  137. mojarra.dpf(f);
  138. };
  139. /*
  140. * This is called by functions that need access to their calling
  141. * context, in the form of <code>this</code> and <code>event</code>
  142. * objects.
  143. *
  144. * @param f the function to execute
  145. * @param t this of the calling function
  146. * @param e event of the calling function
  147. * @return object that f returns
  148. */
  149. mojarra.jsfcbk = function jsfcbk(f, t, e) {
  150. return f.call(t,e);
  151. };
  152. /*
  153. * This is called by the AjaxBehaviorRenderer script to
  154. * trigger a jsf.ajax.request() call.
  155. *
  156. * @param s the source element or id
  157. * @param e event of the calling function
  158. * @param n name of the behavior event that has fired
  159. * @param ex execute list
  160. * @param re render list
  161. * @param op options object
  162. */
  163. mojarra.ab = function ab(s, e, n, ex, re, op) {
  164. if (!op) {
  165. op = {};
  166. }
  167. if (n) {
  168. op["javax.faces.behavior.event"] = n;
  169. }
  170. if (ex) {
  171. op["execute"] = ex;
  172. }
  173. if (re) {
  174. op["render"] = re;
  175. }
  176. jsf.ajax.request(s, e, op);
  177. };