ampersand-dom-bindings
Advanced tools
Comparing version 2.1.0 to 2.2.0
@@ -130,2 +130,8 @@ var Store = require('key-tree-store'); | ||
}; | ||
} else if (type === 'innerHTML') { | ||
return function (el, value) { | ||
getMatches(el, selector).forEach(function (match) { | ||
dom.html(match, value); | ||
}); | ||
}; | ||
} else { | ||
@@ -132,0 +138,0 @@ throw new Error('no such binding type: ' + type); |
{ | ||
"name": "ampersand-dom-bindings", | ||
"description": "Takes binding declarations and returns key-tree-store of functions that can be used to apply those bindings.", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"author": "'Henrik Joreteg' <henrik@andyet.net>", | ||
@@ -6,0 +6,0 @@ "bugs": { |
@@ -119,3 +119,13 @@ # ampersand-dom-bindings | ||
### innerHTML | ||
renders innerHTML, can be a string or DOM, based on property value of model | ||
```js | ||
'model.key': { | ||
type: 'innerHTML', | ||
selector: '#something' // or role | ||
} | ||
``` | ||
## Handling multiple bindings for a given key | ||
@@ -122,0 +132,0 @@ |
@@ -141,2 +141,22 @@ var test = require('tape'); | ||
test('innerHTML bindings', function (t) { | ||
var el = getEl(); | ||
var bindings = domBindings({ | ||
'model': { | ||
type: 'innerHTML', | ||
selector: '' | ||
} | ||
}); | ||
t.notOk(el.innerHTML, 'should be empty to start'); | ||
bindings.run('', null, el, '<span></span>'); | ||
t.equal(el.innerHTML, '<span></span>', 'should hav a span now'); | ||
bindings.run('', null, el, ''); | ||
t.notOk(el.innerHTML, 'should be empty again'); | ||
t.end(); | ||
}); | ||
// TODO: tests for toggle | ||
@@ -143,0 +163,0 @@ |
15916
256
235