Skip to content

Commit

Permalink
Assume you're going to get htmlparser from npm, ok?
Browse files Browse the repository at this point in the history
  • Loading branch information
nickstenning committed Jul 23, 2010
1 parent 6301014 commit eefb3c1
Showing 1 changed file with 40 additions and 40 deletions.
80 changes: 40 additions & 40 deletions lib/jsdom/browser/index.js
Expand Up @@ -11,9 +11,9 @@ Object.defineProperty(Array.prototype, 'toString', {value: function() {


exports.windowAugmentation = function(dom, options) {

if(!options) options = {};

var browser = browserAugmentation(dom, options);
var Window = {
document: new browser.Document(),
Expand Down Expand Up @@ -74,28 +74,28 @@ exports.windowAugmentation = function(dom, options) {
};

var browserAugmentation = exports.browserAugmentation = function(dom, options) {

if(!options) options = {};

// set up html parser - use a provided one or try and load from library

var htmltodom;

if(options.parser) {
htmltodom = new HtmlToDom(options.parser);
} else {
try {
var htmlparser = require('node-htmlparser/node-htmlparser');
var htmlparser = require('htmlparser');
htmltodom = new HtmlToDom(htmlparser);
} catch(e) {
htmltodom = new HtmlToDom();
}
}

/***************************************
* Browser Augmentation *
***************************************/

dom.Node.prototype.addEventListener = function(){};

dom.Element.prototype.getElementsByClassName = function(className) {
Expand All @@ -105,8 +105,8 @@ var browserAugmentation = exports.browserAugmentation = function(dom, options) {
return false;
}

if (child.nodeType &&
child.nodeType === dom.Node.prototype.ENTITY_REFERENCE_NODE)
if (child.nodeType &&
child.nodeType === dom.Node.prototype.ENTITY_REFERENCE_NODE)
{
child = child._entity;
}
Expand Down Expand Up @@ -194,20 +194,20 @@ var browserAugmentation = exports.browserAugmentation = function(dom, options) {

dom.Element.prototype.__defineSetter__('innerHTML', function(html) {
//Check for lib first

if (html === null) {
return null;
}

//Clear the children first:
for (var i = this.childNodes.length-1; i >= 0; i--) {
if (this.childNodes[i].parentNode) {
this.childNodes[i].parentNode.removeChild(this.childNodes[i]);
}
}

var nodes = htmltodom.appendHtmlToElement(html, this);

//sys.puts('OUT: ' + this.outerHTML);

return html;
Expand All @@ -217,7 +217,7 @@ dom.Element.prototype.__defineSetter__('innerHTML', function(html) {
dom.Document.prototype.__defineGetter__("body", function() {
return this.getElementsByTagName("body").item(0);
});

dom.Element.prototype.createCaption = function(str) {
var el = document.createElement('caption');
el.innerHTML = str;
Expand Down Expand Up @@ -247,15 +247,15 @@ dom.Element.prototype.__defineSetter__('innerHTML', function(html) {
}
return t;
});

dom.Element.prototype.scrollTop = 0;
dom.Element.prototype.scrollLeft = 0;


dom.Element.prototype.__defineSetter__("href", function(val) {
this.setAttribute("href", val);
});

dom.Element.prototype.__defineGetter__("href",function() {
return this.getAttribute("href");
});
Expand All @@ -264,36 +264,36 @@ dom.Element.prototype.__defineSetter__('innerHTML', function(html) {
dom.Element.prototype.__defineSetter__("height", function(val) {
this.setAttribute("height", val);
});

dom.Element.prototype.__defineGetter__("height",function() {
return this.getAttribute("height");
});

dom.Element.prototype.__defineSetter__("width", function(val) {
this.setAttribute("width", val);
});

dom.Element.prototype.__defineGetter__("width",function() {
return this.getAttribute("width");
});
dom.Element.prototype.__defineSetter__("src", function(val) {
this.setAttribute("src", val);
});

dom.Element.prototype.__defineGetter__("src",function() {
return this.getAttribute("src");
});
dom.Element.prototype.__defineSetter__("lang", function(val) {
this.setAttribute("lang", val);
});

dom.Element.prototype.__defineGetter__("lang",function() {
return this.getAttribute("lang");
});
dom.Element.prototype.__defineSetter__("className", function(className) {
this.setAttribute("class", className);
});

dom.Element.prototype.__defineGetter__("className",function() {
return this.getAttribute("class");
});
Expand Down Expand Up @@ -427,11 +427,11 @@ dom.Element.prototype.__defineSetter__('innerHTML', function(html) {
});

dom.Element.prototype.__defineGetter__('textContent', function() {
var stripHTML = /<\S[^><]*>/g;
var stripHTML = /<\S[^><]*>/g;
var out = this.innerHTML;
//Encode all the spaces
out = out.replace(/&nbsp;/g, ' ');
//Remove all the HTML
//Remove all the HTML
out = out.replace(stripHTML, '');
//Now decode the encoded text content
out = html_entity_decode(out);
Expand All @@ -454,10 +454,10 @@ dom.Element.prototype.__defineSetter__('innerHTML', function(html) {
http://phpjs.org/pages/license/#MIT
* More info at: http://phpjs.org
*
*
* This is version: 3.09
* php.js is copyright 2010 Kevin van Zonneveld.
*
*
* Portions copyright Brett Zamir (http://brett-zamir.me), Kevin van Zonneveld
* (http://kevin.vanzonneveld.net), Onno Marsman, Theriault, Michael White
* (http://getsprink.com), Waldo Malqui Silva, Paulo Ricardo F. Santos, Jack,
Expand Down Expand Up @@ -537,29 +537,29 @@ http://phpjs.org/pages/license/#MIT
* (http://www.winternet.no), Howard Yeend, Kheang Hok Chin
* (http://www.distantia.ca/), Jay Klehr, Leslie Hoare, mk.keck, Ben Bryan,
* booeyOH, Amir Habibi (http://www.residence-mixte.com/), Cagri Ekin
*
*
* Dual licensed under the MIT (MIT-LICENSE.txt)
* and GPL (GPL-LICENSE.txt) licenses.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL KEVIN VAN ZONNEVELD BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
*/

var htmlentities = function(string, quote_style) {
// http://kevin.vanzonneveld.net
Expand All @@ -579,7 +579,7 @@ var htmlentities = function(string, quote_style) {

var hash_map = {}, symbol = '', tmp_str = '', entity = '';
tmp_str = string.toString();

if (false === (hash_map = get_html_translation_table('HTML_ENTITIES', quote_style))) {
return false;
}
Expand All @@ -588,7 +588,7 @@ var htmlentities = function(string, quote_style) {
entity = hash_map[symbol];
tmp_str = tmp_str.split(symbol).join(entity);
}

return tmp_str;
};

Expand All @@ -613,7 +613,7 @@ var html_entity_decode = function(string, quote_style) {

var hash_map = {}, symbol = '', tmp_str = '', entity = '';
tmp_str = string.toString();

if (false === (hash_map = get_html_translation_table('HTML_ENTITIES', quote_style))) {
return false;
}
Expand All @@ -628,7 +628,7 @@ var html_entity_decode = function(string, quote_style) {
tmp_str = tmp_str.split(entity).join(symbol);
}
tmp_str = tmp_str.split('&#039;').join("'");

return tmp_str;
};

Expand All @@ -653,11 +653,11 @@ var get_html_translation_table = function(table, quote_style) {
// % note: chooses to create the constants themselves.
// * example 1: get_html_translation_table('HTML_SPECIALCHARS');
// * returns 1: {'"': '&quot;', '&': '&amp;', '<': '&lt;', '>': '&gt;'}

var entities = {}, hash_map = {}, decimal = 0, symbol = '';
var constMappingTable = {}, constMappingQuoteStyle = {};
var useTable = {}, useQuoteStyle = {};

// Translate arguments
constMappingTable[0] = 'HTML_SPECIALCHARS';
constMappingTable[1] = 'HTML_ENTITIES';
Expand Down Expand Up @@ -788,7 +788,7 @@ var get_html_translation_table = function(table, quote_style) {
symbol = String.fromCharCode(decimal);
hash_map[symbol] = entities[decimal];
}

return hash_map;
};

Expand Down

0 comments on commit eefb3c1

Please sign in to comment.