xooie 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,132 @@
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/dialog', ['jquery', 'xooie/base'], function($, Base) {
18
+
19
+ var Dialog = Base('dialog', function(){
20
+ var self = this;
21
+
22
+ this.id = Dialog._counter++;
23
+
24
+ Dialog._instances[this.id] = this;
25
+
26
+ this.root.attr('data-dialog-id', this.id);
27
+
28
+ //add accessibility attributes
29
+ this.root.find(this.options.containerSelector).attr('role', 'dialog');
30
+
31
+ this.root.addClass('xooie-dialog');
32
+
33
+ this.handlers = {
34
+ mouseup: function(event){
35
+ Dialog.close(self.id);
36
+ },
37
+
38
+ keyup: function(event){
39
+ if([13,32].indexOf(event.which) !== -1){
40
+ Dialog.close(self.id);
41
+ }
42
+ }
43
+ };
44
+ });
45
+
46
+ Dialog.setDefaultOptions({
47
+ closeButtonSelector: '[data-role="closeButton"]',
48
+ containerSelector: '[data-role="container"]',
49
+
50
+ dialogActiveClass: 'is-dialog-active'
51
+ });
52
+
53
+ Dialog.setCSSRules({
54
+ '.xooie-dialog': {
55
+ position: 'fixed',
56
+ top: 0,
57
+ bottom: 0,
58
+ left: 0,
59
+ right: 0
60
+ }
61
+ });
62
+
63
+ Dialog.prototype.activate = function(){
64
+ this.root.addClass(this.options.dialogActiveClass);
65
+
66
+ if(Dialog._active === this) {
67
+ return;
68
+ }
69
+
70
+ if(Dialog._active){
71
+ Dialog._active.deactivate();
72
+ }
73
+
74
+ this.root.find(this.options.closeButtonSelector)
75
+ .on(this.handlers);
76
+
77
+ Dialog._active = this;
78
+
79
+ this.root.trigger('dialogActive');
80
+ };
81
+
82
+ Dialog.prototype.deactivate = function(){
83
+ this.root.removeClass(this.options.dialogActiveClass);
84
+
85
+ if (Dialog._active !== this) {
86
+ return;
87
+ }
88
+
89
+ this.root.find(this.options.closeButtonSelector)
90
+ .off(this.handlers);
91
+
92
+ Dialog._active = null;
93
+
94
+ this.root.trigger('dialogInactive');
95
+ };
96
+
97
+ Dialog._instances = [];
98
+ Dialog._counter = 0;
99
+ Dialog._active = null;
100
+ Dialog._queue = [];
101
+
102
+ Dialog.open = function(id){
103
+ //get dialog instance
104
+ var dialog = this._instances[id];
105
+
106
+ if (typeof dialog === 'undefined' || this._active === dialog){
107
+ return;
108
+ }
109
+
110
+ if (this._active) {
111
+ this._queue.push(dialog);
112
+ } else {
113
+ dialog.activate();
114
+ }
115
+
116
+ };
117
+
118
+ Dialog.close = function(){
119
+ //get dialog instance
120
+ if(!this._active) {
121
+ return;
122
+ }
123
+
124
+ this._active.deactivate();
125
+
126
+ if (this._queue.length > 0) {
127
+ this._queue.pop().activate();
128
+ }
129
+ };
130
+
131
+ return Dialog;
132
+ });
@@ -0,0 +1,273 @@
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
+ });
@@ -14,9 +14,10 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- define('xooie/event_handler', ['jquery', 'xooie/helpers'], function($, helpers) {
17
+ define('xooie/event_handler', ['jquery', 'xooie/helpers'], function ($, helpers) {
18
+ 'use strict';
18
19
 
19
- var EventHandler = function(namespace) {
20
+ var EventHandler = function (namespace) {
20
21
  this.namespace = namespace;
21
22
 
22
23
  this.handlers = {};
@@ -25,20 +26,17 @@ define('xooie/event_handler', ['jquery', 'xooie/helpers'], function($, helpers)
25
26
  };
26
27
 
27
28
  function format(type, namespace) {
28
- if (!namespace) {
29
- return type;
30
- } else {
31
- return type + '.' + namespace;
32
- }
29
+ return !namespace ? type : type + '.' + namespace;
33
30
  }
34
31
 
35
- EventHandler.prototype.add = function(type, method) {
36
- var self = this,
37
- formattedType, t;
32
+ EventHandler.prototype.add = function (type, method) {
33
+ var self, formattedType, t;
34
+
35
+ self = this;
38
36
 
39
37
  if (helpers.isObject(type) && helpers.isUndefined(method)) {
40
- for(t in type) {
41
- if (helpers.isFunction(type[t])) {
38
+ for (t in type) {
39
+ if (type.hasOwnProperty(t) && helpers.isFunction(type[t])) {
42
40
  this.add(t, type[t]);
43
41
  }
44
42
  }
@@ -49,7 +47,7 @@ define('xooie/event_handler', ['jquery', 'xooie/helpers'], function($, helpers)
49
47
  formattedType = format(type, this.namespace);
50
48
 
51
49
  if (helpers.isUndefined(this.handlers[formattedType])) {
52
- this.handlers[formattedType] = function(e) {
50
+ this.handlers[formattedType] = function (e) {
53
51
  self.fire(e, this, arguments);
54
52
  };
55
53
  }
@@ -61,15 +59,15 @@ define('xooie/event_handler', ['jquery', 'xooie/helpers'], function($, helpers)
61
59
  this._callbacks[type].add(method);
62
60
  };
63
61
 
64
- EventHandler.prototype.clear = function(type) {
65
- delete(this.handlers[format(type, this.namespace)]);
62
+ EventHandler.prototype.clear = function (type) {
63
+ delete (this.handlers[format(type, this.namespace)]);
66
64
 
67
65
  if (!helpers.isUndefined(this._callbacks[type])) {
68
66
  this._callbacks[type].empty();
69
67
  }
70
68
  };
71
69
 
72
- EventHandler.prototype.fire = function(event, context, args) {
70
+ EventHandler.prototype.fire = function (event, context, args) {
73
71
  if (event.namespace && event.namespace !== this.namespace) {
74
72
  return;
75
73
  }
@@ -18,10 +18,11 @@
18
18
 
19
19
  // Adds Array.prototype.indexOf functionality to IE<9 (From MDN)
20
20
  if (!Array.prototype.indexOf) {
21
- Array.prototype.indexOf = function (searchElement , fromIndex) {
22
- var i,
23
- pivot = (fromIndex) ? fromIndex : 0,
24
- length;
21
+ Array.prototype.indexOf = function (searchElement, fromIndex) {
22
+ 'use strict';
23
+ var i, pivot, length;
24
+
25
+ pivot = fromIndex || 0;
25
26
 
26
27
  if (!this) {
27
28
  throw new TypeError();
@@ -37,7 +38,7 @@ if (!Array.prototype.indexOf) {
37
38
  pivot = length - Math.abs(pivot);
38
39
  }
39
40
 
40
- for (i = pivot; i < length; i++) {
41
+ for (i = pivot; i < length; i += 1) {
41
42
  if (this[i] === searchElement) {
42
43
  return i;
43
44
  }
@@ -48,25 +49,29 @@ if (!Array.prototype.indexOf) {
48
49
 
49
50
  // Adds Function.prototype.bind to browsers that do not support it
50
51
  if (!Function.prototype.bind) {
51
- Function.prototype.bind = function(context) {
52
- var f = this,
53
- args = Array.prototype.slice.call(arguments, 1);
52
+ Function.prototype.bind = function (context) {
53
+ 'use strict';
54
+ var f, args;
55
+
56
+ f = this;
57
+ args = Array.prototype.slice.call(arguments, 1);
54
58
 
55
- return function() {
56
- return f.apply(context, args.concat(Array.prototype.slice.call(arguments)));
57
- };
59
+ return function () {
60
+ return f.apply(context, args.concat(Array.prototype.slice.call(arguments)));
58
61
  };
62
+ };
59
63
  }
60
64
 
61
-
62
65
  /**
63
66
  * class Xooie.helpers
64
67
  *
65
68
  * A collection of helper methods used by Xooie modules.
66
69
  **/
67
70
 
68
- define('xooie/helpers', ['jquery'], function($){
69
- var helpers = {};
71
+ define('xooie/helpers', [], function () {
72
+ 'use strict';
73
+
74
+ var helpers = {
70
75
  /**
71
76
  * Xooie.helpers.toAry(str) -> Array
72
77
  * - str (String | Array): The string to be converted to an array, or an array.
@@ -74,32 +79,37 @@ define('xooie/helpers', ['jquery'], function($){
74
79
  * Converts a string to an array, or returns the passed argument if it is already an array. Used
75
80
  * when parsing data attributes that can be either a space-delineated string or an array.
76
81
  **/
77
- helpers.toAry = function(str) {
78
- if (typeof str === 'string') {
79
- return str.split(/\s+/);
80
- } else if (str instanceof Array) {
81
- return str;
82
- }
83
- };
82
+ toAry: function (str) {
83
+ if (typeof str === 'string') {
84
+ return str.split(/\s+/);
85
+ }
84
86
 
85
- helpers.toInt = function(int) {
86
- return parseInt(int, 10);
87
- };
87
+ if (str instanceof Array) {
88
+ return str;
89
+ }
90
+ },
88
91
 
89
- helpers.isArray = Array.isArray || function(ary) {
90
- return Array.prototype.toString(ary) === '[object Array]';
91
- };
92
+ toInt: function (int) {
93
+ return parseInt(int, 10);
94
+ },
92
95
 
93
- helpers.isObject = function(obj) {
94
- return Object.prototype.toString(obj) === '[object Object]';
95
- };
96
+ isArray: (function () {
97
+ return Array.isArray || function (ary) {
98
+ return Array.prototype.toString(ary) === '[object Array]';
99
+ };
100
+ }()),
96
101
 
97
- helpers.isUndefined = function(obj) {
98
- return obj === void 0;
99
- };
102
+ isObject: function (obj) {
103
+ return Object.prototype.toString(obj) === '[object Object]';
104
+ },
105
+
106
+ isUndefined: function (obj) {
107
+ return obj === undefined;
108
+ },
100
109
 
101
- helpers.isFunction = function(func) {
102
- return typeof func === 'function';
110
+ isFunction: function (func) {
111
+ return typeof func === 'function';
112
+ }
103
113
  };
104
114
 
105
115
  return helpers;