2015-03-09 11:35:46 +01:00
|
|
|
import {List, ListWrapper} from 'angular2/src/facade/collection';
|
2015-03-19 11:35:48 +01:00
|
|
|
import {isPresent, isFunction} from 'angular2/src/facade/lang';
|
2015-03-09 11:35:46 +01:00
|
|
|
import {DomAdapter} from './dom_adapter';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Provides DOM operations in any browser environment.
|
|
|
|
*/
|
|
|
|
export class GenericBrowserDomAdapter extends DomAdapter {
|
2015-06-30 17:38:33 -07:00
|
|
|
getDistributedNodes(el): List<Node> { return el.getDistributedNodes(); }
|
2015-05-12 11:19:47 -07:00
|
|
|
resolveAndSetHref(el, baseUrl: string, href: string) {
|
2015-03-09 11:35:46 +01:00
|
|
|
el.href = href == null ? baseUrl : baseUrl + '/../' + href;
|
|
|
|
}
|
2015-05-12 11:19:47 -07:00
|
|
|
cssToRules(css: string): List<any> {
|
2015-03-09 11:35:46 +01:00
|
|
|
var style = this.createStyleElement(css);
|
|
|
|
this.appendChild(this.defaultDoc().head, style);
|
2015-06-17 11:17:21 -07:00
|
|
|
var rules = [];
|
2015-03-09 11:35:46 +01:00
|
|
|
if (isPresent(style.sheet)) {
|
|
|
|
// TODO(sorvell): Firefox throws when accessing the rules of a stylesheet
|
|
|
|
// with an @import
|
|
|
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=625013
|
|
|
|
try {
|
2015-06-26 11:10:52 -07:00
|
|
|
var rawRules = (<any>style.sheet).cssRules;
|
2015-03-09 11:35:46 +01:00
|
|
|
rules = ListWrapper.createFixedSize(rawRules.length);
|
2015-05-12 11:19:47 -07:00
|
|
|
for (var i = 0; i < rawRules.length; i++) {
|
2015-03-09 11:35:46 +01:00
|
|
|
rules[i] = rawRules[i];
|
|
|
|
}
|
2015-05-12 11:19:47 -07:00
|
|
|
} catch (e) {
|
2015-03-09 11:35:46 +01:00
|
|
|
//
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// console.warn('sheet not found', style);
|
|
|
|
}
|
|
|
|
this.remove(style);
|
|
|
|
return rules;
|
|
|
|
}
|
2015-05-12 11:19:47 -07:00
|
|
|
supportsDOMEvents(): boolean { return true; }
|
2015-06-26 11:10:52 -07:00
|
|
|
supportsNativeShadowDOM(): boolean {
|
|
|
|
return isFunction((<any>this.defaultDoc().body).createShadowRoot);
|
|
|
|
}
|
2015-03-09 11:35:46 +01:00
|
|
|
}
|