blob: 49b08acfc56648c17e0ec78acd96a3b91c6b4cd4 (
plain) (
blame)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
/**
* Gumby Framework
* ---------------
*
* Follow @gumbycss on twitter and spread the love.
* We worked super hard on making this awesome and released it to the web.
* All we ask is you leave this intact. #gumbyisawesome
*
* Gumby Framework
* http://gumbyframework.com
*
* Built with love by your friends @digitalsurgeons
* http://www.digitalsurgeons.com
*
* Free to use under the MIT license.
* http://www.opensource.org/licenses/mit-license.php
*/
!function() {
'use strict';
function Gumby() {
this.$dom = $(document);
this.isOldie = !!this.$dom.find('html').hasClass('oldie');
this.click = 'click';
this.onReady = this.onOldie = this.onTouch = false;
this.uiModules = {};
this.inits = {};
}
// initialize Gumby
Gumby.prototype.init = function() {
// init UI modules
this.initUIModules();
var scope = this;
// call ready() code when dom is ready
this.$dom.ready(function() {
if(scope.onReady) {
scope.onReady();
}
// call oldie() callback if applicable
if(scope.isOldie && scope.onOldie) {
scope.onOldie();
}
// call touch() callback if applicable
if(Modernizr.touch && scope.onTouch) {
scope.onTouch();
}
});
};
// public helper - set Gumby ready callback
Gumby.prototype.ready = function(code) {
if(code && typeof code === 'function') {
this.onReady = code;
}
};
// public helper - set oldie callback
Gumby.prototype.oldie = function(code) {
if(code && typeof code === 'function') {
this.onOldie = code;
}
};
// public helper - set touch callback
Gumby.prototype.touch = function(code) {
if(code && typeof code === 'function') {
this.onTouch = code;
}
};
// public helper - return debuggin object including uiModules object
Gumby.prototype.debug = function() {
return {
$dom: this.$dom,
isOldie: this.isOldie,
uiModules: this.uiModules,
click: this.click
};
};
// grab attribute value, testing data- gumby- and no prefix
Gumby.prototype.selectAttr = function() {
var i = 0;
// any number of attributes can be passed
for(; i < arguments.length; i++) {
// various formats
var attr = arguments[i],
dataAttr = 'data-'+arguments[i],
gumbyAttr = 'gumby-'+arguments[i];
// first test for data-attr
if(this.attr(dataAttr)) {
return this.attr(dataAttr);
// next test for gumby-attr
} else if(this.attr(gumbyAttr)) {
return this.attr(gumbyAttr);
// finally no prefix
} else if(this.attr(attr)) {
return this.attr(attr);
}
}
// none found
return false;
};
// add an initialisation method
Gumby.prototype.addInitalisation = function(ref, code) {
this.inits[ref] = code;
};
// initialize a uiModule
Gumby.prototype.initialize = function(ref) {
if(this.inits[ref] && typeof this.inits[ref] === 'function') {
this.inits[ref]();
}
};
// store a UI module
Gumby.prototype.UIModule = function(data) {
var module = data.module;
this.uiModules[module] = data;
};
// loop round and init all UI modules
Gumby.prototype.initUIModules = function() {
var x;
for(x in this.uiModules) {
this.uiModules[x].init();
}
};
window.Gumby = new Gumby();
}();
|