Comparing version 0.1.3 to 0.1.4
{ | ||
"name": "htmldom", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "Simplified html handle in nodejs", | ||
@@ -5,0 +5,0 @@ "main": "htmldom.js", |
@@ -139,3 +139,8 @@ # htmldom — Simplified html handle in nodejs | ||
``` | ||
* html(html) | ||
* parent(selector) | ||
``` | ||
$('').parent() | ||
$('').parent('.cls') | ||
``` | ||
* html(content) | ||
```js | ||
@@ -145,2 +150,10 @@ $('').html() // get html | ||
``` | ||
* append(content) | ||
```js | ||
$('').append('<h3>title'); | ||
``` | ||
* prepend(content) | ||
```js | ||
$('').prepend('<h3>title'); | ||
``` | ||
* remove() | ||
@@ -147,0 +160,0 @@ ```js |
@@ -214,2 +214,21 @@ var css = require('./css'); | ||
/** | ||
* $('').parent(); | ||
* $('').parent('.cls') | ||
*/ | ||
$.prototype.parent = function(selector) { | ||
var result = []; | ||
selector = css.parser(selector || ''); | ||
for (var i = 0; i < this.length; i++) { | ||
var parent = this[i].parent; | ||
if (parent && css.match(parent, selector)) { | ||
result.push(parent); | ||
} | ||
} | ||
return $(result, this.document); | ||
} | ||
/** | ||
* @example | ||
@@ -223,3 +242,3 @@ * $('').eq(0) | ||
} | ||
return $(this[index]); | ||
return $(this[index], this.document); | ||
} | ||
@@ -246,3 +265,3 @@ | ||
return $(result); | ||
return $(result, this.document); | ||
}; | ||
@@ -304,29 +323,2 @@ | ||
* @example | ||
* $('').html() // get | ||
* $('').html('<div></div>') // set | ||
*/ | ||
$.prototype.html = function(html) { | ||
var HtmlDom = require('../htmldom'); | ||
if (util.isUndefined(html)) { | ||
if (this.length) { | ||
var htmldom = new HtmlDom(); | ||
return htmldom.html(this[0].children); | ||
} else { | ||
return null; | ||
} | ||
} else { | ||
this.each(function(index, item) { | ||
var htmldom = new HtmlDom(html); | ||
htmldom.dom.forEach(function(child) { | ||
child.parent = item; | ||
}); | ||
item.children = htmldom.dom; | ||
}); | ||
} | ||
return this; | ||
}; | ||
/** | ||
* @example | ||
* $('').remove() | ||
@@ -469,2 +461,65 @@ */ | ||
$.prototype._createdom = function(html, callback) { | ||
var HtmlDom = require('../htmldom'); | ||
for (var i = 0; i < this.length; i++) { | ||
var htmldom = new HtmlDom(html).dom; | ||
callback(this[i], htmldom); | ||
} | ||
} | ||
/** | ||
* @example | ||
* $('').html() // get | ||
* $('').html('<div></div>') // set | ||
*/ | ||
$.prototype.html = function(content) { | ||
if (util.isUndefined(content)) { | ||
if (this.length) { | ||
var HtmlDom = require('../htmldom'); | ||
var htmldom = new HtmlDom(); | ||
return htmldom.html(this[0].children); | ||
} else { | ||
return null; | ||
} | ||
} else { | ||
this._createdom(content, function(item, children) { | ||
children.forEach(function(child) { | ||
child.parent = item; | ||
}); | ||
item.children = children; | ||
}); | ||
} | ||
return this; | ||
}; | ||
/** | ||
* $('').append('<ul><li>1'); | ||
*/ | ||
$.prototype.append = function(content) { | ||
this._createdom(content, function(item, children) { | ||
children.forEach(function(child) { | ||
child.parent = item; | ||
item.children.push(child); | ||
}); | ||
}); | ||
return this; | ||
}; | ||
/** | ||
* $('') | ||
*/ | ||
$.prototype.prepend = function(content) { | ||
this._createdom(content, function(item, children) { | ||
length = children.length; | ||
while (length--) { | ||
var child = children[length]; | ||
child.parent = item; | ||
item.children.unshift(child); | ||
} | ||
}); | ||
}; | ||
module.exports = $; |
@@ -1,3 +0,1 @@ | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var HtmlDom = require('../../htmldom'); | ||
@@ -4,0 +2,0 @@ var assert = require('assert'); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
69228
42
2122
270
6