3 Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
4 This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6 The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
7 Code distributed by Google as part of the polymer project is also
8 subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
12 <title>core-list
</title>
13 <meta name=
"viewport" content=
"width=device-width, initial-scale=1.0, maximum-scale=1.0">
14 <script src=
"../webcomponentsjs/webcomponents.js"></script>
15 <link rel=
"import" href=
"../polymer/polymer.html">
16 <link rel=
"import" href=
"core-list.html">
20 -webkit-tap-highlight-color: transparent;
32 background: red !important;
33 border-bottom:
1px solid black;
39 <list-test></list-test>
41 <polymer-element name=
"list-test" layout vertical
>
45 box-sizing: border-box;
47 border-bottom:
1px solid #ddd;
50 background-color: white;
61 background-repeat: no-repeat;
62 background-position:
10px
10px;
63 background-size:
60px;
86 background: lightgray;
98 <button on-tap=
"{{addRecord}}">Add row at index:
</button>
99 <input value=
"{{addIdx}}" class=
"narrow" type=
"number">
101 <button on-tap=
"{{deleteRecord}}">Delete row at index:
</button>
102 <input value=
"{{deleteIdx}}" class=
"narrow" type=
"number">
104 <button on-tap=
"{{deleteAll}}">Delete all
</button>
105 <button on-tap=
"{{deleteArray}}">Delete data array
</button>
106 <button on-tap=
"{{initArrayEmpty}}">Init empty array
</button>
107 <button on-tap=
"{{initArrayFull}}">Init full array
</button>
109 <label><input type=
"checkbox" checked=
"{{selectionEnabled}}">Selection enabled
</label>
110 <label><input type=
"checkbox" checked=
"{{multi}}">Multiple selection
</label>
112 <button on-tap=
"{{clearSelection}}">Clear selection
</button>
113 <button on-tap=
"{{deleteSelection}}">Delete selection
</button>
115 <div layout horizontal wrap
class=
"spaced">
117 <template repeat=
"{{multi ? selection: [selection]}}">
118 <div class=
"selection-display">Id {{id}}: {{checked}} {{value}} {{['a','b','c'][type]}}
</div>
121 <core-list id=
"list" data=
"{{data}}" selectionEnabled=
"{{selectionEnabled}}"
122 selection=
"{{selection}}" height=
"80" flex multi?={{multi}}
>
124 <div class=
"item {{ {selected: selected} | tokenList }}">
125 <div class=
"message" style=
"background-image: url(images/{{model.image}}.png);">
126 <span class=
"from">{{model.name}}
</span>
127 <div class=
"subject">Row: {{index}}, Record ID: {{model.id}}
</div>
128 <input type=
"checkbox" checked=
"{{model.checked}}">
129 <input type=
"number" value=
"{{model.value}}" class=
"narrow">
130 <select selectedIndex=
"{{model.type}}"><option>a
</option><option>b
</option><option>c
</option></select>
131 <span class=
"body">{{model.details}}
</span>
142 "Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit...",
143 "Lorem Ipsum is simply dummy text of the printing and typesetting industry."
147 generateString: function(inLength
) {
149 for (var i
=0; i
<inLength
; i
++) {
150 s
+= String
.fromCharCode(Math
.floor(Math
.random() * 26) + 97);
154 generateName: function(inMin
, inMax
) {
155 return this.generateString(Math
.floor(Math
.random() * (inMax
- inMin
+ 1) + inMin
));
159 Polymer('list-test', {
164 this.initArrayFull();
165 window
.list
= this.$.list
;
167 generateData: function() {
168 var names
= [], data
= [];
169 for (var i
=0; i
<this.count
; i
++) {
170 names
.push(namegen
.generateName(4, 8));
173 for (i
=0; i
<this.count
; i
++) {
177 details
: strings
[i
% 3],
186 addRecord: function() {
187 this.data
.splice(this.addIdx
, 0, {
189 name
: namegen
.generateName(4, 8),
190 details
: strings
[this.count
% 3],
191 image
: this.count
% 4,
197 deleteRecord: function() {
198 this.data
.splice(this.deleteIdx
, 1);
200 deleteSelection: function() {
203 if (this.selection
.length
) {
204 for (i
=0; i
<this.selection
.length
; i
++) {
205 idx
= this.data
.indexOf(this.selection
[i
]);
206 this.data
.splice(idx
, 1);
210 idx
= this.data
.indexOf(this.selection
);
211 this.data
.splice(idx
, 1);
214 clearSelection: function() {
215 this.$.list
.clearSelection();
217 deleteAll: function() {
218 this.data
.splice(0,this.data
.length
);
219 // this.data.length = 0;
221 deleteArray: function() {
224 initArrayEmpty: function() {
227 initArrayFull: function() {
228 this.data
= this.generateData();