[KSS-checkins] r41973 - kukit/kukit.js/branch/ree-load-event-cleanup/kukit
reebalazs at codespeak.net
reebalazs at codespeak.net
Mon Apr 9 11:02:27 CEST 2007
Author: reebalazs
Date: Mon Apr 9 11:02:26 2007
New Revision: 41973
Modified:
kukit/kukit.js/branch/ree-load-event-cleanup/kukit/dom.js
kukit/kukit.js/branch/ree-load-event-cleanup/kukit/eventreg.js
kukit/kukit.js/branch/ree-load-event-cleanup/kukit/plugin.js
kukit/kukit.js/branch/ree-load-event-cleanup/kukit/serveraction.js
Log:
Refactor load event, separate iload and load events.
The new event binder handles both events together.
A new parameter, evt-iload-directmark is introduced, this means
we don't use detection but the iframe must cooperate on telling
us wnen we are done.
There is deprecation warning issued for the load events, if
bound on an iframe, in which case an iload event must be used.
Modified: kukit/kukit.js/branch/ree-load-event-cleanup/kukit/dom.js
==============================================================================
--- kukit/kukit.js/branch/ree-load-event-cleanup/kukit/dom.js (original)
+++ kukit/kukit.js/branch/ree-load-event-cleanup/kukit/dom.js Mon Apr 9 11:02:26 2007
@@ -1,9 +1,6 @@
/*
-* Copyright (c) 2005-2006
-* Authors:
-* Godefroid Chapelle <gotcha at bubblenet.be>
-* Florian Schulze <florian.schulze at gmx.net>
-* Balázs Reé <ree at greenfinity.hu>
+* Copyright (c) 2005-2007
+* Authors: KSS Project Contributors (see docs/CREDITS.txt)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as published
@@ -307,12 +304,12 @@
*
* Scheduler for embedded window content loaded
*/
-kukit.dom.EmbeddedContentLoadedScheduler = function(framename, func) {
+kukit.dom.EmbeddedContentLoadedScheduler = function(framename, func, directmark) {
this.framename = framename;
this.func = func;
+ this.directmark = directmark;
var self = this;
var f = function() {
- kukit.logDebug('Is iframe loaded ?');
self.check();
};
this.counter = new kukit.ut.TimerCounter(250, f, true);
@@ -337,35 +334,50 @@
};
kukit.dom.EmbeddedContentLoadedScheduler.prototype.check = function() {
- // quit if the init function has already been called
+
+ kukit.logDebug('Is iframe loaded ?');
+
var doc = kukit.dom.getIframeDocument(this.framename);
+
+ // quit if the init function has already been called
+ // XXX I believe we want to call the function too, then
if (doc._embeddedContentLoadedInitDone) {
- return;
+ kukit.logWarning('Iframe already initialized, but we execute the action enyway, as requested.');
+ this.counter.restart = false;
}
- // obviously we are not there... this happens on FF
-
- /*Commented out by GC
- if (doc.location.href == 'about:blank') {
- return;
- }*/
-
+ // directmark=true implements a more reliable autosense method
+ // that involves cooperation from the internal document. In this
+ // case the internal document sets the _kssReadyForLoadEvent attribute
+ // on the document, when loaded. It is safe to check for this in any
+ // case, however if this option is selected, we rely only on this,
+ // and skip the otherwise problematic default checking.
if (typeof doc._kssReadyForLoadEvent != 'undefined') {
this.counter.restart = false;
}
- // First check for Safari or
- //if DOM methods are supported, and the body element exists
- //(using a double-check including document.body, for the benefit of older moz builds [eg ns7.1]
- //in which getElementsByTagName('body')[0] is undefined, unless this script is in the body section)
-
- /*Commented out by GC
- if(/KHTML|WebKit/i.test(navigator.userAgent)) {
- if(/loaded|complete/.test(doc.readyState)) {
+
+ if (! this.directmark && this.counter.restart) {
+
+ // obviously we are not there... this happens on FF
+ if (doc.location.href == 'about:blank') {
+ return;
+ } /* */
+
+ // First check for Safari or
+ //if DOM methods are supported, and the body element exists
+ //(using a double-check including document.body, for the benefit of older moz builds [eg ns7.1]
+ //in which getElementsByTagName('body')[0] is undefined, unless this script is in the body section)
+
+ if(/KHTML|WebKit/i.test(navigator.userAgent)) {
+ if(/loaded|complete/.test(doc.readyState)) {
+ this.counter.restart = false;
+ }
+ } else if(typeof doc.getElementsByTagName != 'undefined' && (doc.getElementsByTagName('body')[0] != null || doc.body != null)) {
this.counter.restart = false;
- }
- } else if(typeof doc.getElementsByTagName != 'undefined' && (doc.getElementsByTagName('body')[0] != null || doc.body != null)) {
- this.counter.restart = false;
- }*/
+ } /* */
+
+ }
+
if ( ! this.counter.restart) {
kukit.logDebug('Yes, iframe is loaded.');
doc._embeddedContentLoadedInitDone = true;
Modified: kukit/kukit.js/branch/ree-load-event-cleanup/kukit/eventreg.js
==============================================================================
--- kukit/kukit.js/branch/ree-load-event-cleanup/kukit/eventreg.js (original)
+++ kukit/kukit.js/branch/ree-load-event-cleanup/kukit/eventreg.js Mon Apr 9 11:02:26 2007
@@ -696,10 +696,11 @@
kukit.er.OperRegistry.prototype.iter_node = function (eventset, binderinstance) {
for (var nodehash in this.infopernode) {
var rules_per_node = this.infopernode[nodehash];
- // filter only the nodes we are interested in
+ // filter only the events we are interested in
var filtered_rules = {};
var found = false;
- for (var name in eventset.names) {
+ for (var i=0; i<eventset.names.length; i++) {
+ var name = eventset.names[i];
var oper = rules_per_node[name];
if (typeof(oper) != 'undefined') {
filtered_rules[name] = oper;
Modified: kukit/kukit.js/branch/ree-load-event-cleanup/kukit/plugin.js
==============================================================================
--- kukit/kukit.js/branch/ree-load-event-cleanup/kukit/plugin.js (original)
+++ kukit/kukit.js/branch/ree-load-event-cleanup/kukit/plugin.js Mon Apr 9 11:02:26 2007
@@ -1,9 +1,6 @@
/*
-* Copyright (c) 2005-2006
-* Authors:
-* Godefroid Chapelle <gotcha at bubblenet.be>
-* Florian Schulze <florian.schulze at gmx.net>
-* Balázs Reé <ree at greenfinity.hu>
+* Copyright (c) 2005-2007
+* Authors: KSS Project Contributors (see docs/CREDITS.txt)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as published
@@ -271,14 +268,21 @@
kukit.pl.LoadEventBinder = function() {
};
-kukit.pl.LoadEventBinder.prototype.__bind__ = function(name, func_to_bind, oper) {
- oper.completeParms([], {'initial': 'true', 'insert': 'true'}, 'load event binding');
- oper.evalBool('initial', 'load event binding');
- oper.evalBool('insert', 'load event binding');
- // Bind the function to the onload event of the node.
- // If this is an iframe node, we have the possibility
- // to wait until the execution totally finishes, so we load the real load event.
- // node._kukitmark contains the binding phase.
+kukit.pl.LoadEventBinder.prototype.process_parms = function(oper, iload) {
+ if (! oper) {
+ return;
+ }
+ if (iload) {
+ oper.completeParms([], {'initial': 'true', 'insert': 'true', 'directmark': 'false'}, 'iload event binding');
+ // directmark=true changes the iload autosense method to one that requires the iframe set
+ // the _kssReadyForLoadEvent attribute on the document. This parameter is explicitely required since
+ // otherwise in this case we never notice if the document has arrived.
+ oper.evalBool('directmark', 'iload event binding');
+ } else {
+ oper.completeParms([], {'initial': 'true', 'insert': 'true'}, 'load event binding');
+ }
+ oper.evalBool('initial', 'load/iload event binding');
+ oper.evalBool('insert', 'load/iload event binding');
var phase = oper.node._kukitmark;
if (phase == 1 && ! oper.parms.initial) {
kukit.logDebug('EventRule #' + oper.eventrule.getNr() + ' mergeid ' + oper.eventrule.kss_selector.mergeid + ' event ignored, oninitial=false.');
@@ -288,23 +292,78 @@
kukit.logDebug('EventRule #' + oper.eventrule.getNr() + ' mergeid ' + oper.eventrule.kss_selector.mergeid + ' event ignored, oninsert=false.');
return;
}
- if (oper.node != null && oper.node.tagName.toLowerCase() == 'iframe' &&
- (phase == 2 || (phase == 1 && kukit.engine.initializedOnDOMLoad))) {
- kukit.logDebug('EventRule #' + oper.eventrule.getNr() + ' mergeid ' + oper.eventrule.kss_selector.mergeid + ' event selected delayed execution (when iframe loaded)');
- // We want the event execute once the iframe is loaded.
- var f = function() {
- kukit.engine.bindScheduler.addPost(func_to_bind, 'Execute load event for iframe ' + oper.node.name);
- };
- new kukit.dom.EmbeddedContentLoadedScheduler(oper.node.id, f);
+ return oper;
+};
+kukit.pl.LoadEventBinder.prototype.__bind__ = function(opers_by_eventname) {
+ // This bind method handles load and iload events together, and opers_by_eventname is
+ // a dictionary of opers which can contain a load and an iload key, either one or both.
+ var loadoper = opers_by_eventname.load;
+ var iloadoper = opers_by_eventname.iload;
+ loadoper = this.process_parms(loadoper);
+ iloadoper = this.process_parms(iloadoper);
+ var anyoper = loadoper || iloadoper;
+ if (! anyoper) {
+ return;
+ }
+ if (anyoper.node != null && anyoper.node.tagName.toLowerCase() == 'iframe') {
+ // In an iframe.
+ //
+ // BBB If there is only a load (and no iload) event bound to this node,
+ // we interpret it as an iload event, but issue deprecation warning.
+ // This conserves legacy behaviour when the load event was actually doing an iload,
+ // when it was bound to an iframe node.
+ // The deprecation tells that the event should be changed from load to iload.
+ if (loadoper && ! iloadoper) {
+ iloadoper = loadoper;
+ loadoper = null;
+ // with the legacy loads we suppose directmark=true
+ iloadoper.parms.directmark = true;
+ kukit.logWarning('Deprecated the use of "load" event for iframes. It will behave differently in the future. Use the "iload" event (maybe with evt-iload-directmark: true) instead!');
+ }
} else {
- kukit.logDebug('EventRule #' + oper.eventrule.getNr() + ' mergeid ' + oper.eventrule.kss_selector.mergeid + ' event selected normal postponed execution.');
+ // Not an iframe. So iload is not usable.
+ if (iloadoper) {
+ throw 'iload event can only be bound on an iframe node.';
+ }
+ }
+ // Now, bind the events.
+ if (loadoper) {
+ kukit.logDebug('EventRule #' + loadoper.eventrule.getNr() + ' mergeid ' + loadoper.eventrule.kss_selector.mergeid + ' event selected normal postponed execution.');
// for any other node than iframe, or even for iframe in phase1, we need to execute immediately.
- kukit.engine.bindScheduler.addPost(func_to_bind, 'Execute load event for node ' + oper.node.tagName.toLowerCase());
+ var func_to_bind = loadoper.makeExecuteActionsHook();
+ kukit.engine.bindScheduler.addPost(func_to_bind, 'Execute load event for node ' + loadoper.node.tagName.toLowerCase());
+ }
+ if (iloadoper) {
+ var phase = iloadoper.node._kukitmark;
+ // For phase 2 we need to execute posponed, for phase1 immediately.
+ // XXX it would be better not need this and do always postponed.
+ if (phase == 2 || (phase == 1 && kukit.engine.initializedOnDOMLoad)) {
+ kukit.logDebug('EventRule #' + iloadoper.eventrule.getNr() + ' mergeid ' + iloadoper.eventrule.kss_selector.mergeid + ' event selected delayed execution (when iframe loaded)');
+ // We want the event execute once the iframe is loaded.
+ // In a somewhat tricky way, we start the scheduler only from the normal delayed execution. This will enable that in
+ // case we had a load event on the same node, it could modify the name and id parameters and we only start
+ // the autosense loop (which is based on name and id) after the load event's action executed.
+ // (Note, oper.node.id may lie in the log then and show the original, unchanged id but we ignore this for the time.)
+ var g = function() {
+ var f = function() {
+ var func_to_bind = iloadoper.makeExecuteActionsHook();
+ kukit.engine.bindScheduler.addPost(func_to_bind, 'Execute iload event for iframe ' + iloadoper.node.name);
+ };
+ new kukit.dom.EmbeddedContentLoadedScheduler(iloadoper.node.id, f, iloadoper.parms.directmark);
+ }
+ kukit.engine.bindScheduler.addPost(g, 'Schedule iload event for iframe ' + iloadoper.node.name);
+ } else {
+ kukit.logDebug('EventRule #' + iloadoper.eventrule.getNr() + ' mergeid ' + iloadoper.eventrule.kss_selector.mergeid + ' event selected normal postponed execution.');
+ var func_to_bind = iloadoper.makeExecuteActionsHook();
+ kukit.engine.bindScheduler.addPost(func_to_bind, 'Execute iload event for iframe ' + iloadoper.node.name);
+ }
}
};
-kukit.eventsGlobalRegistry.register(null, 'load', kukit.pl.LoadEventBinder, '__bind__', null);
+// Use the "node" iterator to provide expected invocation and call signature of the bind method.
+kukit.eventsGlobalRegistry.registerForAllEvents(null, ['load', 'iload'], kukit.pl.LoadEventBinder, '__bind__', null, 'node');
+
/*
* class SpinnerEventBinder
@@ -717,4 +776,4 @@
kukit.commandsGlobalRegistry.registerFromAction('copyChildNodesFrom', kukit.cr.makeSelectorCommand, 'copyChildrenFrom');
kukit.commandsGlobalRegistry.registerFromAction('copyChildNodesTo', kukit.cr.makeSelectorCommand, 'copyChildrenTo');
kukit.commandsGlobalRegistry.registerFromAction('setStateVar', kukit.cr.makeGlobalCommand, 'setStatevar');
-
+
Modified: kukit/kukit.js/branch/ree-load-event-cleanup/kukit/serveraction.js
==============================================================================
--- kukit/kukit.js/branch/ree-load-event-cleanup/kukit/serveraction.js (original)
+++ kukit/kukit.js/branch/ree-load-event-cleanup/kukit/serveraction.js Mon Apr 9 11:02:26 2007
@@ -1,9 +1,6 @@
/*
-* Copyright (c) 2005-2006
-* Authors:
-* Godefroid Chapelle <gotcha at bubblenet.be>
-* Florian Schulze <florian.schulze at gmx.net>
-* Balázs Reé <ree at greenfinity.hu>
+* Copyright (c) 2005-2007
+* Authors: KSS Project Contributors (see docs/CREDITS.txt)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as published
More information about the Kukit-checkins
mailing list