Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"iron-component-page": "PolymerElements/iron-component-page#^1.0.0",
"iron-test-helpers": "PolymerElements/iron-test-helpers#^1.1.2",
"paper-styles": "PolymerElements/paper-styles#^1.1.0",
"paper-checkbox": "PolymerElements/paper-checkbox#^1.0.0"
"paper-checkbox": "PolymerElements/paper-checkbox#^1.0.0",
"paper-input": "polymerelements/paper-input#^1.1.23"
}
}
21 changes: 21 additions & 0 deletions demo-snippet.html
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@
on-tap="_copyToClipboard">
</paper-icon-button>
</div>

<template is="dom-if" if="_boundDataJson">
<div class="code-container">
<marked-element markdown=[[_boundDataJson]]>
<div class="markdown-html code"></div>
</marked-element>
</div>
</template>
</template>

<script>
Expand All @@ -126,6 +134,10 @@
_markdown: {
type: String,
value: ''
},
_boundDataJson: {
type: Object,
value: ''
}
},

Expand All @@ -148,6 +160,15 @@
// Stamp the template.
if (!template.is) {
Polymer.dom(this).appendChild(document.importNode(template.content, true));
} else if(template.id) {
var dataGetter = window[template.id];

// set template data if a global function with the same name exists
if(dataGetter && typeof dataGetter === 'function') {
var boundData = dataGetter();
this._boundDataJson = '``` js\nvar data = ' + JSON.stringify(boundData, null, 2) + '\n' + '```';
template.data = boundData;
}
}
},

Expand Down
17 changes: 17 additions & 0 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<link rel="import" href="../../paper-styles/color.html">
<link rel="import" href="../../iron-flex-layout/iron-flex-layout.html">
<link rel="import" href="../../paper-checkbox/paper-checkbox.html">
<link rel="import" href="../../paper-input/paper-input.html">
<link rel="import" href="../demo-snippet.html">
<link rel="import" href="../demo-pages-shared-styles.html">

Expand Down Expand Up @@ -83,6 +84,22 @@ <h4>Demo of an element with bindings</h4>
<paper-checkbox checked="{{active}}">Two-Way Binding</paper-checkbox>
</template>
</demo-snippet>

<h4>Demo of an element with initial bound value</h4>
<demo-snippet class="centered-demo small-text">
<template id="defaultBinding" is="dom-bind">
<paper-input value="{{data.someText}}"></paper-input>
<paper-input value="{{data.someText}}"></paper-input>
</template>

<script>
function defaultBinding() {
return {
someText: 'Lorem Ipsum Dolor'
}
}
</script>
</demo-snippet>
</div>
</body>
</html>
31 changes: 31 additions & 0 deletions test/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<link rel="import" href="../demo-snippet.html">
<script src="../../iron-test-helpers/test-helpers.js"></script>
<link rel="import" href="../../paper-checkbox/paper-checkbox.html">
<link rel="import" href="../../paper-input/paper-input.html">

</head>
<body>
Expand Down Expand Up @@ -62,6 +63,21 @@
</template>
</demo-snippet>

<demo-snippet id="domBindDeclarative">
<template is="dom-bind" id="boundData">
<paper-input value="{{data.theValue}}"></paper-input>
<span>[[data.theValue]]</span>
</template>

<script>
function boundData() {
return {
theValue: 'initial input value'
}
}
</script>
</demo-snippet>

<script>
suite('display', function() {
var emptyHeight;
Expand Down Expand Up @@ -142,6 +158,21 @@
done();
});
});

test('can be bound declaratively to global function of same name', function(done) {
var element = document.getElementById('domBindDeclarative');
var span = Polymer.dom(element).querySelector('span');
var input = Polymer.dom(element).querySelector('paper-input');

// Render the distributed children.
Polymer.dom.flush();

flush(function() {
expect(span.textContent).to.be.equal('initial input value');
expect(input.value).to.be.equal('initial input value');
done();
});
})
});

suite('parsing', function() {
Expand Down