UNPKG

xmlapi-web

Version:

browser implementation of xmlapi

103 lines (102 loc) 3.72 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; const webapi_node_1 = require('./webapi_node'); const webapi_attribute_1 = require('./webapi_attribute'); const utils_1 = require('./utils'); const xmlapi_1 = require('xmlapi'); const utils_2 = require('xmlapi/utils'); let WebapiElement_1; let WebapiElement = WebapiElement_1 = class WebapiElement extends webapi_node_1.WebapiNode { constructor(wrapee) { super(wrapee); this.wrapee = wrapee; } get native() { return this.wrapee; } get namespaceUri() { return this.wrapee.namespaceURI; } get namespacePrefix() { return this.wrapee.lookupPrefix(this.namespaceUri); } get nameLocal() { return this.wrapee.localName; } get namePrefixed() { return this.wrapee.tagName; } getAttributes() { let attributes = this.wrapee.attributes; let ret = new Array(); for (let i = 0; i < attributes.length; ++i) { ret.push(new webapi_attribute_1.WebapiAttribute(attributes.item(i))); } return ret; } get firstChild() { return utils_1.nodeOrElementOrNull(this.wrapee.firstChild); } get lastChild() { return utils_1.nodeOrElementOrNull(this.wrapee.lastChild); } child(index) { return utils_1.nodeOrElementOrNull(this.wrapee.childNodes.item(index)); } firstElementChild() { return utils_2.wrappedOrNull(WebapiElement_1, this.wrapee.firstElementChild); } previousElementSibling() { return utils_2.wrappedOrNull(WebapiElement_1, this.wrapee.previousElementSibling); } nextElementSibling() { return utils_2.wrappedOrNull(WebapiElement_1, this.wrapee.nextElementSibling); } appendChild(child) { this.wrapee.appendChild(child.wrapee); // see http://stackoverflow.com/a/13723325/5271870 return child; } getAttribute(name) { return this.wrapee.getAttribute(name); } getAttributeNs(nsUri, localName) { return this.wrapee.getAttributeNS(nsUri, localName); } setAttribute(name, value) { this.wrapee.setAttribute(name, value.toString()); return this; } renameAttributeIfExists(nameOld, nameNew) { throw new Error('renameAttribute() not implemented for WebapiElement yet'); } removeAttribute(name) { this.wrapee.removeAttribute(name); } buildNsMap() { let ret = {}; // for (let el of merge(this, this.walkAncestors())) { // for (let attribute of el.getAttributes()) { // let prefix = attribute.namespacePrefix; // if (prefix === 'xmlns' && !(prefix in ret)) { // ret[attribute.localName] = attribute.value; // } // else if (!prefix && attribute.localName === 'xmlns' && !('' in ret)) { // ret[''] = attribute.value; // } // } // } return ret; } clone() { return super.clone(); } }; WebapiElement = WebapiElement_1 = __decorate([ utils_2.mixin(xmlapi_1.AbstractElement) ], WebapiElement); exports.WebapiElement = WebapiElement;