2014-09-19 16:38:37 -07:00
|
|
|
library angular.core.facade.dom;
|
2014-09-18 14:56:38 -07:00
|
|
|
|
|
|
|
|
import 'dart:html';
|
2014-10-10 20:44:55 -07:00
|
|
|
import 'dart:js' show JsObject;
|
2014-09-18 14:56:38 -07:00
|
|
|
|
2014-11-17 11:01:21 -08:00
|
|
|
export 'dart:html' show DocumentFragment, Node, Element, TemplateElement, Text, document, location;
|
2014-09-19 16:38:37 -07:00
|
|
|
|
2014-11-11 17:33:47 -08:00
|
|
|
// TODO(tbosch): Is there a builtin one? Why is Dart
|
|
|
|
|
// removing unknown elements by default?
|
|
|
|
|
class IdentitySanitizer implements NodeTreeSanitizer {
|
|
|
|
|
void sanitizeTree(Node node) {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final identitySanitizer = new IdentitySanitizer();
|
|
|
|
|
|
2014-09-18 14:56:38 -07:00
|
|
|
class DOM {
|
|
|
|
|
static query(selector) {
|
2014-10-02 12:27:01 -07:00
|
|
|
return document.querySelector(selector);
|
2014-09-18 14:56:38 -07:00
|
|
|
}
|
2014-11-07 14:30:04 -08:00
|
|
|
static Element querySelector(el, String selector) {
|
|
|
|
|
return el.querySelector(selector);
|
|
|
|
|
}
|
2014-10-27 11:47:13 -04:00
|
|
|
static ElementList querySelectorAll(el, String selector) {
|
|
|
|
|
return el.querySelectorAll(selector);
|
|
|
|
|
}
|
2014-09-18 14:56:38 -07:00
|
|
|
static on(element, event, callback) {
|
|
|
|
|
element.addEventListener(event, callback);
|
|
|
|
|
}
|
|
|
|
|
static getInnerHTML(el) {
|
|
|
|
|
return el.innerHtml;
|
|
|
|
|
}
|
2014-11-11 17:33:47 -08:00
|
|
|
static getOuterHTML(el) {
|
|
|
|
|
return el.outerHtml;
|
|
|
|
|
}
|
2014-09-28 13:55:01 -07:00
|
|
|
static setInnerHTML(el, value) {
|
2014-09-18 14:56:38 -07:00
|
|
|
el.innerHtml = value;
|
|
|
|
|
}
|
2014-10-27 11:47:13 -04:00
|
|
|
static Node firstChild(el) {
|
|
|
|
|
return el.firstChild;
|
|
|
|
|
}
|
2014-11-11 17:33:47 -08:00
|
|
|
static Element parentElement(el) {
|
|
|
|
|
return el.parent;
|
|
|
|
|
}
|
2014-10-27 11:47:13 -04:00
|
|
|
static List<Node> childNodes(el) {
|
|
|
|
|
return el.childNodes;
|
|
|
|
|
}
|
2014-11-11 17:33:47 -08:00
|
|
|
static appendChild(el, node) {
|
|
|
|
|
el.append(node);
|
|
|
|
|
}
|
2014-09-26 11:20:08 -07:00
|
|
|
static setText(Text text, String value) {
|
|
|
|
|
text.text = value;
|
|
|
|
|
}
|
2014-09-28 13:55:01 -07:00
|
|
|
static createTemplate(html) {
|
2014-11-11 17:33:47 -08:00
|
|
|
var t = new TemplateElement();
|
|
|
|
|
t.setInnerHtml(html, treeSanitizer:identitySanitizer);
|
2014-09-28 13:55:01 -07:00
|
|
|
return t;
|
|
|
|
|
}
|
2014-11-07 14:30:04 -08:00
|
|
|
static createElement(tagName, [doc=null]) {
|
|
|
|
|
if (doc == null) doc = document;
|
|
|
|
|
return doc.createElement(tagName);
|
|
|
|
|
}
|
2014-09-28 20:02:32 -07:00
|
|
|
static clone(Node node) {
|
|
|
|
|
return node.clone(true);
|
|
|
|
|
}
|
2014-10-10 20:44:55 -07:00
|
|
|
static setProperty(Element element, String name, value) {
|
|
|
|
|
new JsObject.fromBrowserObject(element)[name] = value;
|
|
|
|
|
}
|
2014-11-11 17:33:47 -08:00
|
|
|
static getProperty(Element element, String name) {
|
|
|
|
|
return new JsObject.fromBrowserObject(element)[name];
|
|
|
|
|
}
|
2014-10-10 20:44:55 -07:00
|
|
|
static getElementsByClassName(Element element, String name) {
|
|
|
|
|
return element.getElementsByClassName(name);
|
|
|
|
|
}
|
|
|
|
|
static getElementsByTagName(Element element, String name) {
|
|
|
|
|
return element.querySelectorAll(name);
|
|
|
|
|
}
|
2014-11-11 17:33:47 -08:00
|
|
|
static List classList(Element element) {
|
|
|
|
|
return element.classes.toList();
|
|
|
|
|
}
|
|
|
|
|
static addClass(Element element, classname) {
|
|
|
|
|
element.classes.add(classname);
|
|
|
|
|
}
|
|
|
|
|
static hasClass(Element element, classname) {
|
|
|
|
|
return element.classes.contains(classname);
|
|
|
|
|
}
|
|
|
|
|
static attributeMap(Element element) {
|
|
|
|
|
return element.attributes;
|
|
|
|
|
}
|
2014-11-14 10:37:42 -08:00
|
|
|
static Node templateAwareRoot(Element el) {
|
|
|
|
|
return el is TemplateElement ? el.content : el;
|
|
|
|
|
}
|
2014-11-07 14:30:04 -08:00
|
|
|
static HtmlDocument createHtmlDocument() {
|
|
|
|
|
return document.implementation.createHtmlDocument('fakeTitle');
|
|
|
|
|
}
|
|
|
|
|
static HtmlDocument defaultDoc() {
|
|
|
|
|
return document;
|
|
|
|
|
}
|
2014-09-26 11:20:08 -07:00
|
|
|
}
|