-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Steven Orvell
committed
Jul 15, 2015
1 parent
348896a
commit 8922323
Showing
6 changed files
with
380 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
|
||
<title>dom-bind</title> | ||
|
||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
|
||
<script src="../../../webcomponentsjs/webcomponents-lite.js"></script> | ||
<link rel="import" href="../../polymer.html" async> | ||
|
||
<script> | ||
document.querySelector('link').addEventListener('load', function() { | ||
app.render(); | ||
}); | ||
</script> | ||
|
||
</head> | ||
<body> | ||
|
||
<template is="dom-bind" id="app"> | ||
|
||
<h3>Repeat index</h3> | ||
<template is="dom-repeat" items="{{employees}}"> | ||
<div style="padding: 3px 0px;"> | ||
<button on-tap="modify">Modify</button> | ||
<span>{{index}}</span> | ||
<span>{{item.first}}</span> | ||
<span>{{item.last}}</span> | ||
</div> | ||
</template> | ||
|
||
<h3>Show person by index, demonstrate "dom-if" expressions</h3> | ||
<template is="dom-repeat" items="{{employees}}"> | ||
<div> | ||
<template is="dom-if" if="{{testit(index)}}"> | ||
<div style="padding: 3px 0px;"> | ||
<button on-tap="modify">Modify</button> | ||
<span>{{index}}</span> | ||
<span>{{item.first}}</span> | ||
<span>{{item.last}}</span> | ||
</div> | ||
</template> | ||
</div> | ||
</template> | ||
|
||
<h3>Show person by index, demonstrate filter</h3> | ||
<template is="dom-repeat" items="{{employees}}" filter="onlyRob"> | ||
<div> | ||
<div style="padding: 3px 0px;"> | ||
<button on-tap="modify">Modify</button> | ||
<span>{{index}}</span> | ||
<span>{{item.first}}</span> | ||
<span>{{item.last}}</span> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
</template> | ||
|
||
<script> | ||
var logEl = document.getElementById('log'); | ||
var app = document.getElementById('app'); | ||
app.testit = function(i) { | ||
return i > 1; | ||
}; | ||
app.modify = function(e) { | ||
e.model.set('item.last', e.model.item.last + '*'); | ||
}; | ||
app.onlyRob = function(item) { | ||
return item.first == 'Rob'; | ||
}; | ||
app.bar = true; | ||
app.employees = [ | ||
{first: 'Bob', last: 'Smith'}, | ||
{first: 'Sally', last: 'Johnson'}, | ||
{first: 'Rob', last: 'Instructs'}, | ||
{first: 'Scott', last: 'Explains'}, | ||
{first: 'Taylor', last: 'Blogs'} | ||
]; | ||
|
||
</script> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<!doctype html> | ||
<!-- | ||
@license | ||
Copyright (c) 2014 The Polymer Project Authors. All rights reserved. | ||
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt | ||
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt | ||
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt | ||
Code distributed by Google as part of the polymer project is also | ||
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt | ||
--> | ||
<script src="../../../webcomponentsjs/webcomponents-lite.js"></script> | ||
<link rel="import" href="../../polymer.html"> | ||
|
||
<body> | ||
<x-test></x-test> | ||
|
||
<dom-module id="x-foo"> | ||
<template> | ||
<content></content> | ||
</template> | ||
<script> | ||
HTMLImports.whenReady(function() { | ||
Polymer({ | ||
is: 'x-foo' | ||
}); | ||
}); | ||
</script> | ||
</dom-module> | ||
|
||
<dom-module id="x-test"> | ||
<template> | ||
Greeting: | ||
<x-foo id="myCustomElement"></x-foo> | ||
</template> | ||
<script> | ||
HTMLImports.whenReady(function() { | ||
Polymer({ | ||
is: 'x-test', | ||
attached: function() { | ||
var appendTo = this.$.myCustomElement, | ||
t = document.createElement('template', 'dom-bind'), | ||
span = document.createElement('span'); | ||
span.innerHTML = '{{hello}}'; | ||
t.content.appendChild(span); | ||
t.hello = 'hey'; | ||
Polymer.dom(appendTo).appendChild(t); | ||
} | ||
}); | ||
}); | ||
</script> | ||
</dom-module> | ||
|
||
|
||
</body> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<!doctype html> | ||
<!-- | ||
@license | ||
Copyright (c) 2014 The Polymer Project Authors. All rights reserved. | ||
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt | ||
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt | ||
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt | ||
Code distributed by Google as part of the polymer project is also | ||
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt | ||
--> | ||
<script src="../../../webcomponentsjs/webcomponents-lite.js"></script> | ||
<link rel="import" href="../../polymer.html"> | ||
|
||
<body> | ||
<x-outer></x-outer> | ||
|
||
<dom-module id="x-outer"> | ||
<template> | ||
<x-test id="test1"></x-test> | ||
<button on-tap="_addDomBindDirectly">Add dom-bind directly</button> | ||
<span><<< Doesn't work the first time</span> | ||
<br /><br /> | ||
<x-test id="test2"></x-test> | ||
<button on-tap="_addDomBindIndirectly">Add dom-bind indirectly</button> | ||
<span><<< Works every time</span> | ||
</template> | ||
</dom-module> | ||
|
||
<dom-module id="x-test"> | ||
<template> | ||
<content></content> | ||
</template> | ||
</dom-module> | ||
|
||
<script> | ||
HTMLImports.whenReady(function() { | ||
Polymer({ | ||
is: 'x-test' | ||
}); | ||
|
||
Polymer({ | ||
is: 'x-outer', | ||
_addDomBindDirectly: function() { | ||
var domBind = this._createDomBind(); | ||
Polymer.dom(this.$.test1).appendChild(domBind); | ||
}, | ||
_addDomBindIndirectly: function() { | ||
var domBind = this._createDomBind(); | ||
|
||
var tempContainer = document.createElement("div"); | ||
tempContainer.appendChild(domBind); | ||
|
||
Polymer.dom(this.$.test2).appendChild(tempContainer); | ||
}, | ||
_createDomBind: function() { | ||
var domBind = document.createElement("template", "dom-bind"); | ||
domBind.test = "hello"; | ||
|
||
var doc = domBind.content.ownerDocument; | ||
var div = doc.createElement("div"); | ||
div.textContent = "{{test}}"; | ||
|
||
domBind.content.appendChild(div); | ||
|
||
return domBind; | ||
} | ||
}); | ||
}); | ||
</script> | ||
|
||
|
||
</body> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.