refactor (angular2/src/dom): tsifying angular2/src/dom
translates parse5_adapter.cjs to typescript Closes #2230
This commit is contained in:
parent
f19970a481
commit
6404dd8293
|
@ -0,0 +1,2 @@
|
||||||
|
library angular2.src.dom.parse5_adapter;
|
||||||
|
// no dart implementation
|
|
@ -24,25 +24,15 @@ function _notImplemented(methodName) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Parse5DomAdapter extends DomAdapter {
|
export class Parse5DomAdapter extends DomAdapter {
|
||||||
static makeCurrent() {
|
static makeCurrent() { setRootDomAdapter(new Parse5DomAdapter()); }
|
||||||
setRootDomAdapter(new Parse5DomAdapter());
|
|
||||||
}
|
|
||||||
|
|
||||||
logError(error) {
|
logError(error) { console.error(error); }
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
get attrToPropMap() {
|
get attrToPropMap() { return _attrToPropMap; }
|
||||||
return _attrToPropMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
query(selector) {
|
query(selector) { throw _notImplemented('query'); }
|
||||||
throw _notImplemented('query');
|
querySelector(el, selector: string) { return this.querySelectorAll(el, selector)[0]; }
|
||||||
}
|
querySelectorAll(el, selector: string) {
|
||||||
querySelector(el, selector:string) {
|
|
||||||
return this.querySelectorAll(el, selector)[0];
|
|
||||||
}
|
|
||||||
querySelectorAll(el, selector:string) {
|
|
||||||
var res = ListWrapper.create();
|
var res = ListWrapper.create();
|
||||||
var _recursive = (result, node, selector, matcher) => {
|
var _recursive = (result, node, selector, matcher) => {
|
||||||
var cNodes = node.childNodes;
|
var cNodes = node.childNodes;
|
||||||
|
@ -61,7 +51,7 @@ export class Parse5DomAdapter extends DomAdapter {
|
||||||
_recursive(res, el, selector, matcher);
|
_recursive(res, el, selector, matcher);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
elementMatches(node, selector:string, matcher = null):boolean {
|
elementMatches(node, selector: string, matcher = null): boolean {
|
||||||
var result = false;
|
var result = false;
|
||||||
if (selector && selector.charAt(0) == "#") {
|
if (selector && selector.charAt(0) == "#") {
|
||||||
result = this.getAttribute(node, 'id') == selector.substring(1);
|
result = this.getAttribute(node, 'id') == selector.substring(1);
|
||||||
|
@ -84,14 +74,14 @@ export class Parse5DomAdapter extends DomAdapter {
|
||||||
cssSelector.addClassName(classList[i]);
|
cssSelector.addClassName(classList[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
matcher.match(cssSelector, function(selector, cb) {result = true;});
|
matcher.match(cssSelector, function(selector, cb) { result = true; });
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
on(el, evt, listener) {
|
on(el, evt, listener) {
|
||||||
var listenersMap = el._eventListenersMap;
|
var listenersMap: StringMap<any, any> = el._eventListenersMap;
|
||||||
if (isBlank(listenersMap)) {
|
if (isBlank(listenersMap)) {
|
||||||
var listenersMap = StringMapWrapper.create();
|
var listenersMap: StringMap<any, any> = StringMapWrapper.create();
|
||||||
el._eventListenersMap = listenersMap;
|
el._eventListenersMap = listenersMap;
|
||||||
}
|
}
|
||||||
var listeners = StringMapWrapper.get(listenersMap, evt);
|
var listeners = StringMapWrapper.get(listenersMap, evt);
|
||||||
|
@ -103,14 +93,16 @@ export class Parse5DomAdapter extends DomAdapter {
|
||||||
}
|
}
|
||||||
onAndCancel(el, evt, listener): Function {
|
onAndCancel(el, evt, listener): Function {
|
||||||
this.on(el, evt, listener);
|
this.on(el, evt, listener);
|
||||||
return () => {ListWrapper.remove(StringMapWrapper.get(el._eventListenersMap, evt), listener);};
|
return () => {
|
||||||
|
ListWrapper.remove(StringMapWrapper.get(el._eventListenersMap, evt), listener);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
dispatchEvent(el, evt) {
|
dispatchEvent(el, evt) {
|
||||||
if (isBlank(evt.target)) {
|
if (isBlank(evt.target)) {
|
||||||
evt.target = el;
|
evt.target = el;
|
||||||
}
|
}
|
||||||
if (isPresent(el._eventListenersMap)) {
|
if (isPresent(el._eventListenersMap)) {
|
||||||
var listeners = StringMapWrapper.get(el._eventListenersMap, evt.type);
|
var listeners: any = StringMapWrapper.get(el._eventListenersMap, evt.type);
|
||||||
if (isPresent(listeners)) {
|
if (isPresent(listeners)) {
|
||||||
for (var i = 0; i < listeners.length; i++) {
|
for (var i = 0; i < listeners.length; i++) {
|
||||||
listeners[i](evt);
|
listeners[i](evt);
|
||||||
|
@ -124,53 +116,31 @@ export class Parse5DomAdapter extends DomAdapter {
|
||||||
this.dispatchEvent(el._window, evt);
|
this.dispatchEvent(el._window, evt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
createMouseEvent(eventType) {
|
createMouseEvent(eventType) { return this.createEvent(eventType); }
|
||||||
return this.createEvent(eventType);
|
|
||||||
}
|
|
||||||
createEvent(eventType) {
|
createEvent(eventType) {
|
||||||
var evt = {
|
var evt = {
|
||||||
type: eventType,
|
type: eventType,
|
||||||
defaultPrevented: false,
|
defaultPrevented: false,
|
||||||
preventDefault: () => {evt.defaultPrevented = true}
|
preventDefault: () => { evt.defaultPrevented = true }
|
||||||
};
|
};
|
||||||
return evt;
|
return evt;
|
||||||
}
|
}
|
||||||
preventDefault(evt) {
|
preventDefault(evt) { evt.returnValue = false; }
|
||||||
evt.returnValue = false;
|
getInnerHTML(el) { return serializer.serialize(this.templateAwareRoot(el)); }
|
||||||
}
|
|
||||||
getInnerHTML(el) {
|
|
||||||
return serializer.serialize(this.templateAwareRoot(el));
|
|
||||||
}
|
|
||||||
getOuterHTML(el) {
|
getOuterHTML(el) {
|
||||||
serializer.html = '';
|
serializer.html = '';
|
||||||
serializer._serializeElement(el);
|
serializer._serializeElement(el);
|
||||||
return serializer.html;
|
return serializer.html;
|
||||||
}
|
}
|
||||||
nodeName(node):string {
|
nodeName(node): string { return node.tagName; }
|
||||||
return node.tagName;
|
nodeValue(node): string { return node.nodeValue; }
|
||||||
}
|
type(node: any): string { throw _notImplemented('type'); }
|
||||||
nodeValue(node):string {
|
content(node) { return node.childNodes[0]; }
|
||||||
return node.nodeValue;
|
firstChild(el) { return el.firstChild; }
|
||||||
}
|
nextSibling(el) { return el.nextSibling; }
|
||||||
type(node:string) {
|
parentElement(el) { return el.parent; }
|
||||||
throw _notImplemented('type');
|
childNodes(el) { return el.childNodes; }
|
||||||
}
|
childNodesAsList(el): List<any> {
|
||||||
content(node) {
|
|
||||||
return node.childNodes[0];
|
|
||||||
}
|
|
||||||
firstChild(el) {
|
|
||||||
return el.firstChild;
|
|
||||||
}
|
|
||||||
nextSibling(el) {
|
|
||||||
return el.nextSibling;
|
|
||||||
}
|
|
||||||
parentElement(el) {
|
|
||||||
return el.parent;
|
|
||||||
}
|
|
||||||
childNodes(el) {
|
|
||||||
return el.childNodes;
|
|
||||||
}
|
|
||||||
childNodesAsList(el):List {
|
|
||||||
var childNodes = el.childNodes;
|
var childNodes = el.childNodes;
|
||||||
var res = ListWrapper.createFixedSize(childNodes.length);
|
var res = ListWrapper.createFixedSize(childNodes.length);
|
||||||
for (var i = 0; i < childNodes.length; i++) {
|
for (var i = 0; i < childNodes.length; i++) {
|
||||||
|
@ -216,9 +186,7 @@ export class Parse5DomAdapter extends DomAdapter {
|
||||||
treeAdapter.insertBefore(el.parent, node, el);
|
treeAdapter.insertBefore(el.parent, node, el);
|
||||||
}
|
}
|
||||||
insertAllBefore(el, nodes) {
|
insertAllBefore(el, nodes) {
|
||||||
ListWrapper.forEach(nodes, (n) => {
|
ListWrapper.forEach(nodes, (n) => { this.insertBefore(el, n); });
|
||||||
this.insertBefore(el, n);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
insertAfter(el, node) {
|
insertAfter(el, node) {
|
||||||
if (el.nextSibling) {
|
if (el.nextSibling) {
|
||||||
|
@ -247,7 +215,7 @@ export class Parse5DomAdapter extends DomAdapter {
|
||||||
return textContent;
|
return textContent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setText(el, value:string) {
|
setText(el, value: string) {
|
||||||
if (this.isTextNode(el)) {
|
if (this.isTextNode(el)) {
|
||||||
el.data = value;
|
el.data = value;
|
||||||
} else {
|
} else {
|
||||||
|
@ -255,18 +223,10 @@ export class Parse5DomAdapter extends DomAdapter {
|
||||||
treeAdapter.insertText(el, value);
|
treeAdapter.insertText(el, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
getValue(el) {
|
getValue(el) { return el.value; }
|
||||||
return el.value;
|
setValue(el, value: string) { el.value = value; }
|
||||||
}
|
getChecked(el) { return el.checked; }
|
||||||
setValue(el, value:string) {
|
setChecked(el, value: boolean) { el.checked = value; }
|
||||||
el.value = value;
|
|
||||||
}
|
|
||||||
getChecked(el) {
|
|
||||||
return el.checked;
|
|
||||||
}
|
|
||||||
setChecked(el, value:boolean) {
|
|
||||||
el.checked = value;
|
|
||||||
}
|
|
||||||
createTemplate(html) {
|
createTemplate(html) {
|
||||||
var template = treeAdapter.createElement("template", 'http://www.w3.org/1999/xhtml', []);
|
var template = treeAdapter.createElement("template", 'http://www.w3.org/1999/xhtml', []);
|
||||||
var content = parser.parseFragment(html);
|
var content = parser.parseFragment(html);
|
||||||
|
@ -276,13 +236,12 @@ export class Parse5DomAdapter extends DomAdapter {
|
||||||
createElement(tagName) {
|
createElement(tagName) {
|
||||||
return treeAdapter.createElement(tagName, 'http://www.w3.org/1999/xhtml', []);
|
return treeAdapter.createElement(tagName, 'http://www.w3.org/1999/xhtml', []);
|
||||||
}
|
}
|
||||||
createTextNode(text: string) {
|
createTextNode(text: string) { throw _notImplemented('createTextNode'); }
|
||||||
throw _notImplemented('createTextNode');
|
createScriptTag(attrName: string, attrValue: string) {
|
||||||
|
return treeAdapter.createElement("script", 'http://www.w3.org/1999/xhtml',
|
||||||
|
[{name: attrName, value: attrValue}]);
|
||||||
}
|
}
|
||||||
createScriptTag(attrName:string, attrValue:string) {
|
createStyleElement(css: string) {
|
||||||
return treeAdapter.createElement("script", 'http://www.w3.org/1999/xhtml', [{name: attrName, value: attrValue}]);
|
|
||||||
}
|
|
||||||
createStyleElement(css:string) {
|
|
||||||
var style = this.createElement('style');
|
var style = this.createElement('style');
|
||||||
this.setText(style, css);
|
this.setText(style, css);
|
||||||
return style;
|
return style;
|
||||||
|
@ -292,15 +251,9 @@ export class Parse5DomAdapter extends DomAdapter {
|
||||||
el.shadowRoot.parent = el;
|
el.shadowRoot.parent = el;
|
||||||
return el.shadowRoot;
|
return el.shadowRoot;
|
||||||
}
|
}
|
||||||
getShadowRoot(el) {
|
getShadowRoot(el) { return el.shadowRoot; }
|
||||||
return el.shadowRoot;
|
getHost(el) { return el.host; }
|
||||||
}
|
getDistributedNodes(el: any): List<any> { throw _notImplemented('getDistributedNodes'); }
|
||||||
getHost(el) {
|
|
||||||
return el.host;
|
|
||||||
}
|
|
||||||
getDistributedNodes(el) {
|
|
||||||
throw _notImplemented('getDistributedNodes');
|
|
||||||
}
|
|
||||||
clone(node) {
|
clone(node) {
|
||||||
// e.g. document fragment
|
// e.g. document fragment
|
||||||
if (node.type === 'root') {
|
if (node.type === 'root') {
|
||||||
|
@ -315,16 +268,14 @@ export class Parse5DomAdapter extends DomAdapter {
|
||||||
return newParser.parseFragment(serialized).childNodes[0];
|
return newParser.parseFragment(serialized).childNodes[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hasProperty(element, name:string) {
|
hasProperty(element, name: string) { return _HTMLElementPropertyList.indexOf(name) > -1; }
|
||||||
return _HTMLElementPropertyList.indexOf(name) > -1;
|
getElementsByClassName(element, name: string) {
|
||||||
}
|
|
||||||
getElementsByClassName(element, name:string) {
|
|
||||||
return this.querySelectorAll(element, "." + name);
|
return this.querySelectorAll(element, "." + name);
|
||||||
}
|
}
|
||||||
getElementsByTagName(element, name:string) {
|
getElementsByTagName(element: any, name: string): List<any> {
|
||||||
throw _notImplemented('getElementsByTagName');
|
throw _notImplemented('getElementsByTagName');
|
||||||
}
|
}
|
||||||
classList(element):List {
|
classList(element): List<string> {
|
||||||
var classAttrValue = null;
|
var classAttrValue = null;
|
||||||
var attributes = element.attribs;
|
var attributes = element.attribs;
|
||||||
if (attributes && attributes.hasOwnProperty("class")) {
|
if (attributes && attributes.hasOwnProperty("class")) {
|
||||||
|
@ -332,7 +283,7 @@ export class Parse5DomAdapter extends DomAdapter {
|
||||||
}
|
}
|
||||||
return classAttrValue ? classAttrValue.trim().split(/\s+/g) : [];
|
return classAttrValue ? classAttrValue.trim().split(/\s+/g) : [];
|
||||||
}
|
}
|
||||||
addClass(element, classname:string) {
|
addClass(element, classname: string) {
|
||||||
var classList = this.classList(element);
|
var classList = this.classList(element);
|
||||||
var index = classList.indexOf(classname);
|
var index = classList.indexOf(classname);
|
||||||
if (index == -1) {
|
if (index == -1) {
|
||||||
|
@ -340,7 +291,7 @@ export class Parse5DomAdapter extends DomAdapter {
|
||||||
element.attribs["class"] = element.className = ListWrapper.join(classList, " ");
|
element.attribs["class"] = element.className = ListWrapper.join(classList, " ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
removeClass(element, classname:string) {
|
removeClass(element, classname: string) {
|
||||||
var classList = this.classList(element);
|
var classList = this.classList(element);
|
||||||
var index = classList.indexOf(classname);
|
var index = classList.indexOf(classname);
|
||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
|
@ -348,7 +299,7 @@ export class Parse5DomAdapter extends DomAdapter {
|
||||||
element.attribs["class"] = element.className = ListWrapper.join(classList, " ");
|
element.attribs["class"] = element.className = ListWrapper.join(classList, " ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hasClass(element, classname:string) {
|
hasClass(element, classname: string) {
|
||||||
return ListWrapper.contains(this.classList(element), classname);
|
return ListWrapper.contains(this.classList(element), classname);
|
||||||
}
|
}
|
||||||
_readStyleAttribute(element) {
|
_readStyleAttribute(element) {
|
||||||
|
@ -376,21 +327,17 @@ export class Parse5DomAdapter extends DomAdapter {
|
||||||
}
|
}
|
||||||
element.attribs["style"] = styleAttrValue;
|
element.attribs["style"] = styleAttrValue;
|
||||||
}
|
}
|
||||||
setStyle(element, stylename:string, stylevalue:string) {
|
setStyle(element, stylename: string, stylevalue: string) {
|
||||||
var styleMap = this._readStyleAttribute(element);
|
var styleMap = this._readStyleAttribute(element);
|
||||||
styleMap[stylename] = stylevalue;
|
styleMap[stylename] = stylevalue;
|
||||||
this._writeStyleAttribute(element, styleMap);
|
this._writeStyleAttribute(element, styleMap);
|
||||||
}
|
}
|
||||||
removeStyle(element, stylename:string) {
|
removeStyle(element, stylename: string) { this.setStyle(element, stylename, null); }
|
||||||
this.setStyle(element, stylename, null);
|
getStyle(element, stylename: string) {
|
||||||
}
|
|
||||||
getStyle(element, stylename:string) {
|
|
||||||
var styleMap = this._readStyleAttribute(element);
|
var styleMap = this._readStyleAttribute(element);
|
||||||
return styleMap.hasOwnProperty(stylename) ? styleMap[stylename] : "";
|
return styleMap.hasOwnProperty(stylename) ? styleMap[stylename] : "";
|
||||||
}
|
}
|
||||||
tagName(element):string {
|
tagName(element): string { return element.tagName == "style" ? "STYLE" : element.tagName; }
|
||||||
return element.tagName == "style" ? "STYLE" : element.tagName;
|
|
||||||
}
|
|
||||||
attributeMap(element) {
|
attributeMap(element) {
|
||||||
var res = MapWrapper.create();
|
var res = MapWrapper.create();
|
||||||
var elAttrs = treeAdapter.getAttrList(element);
|
var elAttrs = treeAdapter.getAttrList(element);
|
||||||
|
@ -400,25 +347,25 @@ export class Parse5DomAdapter extends DomAdapter {
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
hasAttribute(element, attribute:string) {
|
hasAttribute(element, attribute: string) {
|
||||||
return element.attribs && element.attribs.hasOwnProperty(attribute);
|
return element.attribs && element.attribs.hasOwnProperty(attribute);
|
||||||
}
|
}
|
||||||
getAttribute(element, attribute:string) {
|
getAttribute(element, attribute: string) {
|
||||||
return element.attribs && element.attribs.hasOwnProperty(attribute)? element.attribs[attribute]: null;
|
return element.attribs && element.attribs.hasOwnProperty(attribute) ?
|
||||||
|
element.attribs[attribute] :
|
||||||
|
null;
|
||||||
}
|
}
|
||||||
setAttribute(element, attribute:string, value:string) {
|
setAttribute(element, attribute: string, value: string) {
|
||||||
if (attribute) {
|
if (attribute) {
|
||||||
element.attribs[attribute] = value;
|
element.attribs[attribute] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
removeAttribute(element, attribute:string) {
|
removeAttribute(element, attribute: string) {
|
||||||
if (attribute) {
|
if (attribute) {
|
||||||
delete element.attribs[attribute];
|
StringMapWrapper.delete(element.attribs, attribute);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
templateAwareRoot(el) {
|
templateAwareRoot(el) { return this.isTemplateElement(el) ? this.content(el) : el; }
|
||||||
return this.isTemplateElement(el) ? this.content(el) : el;
|
|
||||||
}
|
|
||||||
createHtmlDocument() {
|
createHtmlDocument() {
|
||||||
var newDoc = treeAdapter.createDocument();
|
var newDoc = treeAdapter.createDocument();
|
||||||
newDoc.title = "fake title";
|
newDoc.title = "fake title";
|
||||||
|
@ -437,88 +384,75 @@ export class Parse5DomAdapter extends DomAdapter {
|
||||||
}
|
}
|
||||||
return defDoc;
|
return defDoc;
|
||||||
}
|
}
|
||||||
getBoundingClientRect(el) {
|
getBoundingClientRect(el) { return {left: 0, top: 0, width: 0, height: 0}; }
|
||||||
return {left: 0, top: 0, width: 0, height: 0};
|
getTitle() { return this.defaultDoc().title || ""; }
|
||||||
}
|
setTitle(newTitle: string) { this.defaultDoc().title = newTitle; }
|
||||||
getTitle() {
|
isTemplateElement(el: any): boolean {
|
||||||
return this.defaultDoc().title || "";
|
|
||||||
}
|
|
||||||
setTitle(newTitle:string) {
|
|
||||||
this.defaultDoc().title = newTitle;
|
|
||||||
}
|
|
||||||
isTemplateElement(el:any):boolean {
|
|
||||||
return this.isElementNode(el) && this.tagName(el) === "template";
|
return this.isElementNode(el) && this.tagName(el) === "template";
|
||||||
}
|
}
|
||||||
isTextNode(node):boolean {
|
isTextNode(node): boolean { return treeAdapter.isTextNode(node); }
|
||||||
return treeAdapter.isTextNode(node);
|
isCommentNode(node): boolean { return treeAdapter.isCommentNode(node); }
|
||||||
}
|
isElementNode(node): boolean { return node ? treeAdapter.isElementNode(node) : false; }
|
||||||
isCommentNode(node):boolean {
|
hasShadowRoot(node): boolean { return isPresent(node.shadowRoot); }
|
||||||
return treeAdapter.isCommentNode(node);
|
isShadowRoot(node): boolean { return this.getShadowRoot(node) == node; }
|
||||||
}
|
importIntoDoc(node) { return this.clone(node); }
|
||||||
isElementNode(node):boolean {
|
|
||||||
return node ? treeAdapter.isElementNode(node) : false;
|
|
||||||
}
|
|
||||||
hasShadowRoot(node):boolean {
|
|
||||||
return isPresent(node.shadowRoot);
|
|
||||||
}
|
|
||||||
isShadowRoot(node): boolean {
|
|
||||||
return this.getShadowRoot(node) == node;
|
|
||||||
}
|
|
||||||
importIntoDoc(node) {
|
|
||||||
return this.clone(node);
|
|
||||||
}
|
|
||||||
isPageRule(rule): boolean {
|
isPageRule(rule): boolean {
|
||||||
return rule.type === 6; //CSSRule.PAGE_RULE
|
return rule.type === 6; // CSSRule.PAGE_RULE
|
||||||
}
|
}
|
||||||
isStyleRule(rule): boolean {
|
isStyleRule(rule): boolean {
|
||||||
return rule.type === 1; //CSSRule.MEDIA_RULE
|
return rule.type === 1; // CSSRule.MEDIA_RULE
|
||||||
}
|
}
|
||||||
isMediaRule(rule): boolean {
|
isMediaRule(rule): boolean {
|
||||||
return rule.type === 4; //CSSRule.MEDIA_RULE
|
return rule.type === 4; // CSSRule.MEDIA_RULE
|
||||||
}
|
}
|
||||||
isKeyframesRule(rule): boolean {
|
isKeyframesRule(rule): boolean {
|
||||||
return rule.type === 7; //CSSRule.KEYFRAMES_RULE
|
return rule.type === 7; // CSSRule.KEYFRAMES_RULE
|
||||||
}
|
}
|
||||||
getHref(el): string {
|
getHref(el): string { return el.href; }
|
||||||
return el.href;
|
resolveAndSetHref(el, baseUrl: string, href: string) {
|
||||||
}
|
|
||||||
resolveAndSetHref(el, baseUrl:string, href:string) {
|
|
||||||
if (href == null) {
|
if (href == null) {
|
||||||
el.href = baseUrl;
|
el.href = baseUrl;
|
||||||
} else {
|
} else {
|
||||||
el.href = url.resolve(baseUrl, href);
|
el.href = url.resolve(baseUrl, href);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_buildRules(parsedRules, css) {
|
_buildRules(parsedRules, css?) {
|
||||||
var rules = ListWrapper.create();
|
var rules = ListWrapper.create();
|
||||||
for (var i = 0; i < parsedRules.length; i++) {
|
for (var i = 0; i < parsedRules.length; i++) {
|
||||||
var parsedRule = parsedRules[i];
|
var parsedRule = parsedRules[i];
|
||||||
var rule = {cssText: css};
|
var rule: StringMap<string, any> = StringMapWrapper.create();
|
||||||
rule.style = {content: "", cssText: ""};
|
StringMapWrapper.set(rule, "cssText", css);
|
||||||
|
StringMapWrapper.set(rule, "style", {content: "", cssText: ""});
|
||||||
if (parsedRule.type == "rule") {
|
if (parsedRule.type == "rule") {
|
||||||
rule.type = 1;
|
StringMapWrapper.set(rule, "type", 1);
|
||||||
rule.selectorText = parsedRule.selectors.join(", ").replace(/\s{2,}/g, " ").replace(/\s*~\s*/g, " ~ ")
|
StringMapWrapper.set(rule, "selectorText", parsedRule.selectors.join(", ")
|
||||||
.replace(/\s*\+\s*/g, " + ").replace(/\s*>\s*/g, " > ").replace(/\[(\w+)=(\w+)\]/g, '[$1="$2"]');
|
.replace(/\s{2,}/g, " ")
|
||||||
|
.replace(/\s*~\s*/g, " ~ ")
|
||||||
|
.replace(/\s*\+\s*/g, " + ")
|
||||||
|
.replace(/\s*>\s*/g, " > ")
|
||||||
|
.replace(/\[(\w+)=(\w+)\]/g, '[$1="$2"]'));
|
||||||
if (isBlank(parsedRule.declarations)) {
|
if (isBlank(parsedRule.declarations)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (var j = 0; j < parsedRule.declarations.length; j++) {
|
for (var j = 0; j < parsedRule.declarations.length; j++) {
|
||||||
var declaration = parsedRule.declarations[j];
|
var declaration = parsedRule.declarations[j];
|
||||||
rule.style[declaration.property] = declaration.value;
|
StringMapWrapper.set(StringMapWrapper.get(rule, "style"), declaration.property,
|
||||||
rule.style.cssText += declaration.property + ": " + declaration.value + ";";
|
declaration.value);
|
||||||
|
StringMapWrapper.get(rule, "style").cssText +=
|
||||||
|
declaration.property + ": " + declaration.value + ";";
|
||||||
}
|
}
|
||||||
} else if (parsedRule.type == "media") {
|
} else if (parsedRule.type == "media") {
|
||||||
rule.type = 4;
|
StringMapWrapper.set(rule, "type", 4);
|
||||||
rule.media = {mediaText: parsedRule.media};
|
StringMapWrapper.set(rule, "media", {mediaText: parsedRule.media});
|
||||||
if (parsedRule.rules) {
|
if (parsedRule.rules) {
|
||||||
rule.cssRules = this._buildRules(parsedRule.rules);
|
StringMapWrapper.set(rule, "cssRules", this._buildRules(parsedRule.rules));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ListWrapper.push(rules, rule);
|
ListWrapper.push(rules, rule);
|
||||||
}
|
}
|
||||||
return rules;
|
return rules;
|
||||||
}
|
}
|
||||||
cssToRules(css:string): List {
|
cssToRules(css: string): List<any> {
|
||||||
css = css.replace(/url\(\'(.+)\'\)/g, 'url($1)');
|
css = css.replace(/url\(\'(.+)\'\)/g, 'url($1)');
|
||||||
var rules = ListWrapper.create();
|
var rules = ListWrapper.create();
|
||||||
var parsedCSS = cssParse(css, {silent: true});
|
var parsedCSS = cssParse(css, {silent: true});
|
||||||
|
@ -527,13 +461,9 @@ export class Parse5DomAdapter extends DomAdapter {
|
||||||
}
|
}
|
||||||
return rules;
|
return rules;
|
||||||
}
|
}
|
||||||
supportsDOMEvents(): boolean {
|
supportsDOMEvents(): boolean { return false; }
|
||||||
return false;
|
supportsNativeShadowDOM(): boolean { return false; }
|
||||||
}
|
getGlobalEventTarget(target: string) {
|
||||||
supportsNativeShadowDOM(): boolean {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
getGlobalEventTarget(target:string) {
|
|
||||||
if (target == "window") {
|
if (target == "window") {
|
||||||
return this.defaultDoc()._window;
|
return this.defaultDoc()._window;
|
||||||
} else if (target == "document") {
|
} else if (target == "document") {
|
||||||
|
@ -542,47 +472,197 @@ export class Parse5DomAdapter extends DomAdapter {
|
||||||
return this.defaultDoc().body;
|
return this.defaultDoc().body;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
getHistory() {
|
getHistory() { throw 'not implemented'; }
|
||||||
throw 'not implemented';
|
getLocation() { throw 'not implemented'; }
|
||||||
}
|
getUserAgent() { return "Fake user agent"; }
|
||||||
getLocation() {
|
getData(el, name: string): string { return this.getAttribute(el, 'data-' + name); }
|
||||||
throw 'not implemented';
|
setData(el, name: string, value: string) { this.setAttribute(el, 'data-' + name, value); }
|
||||||
}
|
|
||||||
getUserAgent() {
|
|
||||||
return "Fake user agent";
|
|
||||||
}
|
|
||||||
getData(el, name:string):string {
|
|
||||||
return this.getAttribute(el, 'data-'+name);
|
|
||||||
}
|
|
||||||
setData(el, name:string, value:string) {
|
|
||||||
this.setAttribute(el, 'data-'+name, value);
|
|
||||||
}
|
|
||||||
// TODO(tbosch): move this into a separate environment class once we have it
|
// TODO(tbosch): move this into a separate environment class once we have it
|
||||||
setGlobalVar(name: string, value: any) {
|
setGlobalVar(name: string, value: any) { global[name] = value; }
|
||||||
global[name] = value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: build a proper list, this one is all the keys of a HTMLInputElement
|
// TODO: build a proper list, this one is all the keys of a HTMLInputElement
|
||||||
var _HTMLElementPropertyList = ["webkitEntries","incremental","webkitdirectory","selectionDirection","selectionEnd",
|
var _HTMLElementPropertyList = [
|
||||||
"selectionStart","labels","validationMessage","validity","willValidate","width","valueAsNumber","valueAsDate",
|
"webkitEntries",
|
||||||
"value","useMap","defaultValue","type","step","src","size","required","readOnly","placeholder","pattern","name",
|
"incremental",
|
||||||
"multiple","min","minLength","maxLength","max","list","indeterminate","height","formTarget","formNoValidate",
|
"webkitdirectory",
|
||||||
"formMethod","formEnctype","formAction","files","form","disabled","dirName","checked","defaultChecked","autofocus",
|
"selectionDirection",
|
||||||
"autocomplete","alt","align","accept","onautocompleteerror","onautocomplete","onwaiting","onvolumechange",
|
"selectionEnd",
|
||||||
"ontoggle","ontimeupdate","onsuspend","onsubmit","onstalled","onshow","onselect","onseeking","onseeked","onscroll",
|
"selectionStart",
|
||||||
"onresize","onreset","onratechange","onprogress","onplaying","onplay","onpause","onmousewheel","onmouseup",
|
"labels",
|
||||||
"onmouseover","onmouseout","onmousemove","onmouseleave","onmouseenter","onmousedown","onloadstart",
|
"validationMessage",
|
||||||
"onloadedmetadata","onloadeddata","onload","onkeyup","onkeypress","onkeydown","oninvalid","oninput","onfocus",
|
"validity",
|
||||||
"onerror","onended","onemptied","ondurationchange","ondrop","ondragstart","ondragover","ondragleave","ondragenter",
|
"willValidate",
|
||||||
"ondragend","ondrag","ondblclick","oncuechange","oncontextmenu","onclose","onclick","onchange","oncanplaythrough",
|
"width",
|
||||||
"oncanplay","oncancel","onblur","onabort","spellcheck","isContentEditable","contentEditable","outerText",
|
"valueAsNumber",
|
||||||
"innerText","accessKey","hidden","webkitdropzone","draggable","tabIndex","dir","translate","lang","title",
|
"valueAsDate",
|
||||||
"childElementCount","lastElementChild","firstElementChild","children","onwebkitfullscreenerror",
|
"value",
|
||||||
"onwebkitfullscreenchange","nextElementSibling","previousElementSibling","onwheel","onselectstart",
|
"useMap",
|
||||||
"onsearch","onpaste","oncut","oncopy","onbeforepaste","onbeforecut","onbeforecopy","shadowRoot","dataset",
|
"defaultValue",
|
||||||
"classList","className","outerHTML","innerHTML","scrollHeight","scrollWidth","scrollTop","scrollLeft",
|
"type",
|
||||||
"clientHeight","clientWidth","clientTop","clientLeft","offsetParent","offsetHeight","offsetWidth","offsetTop",
|
"step",
|
||||||
"offsetLeft","localName","prefix","namespaceURI","id","style","attributes","tagName","parentElement","textContent",
|
"src",
|
||||||
"baseURI","ownerDocument","nextSibling","previousSibling","lastChild","firstChild","childNodes","parentNode",
|
"size",
|
||||||
"nodeType","nodeValue","nodeName","closure_lm_714617","__jsaction"];
|
"required",
|
||||||
|
"readOnly",
|
||||||
|
"placeholder",
|
||||||
|
"pattern",
|
||||||
|
"name",
|
||||||
|
"multiple",
|
||||||
|
"min",
|
||||||
|
"minLength",
|
||||||
|
"maxLength",
|
||||||
|
"max",
|
||||||
|
"list",
|
||||||
|
"indeterminate",
|
||||||
|
"height",
|
||||||
|
"formTarget",
|
||||||
|
"formNoValidate",
|
||||||
|
"formMethod",
|
||||||
|
"formEnctype",
|
||||||
|
"formAction",
|
||||||
|
"files",
|
||||||
|
"form",
|
||||||
|
"disabled",
|
||||||
|
"dirName",
|
||||||
|
"checked",
|
||||||
|
"defaultChecked",
|
||||||
|
"autofocus",
|
||||||
|
"autocomplete",
|
||||||
|
"alt",
|
||||||
|
"align",
|
||||||
|
"accept",
|
||||||
|
"onautocompleteerror",
|
||||||
|
"onautocomplete",
|
||||||
|
"onwaiting",
|
||||||
|
"onvolumechange",
|
||||||
|
"ontoggle",
|
||||||
|
"ontimeupdate",
|
||||||
|
"onsuspend",
|
||||||
|
"onsubmit",
|
||||||
|
"onstalled",
|
||||||
|
"onshow",
|
||||||
|
"onselect",
|
||||||
|
"onseeking",
|
||||||
|
"onseeked",
|
||||||
|
"onscroll",
|
||||||
|
"onresize",
|
||||||
|
"onreset",
|
||||||
|
"onratechange",
|
||||||
|
"onprogress",
|
||||||
|
"onplaying",
|
||||||
|
"onplay",
|
||||||
|
"onpause",
|
||||||
|
"onmousewheel",
|
||||||
|
"onmouseup",
|
||||||
|
"onmouseover",
|
||||||
|
"onmouseout",
|
||||||
|
"onmousemove",
|
||||||
|
"onmouseleave",
|
||||||
|
"onmouseenter",
|
||||||
|
"onmousedown",
|
||||||
|
"onloadstart",
|
||||||
|
"onloadedmetadata",
|
||||||
|
"onloadeddata",
|
||||||
|
"onload",
|
||||||
|
"onkeyup",
|
||||||
|
"onkeypress",
|
||||||
|
"onkeydown",
|
||||||
|
"oninvalid",
|
||||||
|
"oninput",
|
||||||
|
"onfocus",
|
||||||
|
"onerror",
|
||||||
|
"onended",
|
||||||
|
"onemptied",
|
||||||
|
"ondurationchange",
|
||||||
|
"ondrop",
|
||||||
|
"ondragstart",
|
||||||
|
"ondragover",
|
||||||
|
"ondragleave",
|
||||||
|
"ondragenter",
|
||||||
|
"ondragend",
|
||||||
|
"ondrag",
|
||||||
|
"ondblclick",
|
||||||
|
"oncuechange",
|
||||||
|
"oncontextmenu",
|
||||||
|
"onclose",
|
||||||
|
"onclick",
|
||||||
|
"onchange",
|
||||||
|
"oncanplaythrough",
|
||||||
|
"oncanplay",
|
||||||
|
"oncancel",
|
||||||
|
"onblur",
|
||||||
|
"onabort",
|
||||||
|
"spellcheck",
|
||||||
|
"isContentEditable",
|
||||||
|
"contentEditable",
|
||||||
|
"outerText",
|
||||||
|
"innerText",
|
||||||
|
"accessKey",
|
||||||
|
"hidden",
|
||||||
|
"webkitdropzone",
|
||||||
|
"draggable",
|
||||||
|
"tabIndex",
|
||||||
|
"dir",
|
||||||
|
"translate",
|
||||||
|
"lang",
|
||||||
|
"title",
|
||||||
|
"childElementCount",
|
||||||
|
"lastElementChild",
|
||||||
|
"firstElementChild",
|
||||||
|
"children",
|
||||||
|
"onwebkitfullscreenerror",
|
||||||
|
"onwebkitfullscreenchange",
|
||||||
|
"nextElementSibling",
|
||||||
|
"previousElementSibling",
|
||||||
|
"onwheel",
|
||||||
|
"onselectstart",
|
||||||
|
"onsearch",
|
||||||
|
"onpaste",
|
||||||
|
"oncut",
|
||||||
|
"oncopy",
|
||||||
|
"onbeforepaste",
|
||||||
|
"onbeforecut",
|
||||||
|
"onbeforecopy",
|
||||||
|
"shadowRoot",
|
||||||
|
"dataset",
|
||||||
|
"classList",
|
||||||
|
"className",
|
||||||
|
"outerHTML",
|
||||||
|
"innerHTML",
|
||||||
|
"scrollHeight",
|
||||||
|
"scrollWidth",
|
||||||
|
"scrollTop",
|
||||||
|
"scrollLeft",
|
||||||
|
"clientHeight",
|
||||||
|
"clientWidth",
|
||||||
|
"clientTop",
|
||||||
|
"clientLeft",
|
||||||
|
"offsetParent",
|
||||||
|
"offsetHeight",
|
||||||
|
"offsetWidth",
|
||||||
|
"offsetTop",
|
||||||
|
"offsetLeft",
|
||||||
|
"localName",
|
||||||
|
"prefix",
|
||||||
|
"namespaceURI",
|
||||||
|
"id",
|
||||||
|
"style",
|
||||||
|
"attributes",
|
||||||
|
"tagName",
|
||||||
|
"parentElement",
|
||||||
|
"textContent",
|
||||||
|
"baseURI",
|
||||||
|
"ownerDocument",
|
||||||
|
"nextSibling",
|
||||||
|
"previousSibling",
|
||||||
|
"lastChild",
|
||||||
|
"firstChild",
|
||||||
|
"childNodes",
|
||||||
|
"parentNode",
|
||||||
|
"nodeType",
|
||||||
|
"nodeValue",
|
||||||
|
"nodeName",
|
||||||
|
"closure_lm_714617",
|
||||||
|
"__jsaction"
|
||||||
|
];
|
|
@ -160,7 +160,7 @@ export class SelectorMatcher {
|
||||||
this._listContexts = ListWrapper.create();
|
this._listContexts = ListWrapper.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
addSelectables(cssSelectors: List<CssSelector>, callbackCtxt: any) {
|
addSelectables(cssSelectors: List<CssSelector>, callbackCtxt?: any) {
|
||||||
var listContext = null;
|
var listContext = null;
|
||||||
if (cssSelectors.length > 1) {
|
if (cssSelectors.length > 1) {
|
||||||
listContext = new SelectorListContext(cssSelectors);
|
listContext = new SelectorListContext(cssSelectors);
|
||||||
|
|
Loading…
Reference in New Issue