Plato on Github
Report Home
node_modules\atropa-HTMLParser\src\atropa-HTMLParser.js
Maintainability
66.70
Lines of code
137
Difficulty
25.67
Estimated Errors
0.61
Function weight
By Complexity
By SLOC
/// <reference path="../docs/vsdoc/OpenLayersAll.js"/> var atropa = require('atropa-header'); /*jslint indent: 4, maxerr: 50, white: true, browser: true, devel: true, plusplus: true, regexp: true */ /*global atropa */ // end header atropa.requires( 'HTMLParser', function () { "use strict"; var supported = true; [ document.implementation.createDocumentType, document.implementation.createDocument ].forEach(function (prerequisite) { if(prerequisite === undefined) { supported = false; } }); return supported; } ); /** * Creates a new HTML Parser<br /> * Carry out DOM operations without loading content to the active document. * @author <a href="mailto:matthewkastor@gmail.com"> * Matthew Christopher Kastor-Inare III </a><br /> * ☭ Hial Atropa!! ☭ * @version 20120909 * @class Creates a new HTML Parser * @returns {HTML DOM Document} Returns a blank HTML Document for you to load * data into * @requires atropa.data */ atropa.HTMLParser = function HTMLParser() { "use strict"; var my = this; /** * Holds the created HTML DOM Document. * @type HTML DOM Document * @fieldOf atropa.HTMLParser# */ this.doc = {}; /** * Creates a blank HTML DOM Document. * @author <a href="mailto:matthewkastor@gmail.com"> * Matthew Christopher Kastor-Inare III </a><br /> * ☭ Hial Atropa!! ☭ * @version 20120909 * @methodOf atropa.HTMLParser# * @returns {HTML DOM Document} Resets the doc property of this instance * and, returns a blank HTML Document for you to load data into. */ this.newDocument = function () { var dt; dt = document.implementation.createDocumentType( "html", "-//W3C//DTD HTML 4.01 Transitional//EN", "http://www.w3.org/TR/html4/loose.dtd" ); my.doc = document.implementation.createDocument('', '', dt); if (my.doc.nodeType !== 9) { atropa.data.HTMLParser.support = 'unsupported'; throw new Error(atropa.data.HTMLParser.error + 'the document nodeType returned an unexpected value'); } return my.doc; }; /** * Creates a new HTML DOM Document and loads the given string into it. * @author <a href="mailto:matthewkastor@gmail.com"> * Matthew Christopher Kastor-Inare III </a><br /> * ☭ Hial Atropa!! ☭ * @version 20120909 * @methodOf atropa.HTMLParser# * @param {String} htmlstring a string of HTML data * @returns {HTML DOM Document} Resets the doc property of this instance, * loading a new document with the string given. */ this.loadString = function (htmlstring) { if (!htmlstring) { return false; } try { my.newDocument(); my.doc.appendChild(my.doc.createElement('html')); my.doc.documentElement.innerHTML = htmlstring; } catch (e) { atropa.data.HTMLParser.support = 'unsupported'; throw new Error(atropa.data.HTMLParser.error + 'atropa.HTMLParser can not load ' + 'the hidden document from string because: ' + e); } return my.doc; }; function init () { var eqTest; atropa.supportCheck('HTMLParser'); try { eqTest = my.loadString( '<head></head><body><p>test</p></body>' ).body.textContent; } catch (e) { atropa.data.HTMLParser.support = 'unsupported'; throw new Error(atropa.data.HTMLParser.error + e); } if('test' !== eqTest) { atropa.data.HTMLParser.support = 'unsupported'; throw new Error(atropa.data.HTMLParser.error); } my.newDocument(); } init(); }; while(atropa.data.requirements.length > 0) { atropa.data.requirements.pop()(); } module.exports = atropa;