-
Notifications
You must be signed in to change notification settings - Fork 0
/
vcsb.js
50 lines (40 loc) · 1.16 KB
/
vcsb.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
(function(){
var root = this;
var vcsb;
if (typeof exports !== 'undefined') {
vcsb = exports;
}
else {
vcsb = root.vcsb = {};
}
var _ = root._;
if (!_ && (typeof require !== 'undefined')) _ = require('underscore')._;
var $ = root.jQuery || root.Zepto;
if (typeof require !== 'undefined'){
vcsb.data = require('data');
}
else {
vcsb.data = $.ajax({
url: "./data.json"
});
}
var randomInt = function(min, max){
return Math.floor(Math.random() * (max - min + 1)) + min;
};
vcsb.buildMsg = function(data, cb){
var num1 = randomInt(0, data.cool.length-1);
var num2 = randomInt(0, data.story.length-1);
var num3 = randomInt(0, data.bro.length-1);
cb(data.cool[num1] + " " + data.story[num2] + ", " + data.bro[num3]);
};
vcsb.getMsg = function(cb){
if(typeof vcsb.data.done !== 'undefined'){
vcsb.data.done(function(data){
vcsb.buildMsg(data, cb);
});
}
else{
vcsb.buildMsg(vcsb.data, cb);
}
};
}).call(this);