xooie 1.0.5 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,273 +0,0 @@
1
- /*
2
- * Copyright 2012 Comcast
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
-
17
- define('xooie/dropdown', ['jquery', 'xooie/base'], function($, Base) {
18
-
19
- var parseWhich = function(which) {
20
- if (typeof which === 'string') {
21
- which = which.split(',');
22
- return which.map(function(string){ return parseInt(string, 10); });
23
- } else if (typeof which === 'number') {
24
- return [which];
25
- }
26
-
27
- return which;
28
- };
29
-
30
- var Dropdown = Base('dropdown', function() {
31
- var self = this,
32
- handles = self.getHandle(),
33
- expanders = self.getExpander();
34
-
35
- this.handlers = {
36
- off: function(event){
37
- if ((typeof event.data.not !== 'undefined' && ($(event.data.not).is($(this)) || $(event.target).parents(event.data.not).length > 0)) || (typeof event.data.which !== 'undefined' && event.data.which.indexOf(event.which) === -1) || ($(event.target).is(self.getExpander(event.data.index)) || $(event.target).parents(self.options.dropdownExpanderSelector).length > 0) && !$(event.target).is($(this))) {
38
- return true;
39
- }
40
-
41
- event.preventDefault();
42
-
43
- self.collapse(event.data.index, event.data);
44
- },
45
-
46
- on: function(event){
47
- var index = event.data.index || parseInt($(this).attr('data-dropdown-index'), 10),
48
- delay = event.data.delay,
49
- handle = $(this);
50
-
51
- if ((typeof event.data.not !== 'undefined' && ($(event.data.not).is($(this)) || $(event.target).parents(event.data.not).length > 0)) || typeof event.data.which !== 'undefined' && event.data.which.indexOf(event.which) === -1) {
52
- return true;
53
- }
54
-
55
- event.preventDefault();
56
-
57
- self.expand(index, event.data);
58
- }
59
- };
60
-
61
- this.timers = {
62
- expand: [],
63
- collapse: [],
64
- throttle: []
65
- };
66
-
67
- this.addHandlers('on');
68
-
69
- this.root.on({
70
- dropdownExpand: function(event, index){
71
- self.removeHandlers('on', index);
72
-
73
- self.addHandlers('off', index);
74
-
75
- $(this).attr('aria-selected', true);
76
- self.getExpander(index).attr('aria-hidden', false);
77
- },
78
-
79
- dropdownCollapse: function(event, index){
80
- self.removeHandlers('off', index);
81
-
82
- self.addHandlers('on', index);
83
-
84
- $(this).attr('aria-selected', false);
85
- self.getExpander(index).attr('aria-hidden', true);
86
- }
87
- }, this.options.dropdownHandleSelector);
88
-
89
- this.root.on('xooie-init.dropdown xooie-refresh.dropdown', function(){
90
- handles.each(function(index){
91
- var handle = $(this),
92
- expander = expanders.eq(index);
93
-
94
-
95
- handle.attr({
96
- 'data-dropdown-index': index,
97
- 'aria-selected': false
98
- });
99
- expander.attr({
100
- 'data-dropdown-index': index,
101
- 'aria-hidden': true
102
- });
103
- });
104
- });
105
-
106
- expanders.on('mouseover focus', function(){
107
- var index = parseInt($(this).attr('data-dropdown-index'), 10);
108
-
109
- if (self.timers.collapse[index]){
110
- self.timers.collapse[index] = clearTimeout(self.timers.collapse[index]);
111
-
112
- $(this).on('mouseleave blur', {index: index}, function(event){
113
- self.collapse(event.data.index, 0);
114
- $(this).unbind(event);
115
- });
116
- }
117
- });
118
-
119
- });
120
-
121
- Dropdown.setDefaultOptions({
122
- dropdownHandleSelector: '[data-role="dropdown-handle"]',
123
- dropdownExpanderSelector: '[data-role="dropdown-content"]',
124
-
125
- activeDropdownClass: 'is-dropdown-active',
126
-
127
- throttleDelay: 300,
128
- triggers: {
129
- on: {
130
- focus: {
131
- delay: 0
132
- }
133
- },
134
- off: {
135
- blur: {
136
- delay: 0
137
- }
138
- }
139
- }
140
-
141
- });
142
-
143
- Dropdown.prototype.getTriggerHandle = function(triggerData, index){
144
- var handles = this.getHandle(index);
145
-
146
- if (triggerData.selector) {
147
- return triggerData.selector === 'document' ? $(document) : $(triggerData.selector);
148
- } else {
149
- return handles;
150
- }
151
- };
152
-
153
- Dropdown.prototype.addHandlers = function(state, index){
154
- var trigger, handle, triggerData, countName;
155
-
156
- triggerData = this.options.triggers[state];
157
-
158
- for (trigger in triggerData) {
159
- if (typeof triggerData[trigger].which !== 'undefined') {
160
- triggerData[trigger].which = parseWhich(triggerData[trigger].which);
161
- }
162
-
163
- countName = [trigger,state,'count'].join('-');
164
-
165
- handle = this.getTriggerHandle(triggerData[trigger], index);
166
-
167
- handle.data(countName, handle.data(countName) + 1 || 1);
168
-
169
- handle.on(trigger, $.extend({delay: 0, index: index}, triggerData[trigger]), this.handlers[state]);
170
- }
171
- };
172
-
173
- Dropdown.prototype.removeHandlers = function(state, index){
174
- var trigger, handle, triggerData, countName, eventCount;
175
-
176
- triggerData = this.options.triggers[state];
177
-
178
- for (trigger in triggerData) {
179
- handle = this.getTriggerHandle(triggerData[trigger], index);
180
-
181
- countName = [trigger,state,'count'].join('-');
182
-
183
- eventCount = handle.data(countName) - 1;
184
-
185
- if (eventCount <= 0) {
186
- handle.unbind(trigger, this.handlers[state]);
187
-
188
- handle.data(countName, 0);
189
- } else {
190
- handle.data(countName, eventCount);
191
- }
192
- }
193
- };
194
-
195
- Dropdown.prototype.getHandle = function(index){
196
- var handles = this.root.find(this.options.dropdownHandleSelector);
197
-
198
- return (typeof index !== 'undefined' && index >= 0) ? handles.eq(index) : handles;
199
- };
200
-
201
- Dropdown.prototype.getExpander = function(index){
202
- var selectorString;
203
-
204
- if (typeof index === 'undefined' || isNaN(index)) {
205
- selectorString = this.options.dropdownExpanderSelector;
206
- } else {
207
- selectorString = this.options.dropdownExpanderSelector + '[data-dropdown-index="' + index + '"]';
208
- }
209
-
210
- return this.root.find(selectorString);
211
- };
212
-
213
- Dropdown.prototype.setState = function(index, data, active){
214
- if (typeof index === 'undefined' || isNaN(index)) {
215
- return;
216
- }
217
-
218
- var state = active ? 'expand' : 'collapse',
219
- counterState = active ? 'collapse' : 'expand',
220
- delay = data.delay;
221
-
222
- this.timers[counterState][index] = clearTimeout(this.timers[counterState][index]);
223
-
224
- if (this.timers.throttle[index] || this.timers[state][index]) {
225
- return;
226
- }
227
-
228
- this.timers[state][index] = setTimeout(function(i, _state, _active, _data) {
229
- var expander = this.getExpander(i),
230
- handle = this.getHandle(i),
231
- self = this;
232
-
233
- this.timers[_state][i] = clearTimeout(this.timers[_state][i]);
234
-
235
- expander.toggleClass(this.options.activeDropdownClass, _active);
236
- this.getHandle(i).toggleClass(this.options.activeDropdownClass, _active);
237
-
238
- if (_active){
239
- handle.trigger('dropdownExpand', [i, _data]);
240
- //this.setFocus(expander);
241
- } else {
242
- handle.trigger('dropdownCollapse', [i, _data]);
243
- }
244
-
245
- if (this.options.throttleDelay > 0){
246
- this.timers.throttle[i] = setTimeout(function(){
247
- self.timers.throttle[i] = clearTimeout(self.timers.throttle[i]);
248
- }, this.options.throttleDelay);
249
- }
250
-
251
- }.bind(this, index, state, active, data), delay);
252
- };
253
-
254
- Dropdown.prototype.expand = function(index, data) {
255
- if (!this.getHandle(index).hasClass(this.options.activeDropdownClass)) {
256
- this.setState(index, data, true);
257
- }
258
- };
259
-
260
- Dropdown.prototype.collapse = function(index, data) {
261
- if (this.getHandle(index).hasClass(this.options.activeDropdownClass)) {
262
- this.setState(index, data, false);
263
- }
264
- };
265
-
266
- Dropdown.prototype.setFocus = function(element){
267
- element.find('a,input,textarea,button,select,iframe,[tabindex][tabindex!=-1]')
268
- .first()
269
- .focus();
270
- };
271
-
272
- return Dropdown;
273
- });
@@ -1,125 +0,0 @@
1
- /*
2
- * Copyright 2012 Comcast
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
-
17
- define('xooie/tab', ['jquery', 'xooie/base'], function($, Base) {
18
-
19
- var Tab = Base('tab', function() {
20
- var self = this;
21
-
22
- this.createTabs();
23
- });
24
-
25
- Tab.setDefaultOptions({
26
- panelSelector: '[data-role="tab-panel"]',
27
- stripSelector: '[data-role="tab-strip"]',
28
- controlSelector: '[data-role="tab-selector"]',
29
- controlButtonSelector: '[data-tab-control]',
30
- tabTemplateSelector: '[data-role="tab-template"]',
31
-
32
- activeTabClass: 'is-tab-active'
33
- });
34
-
35
- $.extend(Tab.prototype, {
36
- switchToTab: function(index, key) {
37
- if (index !== this._currentTab && index >= 0 && index < this.getPanel().length) {
38
- var e = $.Event('tabChange');
39
- e.fromTab = this._currentTab;
40
- e.toTab = index;
41
- e.which = key;
42
-
43
- this.getPanel(this._currentTab).removeClass(this.options.activeTabClass);
44
- this.getTab(this._currentTab).removeClass(this.options.activeTabClass);
45
-
46
- this.getPanel(index).addClass(this.options.activeTabClass);
47
- this.getTab(index).addClass(this.options.activeTabClass);
48
-
49
- this._currentTab = index;
50
-
51
- this.root.trigger(e);
52
- }
53
- },
54
-
55
- getPanel: function(index) {
56
- var panels = this.root.find(this.options.panelSelector);
57
-
58
- if (typeof index === 'undefined') {
59
- return panels;
60
- } else {
61
- return panels.eq(index);
62
- }
63
- },
64
-
65
- getTab: function(index) {
66
- var tabs = this.root.find(this.options.controlSelector);
67
- if (typeof index === 'undefined') {
68
- return tabs;
69
- } else {
70
- return tabs.eq(index);
71
- }
72
- },
73
-
74
- createTabs: function() {
75
- var tabStrip = this.root.find(this.options.stripSelector),
76
- template = this.root.find(this.options.tabTemplateSelector),
77
- panels = this.getPanel(),
78
- i, element, control,
79
- activeTab = 0, handler, self = this;
80
-
81
- if (template.length === 0){
82
- return;
83
- }
84
-
85
- this.getTab().remove();
86
-
87
- handler = function(event) {
88
- var keys = [13,32];
89
-
90
- if ([1,13,32].indexOf(event.which) !== -1){
91
- self.switchToTab($(this).data('tab-index'), event.which);
92
- }
93
- };
94
-
95
- for (i = 0; i < panels.length; i++) {
96
- if(tabStrip.length > 0 && template.length > 0) {
97
- element = this.render(template, {
98
- panel_label: panels.eq(i).attr('data-tab-label'),
99
- panel_index: i,
100
- panel_has_next: (i < panels.length - 1)
101
- });
102
-
103
- if (element.is(this.options.controlButtonSelector)) {
104
- control = element;
105
- } else {
106
- control = element.find(this.options.controlButtonSelector);
107
- }
108
-
109
- control.data('tab-index', i)
110
- .on('mouseup keyup', handler);
111
-
112
- tabStrip.append(element);
113
- }
114
-
115
- if (panels.eq(i).hasClass(this.options.activeTabClass)) {
116
- activeTab = i;
117
- }
118
- }
119
-
120
- this.switchToTab(activeTab);
121
- }
122
- });
123
-
124
- return Tab;
125
- });
@@ -1,169 +0,0 @@
1
- /*
2
- * Copyright 2012 Comcast
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
-
17
- var $X, Xooie;
18
-
19
- $X = Xooie = (function(static_config) {
20
- var config = {
21
- modules: {},
22
- addons: {}
23
- },
24
- obj = function() {
25
- return false;
26
- },
27
- gcTimer = null;
28
-
29
- function copyObj(dst, src) {
30
- var name;
31
-
32
- for (name in src) {
33
- if (src.hasOwnProperty(name)) {
34
- dst[name] = src[name];
35
- }
36
- }
37
- }
38
-
39
- function gcCallback() {
40
- if (typeof Xooie.garbageCollect !== 'undefined') {
41
- Xooie.garbageCollect();
42
- }
43
- }
44
-
45
- obj.config = function(cfg) {
46
- var name;
47
-
48
- for (name in cfg) {
49
- if (cfg.hasOwnProperty(name)) {
50
- if (name === 'modules' || name == 'addons') {
51
- copyObj(config[name], cfg[name]);
52
- } else {
53
- config[name] = cfg[name];
54
- }
55
- }
56
- }
57
-
58
- if (typeof cfg.gcInterval !== 'undefined') {
59
- if (config.gcInterval) {
60
- gcTimer = setInterval(gcCallback, config.gcInterval);
61
- } else {
62
- if (gcTimer) {
63
- clearInterval(gcTimer);
64
- }
65
- gcTimer = null;
66
- }
67
- }
68
- };
69
-
70
- obj.mapName = function(name, type, root) {
71
- if (typeof config[type][name] === 'undefined') {
72
- return root + name;
73
- } else {
74
- return config[type][name];
75
- }
76
- };
77
-
78
- obj.config({
79
- gcInterval: 0
80
- });
81
-
82
- if (static_config) {
83
- obj.config(static_config);
84
- }
85
-
86
- return obj;
87
- }(Xooie));
88
-
89
- define('xooie', ['jquery'], function($){
90
- var config = Xooie.config,
91
- mapName = Xooie.mapName,
92
- loadedModules = {};
93
-
94
- $X = Xooie = function(element){
95
- element = $(element);
96
-
97
- var widgetElements = element.find('[data-widget-type]');
98
-
99
- if (element.is('[data-widget-type]')){
100
- widgetElements = widgetElements.add(element);
101
- }
102
-
103
- widgetElements.each(function(){
104
- var node = $(this),
105
- module_name,
106
- types = node.data('widgetType').split(/\s+/),
107
- require_handler = function(Widget) {
108
- new Widget(node);
109
- };
110
-
111
- for (var i = 0; i < types.length; i++) {
112
- module_name = $X.mapName(types[i], 'modules', 'xooie/');
113
-
114
- $X._requireShim(module_name, require_handler);
115
- }
116
- });
117
- };
118
-
119
- Xooie.config = config;
120
- Xooie.mapName = mapName;
121
-
122
- Xooie._requireShim = function(module, callback) {
123
- var moduleSpec;
124
-
125
- if (typeof loadedModules[module] === 'undefined') {
126
- moduleSpec = loadedModules[module] = {
127
- content: null,
128
- loaded: false,
129
- callbacks: []
130
- };
131
-
132
- require([module], function(Module) {
133
- var i;
134
-
135
- moduleSpec.content = Module;
136
- moduleSpec.loaded = true;
137
-
138
- for (i = 0; i < moduleSpec.callbacks.length; i++) {
139
- moduleSpec.callbacks[i](Module);
140
- }
141
-
142
- moduleSpec.callbacks = [];
143
- });
144
- } else {
145
- moduleSpec = loadedModules[module];
146
- }
147
-
148
- if (moduleSpec.loaded) {
149
- callback(moduleSpec.content);
150
- } else {
151
- moduleSpec.callbacks.push(callback);
152
- }
153
- };
154
-
155
- Xooie.registeredClasses = [];
156
- Xooie.garbageCollect = function() {
157
- for (var i = 0; i < this.registeredClasses.length; i++) {
158
- this.registeredClasses[i].garbageCollect();
159
- }
160
- };
161
-
162
- return Xooie;
163
- });
164
-
165
- require(['jquery', 'xooie'], function($, $X){
166
- $(document).ready(function() {
167
- $X($(this));
168
- });
169
- });