2015-10-01 10:07:49 -07:00
|
|
|
import {Injectable} from 'angular2/src/core/di';
|
2015-08-27 16:29:02 -07:00
|
|
|
import {isPresent, isBlank} from 'angular2/src/core/facade/lang';
|
2015-08-20 14:28:25 -07:00
|
|
|
import {StringMapWrapper} from 'angular2/src/core/facade/collection';
|
|
|
|
import {DOM} from 'angular2/src/core/dom/dom_adapter';
|
2015-07-29 14:01:18 +02:00
|
|
|
|
|
|
|
import {ElementSchemaRegistry} from './element_schema_registry';
|
|
|
|
|
2015-10-01 10:07:49 -07:00
|
|
|
@Injectable()
|
2015-07-29 14:01:18 +02:00
|
|
|
export class DomElementSchemaRegistry extends ElementSchemaRegistry {
|
2015-09-29 11:11:06 -07:00
|
|
|
private _protoElements = new Map<string, Element>();
|
2015-08-27 16:29:02 -07:00
|
|
|
|
|
|
|
private _getProtoElement(tagName: string): Element {
|
|
|
|
var element = this._protoElements.get(tagName);
|
|
|
|
if (isBlank(element)) {
|
|
|
|
element = DOM.createElement(tagName);
|
|
|
|
this._protoElements.set(tagName, element);
|
|
|
|
}
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
2015-08-27 16:29:02 -07:00
|
|
|
var elm = this._getProtoElement(tagName);
|
2015-07-29 14:01:18 +02:00
|
|
|
return DOM.hasProperty(elm, propName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getMappedPropName(propName: string): string {
|
|
|
|
var mappedPropName = StringMapWrapper.get(DOM.attrToPropMap, propName);
|
|
|
|
return isPresent(mappedPropName) ? mappedPropName : propName;
|
|
|
|
}
|
|
|
|
}
|