Author: reebalazs
Date: Tue Jul 29 12:51:21 2008
New Revision: 56841

Modified:
   kukit/kukit.js/branch/1.4/3rd_party/cssQuery-compat.js
   kukit/kukit.js/branch/1.4/doc/HISTORY.txt
Log:
Backport -r56837:56839 from trunk: Fix cssQuery-compat.js to use newest base2 
api.

Modified: kukit/kukit.js/branch/1.4/3rd_party/cssQuery-compat.js
==============================================================================
--- kukit/kukit.js/branch/1.4/3rd_party/cssQuery-compat.js      (original)
+++ kukit/kukit.js/branch/1.4/3rd_party/cssQuery-compat.js      Tue Jul 29 
12:51:21 2008
@@ -5,24 +5,49 @@
  * want to use cssQuery.
  *
  * When both cssQuery and base2 are present, this code does nothing.
- * When cssQuery is missing, this code defines a compatibility cssQuery
- * function that actually reuses base2 for querying.
+ * When cssQuery is missing at the time this code is loaded,
+ * it defines a compatibility cssQuery function that actually reuses 
+ * base2 for querying.
  *
  */
 
+// Check that cssQuery is missing originally.
+// If it is present, do not redefine it.
 if (typeof(window.cssQuery) == 'undefined') {
     // Define the compatibility layer.
-    window.cssQuery = function(selector, element) {
-        if (typeof(element) == 'undefined') {
-            // if parameter is not given, we need to use document.
-            element = document;
+    window.cssQuery = function _cssQueryStub(selector, element) {
+        // This stub checks which base2 api to use.
+        // It only runs once and also returns the result.
+        //
+        // Base2 legacy version: matchAll has to be used
+        // Base2 recent version: querySelectorAll has to be used
+        var _USE_BASE2_LEGACY = (typeof(base2.DOM.Document.querySelectorAll) 
== 'undefined');
+        var f;
+        if (! _USE_BASE2_LEGACY) {
+            f = function(selector, element) {
+                return base2.DOM.Document.querySelectorAll(element, selector);
+            };
+        } else {
+            f = function(selector, element) {
+                return base2.DOM.Document.matchAll(element, selector);
+            };
         }
-        var results = base2.DOM.Document.matchAll(element, selector);
-        var nodes = [];
-        for(var i = 0; i < results.length; i++) {
-            nodes.push(results.item(i));
-        }
-        return nodes;
+        // redefine the function with its final version
+        window.cssQuery = function cssQuery(selector, element) {
+            if (typeof(element) == 'undefined') {
+                // if parameter is not given, we need to use document.
+                element = document;
+            }
+            var results = f(selector, element);
+            var nodes = [];
+            for(var i = 0; i < results.length; i++) {
+                nodes.push(results.item(i));
+            }
+            return nodes;
+        };
+        // since we are in the stub, we need to use
+        // the newly redefined function
+        return window.cssQuery(selector, element);
     };
 };
 

Modified: kukit/kukit.js/branch/1.4/doc/HISTORY.txt
==============================================================================
--- kukit/kukit.js/branch/1.4/doc/HISTORY.txt   (original)
+++ kukit/kukit.js/branch/1.4/doc/HISTORY.txt   Tue Jul 29 12:51:21 2008
@@ -6,6 +6,9 @@
     
     - ...
   
+    - Fix cssQuery-compat.js to use newest base2 api.
+      [ree]
+
 kukit.js - 1.4.2 Released 2008-07-06
 
     - prepare release
_______________________________________________
Kukit-checkins mailing list
[email protected]
http://codespeak.net/mailman/listinfo/kukit-checkins

Reply via email to