Author: reebalazs
Date: Tue Jul 29 12:45:09 2008
New Revision: 56838
Modified:
kukit/kukit.js/trunk/3rd_party/cssQuery-compat.js
Log:
Fix cssQuery-compat.js to use newest base2 api.
Merge -r56831:56836 from
http://codespeak.net/svn/kukit/kukit.js/branch/ree-binding-improvements
Modified: kukit/kukit.js/trunk/3rd_party/cssQuery-compat.js
==============================================================================
--- kukit/kukit.js/trunk/3rd_party/cssQuery-compat.js (original)
+++ kukit/kukit.js/trunk/3rd_party/cssQuery-compat.js Tue Jul 29 12:45:09 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);
};
};
_______________________________________________
Kukit-checkins mailing list
[email protected]
http://codespeak.net/mailman/listinfo/kukit-checkins