Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
Implement underbar bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelw committed Oct 23, 2013
1 parent 7d97d67 commit 3932ebe
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/TemplateBinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,15 @@
var name = attr.name;
var value = attr.value;

// Allow bindings expressed in attributes to be prefixed with underbars.
// We do this to allow correct semantics for browsers that don't implement
// <template> where certain attributes might trigger side-effects -- and
// for IE which sanitizes certain attributes, disallowing mustache
// replacements in their text.
while (name.length && name[0] === '_') {

This comment has been minimized.

Copy link
@arv

arv Oct 23, 2013

Contributor

no need to check length here

name = name.substring(1);
}

if (isTemplateNode) {
if (name === IF) {
ifFound = true;
Expand Down
34 changes: 34 additions & 0 deletions tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2158,3 +2158,37 @@ suite('Binding Delegate API', function() {
assert.equal('barValue', div.lastChild.getAttribute('bar'));
});
});

suite('Compat', function() {
test('underbar bindings', function() {
var div = createTestHtml(

This comment has been minimized.

Copy link
@arv

arv Oct 23, 2013

Contributor

wrong indentation

'<template bind>' +
'<div _style="color: {{ color }};"></div>' +
'<img _src="{{ url }}">' +
'<a _href="{{ url2 }}">Link</a>' +
'<input type="number" _value="{{ number }}">' +
'</template>');

var model = {
color: 'red',
url: 'pic.jpg',
url2: 'link.html',
number: 4
};

recursivelySetTemplateModel(div, model);
Platform.performMicrotaskCheckpoint();

var subDiv = div.firstChild.nextSibling;
assert.equal('color: red;', subDiv.getAttribute('style'));

var img = subDiv.nextSibling;
assert.equal('pic.jpg', img.getAttribute('src'));

var a = img.nextSibling;
assert.equal('link.html', a.getAttribute('href'));

var input = a.nextSibling;
assert.equal(4, input.value);
});
});

2 comments on commit 3932ebe

@arv
Copy link
Contributor

@arv arv commented on 3932ebe Oct 23, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with nits

@rafaelw
Copy link
Contributor Author

@rafaelw rafaelw commented on 3932ebe Oct 23, 2013 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.