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/05/15 13:12:57 UTC
svn commit: r775085 - in
/myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl:
_util/_HtmlStripper.js _util/_Utils.js xhrCore/_AjaxRequest.js
xhrCore/_AjaxResponse.js xhrCore/_AjaxUtils.js
Author: werpu
Date: Fri May 15 11:12:56 2009
New Revision: 775085
URL: http://svn.apache.org/viewvc?rev=775085&view=rev
Log:
https://issues.apache.org/jira/browse/MYFACES-2114 fixed an error in the
added simple script xhr loader and also added a global eval
to avoid scoping problems in the respinse phase
Modified:
myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_HtmlStripper.js
myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Utils.js
myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxRequest.js
myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxResponse.js
myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxUtils.js
Modified: myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_HtmlStripper.js
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_HtmlStripper.js?rev=775085&r1=775084&r2=775085&view=diff
==============================================================================
--- myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_HtmlStripper.js (original)
+++ myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_HtmlStripper.js Fri May 15 11:12:56 2009
@@ -27,6 +27,8 @@
* the html elements
* so we only have to strip those
*/
+
+
_reserveMyfacesNamespaces();
if(!myfaces._impl._util._LangUtils.exists(myfaces._impl._util,"_HtmlStripper")) {
Modified: myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Utils.js
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Utils.js?rev=775085&r1=775084&r2=775085&view=diff
==============================================================================
--- myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Utils.js (original)
+++ myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Utils.js Fri May 15 11:12:56 2009
@@ -30,18 +30,18 @@
myfaces._impl._util._Utils.browserDetection = function() {
- /**
- * browser detection code
- * cross ported from dojo 1.2
- *
- * dojos browser detection code is very sophisticated
- * hence we port it over it allows a very fine grained detection of
- * browsers including the version number
- * this however only can work out if the user
- * does not alter the user agend, which they normally dont!
- *
- * the exception is the ie detection which relies on specific quirks in ie
- */
+ /**
+ * browser detection code
+ * cross ported from dojo 1.2
+ *
+ * dojos browser detection code is very sophisticated
+ * hence we port it over it allows a very fine grained detection of
+ * browsers including the version number
+ * this however only can work out if the user
+ * does not alter the user agend, which they normally dont!
+ *
+ * the exception is the ie detection which relies on specific quirks in ie
+ */
var n = navigator;
var dua = n.userAgent,
dav = n.appVersion,
@@ -94,7 +94,7 @@
}
};
-
+
/**
* [STATIC]
@@ -125,7 +125,8 @@
go = true;
}
}
- eval(test); // run the script
+ /*we have to run the script under a global context*/
+ myfaces._impl._util._Utils.globalEval(test); // run the script
} catch (e) {
myfaces._impl.xhrCore._Exception.throwNewError(request, context, "Utils", "runScripts", e);
}
@@ -167,7 +168,7 @@
var item = (itemIdToReplace instanceof Node) ? itemIdToReplace :
- myfaces._impl._util._Utils.getElementFromForm(request, context, itemIdToReplace, form);
+ myfaces._impl._util._Utils.getElementFromForm(request, context, itemIdToReplace, form);
if (item == null) {
myfaces._impl.xhrCore._Exception.throwNewWarning
(request, context, "Utils", "replaceHTMLItem", "Unknown Html-Component-ID: " + itemIdToReplace);
@@ -257,13 +258,14 @@
if(myfaces._impl._util._Utils.ieQuircksEvents[attribute]) {
if(myfaces._impl._util._LangUtils.isString(attribute)) {
domNode[attribute] = function(event) {
- eval(attribute);
+ //TODO check the scope of this handler
+ myfaces._impl._util._Utils.globalEval(attribute);
};
}
}
domNode[attribute] = value;
}
- //TODO this needs further testing I will leave it for now...
+ //TODO this needs further testing I will leave it for now...
};
/**
@@ -279,21 +281,21 @@
//
//tested currently safari, ie, firefox, opera
var retVal = (_LangUtils.exists(myfaces._impl._util._Utils.browser,"isIE") &&
- ( myfaces._impl._util._Utils.browser.isIE > 5.5))||
- (_LangUtils.exists(myfaces._impl._util._Utils.browser,"isKhtml") &&
- _LangUtils.exists(myfaces._impl._util._Utils.browser.isKhtml > 0)) ||
- (_LangUtils.exists(myfaces._impl._util._Utils.browser,"isWebKit") &&
- _LangUtils.exists(myfaces._impl._util._Utils.browser.isWebKit > 0));
+ ( myfaces._impl._util._Utils.browser.isIE > 5.5))||
+ (_LangUtils.exists(myfaces._impl._util._Utils.browser,"isKhtml") &&
+ _LangUtils.exists(myfaces._impl._util._Utils.browser.isKhtml > 0)) ||
+ (_LangUtils.exists(myfaces._impl._util._Utils.browser,"isWebKit") &&
+ _LangUtils.exists(myfaces._impl._util._Utils.browser.isWebKit > 0));
- return retVal;
+ return retVal;
- //another way to determine this without direct user agent parsing probably could
- //be to add an embedded script tag programmatically and check for the script variable
- //set by the script if existing, the add went through an eval if not then we
- //have to deal with it outselves, this might be dangerous in case of the ie however
- //so in case of ie we have to parse for all other browsers we can make a dynamic
- //check if the browser does auto eval
- //TODO discuss those things
+ //another way to determine this without direct user agent parsing probably could
+ //be to add an embedded script tag programmatically and check for the script variable
+ //set by the script if existing, the add went through an eval if not then we
+ //have to deal with it outselves, this might be dangerous in case of the ie however
+ //so in case of ie we have to parse for all other browsers we can make a dynamic
+ //check if the browser does auto eval
+ //TODO discuss those things
};
@@ -330,7 +332,7 @@
if('undefined' == typeof includeName || nameSearch == null) {
nameSearch = false;
}
- if('undefined' == typeof localSearchOnly || localSearchOnly == null) {
+ if('undefined' == typeof localSearchOnly || localSearchOnly == null) {
localSearchOnly = false;
}
@@ -339,7 +341,7 @@
//we first check for a name entry!
if(nameSearch && 'undefined' != typeof form.elements[itemIdOrName] && null != form.elements[itemIdOrName]) {
- return element;
+ return element;
}
//if no name entry is found we check for an Id
for ( var f = 0; f < fLen; f++) {
@@ -403,7 +405,7 @@
if (childItems[c].tagName != null
&& childItems[c].tagName.toLowerCase() == childName
&& (itemName == null || (itemName != null && itemName == childItems[c]
- .getAttribute("name")))) {
+ .getAttribute("name")))) {
return childItems[c];
}
}
@@ -432,6 +434,20 @@
};
/**
+ * global eval on scripts
+ *
+ */
+ myfaces._impl._util._Utils.globalEval = function(code) {
+
+ if (window.execScript) {
+ window.execScript(code);
+ return;
+ }
+
+ eval.call(null, code);
+ }
+
+ /**
* gets the local or global options with local ones having higher priority
* if no local or global one was found then the default value is given back
*
Modified: myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxRequest.js
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxRequest.js?rev=775085&r1=775084&r2=775085&view=diff
==============================================================================
--- myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxRequest.js (original)
+++ myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxRequest.js Fri May 15 11:12:56 2009
@@ -79,21 +79,13 @@
myfaces._impl.xhrCore._AjaxRequest.prototype.send = function() {
try {
- if (myfaces._impl._util._Utils.isUserAgentInternetExplorer()) {
- // request object for Internet Explorer
- try {
- this.m_xhr = new ActiveXObject("Msxml2.XMLHTTP");
- } catch (e) {
- this.m_xhr = new ActiveXObject('Microsoft.XMLHTTP');
- }
- } else {
- // request object for standard browser
- this.m_xhr = new XMLHttpRequest();
- }
+ this.m_xhr = this.m_ajaxUtil.getXHRObject();
+
this.m_xhr.open("POST", this.m_sourceForm.action, true);
this.m_xhr.setRequestHeader("Content-Type", this.m_contentType);
this.m_xhr.setRequestHeader("Faces-Request", "partial/ajax");
this.m_xhr.onreadystatechange = myfaces._impl.xhrCore._AjaxRequestQueue.handleCallback;
+
jsf.ajax.sendEvent(this.m_xhr, this.m_context, myfaces._impl.core._jsfImpl._AJAX_STAGE_BEGIN);
this.m_xhr.send(this.m_requestParameters);
} catch (e) {
Modified: myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxResponse.js
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxResponse.js?rev=775085&r1=775084&r2=775085&view=diff
==============================================================================
--- myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxResponse.js (original)
+++ myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxResponse.js Fri May 15 11:12:56 2009
@@ -165,7 +165,7 @@
if (!this.processUpdate(request, context, changes[i])) return false;
} else if (changes[i].tagName == this._PCMD_EVAL) {
//eval is always in CDATA blocks
- eval(changes[i].firstChild.data);
+ myfaces._impl._util._Utils.globalEval(changes[i].firstChild.data);
} else if (changes[i].tagName == this._PCMD_INSERT) {
if (!this.processInsert(request, context, changes[i])) return false;
} else if (changes[i].tagName == this._PCMD_DELETE) {
Modified: myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxUtils.js
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxUtils.js?rev=775085&r1=775084&r2=775085&view=diff
==============================================================================
--- myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxUtils.js (original)
+++ myfaces/core/branches/2_0_0/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxUtils.js Fri May 15 11:12:56 2009
@@ -114,6 +114,41 @@
}
}
+ myfaces._impl.xhrCore._AjaxUtils.prototype.getXHRObject = function() {
+ if('undefined' != typeof XMLHttpRequest && null != XMLHttpRequest) {
+ return new XMLHttpRequest();
+ }
+ //IE
+ try {
+ return new ActiveXObject("Msxml2.XMLHTTP");
+ } catch (e) {
+ return new ActiveXObject('Microsoft.XMLHTTP');
+ }
+
+ }
+
+
+ myfaces._impl.xhrCore._AjaxUtils.prototype.loadScript = function(src, type) {
+ var xhr = this.getXHRObject();
+ xhr.open("GET", src, false);
+ xhr.send(null);
+
+
+
+ //since we are synchronous we do it after not with onReadyStateChange
+ if(xhr.readyState == 4) {
+ if (xhr.status == 200) {
+ myfaces._impl._util._Utils.globalEval(xhr.responseText);
+ } else {
+ throw Error(xhr.responseText);
+ }
+ } else {
+ throw Error("Loading of script "+src+" failed ");
+ }
+ }
+
+
+
/**
* add a single field to stringbuffer for param submission
* @param {HtmlElement} element -