2015-10-01 10:07:49 -07:00
|
|
|
import {Injectable} from 'angular2/src/core/di';
|
2016-04-27 17:41:57 -07:00
|
|
|
import {isPresent, isBlank, CONST_EXPR} from 'angular2/src/facade/lang';
|
2015-11-06 17:34:07 -08:00
|
|
|
import {StringMapWrapper} from 'angular2/src/facade/collection';
|
2016-04-27 17:41:57 -07:00
|
|
|
import {DOM} from 'angular2/src/platform/dom/dom_adapter';
|
|
|
|
import {splitNsName} from 'angular2/src/compiler/html_tags';
|
2016-04-21 15:11:14 -07:00
|
|
|
|
2016-04-27 17:41:57 -07:00
|
|
|
import {ElementSchemaRegistry} from './element_schema_registry';
|
2016-04-21 15:11:14 -07:00
|
|
|
|
2016-04-27 17:41:57 -07:00
|
|
|
const NAMESPACE_URIS =
|
|
|
|
CONST_EXPR({'xlink': 'http://www.w3.org/1999/xlink', 'svg': 'http://www.w3.org/2000/svg'});
|
2015-12-06 14:21:34 +02:00
|
|
|
|
2015-10-01 10:07:49 -07:00
|
|
|
@Injectable()
|
2016-04-27 17:41:57 -07:00
|
|
|
export class DomElementSchemaRegistry extends ElementSchemaRegistry {
|
|
|
|
private _protoElements = new Map<string, Element>();
|
|
|
|
|
|
|
|
private _getProtoElement(tagName: string): Element {
|
|
|
|
var element = this._protoElements.get(tagName);
|
|
|
|
if (isBlank(element)) {
|
|
|
|
var nsAndName = splitNsName(tagName);
|
|
|
|
element = isPresent(nsAndName[0]) ?
|
|
|
|
DOM.createElementNS(NAMESPACE_URIS[nsAndName[0]], nsAndName[1]) :
|
|
|
|
DOM.createElement(nsAndName[1]);
|
|
|
|
this._protoElements.set(tagName, element);
|
|
|
|
}
|
|
|
|
return element;
|
2015-08-27 16:29:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
hasProperty(tagName: string, propName: string): boolean {
|
2015-07-29 14:01:18 +02:00
|
|
|
if (tagName.indexOf('-') !== -1) {
|
|
|
|
// can't tell now as we don't know which properties a custom element will get
|
|
|
|
// once it is instantiated
|
|
|
|
return true;
|
|
|
|
} else {
|
2016-04-27 17:41:57 -07:00
|
|
|
var elm = this._getProtoElement(tagName);
|
|
|
|
return DOM.hasProperty(elm, propName);
|
2015-07-29 14:01:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getMappedPropName(propName: string): string {
|
2016-04-27 17:41:57 -07:00
|
|
|
var mappedPropName = StringMapWrapper.get(DOM.attrToPropMap, propName);
|
2015-07-29 14:01:18 +02:00
|
|
|
return isPresent(mappedPropName) ? mappedPropName : propName;
|
|
|
|
}
|
|
|
|
}
|