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

Commit

Permalink
mock-data element
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott J. Miles committed Aug 28, 2013
1 parent 5573477 commit 4f54c57
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
17 changes: 17 additions & 0 deletions polymer-mock-data/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<title>polymer-mock-data</title>
<script src="../../polymer/polymer.js"></script>
<link rel="import" href="polymer-mock-data.html">
</head>
<body style="font-family: 'Courier New'">
<mock-data-dump></mock-data-dump>
<polymer-element name="mock-data-dump" noscript>
<template>
<polymer-mock-data items="{{items}}"></polymer-mock-data>
<template repeat="{{items}}"><span>{{name}}</span> </template>
</template>
</polymer-element>
</body>
</html>
37 changes: 37 additions & 0 deletions polymer-mock-data/polymer-mock-data.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<polymer-element name="polymer-mock-data" attributes="count items">
<script>
Polymer('polymer-mock-data', {
count: 3000,
items: null,
created: function() {
this.generateRecords();
},
countChanged: function() {
if (!this.items || this.items.length !== this.count) {
this.generateRecords();
}
},
generateRecords: function() {
this.items = [];
for (var i=0; i<this.count; i++) {
this.items.push(this.fakeRecord());
}
},
fakeRecord: function() {
var fields = [];
for (var j=0, c=Math.floor(Math.random()*4)+2; j<c; j++) {
for(var k=0, s=''; k<8; k++) { s += String.fromCharCode([Math.floor(Math.random()*26) + 65 + (k > 0 ? 32 : 0)]) };
fields.push({
icon: ['twitter', 'gplus', 'filter', 'contact'][Math.floor(Math.random()*4)],
label: String.fromCharCode(j%26 + 65) + Math.floor((Math.random() + 1) * 1000),
value: s
});
}
return {
name: String.fromCharCode(Math.floor(Math.random()*26) + 65) + Math.floor((Math.random() + 1) * 1000),
fields: fields
};
}
});
</script>
</polymer-element>

0 comments on commit 4f54c57

Please sign in to comment.