namespace drunk { import util = drunk . util ; import Binding = drunk . Binding ; @ binding ( 'attr' ) class AttributeBinding extends Binding implements IBindingDefinition { attribute : string ; update ( attributes ) { if ( this . attribute ) { this . _setAttribute ( this . attribute , attributes ) ; } else if ( Object . prototype . toString . call ( attributes ) === '[object Object]' ) { Object . keys ( attributes ) . forEach ( name => { this . _setAttribute ( name , attributes [ name ] ) ; } ) ; } } private _setAttribute ( name , value ) { if ( name === 'style' && value && typeof value != 'string' ) { let props = Object . keys ( value ) . map ( prop => `${ prop }:${ value [ prop ] }` ) ; return this . element . setAttribute ( 'style' , props . join ( ';' ) ) ; } if ( name === 'src' || name === 'href' ) { value = value == null ? '' : value ; } this . element . setAttribute ( name , value ) ; } } }