Skip to content

Commit

Permalink
Fixed length issue (now its a special call); Now a wrapped HTML begin…
Browse files Browse the repository at this point in the history
…s with all its 'roots' selected.
  • Loading branch information
Hypher committed Feb 10, 2011
1 parent 022d861 commit 27d6c45
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
24 changes: 14 additions & 10 deletions index.js
Expand Up @@ -61,7 +61,7 @@ function findAll(obj, val) {
var aliases = {
'get': 'eq',
'count': 'length',
'len': 'length'
'nb': 'length'
};


Expand All @@ -83,7 +83,7 @@ function printHelp() {
console.log("one matching element per line.");
console.log();
console.log("OPTIONS are:");
console.log(" --outerHTML, -o : outputs the outerHTML of each element instead of innerHTML");
console.log(" --outerHTML, -o : outputs the outerHTML of each matched element instead of innerHTML");
console.log(" --flatten, -f : ensures that each matched element is output on a single line");
console.log(" --explain : outputs step-by-step what is done.");
console.log();
Expand All @@ -94,9 +94,9 @@ function printHelp() {
console.log("All these jQuery functions are supported:");
var jfns = jquery.getJQueryFns();
console.log(listProps(jfns).wordwrap(80));
//console.log();
//console.log("These special functions are available:")
//console.log(" None yet.");
console.log();
console.log("These special functions are available:")
console.log(" length (count, nb): returns the number of matched elements");
}


Expand Down Expand Up @@ -187,9 +187,9 @@ function parseArguments() {
outerHTML = true;
flattenHTML = true;
break;
//case 'special':
// calls.push(new Call(arg));
//break;
case 'length':
calls.push(new Call(arg));
break;
case ',':
noMoreParams = true;
break;
Expand Down Expand Up @@ -231,7 +231,7 @@ function processHTML(html, calls) {
wrapped = html != normalized,
window = jsdom.jsdom(normalized, null, jsdomOptions).createWindow(),
$ = jquery.create(window),
ctx = $(wrapped ? 'body' : '*'),
ctx = $(wrapped ? 'body>*' : 'html'),
ret,
call;

Expand All @@ -255,6 +255,10 @@ function processHTML(html, calls) {
}).get().join('\n'));
} else {
switch (call.name) {
case 'length':
if(explain) console.log("Return $.length");
returns(ctx.length);
break;
default:
console.error("Unknown call "+call.name);
}
Expand All @@ -263,7 +267,7 @@ function processHTML(html, calls) {

if(outerHTML) {
ctx = ctx.map(function(){ return ($('<html/>').append(this))[0]; });
if(explain) console.error("outerHTML wraps all $ elements in a separate document");
if(explain) console.error("outerHTML wraps all elements in a separate document");
}
if(flattenHTML && explain) {
console.error("flattenHTML removes newlines from elements' HTML");
Expand Down
1 change: 0 additions & 1 deletion jquery.js
Expand Up @@ -79,7 +79,6 @@ exports.getJQueryProps = function() {

// if a prop is true, its a DOMElement prop and jQuery.get is called before evaluation
var jQueryProps = {
length:false,
selector:false,

tagName:true,
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "jkwery",
"description": "Another command-line jQuery",
"version": "0.1.2",
"version": "0.1.3",
"keywords": ["jquery", "html", "dom", "parser"],
"author": "P Gotab", "contributors": [ "TJ Holowaychuk" ],
"homepage": "http://github.com/Hypher/jkwery",
Expand Down

0 comments on commit 27d6c45

Please sign in to comment.