-
Notifications
You must be signed in to change notification settings - Fork 11
/
data.js
105 lines (91 loc) · 3.08 KB
/
data.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
(function(exports) {
'use strict';
function repeat(s, n) {
return Array(n + 1).join(s);
}
function generateFakeDrawerData(numberOfItems) {
var data = [];
var i = 0;
while (i < numberOfItems) {
data[i] = {
icon: 'communication:chat',
label: repeat(String.fromCharCode(65 + i++), 5)
};
}
data[i] = {icon: 'search', label: 'Search'};
return data;
}
function getRandomItem(array) {
return array[Math.floor(Math.random() * array.length)];
}
function generateFakeListData(numberOfItems) {
var possibleAvatarColors = [
'BurlyWood', 'green', 'orange', 'salmon', 'lightblue', 'BlueViolet', 'DarkSeaGreen',
];
var possibleParticipants = [
'Adam', 'Ojan', 'Elliott', 'Chris',
];
var possibleTimes = [
'Now', 'Yesterday', 'Last week',
];
var possibleSubjects = [
'Do you even bench?',
'I like to scroll forever',
'Lunch',
'What if my subject is really long? Longer than that. Like really, really, long?',
];
var possibleSnippets = [
'Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.',
'When, in disgrace with fortune and men\'s eyes, I all alone beweep my outcast state,',
'We the People of the United States, in Order to form a more perfect Union, establish Justice, insure domestic Tranquility',
];
var data = [];
for (var i = 0; i < numberOfItems; ++i) {
data[i] = {
id: i,
avatarColor: getRandomItem(possibleAvatarColors),
participants: getRandomItem(possibleParticipants),
time: getRandomItem(possibleTimes),
subject: getRandomItem(possibleSubjects),
snippet: getRandomItem(possibleSnippets),
};
data[i].avatarLetter = data[i].participants[0].toUpperCase();
}
return data;
}
function FakeDataProvider(numberOfItems) {
// Create a HTMLUnknownElement and do not attach it to the DOM.
this.dispatcher_ = document.createElement('FakeDataProvider-EventDispatcher');
this.data_ = generateFakeListData(numberOfItems);
}
FakeDataProvider.prototype.addEventListener = function(type, callback, capture) {
this.dispatcher_.addEventListener(type, callback, capture);
}
FakeDataProvider.prototype.removeEventListener = function(type, callback, capture) {
this.dispatcher_.removeEventListener(type, callback, capture);
}
FakeDataProvider.prototype.dispatchEvent = function(e) {
this.dispatcher_.dispatchEvent(e);
}
FakeDataProvider.prototype.getItemCount = function() {
return this.data_.length;
}
FakeDataProvider.prototype.getItem = function(index) {
return this.data_[index % this.data_.length];
}
FakeDataProvider.prototype.deleteItemByIds = function(ids) {
self = this;
ids.forEach(function(id) {
self.data_.some(function(element, index) {
if (element.id == id) {
self.data_.splice(index, 1);
return true;
}
})
})
var event = new CustomEvent("data-changed", { items: ids });
this.dispatchEvent(event);
}
exports.FakeDataProvider = FakeDataProvider;
exports.fakeDrawerData = generateFakeDrawerData(26);
})(window);