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

Commit 4f54c57

Browse files
author
Scott J. Miles
committed
mock-data element
1 parent 5573477 commit 4f54c57

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

polymer-mock-data/index.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>polymer-mock-data</title>
5+
<script src="../../polymer/polymer.js"></script>
6+
<link rel="import" href="polymer-mock-data.html">
7+
</head>
8+
<body style="font-family: 'Courier New'">
9+
<mock-data-dump></mock-data-dump>
10+
<polymer-element name="mock-data-dump" noscript>
11+
<template>
12+
<polymer-mock-data items="{{items}}"></polymer-mock-data>
13+
<template repeat="{{items}}"><span>{{name}}</span> </template>
14+
</template>
15+
</polymer-element>
16+
</body>
17+
</html>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<polymer-element name="polymer-mock-data" attributes="count items">
2+
<script>
3+
Polymer('polymer-mock-data', {
4+
count: 3000,
5+
items: null,
6+
created: function() {
7+
this.generateRecords();
8+
},
9+
countChanged: function() {
10+
if (!this.items || this.items.length !== this.count) {
11+
this.generateRecords();
12+
}
13+
},
14+
generateRecords: function() {
15+
this.items = [];
16+
for (var i=0; i<this.count; i++) {
17+
this.items.push(this.fakeRecord());
18+
}
19+
},
20+
fakeRecord: function() {
21+
var fields = [];
22+
for (var j=0, c=Math.floor(Math.random()*4)+2; j<c; j++) {
23+
for(var k=0, s=''; k<8; k++) { s += String.fromCharCode([Math.floor(Math.random()*26) + 65 + (k > 0 ? 32 : 0)]) };
24+
fields.push({
25+
icon: ['twitter', 'gplus', 'filter', 'contact'][Math.floor(Math.random()*4)],
26+
label: String.fromCharCode(j%26 + 65) + Math.floor((Math.random() + 1) * 1000),
27+
value: s
28+
});
29+
}
30+
return {
31+
name: String.fromCharCode(Math.floor(Math.random()*26) + 65) + Math.floor((Math.random() + 1) * 1000),
32+
fields: fields
33+
};
34+
}
35+
});
36+
</script>
37+
</polymer-element>

0 commit comments

Comments
 (0)