Skip to content

Commit

Permalink
Merge branch 'master' of github.com:MatthewMueller/cheerio
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewmueller committed Oct 3, 2012
2 parents 470134b + 346e01d commit b6758a3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 55 deletions.
19 changes: 0 additions & 19 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -443,25 +443,6 @@ $('.pear').html()
### Miscellaneous
DOM element methods that don't fit anywhere else

#### .get( [index] )
Retrieve the DOM elements matched by the cheerio object. If no index is specified, it will get an array of all matched elements.

```js
$('li').get(0)
//=> { raw: 'li class="apple"', ... }

$('li').get()
//=> [ {...}, {...}, {...} ]
```

#### .size()
Return the number of elements in the cheerio object. Same as `length`.

```js
$('li').size()
//=> 3
```

#### .toArray()
Retrieve all the DOM elements contained in the jQuery set, as an array.

Expand Down
51 changes: 15 additions & 36 deletions lib/api/manipulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,46 +16,25 @@ var makeCheerioArray = function(elems) {
}, []);
};

var append = exports.append = function() {
var elems = slice.call(arguments),
dom = makeCheerioArray(elems);

this.each(function(i, el) {
if (_.isFunction(elems[0])) {
// No yet supported
return this;
} else {
if (!el.children) el.children = [];
el.children = el.children.concat(dom);
updateDOM(el.children, el);
}
});
var _insert = function(concatenator) {
return function() {
var elems = slice.call(arguments),
dom = makeCheerioArray(elems);

return this;
return this.each(function(i, el) {
if (_.isFunction(elems[0])) return el; // not yet supported
updateDOM(concatenator(dom, el.children || (el.children = [])), el);
});
};
};

var append = exports.append = _insert(function(dom, children) {
return children.concat(dom);
});

/*
TODO: Refactor, only one line difference between,
this function and append
*/
var prepend = exports.prepend = function() {
var elems = slice.call(arguments),
dom = makeCheerioArray(elems);

this.each(function(i, el) {
if (_.isFunction(elems[0])) {
// No yet supported
return this;
} else {
if (!el.children) el.children = [];
el.children = dom.concat(el.children);
updateDOM(el.children, el);
}
});

return this;
};
var prepend = exports.prepend = _insert(function(dom, children) {
return dom.concat(children);
});

var after = exports.after = function() {
var elems = slice.call(arguments),
Expand Down

0 comments on commit b6758a3

Please sign in to comment.