[Jifty-commit] r1344 - jifty/trunk/share/web/static/js/cssquery
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Thu Jun 22 00:27:51 EDT 2006
Author: nelhage
Date: Thu Jun 22 00:27:50 2006
New Revision: 1344
Modified:
jifty/trunk/share/web/static/js/cssquery/cssQuery-standard.js
jifty/trunk/share/web/static/js/cssquery/cssQuery.js
Log:
Updating cssQuery patches in preparation for throwing them upstream
Modified: jifty/trunk/share/web/static/js/cssquery/cssQuery-standard.js
==============================================================================
--- jifty/trunk/share/web/static/js/cssquery/cssQuery-standard.js (original)
+++ jifty/trunk/share/web/static/js/cssquery/cssQuery-standard.js Thu Jun 22 00:27:50 2006
@@ -1,53 +1,79 @@
-/*
- cssQuery, version 2.0.2 (2005-08-19)
- Copyright: 2004-2005, Dean Edwards (http://dean.edwards.name/)
- License: http://creativecommons.org/licenses/LGPL/2.1/
-*/
-
-cssQuery.addModule("css-standard", function() { // override IE optimisation
-
-// cssQuery was originally written as the CSS engine for IE7. It is
-// optimised (in terms of size not speed) for IE so this module is
-// provided separately to provide cross-browser support.
-
-// -----------------------------------------------------------------------
-// browser compatibility
-// -----------------------------------------------------------------------
-
-// sniff for Win32 Explorer
-isMSIE = eval("false;/*@cc_on at if(@\x5fwin32)isMSIE=true at end@*/");
-
-if (!isMSIE) {
- getElementsByTagName = function($element, $tagName, $namespace) {
- return $namespace ? $element.getElementsByTagNameNS("*", $tagName) :
- $element.getElementsByTagName($tagName);
- };
-
- compareNamespace = function($element, $namespace) {
- return !$namespace || ($namespace == "*") || ($element.prefix == $namespace);
- };
-
- isXML = document.contentType ? function($element) {
- return /xml/i.test(getDocument($element).contentType);
- } : function($element) {
- return getDocument($element).documentElement.tagName != "HTML";
- };
-
- getTextContent = function($element) {
- // mozilla || opera || other
- return $element.textContent || $element.innerText || _getTextContent($element);
- };
-
- function _getTextContent($element) {
- var $textContent = "", $node, i;
- for (i = 0; ($node = $element.childNodes[i]); i++) {
- switch ($node.nodeType) {
- case 11: // document fragment
- case 1: $textContent += _getTextContent($node); break;
- case 3: $textContent += $node.nodeValue; break;
- }
- }
- return $textContent;
- };
-}
-}); // addModule
+/*
+ cssQuery, version 2.0.2 (2005-08-19)
+ Copyright: 2004-2005, Dean Edwards (http://dean.edwards.name/)
+ License: http://creativecommons.org/licenses/LGPL/2.1/
+*/
+
+cssQuery.addModule("css-standard", function() { // override IE optimisation
+
+// cssQuery was originally written as the CSS engine for IE7. It is
+// optimised (in terms of size not speed) for IE so this module is
+// provided separately to provide cross-browser support.
+
+// -----------------------------------------------------------------------
+// browser compatibility
+// -----------------------------------------------------------------------
+
+// sniff for Win32 Explorer
+isMSIE = eval("false;/*@cc_on at if(@\x5fwin32)isMSIE=true at end@*/");
+
+if (!isMSIE) {
+ getElementsByTagName = function($element, $tagName, $namespace) {
+ return $namespace ? $element.getElementsByTagNameNS("*", $tagName) :
+ $element.getElementsByTagName($tagName);
+ };
+
+ compareNamespace = function($element, $namespace) {
+ return !$namespace || ($namespace == "*") || ($element.prefix == $namespace);
+ };
+
+ isXML = document.contentType ? function($element) {
+ return /xml/i.test(getDocument($element).contentType);
+ } : function($element) {
+ return getDocument($element).documentElement.tagName != "HTML";
+ };
+
+ getTextContent = function($element) {
+ // mozilla || opera || other
+ return $element.textContent || $element.innerText || _getTextContent($element);
+ };
+
+ function _getTextContent($element) {
+ var $textContent = "", $node, i;
+ for (i = 0; ($node = $element.childNodes[i]); i++) {
+ switch ($node.nodeType) {
+ case 11: // document fragment
+ case 1: $textContent += _getTextContent($node); break;
+ case 3: $textContent += $node.nodeValue; break;
+ }
+ }
+ return $textContent;
+ };
+
+
+ selectById = function($results, $from, id) {
+ var $match, i;
+ for(i = 0; i < $from.length; i++) {
+ var $match = _getChildById($from[i], id);
+ if($match) $results.push($match);
+ }
+ return $results;
+ }
+
+ function _getChildById($from, $id) {
+ var $match = document.getElementById($id);
+ if($from == document) {
+ return $match;
+ }
+ var $elt = $match;
+ while($elt) {
+ if($elt == $from) {
+ return $match;
+ }
+ $elt = $elt.parentNode;
+ }
+ return null;
+ }
+
+}
+}); // addModule
Modified: jifty/trunk/share/web/static/js/cssquery/cssQuery.js
==============================================================================
--- jifty/trunk/share/web/static/js/cssquery/cssQuery.js (original)
+++ jifty/trunk/share/web/static/js/cssquery/cssQuery.js Thu Jun 22 00:27:50 2006
@@ -2,10 +2,12 @@
cssQuery, version 2.0.2 (2005-08-19)
Copyright: 2004-2005, Dean Edwards (http://dean.edwards.name/)
License: http://creativecommons.org/licenses/LGPL/2.1/
+
+ Modifed by Nelson Elhage <nelhage at bestpractical.com>
+ (2006-06-21) to optimize selection by ID on non-IE browsers
*/
// the following functions allow querying of the DOM using CSS selectors
-var $ID_ONLY = /^#([^\s>+~]+)\s*(.*)$/;
var cssQuery = function() {
var version = "2.0.2";
@@ -19,34 +21,15 @@
var $match = [];
var $useCache = arguments.callee.caching && !$$from;
var $base = ($$from) ? ($$from.constructor == Array) ? $$from : [$$from] : [document];
- //Optimization -- check for selectors beginning with '#id'
- if($base.length == 1) {
- var $$bits = $selector.match($ID_ONLY);
- if($$bits) {
- var $match;
- if($base[0] == document) {
- $match = document.getElementById($$bits[1]);
- } else {
- $match = getChildById($base[0], $$bits[1]);
- }
- if(!$match) {
- return [];
- } else if(!$$bits[2].length) {
- return [$match];
- } else {
- return cssQuery($$bits[2], $match);
- }
- }
- }
// process comma separated selectors
var $$selectors = parseSelector($selector).split($COMMA), i;
for (i = 0; i < $$selectors.length; i++) {
// convert the selector to a stream
$selector = _toStream($$selectors[i]);
- // faster chop if it starts with id (MSIE only)
- if (isMSIE && $selector.slice(0, 3).join("") == " *#") {
+ // faster chop if it starts with id
+ if ($selector.slice(0, 3).join("") == " *#") {
$selector = $selector.slice(2);
- $$from = _msie_selectById([], $base, $selector[1]);
+ $$from = selectById([], $base, $selector[1]);
} else $$from = $base;
// process the stream
var j = 0, $token, $filter, $arguments, $cacheSelector = "";
@@ -266,37 +249,6 @@
return $element.innerText;
};
-function _msie_selectById($results, $from, id) {
- var $match, i, j;
- for (i = 0; i < $from.length; i++) {
- if ($match = $from[i].all.item(id)) {
- if ($match.id == id) $results.push($match);
- else if ($match.length != null) {
- for (j = 0; j < $match.length; j++) {
- if ($match[j].id == id) $results.push($match[j]);
- }
- }
- }
- }
- return $results;
-};
-
-function getChildById($from, $id) {
- if(isMSIE) {
- return _msie_selectById([], [$from], $id);
- } else {
- var $node = document.getElementById($id);
- var $elt = $node;
- while($elt) {
- if($elt == $from) {
- return $node;
- }
- $elt = $elt.parentNode;
- }
- return null;
- }
-}
-
// for IE5.0
if (![].push) Array.prototype.push = function() {
for (var i = 0; i < arguments.length; i++) {
@@ -352,6 +304,21 @@
.replace($IMPLIED_ALL, "$1*$2");
};
+var selectById = function($results, $from, id) {
+ var $match, i, j;
+ for (i = 0; i < $from.length; i++) {
+ if ($match = $from[i].all.item(id)) {
+ if ($match.id == id) $results.push($match);
+ else if ($match.length != null) {
+ for (j = 0; j < $match.length; j++) {
+ if ($match[j].id == id) $results.push($match[j]);
+ }
+ }
+ }
+ }
+ return $results;
+};
+
var Quote = {
toString: function() {return "'"},
match: /^('[^']*')|("[^"]*")$/,
More information about the Jifty-commit
mailing list