Check-in Number:
|
30 | |
Date: |
2007-Apr-13 10:33:15 (local)
2007-Apr-13 08:33:15 (UTC) |
User: | rse |
Branch: | |
Comment: |
second attempt to add Safari support
|
Tickets: |
|
Inspections: |
|
Files: |
|
Modified: jquery/jquery.xsajax.js
===================================================================
--- jquery/jquery.xsajax.js 2007-04-12 19:00:35 UTC (rev 29)
+++ jquery/jquery.xsajax.js 2007-04-13 08:33:15 UTC (rev 30)
@@ -8,6 +8,12 @@
*/
(function($){
+ if ($.browser.safari || navigator.userAgent.match(/Konqueror/i)) {
+ $.extend({
+ _xsajax$node: [],
+ _xsajax$nodes: 0
+ });
+ }
$.extend({
getScriptXS: function () {
/* determine arguments */
@@ -35,6 +41,7 @@
$(document.createElement('script'))
.attr('type', 'text/javascript')
.attr('src', arg.url);
+ var node_helper = null;
/* optionally apply on-load handler for
garbage collecting <script> node after loading
@@ -67,6 +74,22 @@
callback.call(this);
};
}
+ else if ($.browser.safari || navigator.userAgent.match(/Konqueror/i)) {
+ /* Safari/WebKit and Konqueror/KHTML do not emit
+ _any_ events at all, but we can exploit the fact
+ that dynamically generated <script> DOM nodes
+ are executed in sequence (although the scripts
+ theirself are still loaded in parallel) */
+ $._xsajax$nodes++;
+ $._xsajax$node[$._xsajax$nodes] = { callback: callback, scope: node };
+ var helper =
+ 'var ctx = jQuery._xsajax$node[' + $._xsajax$nodes + '];' +
+ 'ctx.callback.call(ctx.scope);';
+ node_helper =
+ $(document.createElement('script'))
+ .attr('type', 'text/javascript')
+ .text(helper);
+ }
else {
/* use regular "onload" event for all other browsers */
$(node).load(callback);
@@ -75,6 +98,14 @@
/* inject <script> node into <head> of document */
$('head', document).append(node);
+
+ /* optionally inject helper <script> node into <head>
+ (Notice: we have to use a strange indirection via
+ setTimeout() to insert this second <script> node here or
+ Konqueror for unknown reasons will not execute the first
+ <script> node at all) */
+ if (node_helper !== null)
+ setTimeout(function () { $('head', document).append(node_helper) }, 100);
}
});
})(jQuery);
Modified: jquery/jquery.xsajax.test.html
===================================================================
--- jquery/jquery.xsajax.test.html 2007-04-12 19:00:35 UTC (rev 29)
+++ jquery/jquery.xsajax.test.html 2007-04-13 08:33:15 UTC (rev 30)
@@ -16,10 +16,10 @@
$(document).ready(function () {
$('div#logbook').append("1. start sequence<br/>");
$.getScriptXS({ url: "jquery.xsajax.test1.js", cb: function(i) {
- $('div#logbook').append("3. loaded script "+i+"<br/>");
+ $('div#logbook').append("5. loaded script "+i+"<br/>");
}, cb_args: "1" });
$.getScriptXS({ url: "jquery.xsajax.test2.js", cb: function(i) {
- $('div#logbook').append("4. loaded script "+i+"<br/>");
+ $('div#logbook').append("8. loaded script "+i+"<br/>");
}, cb_args: "2" });
$('div#logbook').append("2. end sequence<br/>");
});
Modified: jquery/jquery.xsajax.test1.js
===================================================================
--- jquery/jquery.xsajax.test1.js 2007-04-12 19:00:35 UTC (rev 29)
+++ jquery/jquery.xsajax.test1.js 2007-04-13 08:33:15 UTC (rev 30)
@@ -1,10 +1,12 @@
/* just produce some distinguishable output */
(function(){
+ $('div#logbook').append("3. test1 start<br/>");
$('span#output1').html("script #1 loaded");
var i = 7;
setInterval(function () {
$('span#output1').html("i=" + i++);
}, 1000);
+ $('div#logbook').append("4. test1 end<br/>");
})();
Modified: jquery/jquery.xsajax.test2.js
===================================================================
--- jquery/jquery.xsajax.test2.js 2007-04-12 19:00:35 UTC (rev 29)
+++ jquery/jquery.xsajax.test2.js 2007-04-13 08:33:15 UTC (rev 30)
@@ -1,10 +1,12 @@
/* just produce some distinguishable output */
(function(){
+ $('div#logbook').append("6. test2 start<br/>");
$('span#output2').html("script #2 loaded");
var j = 42;
setInterval(function () {
$('span#output2').html("j=" + j++);
}, 1000);
+ $('div#logbook').append("7. test2 end<br/>");
})();