Skip to content

Commit

Permalink
More on rewrite and doc
Browse files Browse the repository at this point in the history
  • Loading branch information
samleb committed Oct 8, 2008
1 parent 3cf2419 commit 70e2746
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions src/bouncer.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var Bouncer = (function() {
Combinators,
Cache = { };

function True() { return true }
function TRUE() { return true }

Matchers = {
// Patterns imported from Prototype JavaScript Framework.
Expand All @@ -59,7 +59,7 @@ var Bouncer = (function() {
},
tagName: function(match) {
var tagName = match[1];
if (tagName === "*") return True;
if (tagName === "*") return TRUE;
tagName = tagName.toUpperCase();
return function(e) {
return e.tagName.toUpperCase() === tagName;
Expand All @@ -77,10 +77,10 @@ var Bouncer = (function() {
throw "Unsupported pseudo selector: " + pseudo;
} else {
pseudo = Pseudos[pseudo];
// check identity with unique `True` reference to ensure
// check identity with unique `TRUE` reference to ensure
// `hasArgument` is not coming from outside (e.g. Function.prototype),
// and we're really dealing with a result from `pseudoWithArgument`.
if (pseudo.hasArgument === True) {
if (pseudo.hasArgument === TRUE) {
// give the argument to the generator
return pseudo.generator(match[2]);
}
Expand Down Expand Up @@ -197,7 +197,7 @@ var Bouncer = (function() {
}
}

return matcher || True;
return matcher || TRUE;

function advance(domain, callback) {
var patterns = domain.patterns;
Expand All @@ -213,7 +213,7 @@ var Bouncer = (function() {

function combine(a, b) {
if (!b) return a;
if (a === True) return b;
if (a === TRUE) return b;
return function(element) {
var result = a(element);
return result && b(result === true ? element : result);
Expand All @@ -222,7 +222,7 @@ var Bouncer = (function() {

function pseudoWithArgument(generator) {
return {
hasArgument: True,
hasArgument: TRUE,
generator: generator
};
}
Expand All @@ -241,6 +241,20 @@ var Bouncer = (function() {
return Cache[expression](element);
},

/**
* @param {String} name The name of the pseudo-selector
* @param {Function} matcher The matcher
* @returns {void}
* @example
* Bouncer.registerPseudo("checked", function(element) {
* return element.checked;
* });
* Bouncer.match(document.forms.new_post.draft, ":checked");
**/
registerPseudo: function(name, matcher) {
Pseudos[name] = matcher;
},

/**
* @param {String} name The name of the pseudo-selector
* @param {Function} generator The generator that should return a matcher
Expand All @@ -255,20 +269,6 @@ var Bouncer = (function() {
**/
registerPseudoWithArgument: function(name, generator) {
Pseudos[name] = pseudoWithArgument(generator);
},

/**
* @param {String} name The name of the pseudo-selector
* @param {Function} matcher The matcher
* @returns {void}
* @example
* Bouncer.registerPseudo("checked", function(element) {
* return element.checked;
* });
* Bouncer.match(document.forms.new_post.draft, ":checked");
**/
registerPseudo: function(name, matcher) {
Pseudos[name] = matcher;
}
};
})();

0 comments on commit 70e2746

Please sign in to comment.