Author: reebalazs
Date: Tue Jul 29 11:46:45 2008
New Revision: 56834
Modified:
kukit/kukit.js/branch/ree-binding-improvements/3rd_party/cssQuery-compat.js
Log:
Fix cssQuery-compat to not require base2 to be loaded precedentally.
Modified:
kukit/kukit.js/branch/ree-binding-improvements/3rd_party/cssQuery-compat.js
==============================================================================
--- kukit/kukit.js/branch/ree-binding-improvements/3rd_party/cssQuery-compat.js
(original)
+++ kukit/kukit.js/branch/ree-binding-improvements/3rd_party/cssQuery-compat.js
Tue Jul 29 11:46:45 2008
@@ -5,43 +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.
- //
- // 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');
- if (! _USE_BASE2_LEGACY) {
- window.cssQuery = function(selector, element) {
+ 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);
+ };
+ }
+ // 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 = base2.DOM.Document.querySelectorAll(element,
selector);
+ var results = f(element, selector);
var nodes = [];
for(var i = 0; i < results.length; i++) {
nodes.push(results.item(i));
}
return nodes;
};
- } else {
- window.cssQuery = function(selector, element) {
- if (typeof(element) == 'undefined') {
- // if parameter is not given, we need to use document.
- element = document;
- }
- 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;
- };
- }
+ // 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