-
Notifications
You must be signed in to change notification settings - Fork 0
/
yip.js
62 lines (46 loc) · 1.38 KB
/
yip.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 (global, $) {
// 'new' an object
var Yip = function(sound, language) {
return new Yip.init(sound, language);
};
var supportedLanguages = ['en', 'es'];
var exclamations = {
en: 'Say',
es: 'Diga'
};
Yip.prototype = {
exclaim: function() {
return exclamations[this.language] + ' ' + this.sound + '!';
},
validate: function() {
if (supportedLanguages.indexOf(this.language) < 0) {
throw "Invalid language";
}
},
setLang: function(lang) {
this.language = lang;
this.validate();
return this;
},
HTMLExclaim: function(selector) {
if(!$) {
throw 'jQuery not loaded';
}
if(!selector) {
throw 'Missing selector';
}
console.log('selector', selector);
var msg = this.exclaim();
$(selector).html(msg);
return this;
}
};
Yip.init = function(sound, language) {
this.sound = sound || 'yeep';
this.language = language || 'en';
};
// trick from jQuery to get around using the 'new' keyword
Yip.init.prototype = Yip.prototype;
// exposing our framework to the global environment
global.yip = global.y$ = Yip;
}(window, jQuery));