/
application.js
56 lines (50 loc) · 1.36 KB
/
application.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
//= require jquery
//= require jquery_ujs
//= require foundation
//= require tabletop
//= require mustache
//= require_tree .
$(document).foundation();
var APP = APP || {};
APP = {
common: {
init: function() {
alert("init");
},
},
mail_merges: {
'new': function() {
var public_spreadsheet_url = 'https://docs.google.com/spreadsheet/pub?key=0AuI4VolCrNFLdGF3YUVqQlRTV2ZHZ3hRVTNrQ2VMRFE&output=html';
Tabletop.init( { key: public_spreadsheet_url,
callback: APP.mail_merges.display,
simpleSheet: true } );
},
'display': function(data, tabletop) {
for(var i = 0; i < data.length; i++) {
var output = Mustache.render("Say {{greeting}} to {{name}} from {{company}}", data[i]);
alert(output);
}
console.log(data);
}
},
}
UTIL = {
exec : function(controller, action){
var ns = APP,
action = (action === undefined) ? "init" : action;
if (controller !== "" &&
ns[controller] &&
typeof ns[controller][action] === "function" ) {
ns[controller][action]();
}
},
init: function() {
var body = document.body,
controller = body.getAttribute("data-controller"),
action = body.getAttribute("data-action");
UTIL.exec("common");
UTIL.exec(controller);
UTIL.exec(controller, action);
}
};
$(document).ready(UTIL.init);