@@ -15,23 +15,34 @@ import {dashCaseToCamelCase, camelCaseToDashCase} from './util';
1515
1616var DOT_REGEXP = RegExpWrapper . create ( '\\.' ) ;
1717
18- const ARIA_PREFIX = 'aria ' ;
19- var ariaSettersCache = StringMapWrapper . create ( ) ;
18+ const ATTRIBUTE_PREFIX = 'attr. ' ;
19+ var attributeSettersCache = StringMapWrapper . create ( ) ;
2020
21- function ariaSetterFactory ( attrName :string ) {
22- var setterFn = StringMapWrapper . get ( ariaSettersCache , attrName ) ;
23- var ariaAttrName ;
21+ function _isValidAttributeValue ( attrName :string , value : any ) {
22+ if ( attrName == "role" ) {
23+ return isString ( value ) ;
24+ } else {
25+ return isPresent ( value ) ;
26+ }
27+ }
28+
29+ function attributeSetterFactory ( attrName :string ) {
30+ var setterFn = StringMapWrapper . get ( attributeSettersCache , attrName ) ;
31+ var dashCasedAttributeName ;
2432
2533 if ( isBlank ( setterFn ) ) {
26- ariaAttrName = camelCaseToDashCase ( attrName ) ;
34+ dashCasedAttributeName = camelCaseToDashCase ( attrName ) ;
2735 setterFn = function ( element , value ) {
28- if ( isPresent ( value ) ) {
29- DOM . setAttribute ( element , ariaAttrName , stringify ( value ) ) ;
36+ if ( _isValidAttributeValue ( dashCasedAttributeName , value ) ) {
37+ DOM . setAttribute ( element , dashCasedAttributeName , stringify ( value ) ) ;
3038 } else {
31- DOM . removeAttribute ( element , ariaAttrName ) ;
39+ DOM . removeAttribute ( element , dashCasedAttributeName ) ;
40+ if ( isPresent ( value ) ) {
41+ throw new BaseException ( "Invalid " + dashCasedAttributeName + " attribute, only string values are allowed, got '" + stringify ( value ) + "'" ) ;
42+ }
3243 }
3344 } ;
34- StringMapWrapper . set ( ariaSettersCache , attrName , setterFn ) ;
45+ StringMapWrapper . set ( attributeSettersCache , attrName , setterFn ) ;
3546 }
3647
3748 return setterFn ;
@@ -82,21 +93,9 @@ function styleSetterFactory(styleName:string, stylesuffix:string) {
8293 return setterFn ;
8394}
8495
85- const ROLE_ATTR = 'role' ;
86- function roleSetter ( element , value ) {
87- if ( isString ( value ) ) {
88- DOM . setAttribute ( element , ROLE_ATTR , value ) ;
89- } else {
90- DOM . removeAttribute ( element , ROLE_ATTR ) ;
91- if ( isPresent ( value ) ) {
92- throw new BaseException ( "Invalid role attribute, only string values are allowed, got '" + stringify ( value ) + "'" ) ;
93- }
94- }
95- }
96-
9796// tells if an attribute is handled by the ElementBinderBuilder step
9897export function isSpecialProperty ( propName :string ) {
99- return StringWrapper . startsWith ( propName , ARIA_PREFIX )
98+ return StringWrapper . startsWith ( propName , ATTRIBUTE_PREFIX )
10099 || StringWrapper . startsWith ( propName , CLASS_PREFIX )
101100 || StringWrapper . startsWith ( propName , STYLE_PREFIX )
102101 || StringMapWrapper . contains ( DOM . attrToPropMap , propName ) ;
@@ -188,10 +187,8 @@ export class ElementBinderBuilder extends CompileStep {
188187 MapWrapper . forEach ( compileElement . propertyBindings , ( expression , property ) => {
189188 var setterFn , styleParts , styleSuffix ;
190189
191- if ( StringWrapper . startsWith ( property , ARIA_PREFIX ) ) {
192- setterFn = ariaSetterFactory ( property ) ;
193- } else if ( StringWrapper . equals ( property , ROLE_ATTR ) ) {
194- setterFn = roleSetter ;
190+ if ( StringWrapper . startsWith ( property , ATTRIBUTE_PREFIX ) ) {
191+ setterFn = attributeSetterFactory ( StringWrapper . substring ( property , ATTRIBUTE_PREFIX . length ) ) ;
195192 } else if ( StringWrapper . startsWith ( property , CLASS_PREFIX ) ) {
196193 setterFn = classSetterFactory ( StringWrapper . substring ( property , CLASS_PREFIX . length ) ) ;
197194 } else if ( StringWrapper . startsWith ( property , STYLE_PREFIX ) ) {
0 commit comments