feat(components): initial implementation of emulated content tag

This commit is contained in:
vsavkin
2015-01-02 14:23:59 -08:00
parent 0f8f4801bd
commit fbcc59dc67
20 changed files with 798 additions and 57 deletions

View File

@ -96,8 +96,14 @@ class ListWrapper {
static bool isList(l) => l is List;
static void insert(List l, int index, value) { l.insert(index, value); }
static void removeAt(List l, int index) { l.removeAt(index); }
static void removeAll(List list, List items) {
for (var i = 0; i < items.length; ++i) {
list.remove(items[i]);
}
}
static void clear(List l) { l.clear(); }
static String join(List l, String s) => l.join(s);
static bool isEmpty(list) => list.isEmpty;
}
bool isListLikeIterable(obj) => obj is Iterable;

View File

@ -143,12 +143,21 @@ export class ListWrapper {
list.splice(index, 1);
return res;
}
static removeAll(list, items) {
for (var i = 0; i < items.length; ++i) {
var index = list.indexOf(items[i]);
list.splice(index, 1);
}
}
static clear(list) {
list.splice(0, list.length);
}
static join(list, s) {
return list.join(s);
}
static isEmpty(list) {
return list.length == 0;
}
}
export function isListLikeIterable(obj):boolean {

View File

@ -47,6 +47,9 @@ class DOM {
static List<Node> childNodes(el) {
return el.childNodes;
}
static childNodesAsList(el) {
return childNodes(el).toList();
}
static clearNodes(el) {
el.nodes = [];
}
@ -56,6 +59,12 @@ class DOM {
static removeChild(el, node) {
node.remove();
}
static insertBefore(el, node) {
el.parentNode.insertBefore(node, el);
}
static insertAllBefore(el, nodes) {
el.parentNode.insertAllBefore(nodes, el);
}
static insertAfter(el, node) {
el.parentNode.insertBefore(node, el.nextNode);
}
@ -74,6 +83,12 @@ class DOM {
if (doc == null) doc = document;
return doc.createElement(tagName);
}
static createScriptTag(String attrName, String attrValue, [doc=null]) {
if (doc == null) doc = document;
var el = doc.createElement("SCRIPT");
el.setAttribute(attrName, attrValue);
return el;
}
static clone(Node node) {
return node.clone(true);
}
@ -95,9 +110,15 @@ class DOM {
static hasClass(Element element, classname) {
return element.classes.contains(classname);
}
static String tagName(Element element) {
return element.tagName;
}
static attributeMap(Element element) {
return element.attributes;
}
static getAttribute(Element element, String attribute) {
return element.getAttribute(attribute);
}
static Node templateAwareRoot(Element el) {
return el is TemplateElement ? el.content : el;
}
@ -107,4 +128,7 @@ class DOM {
static HtmlDocument defaultDoc() {
return document;
}
static bool elementMatches(n, String selector) {
return n is Element && n.matches(selector);
}
}

View File

@ -7,7 +7,7 @@ export var TemplateElement = window.HTMLTemplateElement;
export var document = window.document;
export var location = window.location;
import {List, MapWrapper} from 'facade/collection';
import {List, MapWrapper, ListWrapper} from 'facade/collection';
export class DOM {
static query(selector) {
@ -40,6 +40,14 @@ export class DOM {
static childNodes(el):NodeList {
return el.childNodes;
}
static childNodesAsList(el):List {
var childNodes = el.childNodes;
var res = ListWrapper.createFixedSize(childNodes.length);
for (var i=0; i<childNodes.length; i++) {
res[i] = childNodes[i];
}
return res;
}
static clearNodes(el) {
el.innerHTML = "";
}
@ -49,6 +57,14 @@ export class DOM {
static removeChild(el, node) {
el.removeChild(node);
}
static insertBefore(el, node) {
el.parentNode.insertBefore(node, el);
}
static insertAllBefore(el, nodes) {
ListWrapper.forEach(nodes, (n) => {
el.parentNode.insertBefore(n, el);
});
}
static insertAfter(el, node) {
el.parentNode.insertBefore(node, el.nextSibling);
}
@ -69,6 +85,11 @@ export class DOM {
static createElement(tagName, doc=document) {
return doc.createElement(tagName);
}
static createScriptTag(attrName:string, attrValue:string, doc=document) {
var el = doc.createElement("SCRIPT");
el.setAttribute(attrName, attrValue);
return el;
}
static clone(node:Node) {
return node.cloneNode(true);
}
@ -90,6 +111,9 @@ export class DOM {
static hasClass(element:Element, classname:string) {
return element.classList.contains(classname);
}
static tagName(element:Element):string {
return element.tagName;
}
static attributeMap(element:Element) {
var res = MapWrapper.create();
var elAttrs = element.attributes;
@ -99,6 +123,9 @@ export class DOM {
}
return res;
}
static getAttribute(element:Element, attribute:string) {
return element.getAttribute(attribute);
}
static templateAwareRoot(el:Element):Node {
return el instanceof TemplateElement ? el.content : el;
}
@ -108,4 +135,7 @@ export class DOM {
static defaultDoc() {
return document;
}
static elementMatches(n, selector:string):boolean {
return n instanceof Element && n.matches(selector);
}
}