Author: pyaschenko
Date: 2008-07-15 10:17:11 -0400 (Tue, 15 Jul 2008)
New Revision: 9611
Modified:
trunk/framework/impl/src/main/javascript/ajaxjsf/JSFAJAX.js
trunk/ui/calendar/src/main/resources/org/richfaces/renderkit/html/scripts/calendar.js
Log:
http://jira.jboss.com/jira/browse/RF-3628
Modified: trunk/framework/impl/src/main/javascript/ajaxjsf/JSFAJAX.js
===================================================================
--- trunk/framework/impl/src/main/javascript/ajaxjsf/JSFAJAX.js 2008-07-15 13:32:06 UTC
(rev 9610)
+++ trunk/framework/impl/src/main/javascript/ajaxjsf/JSFAJAX.js 2008-07-15 14:17:11 UTC
(rev 9611)
@@ -394,18 +394,43 @@
}
},
- appendNewHeadElements : function(){
+ appendNewHeadElements : function(callback){
// Append scripts and styles to head, if not presented in page before.
-
this._appendNewElements("script","src",null,null,["type","language","charset"]);
+ var includes =
this._appendNewElements("script","src",null,null,["type","language","charset"]);
var _this = this;
-
this._appendNewElements("link","href","class",["component","user"],["type","rev","media"],{"class":
"className"},
+ includes.concat(
this._appendNewElements("link","href","class",["component","user"],["type","rev","media"],{"class":
"className"},
function (element, script) {
//IE requires to re-set rel or href after insertion to initialize correctly
//see
http://jira.jboss.com/jira/browse/RF-1627#action_12394642
_this._copyAttribute(element,script,"rel");
}
- );
+ ));
+
+ if ( includes.length == 0) {
+ callback();
+ return;
+ }
+
+ A4J.AJAX.headElementsCounter = includes.length;
+
+ var onReadyStateChange = function () {
+ if (this.readyState == 'loaded' || this.readyState == 'complete') {
+ this.onreadystatechange = null;
+ this.onload = null;
+ callback();
+ }
+ };
+ var onLoad = function () {
+ this.onreadystatechange = null;
+ this.onload = null;
+ callback();
+ };
+ for (var i = 0; i<includes.length; i++)
+ {
+ includes[i].onreadystatechange = onReadyStateChange;
+ includes[i].onload = onLoad;
+ }
},
_appendNewElements : function(tag,href,role,roles,attributes,mappings,callback){
@@ -413,6 +438,7 @@
var newscripts = this.getElementsByTagName(tag);
var oldscripts = document.getElementsByTagName(tag);
var mappedRole = (mappings && mappings[role]) || role;
+ var elements = [];
var roleAnchors = {};
if (roles) {
@@ -483,10 +509,11 @@
if (callback) {
callback(element,script);
}
+ if (tag!="link" ||
script.type.toLowerCase()=="text/javascript") elements.push(script);
}
}
}
-
+ return elements;
},
_noSessionHref : function(href){
@@ -777,7 +804,16 @@
return false;
};
+A4J.AJAX.processResponseAfterUpdateHeadElements = function (req, ids)
+{
+ for ( var k =0; k < ids.length ; k++ ) {
+ var id = ids[k];
+ LOG.debug("Update page part from call parameter for ID " + id);
+ req.updatePagePart(id, k==ids.length-1);
+ };
+}
+A4J.AJAX.headElementsCounter = 0;
A4J.AJAX.processResponse = function(req) {
var options = req.options;
@@ -816,14 +852,23 @@
}
var idsFromResponse = req.getResponseHeader("Ajax-Update-Ids");
+ var ids;
+
+ var callback = function () {
+ if (A4J.AJAX.headElementsCounter!=0) {
+ LOG.debug("Script "+A4J.AJAX.headElementsCounter+" was
loaded");
+ --A4J.AJAX.headElementsCounter;
+ }
+ if (A4J.AJAX.headElementsCounter==0) {
+ A4J.AJAX.processResponseAfterUpdateHeadElements(req, ids);
+ }
+ };
+
// 3 strategy for replace :
// if setted affected parameters - replace its
if( options.affected ) {
- req.appendNewHeadElements();
- for ( var k =0; k < options.affected.length ; k++ ) {
- LOG.debug("Update page part from call parameter for ID " +
options.affected[k]);
- req.updatePagePart(options.affected[k], k==options.affected.length-1);
- };
+ ids = options.affected;
+ req.appendNewHeadElements(callback);
// if resopnce contains element with ID "ajax:update" get id's from
// child text element . like :
// <div id="ajax:update" style="display none" >
@@ -834,13 +879,8 @@
} else if( idsFromResponse && idsFromResponse != "" ) {
LOG.debug("Update page by list of rendered areas from response " +
idsFromResponse );
// Append scripts and styles to head, if not presented in page before.
- req.appendNewHeadElements();
- var childs = idsFromResponse.split(",");
- for ( var k=0 ; k < childs.length ; k++ ) {
- var id = childs[k];
- LOG.debug("Attempt to update part of page for Id: "+id);
- req.updatePagePart(id, k==childs.length-1);
- };
+ ids = idsFromResponse.split(",");
+ req.appendNewHeadElements(callback);
} else {
// if none of above - error ?
// A4J.AJAX.replace(form.id,A4J.AJAX.findElement(form.id,xmlDoc));
Modified:
trunk/ui/calendar/src/main/resources/org/richfaces/renderkit/html/scripts/calendar.js
===================================================================
---
trunk/ui/calendar/src/main/resources/org/richfaces/renderkit/html/scripts/calendar.js 2008-07-15
13:32:06 UTC (rev 9610)
+++
trunk/ui/calendar/src/main/resources/org/richfaces/renderkit/html/scripts/calendar.js 2008-07-15
14:17:11 UTC (rev 9611)
@@ -2,9 +2,6 @@
window.LOG = {warn:function(){}};
}
-if(typeof Effect == 'undefined')
- throw("calendar.js requires including script.aculo.us' effects.js
library");
-
if (!window.Richfaces) window.Richfaces={};
Richfaces.Calendar={};