forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeneric_browser_adapter.ts
More file actions
38 lines (37 loc) · 1.35 KB
/
generic_browser_adapter.ts
File metadata and controls
38 lines (37 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import {List, ListWrapper} from 'angular2/src/facade/collection';
import {isPresent, isFunction} from 'angular2/src/facade/lang';
import {DomAdapter} from './dom_adapter';
/**
* Provides DOM operations in any browser environment.
*/
export class GenericBrowserDomAdapter extends DomAdapter {
getDistributedNodes(el) { return el.getDistributedNodes(); }
resolveAndSetHref(el, baseUrl: string, href: string) {
el.href = href == null ? baseUrl : baseUrl + '/../' + href;
}
cssToRules(css: string): List<any> {
var style = this.createStyleElement(css);
this.appendChild(this.defaultDoc().head, style);
var rules = ListWrapper.create();
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 {
var rawRules = style.sheet.cssRules;
rules = ListWrapper.createFixedSize(rawRules.length);
for (var i = 0; i < rawRules.length; i++) {
rules[i] = rawRules[i];
}
} catch (e) {
//
}
} else {
// console.warn('sheet not found', style);
}
this.remove(style);
return rules;
}
supportsDOMEvents(): boolean { return true; }
supportsNativeShadowDOM(): boolean { return isFunction(this.defaultDoc().body.createShadowRoot); }
}