This repository has been archived by the owner on Jun 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresults.js
58 lines (54 loc) · 1.75 KB
/
results.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
function gridify(self) {
var results = [];
var row = [];
Object.keys(self.productList).forEach(function (k, i) {
var item = m('div.col.centered.w25', [
m('img', {src: self.productList[k].imgUrl}),
m('p', [
m('span.title', self.productList[k].title),
m('br'),
m('div.sku', chrome.i18n.getMessage('itemlabel') + k),
m('div.sku', chrome.i18n.getMessage('modellabel') + self.productList[k].model)
])
])
if ((i > 0) && (i % 4 == 0)) {
results.push(row);
row = [item];
} else {
row.push(item);
}
})
results.push(row);
return results
}
var ResultsApp = {};
ResultsApp.oninit = function () {
var self = this;
self.productList = {};
self.listBanner = {title: '', subtitle: ''};
chrome.storage.sync.get(null, function (items) {
if ('productlist' in items) {
self.productList = items['productlist'];
}
if ('listbanner' in items) {
self.listBanner = items['listbanner'];
}
m.redraw();
});
}
ResultsApp.view = function () {
var self = this;
return m('div.container', [
m('div.header.centered.w100', [
m('div.titlelogo', m('img', {src: chrome.runtime.getURL('/assets/img/' + chrome.i18n.getMessage('stapleslogo'))})),
m('div.titles', [
m('h1.title', self.listBanner.title),
m('h2.subtitle', self.listBanner.subtitle)
])
]),
Object.keys(self.productList).length > 0 ? gridify(self).map(function (o) {
return m('div.row', o);
}) : ''
]);
}
m.mount(document.getElementById('infresults'), ResultsApp);