tot - Check-in [32]
Not logged in
[Browse]  [Home]  [Login]  [Reports]  [Search]  [Timeline
  [Patchset
Check-in Number: 32
Date: 2007-Apr-13 11:43:44 (local)
2007-Apr-13 09:43:44 (UTC)
User:rse
Branch:
Comment: final polishing
Tickets:
Inspections:
Files:
jquery/jquery.xsajax.js      31 -> 32
Modified: jquery/jquery.xsajax.js
===================================================================
--- jquery/jquery.xsajax.js	2007-04-13 09:31:45 UTC (rev 31)
+++ jquery/jquery.xsajax.js	2007-04-13 09:43:44 UTC (rev 32)
@@ -41,11 +41,11 @@
                 $(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
                or calling a custom callback function */
+            var node_helper = null;
             if (arg.gc || arg.cb !== null) {
                 var callback = function () {
                     if (arg.cb !== null) {
@@ -74,7 +74,8 @@
                             callback.call(this);
                     };
                 }
-                else if ($.browser.safari || navigator.userAgent.match(/Konqueror/i)) {
+                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
@@ -81,18 +82,25 @@
                        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);';
+                        'ctx.callback.call(ctx.node);' +
+                        'setTimeout(function () {' +
+                        '    jQuery(ctx.node_helper).remove();' +
+                        '}, 100);';
                     node_helper =
                         $(document.createElement('script'))
                         .attr('type', 'text/javascript')
                         .text(helper);
+                    $._xsajax$node[$._xsajax$nodes] = {
+                        callback: callback,
+                        node: node.get(0),
+                        node_helper: node_helper.get(0)
+                    };
                 }
                 else {
-                    /* use regular "onload" event for all other browsers,
-                       including Firefox and Opera. */
+                    /* Firefox, Opera and other reasonable browsers can
+                       use the regular "onload" event... */
                     $(node).load(callback);
                 }
             }
@@ -103,10 +111,13 @@
             /* 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);
+               at least Konqueror (and perhaps also Safari) 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);