You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by we...@apache.org on 2009/04/09 13:09:50 UTC

svn commit: r763603 - in /myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/javax/faces/ajax: jsf.js jsf_impl.js

Author: werpu
Date: Thu Apr  9 11:09:50 2009
New Revision: 763603

URL: http://svn.apache.org/viewvc?rev=763603&view=rev
Log:
https://issues.apache.org/jira/browse/MYFACES-2185

temporary backport from the non asd development base, I cannot commit everything yet due to a pending ICLA.


Modified:
    myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/javax/faces/ajax/jsf.js
    myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/javax/faces/ajax/jsf_impl.js

Modified: myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/javax/faces/ajax/jsf.js
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/javax/faces/ajax/jsf.js?rev=763603&r1=763602&r2=763603&view=diff
==============================================================================
--- myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/javax/faces/ajax/jsf.js (original)
+++ myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/javax/faces/ajax/jsf.js Thu Apr  9 11:09:50 2009
@@ -123,4 +123,21 @@
     };
 }
 
+if ('undefined' == typeof jsf.util || null == jsf.util) {
+    jsf.util = new Object();
 
+    /**
+     * varargs function which executes a chain of code (functions or any other code)
+     *
+     * if any of the code returns false, the execution
+     * is terminated prematurely skipping the rest of the code!
+     *
+     * @param {DomNode} source, the callee object
+     * @param {Event} event, the event object of the callee event triggering this function
+     *
+     */
+    jsf.util.chain = function(source, event) {
+        jsf.ajax._impl.chain.apply(jsf.ajax._impl, arguments);
+    }
+
+}

Modified: myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/javax/faces/ajax/jsf_impl.js
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/javax/faces/ajax/jsf_impl.js?rev=763603&r1=763602&r2=763603&view=diff
==============================================================================
--- myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/javax/faces/ajax/jsf_impl.js (original)
+++ myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/javax/faces/ajax/jsf_impl.js Thu Apr  9 11:09:50 2009
@@ -455,4 +455,51 @@
         return this._projectStage;
     };
 
+      /**
+       * implementation of the external chain function
+       * moved into the impl
+       *
+       * according to the ri the source will bhe the scope
+       * for the functions the event will be the object passed
+       * @param {Object} source the source which also becomes
+       * the scope for the calling function (not sure if this is correct however
+       * the RI does it that way!
+       * @param {Event} event the event object being passed down into the
+       */
+    myfaces._jsfImpl.prototype.chain = function(source, event) {
+        var len = arguments.length;
+        if(len < 3) return;
+        //now we fetch from what is given from the parameter list
+        //we cannot work with splice here in any performant way so we do it the hard way
+        //arguments only are give if not set to undefined even null values!
+
+        var thisVal = ('object' == typeof source ) ? source: null;
+        var param   = ('undefined' != typeof event) ? event: null;
+
+        for(loop = 2; loop < len; loop++) {
+            //we do not change the scope of the incoming functions
+            //but we reuse the argument array capabilities of apply
+            var retVal = false;
+            //The spec states arbitrary codeblock
+            //the ri wraps everything into functions
+            //we do it differently here,
+            //
+            //We wrap only if the block itself
+            //is not a function! Should be compatible
+            //to the ri, but saner in its usage because
+            //it saves one intermediate step in most cases
+            //not my personal design decision, I probably would
+            //enforce functions only to keep the caller code clean,
+            //oh well
+            if('function' == typeof arguments[loop]) {
+                retVal = arguments[loop].call(thisVal, param);
+            } else {
+                retVal = (new Function("evt", arguments[loop])).call(thisVal, param);
+            }
+            //now if one function returns null in between we stop the execution of the cycle
+            //here
+            if('undefined' != typeof retVal && retVal === false) return;
+        }
+    };
+
 }