From f0cc7b1a071532da60596eb6e91be550e7d259cb Mon Sep 17 00:00:00 2001 From: Vladimir Bulyga Date: Tue, 30 Oct 2012 00:40:04 +0200 Subject: [PATCH] that`s work! --- lib/dominiq.js | 13 +++++++++---- lib/jqresque.js | 8 ++++++-- lib/nquery.js | 4 ++-- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/dominiq.js b/lib/dominiq.js index 6953a3f..04cfd87 100644 --- a/lib/dominiq.js +++ b/lib/dominiq.js @@ -8,9 +8,11 @@ var libxml = require('libxmljs'), exports.createHTMLDocument = createHTMLDocument; -function createHTMLDocument(html) { +function createHTMLDocument(html, encoding) { var doc = libxml.parseHtmlString(html); - + + if (encoding) doc.encoding(encoding); + return new HTMLDocument(doc); } @@ -84,8 +86,7 @@ function cloneAndImportNode(document, nodeIn) { } function createTextNode(document, text) { - var node = new libxml.Element(document, 'span', {}, text).childNodes()[0]; - + var node = new libxml.Element(document, 'span', {}, text);//.childNodes();//[0]; node.remove(); return node; @@ -200,6 +201,10 @@ function HTMLElement(node) { this.style = {}; } +HTMLElement.prototype.text = function() { + return this._n.text(); +}; + HTMLElement.prototype.__defineGetter__('textContent', function() { return this._n.text(); }); diff --git a/lib/jqresque.js b/lib/jqresque.js index 1b93810..c3b43b9 100644 --- a/lib/jqresque.js +++ b/lib/jqresque.js @@ -1291,8 +1291,12 @@ exports.init = function(window) { if ( typeof text !== "object" && text !== undefined ) { return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) ); } - - return jQuery.text( this ); + var text = ''; + jQuery(this.get()).each(function(id, el) { + text+=el.textContent; + }); + return text; + //jQuery.text( this ); }, wrapAll: function( html ) { diff --git a/lib/nquery.js b/lib/nquery.js index 663a9bd..5d583fb 100644 --- a/lib/nquery.js +++ b/lib/nquery.js @@ -2,8 +2,8 @@ var Dominiq = require('./dominiq'); var Sizzle = require('./sizzle'); var jQuery = require('./jqresque'); -exports.createHtmlDocument = function(html) { - var doc = Dominiq.createHTMLDocument(html); +exports.createHtmlDocument = function(html, encoding) { + var doc = Dominiq.createHTMLDocument(html, encoding); var window = {document:doc}; var sizzle = Sizzle.init(window); var $ = jQuery.init(window);