UNPKG

node-dom

Version:

Javascript fast W3C DOM generation.

1 lines 6.14 kB
/* Copyright (c) 2011 jCore - Aymeric Vitte - MIT license Implement specific properties for Tags Attempts to return an acceptable result (mostly Node or NodeList which looks acceptable to replace the specified objects that should be normally returned) */ var index=require('./index.js'), core=index.CORE, node=index.NODE, document=index.DOCUMENT; var HTML=exports.HTML=function(name) { var NOT_IMPLEMENTED=function(name,obj) { var args = Array.prototype.slice.call(arguments); args.shift(); args.shift(); if (!this['_ni_'+name]) { this['_ni_'+name] = args.length>0?new obj(args[0],args[1]):new obj(); this._Enum('_ni_'+name,false); }; return this['_ni_'+name]; }; switch(name) { case 'FORM' : return { get elements() { return NOT_IMPLEMENTED.call(this,'elements',core.NodeList);}, get length() {return 0}, submit: function() {}, reset: function() {} }; case 'LINK' || 'BASE' || 'A' : return { get href() { return core.resourceLoader.resolve(this._document, this.__href); }, set href(val) { this.__href=core.resourceLoader.resolve(this._document, val); if ((this.__name in this._document._features['FetchExternalResources'])&&(this.__name=='link')) { //load resources if (this.__dom) { //if in DOM core.resourceLoader.load(this); //and fire onload } }; if (this.__name=='base') { console.log('basssssssssssss'); this._document._base=val; } } }; case 'TITLE' : return { get text() {}, set text(txt) {} }; case 'SELECT' : return { get options() { var tmp=NOT_IMPLEMENTED.call(this,'options',core.NodeList);if ((tmp.length==0)&&(this.firstChild)) {tmp.push(this.firstChild);} }, get length() {return 0}, get selectedIndex() {this[0]=this.firstChild||{value:''};return 0}, set selectedIndex() {}, get value() {return 0}, set value(val) {}, get form() { return NOT_IMPLEMENTED.call(this,'form',node,'form',this._document); }, add: function() {}, remove: function() {} }; case 'OPTION' : return { get form() { return NOT_IMPLEMENTED.call(this,'form',node,'form',this._document); }, get defaultSelected() {return false}, get text() {return ''}, get value() {return ''}, set value() {}, get index() {return 0}, get selected() {return false}, set selected() {} }; case 'INPUT' : return { get form() { return NOT_IMPLEMENTED.call(this,'form',node,'form',this._document); }, get defaultValue() {return ''}, get defaultChecked() {return false}, get checked() {return false}, set checked() {}, get value() {return ''}, set value() {}, select: function() {} }; case 'TEXTAREA' : return { get form() { return NOT_IMPLEMENTED.call(this,'form',node,'form',this._document); }, get defaultValue() {return ''}, get value() {return ''}, set value() {}, get type() {return 'textarea'}, select: function() {} }; case 'BUTTON' || 'LABEL' || 'FIELDSET' || 'LEGEND' : return { get form() { return NOT_IMPLEMENTED.call(this,'form',node,'form',this._document); } }; case 'IMG' : return { get src() { return core.resourceLoader.resolve(this._document, this.__src); }, set src(val) { this.__src=core.resourceLoader.resolve(this._document, val); if (this.__name in this._document._features['FetchExternalResources']) { //load resources if (this.__dom) { //if in DOM core.resourceLoader.load(this); //and fire onload } }; } }; case 'OBJECT' : return { get form() { return NOT_IMPLEMENTED.call(this,'form',node,'form',this._document); }, get contentDocument() {} }; case 'SCRIPT' : return { get src() { return core.resourceLoader.resolve(this._document, this.__src); }, set src(val) { this.__src=core.resourceLoader.resolve(this._document, val); if (this.__name in this._document._features['FetchExternalResources']) { //load resources if (this.__dom) { //if in DOM core.resourceLoader.load(this); //and fire onload } }; } }; case 'TABLE' : return { get caption() { return NOT_IMPLEMENTED.call(this,'caption',node,'caption',this._document); }, get tHead() { return NOT_IMPLEMENTED.call(this,'tHead',node,'thead',this._document); }, get tFoot() { return NOT_IMPLEMENTED.call(this,'tFoot',node,'tfoot',this._document); }, get rows() { return NOT_IMPLEMENTED.call(this,'rows',core.NodeList); }, get tBodies() { return NOT_IMPLEMENTED.call(this,'tbody',node,'tbody',this._document); }, createTHead: function() {return this.tHead}, deleteTHead: function() {this.__tHead=null;}, createTFoot: function() {return this.tFoot}, deleteTFoot: function() {this.__tFoot=null;}, createTBody: function() {return this.tBodies}, deleteTBody: function() {this.__tbody=null;}, createCaption: function() {return this.caption}, deleteCaption: function() {this.__caption=null}, insertRow: function() {return this.tBodies}, deleteRow: function() {} }; case 'THEAD' || 'TBODY' || 'TFOOT' : return { get rows() {return NOT_IMPLEMENTED.call(this,'rows',core.NodeList);}, insertRow: function() {return NOT_IMPLEMENTED.call(this,'tr',node,'tr',this._document);}, deleteRow: function() {}, }; case 'TR' : return { get cells() {return NOT_IMPLEMENTED.call(this,'cells',core.NodeList);}, get rowIndex() {return 0}, get sectionRowIndex() {return 0}, insertCell: function() {return NOT_IMPLEMENTED.call(this,'td',node,'td',this._document);}, deleteCell: function(index) {}, }; case 'TH' || 'TD' : return { get headers() {return NOT_IMPLEMENTED.call(this,'cells',core.NodeList);}, get cellIndex() {return 0} }; case 'FRAME' || 'IFRAME' : return { get src() { return core.resourceLoader.resolve(this._document, this.__src); }, set src(val) { this.__src=core.resourceLoader.resolve(this._document, val); }, get contentDocument() {return new core.HTMLDocument(null,{url:'',features:''})} }; }; return {}; }