luda
Version:
A library helps to build cross-framework UI components.
24 lines (20 loc) • 727 B
text/coffeescript
import luda from '../base/luda.coffee'
import Type from '../base/type.coffee'
import readValue from '../base/read-value.coffee'
import parseValue from '../base/parse-value.coffee'
import splitValues from '../base/split-values.coffee'
import '../collection/each.coffee'
import './remove-attr.coffee'
luda.include
attr: (attr, value) ->
return unless attr
if Type.isString attr
if arguments.length >= 2
return this if value is undefined
return attr if value is null
.forEach (el) -> el.setAttribute attr, parseValue(value)
return this
return unless [0]
return readValue( [0].getAttribute attr)
key, val for key, val of attr
this