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 2011/09/26 14:34:50 UTC
svn commit: r1175830 - in
/myfaces/core/branches/2.0.x/api/src/main/javascript/META-INF/resources/myfaces/_impl:
_util/_Dom.js xhrCore/_AjaxRequest.js xhrCore/_AjaxResponse.js
Author: werpu
Date: Mon Sep 26 12:34:49 2011
New Revision: 1175830
URL: http://svn.apache.org/viewvc?rev=1175830&view=rev
Log:
https://issues.apache.org/jira/browse/MYFACES-3320
Reverting to pure xhr level1 handling due to webkit bugs
https://issues.apache.org/jira/browse/MYFACES-3318
finalizing the new insert update code, so that it also works
with tables and evals the new content
Modified:
myfaces/core/branches/2.0.x/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Dom.js
myfaces/core/branches/2.0.x/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxRequest.js
myfaces/core/branches/2.0.x/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxResponse.js
Modified: myfaces/core/branches/2.0.x/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Dom.js
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Dom.js?rev=1175830&r1=1175829&r2=1175830&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Dom.js (original)
+++ myfaces/core/branches/2.0.x/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Dom.js Mon Sep 26 12:34:49 2011
@@ -240,6 +240,11 @@ myfaces._impl.core._Runtime.singletonExt
this._removeNode(item, false);
},
+ /**
+ * creates a node upon a given node name
+ * @param nodeName {String} the node name to be created
+ * @param attrs {Array} a set of attributes to be set
+ */
createElement: function(nodeName, attrs) {
var ret = document.createElement(nodeName);
if(attrs) {
@@ -277,6 +282,59 @@ myfaces._impl.core._Runtime.singletonExt
},
/**
+ * proper insert before which takes tables into consideration as well as
+ * browser deficiencies
+ * @param item the node to insert before
+ * @param markup the markup to be inserted
+ */
+ insertBefore: function(item, markup) {
+ this._assertStdParams(item, markup, "insertBefore");
+ markup = this._Lang.trim(markup);
+ if (markup === "") return null;
+
+ var evalNodes = this._buildEvalNodes(item, markup);
+ var currentRef = item;
+ var parentNode = item.parentNode;
+ var ret = [];
+ for(var cnt = evalNodes.length -1; cnt >= 0; cnt--) {
+ currentRef = parentNode.insertBefore(evalNodes[cnt], currentRef);
+ ret.push(currentRef);
+ }
+ ret = ret.reverse();
+ this._eval(ret);
+ return ret;
+ },
+
+ /**
+ * proper insert before which takes tables into consideration as well as
+ * browser deficiencies
+ * @param item the node to insert before
+ * @param markup the markup to be inserted
+ */
+ insertAfter: function(item, markup) {
+ this._assertStdParams(item, markup, "insertAfter");
+ markup = this._Lang.trim(markup);
+ if (markup === "") return null;
+
+ var evalNodes = this._buildEvalNodes(item, markup);
+ var currentRef = item;
+ var parentNode = item.parentNode;
+ var ret = [];
+ for(var cnt = 0; cnt < evalNodes.length; cnt++) {
+ if(currentRef.nextSibling) {
+ //TODO winmobile6 has problems with this strategy
+ currentRef = parentNode.insertBefore(evalNodes[cnt], currentRef.nextSibling);
+ } else {
+ currentRef = parentNode.appendChild(evalNodes[cnt]);
+ }
+ ret.push(currentRef);
+ }
+ this._eval(ret);
+ return ret;
+ },
+
+
+ /**
* outerHTML replacement which works cross browserlike
* but still is speed optimized
*
@@ -284,12 +342,7 @@ myfaces._impl.core._Runtime.singletonExt
* @param markup the markup for the replacement
*/
outerHTML : function(item, markup) {
- if (!item) {
- throw Error(this._Lang.getMessage("ERR_MUST_BE_PROVIDED1",null,"myfaces._impl._util._Dom.outerHTML", "item"));
- }
- if (!markup) {
- throw Error(this._Lang.getMessage("ERR_MUST_BE_PROVIDED1",null,"myfaces._impl._util._Dom.outerHTML", "markup"));
- }
+ this._assertStdParams(item, markup, "outerHTML");
markup = this._Lang.trim(markup);
if (markup !== "") {
@@ -306,24 +359,16 @@ myfaces._impl.core._Runtime.singletonExt
// and remove the old item
//first we have to save the node newly insert for easier access in our eval part
- if (this.isManualScriptEval()) {
- var isArr = ret instanceof Array;
- if (isArr && ret.length) {
- for (var cnt = 0; cnt < ret.length; cnt++) {
- this.runScripts(ret[cnt]);
- }
- } else if (!isArr) {
- this.runScripts(ret);
- }
- }
+ this._eval(ret);
return ret;
}
// and remove the old item, in case of an empty newtag and do nothing else
this._removeNode(item, false);
return null;
},
+
/**
- * detchaes a set of nodes from their parent elements
+ * detaches a set of nodes from their parent elements
* in a browser independend manner
* @param {Object} items the items which need to be detached
* @return {Array} an array of nodes with the detached dom nodes
@@ -350,14 +395,9 @@ myfaces._impl.core._Runtime.singletonExt
_outerHTMLCompliant: function(item, markup) {
var evalNodes;
//table element replacements like thead, tbody etc... have to be treated differently
- if (this._isTableElement(item)) {
- evalNodes = this._buildTableNodes(item, markup);
- } else {
- evalNodes = this._buildNodesCompliant(markup);
- }
- var evalNodeLen = evalNodes.length;
+ var evalNodes = this._buildEvalNodes(item, markup);
- if (evalNodeLen == 1) {
+ if (evalNodes.length == 1) {
var ret = evalNodes[0];
item.parentNode.replaceChild(ret, item);
return ret;
@@ -402,13 +442,7 @@ myfaces._impl.core._Runtime.singletonExt
try {
//check for a subtable rendering case
- if (this._isTableElement(item)) {
- evalNodes = this._buildTableNodes(item, markup);
- } else {
- //if no subtable element is given we simply work on our
- //normal markup
- evalNodes = this._buildNodesNonCompliant(markup);
- }
+ var evalNodes = this._buildEvalNodes(item, markup);
if (evalNodes.length == 1) {
var ret = evalNodes[0];
@@ -668,6 +702,59 @@ myfaces._impl.core._Runtime.singletonExt
,
/**
+ * build up the nodes from html markup in a browser independend way
+ * so that it also works with table nodes
+ *
+ * @param item the parent item upon the nodes need to be processed upon after building
+ * @param markup the markup to be built up
+ */
+ _buildEvalNodes: function(item, markup) {
+ var evalNodes = null;
+ if (this._isTableElement(item)) {
+ evalNodes = this._buildTableNodes(item, markup);
+ } else {
+ evalNodes = (this.isDomCompliant()) ? this._buildNodesCompliant(markup): this._buildNodesNonCompliant(markup);
+ }
+ return evalNodes;
+ },
+
+ /**
+ * we have lots of methods with just an item and a markup as params
+ * this method builds an assertion for those methods to reduce code
+ *
+ * @param item the item to be tested
+ * @param markup the mark
+ * @param caller
+ */
+ _assertStdParams: function(item, markup, caller) {
+ //internal error
+ if(!caller) throw Error("Caller must be set for assertion");
+ if (!item) {
+ throw Error(this._Lang.getMessage("ERR_MUST_BE_PROVIDED1",null,"myfaces._impl._util._Dom."+caller, "item"));
+ }
+ if (!markup) {
+ throw Error(this._Lang.getMessage("ERR_MUST_BE_PROVIDED1",null, "myfaces._impl._util._Dom."+caller, "markup"));
+ }
+ },
+
+ /**
+ * internal eval handler used by various functions
+ * @param _nodeArr
+ */
+ _eval: function(_nodeArr) {
+ if (this.isManualScriptEval()) {
+ var isArr = _nodeArr instanceof Array;
+ if (isArr && _nodeArr.length) {
+ for (var cnt = 0; cnt < _nodeArr.length; cnt++) {
+ this.runScripts(_nodeArr[cnt]);
+ }
+ } else if (!isArr) {
+ this.runScripts(_nodeArr);
+ }
+ }
+ },
+
+ /**
* break the standard events from an existing dom node
* (note this method is not yet used, but can be used
* by framework authors to get rid of ie circular event references)
Modified: myfaces/core/branches/2.0.x/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxRequest.js
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxRequest.js?rev=1175830&r1=1175829&r2=1175830&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxRequest.js (original)
+++ myfaces/core/branches/2.0.x/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxRequest.js Mon Sep 26 12:34:49 2011
@@ -262,10 +262,13 @@ myfaces._impl.core._Runtime.extendClass(
var xhr = myfaces._impl.core._Runtime.getXHRObject();
//the current xhr level2 timeout w3c spec is not implemented by the browsers yet
//we have to do a fallback to our custom routines
- if (('undefined' == typeof this._timeout || null == this._timeout) && _Rt.getXHRLvl() >= 2) {
+
+ //Chrome fails in the current builds, on our loadend, we disable the xhr
+ //level2 optimisations for now
+ //if (('undefined' == typeof this._timeout || null == this._timeout) && _Rt.getXHRLvl() >= 2) {
//no timeout we can skip the emulation layer
- return xhr;
- }
+ // return xhr;
+ //}
return new myfaces._impl.xhrCore.engine.Xhr1({xhrObject: xhr});
},
Modified: myfaces/core/branches/2.0.x/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxResponse.js
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxResponse.js?rev=1175830&r1=1175829&r2=1175830&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxResponse.js (original)
+++ myfaces/core/branches/2.0.x/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxResponse.js Mon Sep 26 12:34:49 2011
@@ -615,12 +615,12 @@ myfaces._impl.core._Runtime.singletonExt
**/
processInsert: function(request, context, node) {
/*remapping global namespaces for speed and readability reasons*/
- var _Impl = this._getImpl();
- var _Lang = this._Lang;
- var _Dom = this._Dom;
+ var _Impl = this._getImpl();
+ var _Lang = this._Lang;
+ var _Dom = this._Dom;
//determine which path to go:
- var insertData = this._determineInsertData(request, context, node);
+ var insertData = this._parseInsertData(request, context, node);
if(!insertData) return false;
var opNode = this._Dom.byIdOrName(insertData.opId);
@@ -629,8 +629,12 @@ myfaces._impl.core._Runtime.singletonExt
return false;
}
- //call _insertBefore or _insertAfter
- return this[insertData.insertType](request, context, opNode, insertData.cDataBlock);
+ //call insertBefore or insertAfter in our dom routines
+ var replacementFragment = _Dom[insertData.insertType](opNode, insertData.cDataBlock);
+ if(replacementFragment) {
+ this._pushOperationResult(context, replacementFragment);
+ }
+ return true;
},
/**
@@ -650,13 +654,13 @@ myfaces._impl.core._Runtime.singletonExt
* TODO we have to find a mechanism to replace the direct sendError calls with a javascript exception
* which we then can use for cleaner error code handling
*/
- _determineInsertData: function(request, context, node) {
+ _parseInsertData: function(request, context, node) {
var _Impl = this._getImpl();
var _Lang = this._Lang;
var _Dom = this._Dom;
- var INSERT_TYPE_BEFORE = "_insertBefore";
- var INSERT_TYPE_AFTER = "_insertAfter";
+ var INSERT_TYPE_BEFORE = "insertBefore";
+ var INSERT_TYPE_AFTER = "insertAfter";
var id = node.getAttribute("id");
var beforeId = node.getAttribute("before");
@@ -703,47 +707,6 @@ myfaces._impl.core._Runtime.singletonExt
return ret;
},
- _insertBefore: function(request, context, opNode, cDataBlock) {
- /**
- *we generate a temp holder
- *so that we can use innerHTML for
- *generating the content upfront
- *before inserting it"
- **/
- var nodeHolder = document.createElement("div");
- var parentNode = opNode.parentNode;
-
- parentNode.insertBefore(nodeHolder, opNode);
- var replacementFragment = this.replaceHtmlItem(request, context,
- nodeHolder, cDataBlock);
- if (replacementFragment) {
- this._pushOperationResult(context, replacementFragment);
- }
- return true;
- },
-
- _insertAfter: function(request, context, afterNode, cDataBlock) {
- var nodeHolder = document.createElement("div");
- var parentNode = afterNode.parentNode;
-
- //TODO nextsibling not working in ieMobile 6.1 we have to change the method
- //of accessing it to something else
- if (afterNode.nextSibling) {
- parentNode.insertBefore(nodeHolder, afterNode.nextSibling);
- } else {
- parentNode.appendChild(nodeHolder);
- }
-
- var replacementFragment = this.replaceHtmlItem(request, context,
- nodeHolder, cDataBlock);
-
- if (replacementFragment) {
- this._pushOperationResult(context, replacementFragment);
- }
- return true;
- },
-
-
processDelete : function(request, context, node) {
var _Impl = this._getImpl();
var _Lang = this._Lang;