Showing posts with label Sly. Show all posts
Showing posts with label Sly. Show all posts

Tuesday, April 28, 2009

Prototype on Sly is "3x faster"

HTML:
<script type="text/javascript" src="prototype.js"></script>
<script type="text/javascript" src="Sly.js"></script>

Javascript:
// Overriding CSS Selector Engine.
Sly.handlers = Selector.handlers;
Sly.prototype.findElements = Sly.prototype.search;
Sly.findElement = function(elements, expression, index) {
if (Object.isNumber(expression)) {
index = expression; expression = false;
}
return Sly(expression || '*').filter(elements)[index || 0];
};
Sly.findChildElements = function(element, expressions) {
var result = Sly(expressions.join(',')).search(element);
return Prototype.BrowserFeatures.ElementExtensions ?
result : result.filter(Element.extend);
};
Selector = Sly;
http://slickspeed.firejune.com
http://github.com/digitarald/sly/tree/master

Sunday, March 29, 2009

Rolling out Sly - The JavaScript Selector Engine

Sly is a turbocharged, cross-browser, library-agnostic JavaScript class for querying DOM documents using CSS3 selectors.

Sly awesomeness:

  • Pure and powerful JavaScript matching algorithm for fast and accurate queries
  • Extra optimizations for frequently used selectors and latest browser features
  • Works uniformly in DOM documents, fragments or XML documents
  • Utility methods for matching and filtering of elements
  • Standalone selector parser to produce JavaScript Object representations
  • Customizable pseudo-classes, attribute operators and combinators
  • Just 3 kB! (minified and gzipped, 8 kB without gzip)
  • No dependencies on third-party JS libraries, but developers can override internal methods (like getAttribute) for seamless integration.
  • Code follows the MooTools philosophy, respecting strict standards, throwing no warnings and using meaningful variable names

Querying the DOM with Sly:

// Finds all odd rows in all tables
var rows = Sly.search('table td:odd');

// Finds all links with class "internal" and an attribute "href" starting with "#".
var links = Sly.search('a.internal[href^="#"]');

// Another notation is also possible, since Sly acts as a constructor
var snippets = Sly('pre.highlight.javascript > code').search();

// features is just one element, lists has all list items are siblings of features
var features = Sly.find('#features');
var lists = Sly.search('~ ul', body);
http://digitarald.de/journal/89737433/rolling-out-sly-the-javascript-selector-engine/