Support boolean attributes

pull/15/head
yelouafi 10 years ago
parent 05ff217997
commit 379f736254

@ -198,12 +198,16 @@ h('a', {props: {href: '/foo'}, 'Go to Foo');
### The attributes module
Same as props but set attributes instead of properties on DOM elements (i.e. `setAttribute`).
Same as props but set attributes instead of properties on DOM elements
```javascript
h('a', {attrs: {href: '/foo'}, 'Go to Foo');
```
Attributes are added and updated using `setAttribute`. In case of an attribute that has been previously added/set is no longer present in the `attrs` object, it is removed from the DOM elemnt's attribute list using `removeAttribute`.
In the case of boolean attributes (.e.g. `disabled`, `hidden`, `selected` ...). The meaning doesn't depend on the attribute value (`true` of `false`) but depends instead on the presence/absence of the attribute itself in the DOM element. Those attributes are handled differently by the module : if a boolean attribute is set to a [falsy value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean) (`0`, `-0`, `null`, `false`, `NaN`, `undefined`, or the empty string (`""`)) then the attribute will be removed from the attribute list of the DOM element.
### The style module
The style module is for making your HTML look slick and animate smoothly. At

@ -1,5 +1,5 @@
function isBooleanAttribute(attrName) {
return (/^(?:allowfullscreen|async|autofocus|autoplay|checked|compact|controls|declare|default|defaultchecked|defaultmuted|defaultselected|defer|disabled|draggable|enabled|formnovalidate|hidden|indeterminate|inert|ismap|itemscope|loop|multiple|muted|nohref|noresize|noshade|novalidate|nowrap|open|pauseonexit|readonly|required|reversed|scoped|seamless|selected|sortable|spellcheck|translate|truespeed|typemustmatch|visible)$/).test(attrName);
return (/^(?:allowfullscreen|async|autofocus|autoplay|checked|compact|controls|declare|default|defaultchecked|defaultmuted|defaultselected|defer|disabled|draggable|enabled|formnovalidate|hidden|indeterminate|inert|ismap|itemscope|loop|multiple|muted|nohref|noresize|noshade|novalidate|nowrap|open|pauseonexit|readonly|required|reversed|scoped|seamless|selected|sortable|spellcheck|translate|truespeed|typemustmatch|visible)$/).test(attrName);
}
function updateAttrs(oldVnode, vnode) {

Loading…
Cancel
Save