-
Notifications
You must be signed in to change notification settings - Fork 14
/
app.js
62 lines (56 loc) · 2.23 KB
/
app.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
(function ( root, factory ) {
if ( typeof module === "object" && module.exports ) {
// Node, or CommonJS-Like environments
// Intentionally returning a factory method
module.exports = function(app) {
return factory(app);
};
} else {
// Browser globals
factory( root.app = {}, root );
}
})( typeof global !== "undefined" ? global : this.window || this.global, function ( exports, global) {
exports.init = function() {
function insertResults(results){
exports.components.ui.insertIntoNode(listItemContainer,
results.map(exports.components.utils.apiResultToHTML).join(''));
}
var searchInput = document.querySelector('#searchInput');
var searchButton = document.querySelector('#searchBtn');
var listItemContainer = document.querySelector('#listItemContainer');
var cursor = new app.components.Cursor;
var rangeFilterNodes = {
minInput: document.querySelector('#priceFilterMin'),
maxInput: document.querySelector('#priceFilterMax'),
filterButton: document.querySelector('#priceFilterBtn')
};
var rangeFilterListeners = {
filter: function(ranges) {
exports.components.ui.clearNodeInnerHTML(listItemContainer);
exports.components.api.search({
data: searcher.getValue(),
price: ranges.min + '-' + ranges.max
}).then(function(result) {
insertResults(result.results);
});
}
};
var rangeFilter = new exports.uiComponents.RangeFilter(rangeFilterNodes, rangeFilterListeners);
var searcherNodes = {
searchButton: searchButton,
searchInput: searchInput
};
var searcherListeners = {
search: function(value) {
exports.components.ui.clearNodeInnerHTML(listItemContainer);
exports.components.api.search({
data: value,
}).then(function(result) {
insertResults(result.results);
});
}
};
var searcher = new exports.uiComponents.Searcher(searcherNodes, searcherListeners);
};
document.addEventListener('DOMContentLoaded', exports.init.bind(exports));
});