forked from rmurphey/jqfundamentals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspecials-object-literal.js
61 lines (49 loc) · 1.12 KB
/
specials-object-literal.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
$(document).ready(function() {
var specials = {
config : {
dataUrl : 'json/specials.json',
containerType : '<div/>'
},
init : function() {
$('#specials li.buttons').remove();
specials.$container = $(specials.config.containerType)
.appendTo('#specials');
$('#specials select')
.bind('change', specials.handleChange)
},
getAjaxConfig : function() {
return {
url : specials.config.dataUrl,
type : 'get',
dataType : 'json',
success : specials.handleResponse
};
},
cache : null,
handleResponse : function(json) {
var html = specials.buildHtmlFromJson(json);
specials.cache = html;
specials.$container.html(html);
},
getData : function(val) {
if (specials.cache) {
specials.handleResponse(specials.cache);
return;
}
$.ajax(specials.getAjaxConfig());
},
handleChange : function(e) {
var $select = $(this);
if (!$select.val()) {
specials.$container.empty();
return;
}
specials.getData($select.val());
},
buildHtmlFromJson : function() {
// ...
return('hello');
}
};
specials.init();
});