xooie 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -21,8 +21,8 @@
21
21
  * specific functionality.
22
22
  **/
23
23
 
24
- define('xooie/widgets/base', ['jquery', 'xooie/xooie', 'xooie/helpers', 'xooie/shared', 'xooie/keyboard_navigation'], function($, $X, helpers, shared, keyboardNavigation) {
25
-
24
+ define('xooie/widgets/base', ['jquery', 'xooie/xooie', 'xooie/helpers', 'xooie/shared'], function ($, $X, helpers, shared) {
25
+ "use strict";
26
26
  var Widget;
27
27
 
28
28
  /**
@@ -34,10 +34,12 @@ define('xooie/widgets/base', ['jquery', 'xooie/xooie', 'xooie/helpers', 'xooie/s
34
34
  **/
35
35
 
36
36
  $.event.special['xooie-init'] = {
37
- add: function(handleObj) {
38
- var id = $(this).data('xooieInstance');
39
- if (typeof id !== 'undefined') {
40
- var event = $.Event('xooie-init');
37
+ add: function (handleObj) {
38
+ var id, event;
39
+
40
+ id = $(this).data('xooieInstance');
41
+ if (!helpers.isUndefined(id)) {
42
+ event = $.Event('xooie-init');
41
43
  event.namespace = handleObj.namespace;
42
44
  event.data = handleObj.data;
43
45
 
@@ -59,7 +61,7 @@ define('xooie/widgets/base', ['jquery', 'xooie/xooie', 'xooie/helpers', 'xooie/s
59
61
  *
60
62
  * TODO: Test and document.
61
63
  **/
62
- function roleDetails (name) {
64
+ function roleDetails(name) {
63
65
  return {
64
66
  processor: '_process_role_' + name,
65
67
  renderer: '_render_role_' + name,
@@ -80,7 +82,7 @@ define('xooie/widgets/base', ['jquery', 'xooie/xooie', 'xooie/helpers', 'xooie/s
80
82
  if (helpers.isUndefined(prototype[role.pluralName])) {
81
83
  prototype._definedRoles.push(name);
82
84
 
83
- prototype[role.pluralName] = function() {
85
+ prototype[role.pluralName] = function () {
84
86
  return this[role.getter]();
85
87
  };
86
88
  }
@@ -93,19 +95,18 @@ define('xooie/widgets/base', ['jquery', 'xooie/xooie', 'xooie/helpers', 'xooie/s
93
95
  * Recursively checks for the next available index in [[$X._instanceCache]] using [[$X._instanceIndex]]
94
96
  * as a reference point. Returns the index.
95
97
  **/
96
- function cacheInstance (instance) {
97
- if (typeof instance !== 'undefined') {
98
+ function cacheInstance(instance) {
99
+ if (!helpers.isUndefined(instance)) {
98
100
  var index = $X._instanceIndex;
99
101
 
100
102
  $X._instanceIndex += 1;
101
103
 
102
- if (typeof $X._instanceCache[index] === 'undefined') {
104
+ if (helpers.isUndefined($X._instanceCache[index])) {
103
105
  $X._instanceCache[index] = instance;
104
106
 
105
107
  return index;
106
- } else {
107
- return cacheInstance(instance);
108
108
  }
109
+ return cacheInstance(instance);
109
110
  }
110
111
  }
111
112
 
@@ -117,29 +118,32 @@ define('xooie/widgets/base', ['jquery', 'xooie/xooie', 'xooie/helpers', 'xooie/s
117
118
  * Instantiates a new Xooie widget, or returns an existing widget if it is already associated with the element passed.
118
119
  * Any addons passed into the constructor will be instantiated and added to the [[Xooie.Widget#addons]] collection.
119
120
  **/
120
- Widget = function(element, addons) {
121
- var self = this;
121
+
122
+ Widget = shared.create(function (element, addons) {
123
+ var id, self = this;
122
124
 
123
125
  element = $(element);
126
+ addons = addons || [];
124
127
 
125
128
  //set the default options
126
129
  shared.setData(this, element.data());
127
130
 
128
131
  //do instance tracking
129
132
  if (element.data('xooieInstance')) {
130
- if (typeof $X._instanceCache[element.data('xooieInstance')] !== 'undefined'){
133
+ if (!helpers.isUndefined($X._instanceCache[element.data('xooieInstance')])) {
131
134
  element.trigger(this.get('refreshEvent'));
132
135
  return $X._instanceCache[element.data('xooieInstance')];
133
- } else {
134
- this.cleanup();
135
136
  }
137
+ this.cleanup();
136
138
  }
137
139
 
138
- element.on(this.get('initEvent') + ' ' + this.get('refreshEvent'), function(){
140
+ element.on(this.get('initEvent') + ' ' + this.get('refreshEvent'), function () {
139
141
  self._applyRoles();
140
142
  });
141
143
 
142
- var id = cacheInstance(this);
144
+ id = cacheInstance(this);
145
+
146
+ element.attr('data-xooie-instance', id);
143
147
 
144
148
  this.set('id', id);
145
149
 
@@ -147,35 +151,19 @@ define('xooie/widgets/base', ['jquery', 'xooie/xooie', 'xooie/helpers', 'xooie/s
147
151
 
148
152
  element.addClass(this.get('className'))
149
153
  .addClass(this.get('instanceClass'));
154
+ }, function (element, addons) {
155
+ var i, addonAry = [];
150
156
 
151
- var initCheck = function(){
152
- var i;
153
-
154
- if (!self._extendCount || self._extendCount <= 0) {
155
-
156
- if (typeof addons !== 'undefined') {
157
- for (i = 0; i < addons.length; i+=1) {
158
- new addons[i](self);
159
- }
160
- }
161
-
162
- element.attr('data-xooie-instance', id);
157
+ element = $(element);
163
158
 
164
- element.trigger(self.get('initEvent'));
165
- self._extendCount = null;
166
- } else {
167
- setTimeout(initCheck, 0);
159
+ if (!helpers.isUndefined(addons)) {
160
+ for (i = 0; i < addons.length; i += 1) {
161
+ addonAry.push(new addons[i](this));
168
162
  }
169
- };
170
-
171
- if (this._extendCount > 0) {
172
- setTimeout(initCheck, 0);
173
- } else {
174
- initCheck();
175
163
  }
176
164
 
177
- // new keyboardNavigation();
178
- };
165
+ this.root().trigger(this.get('initEvent'));
166
+ });
179
167
 
180
168
  /** internal
181
169
  * Xooie.Widget._renderMethods -> Object
@@ -190,36 +178,32 @@ define('xooie/widgets/base', ['jquery', 'xooie/xooie', 'xooie/helpers', 'xooie/s
190
178
  **/
191
179
  Widget._renderMethods = {
192
180
  //TODO: make this a default template
193
- 'micro_template': function(template, view) {
194
- if (typeof template.micro_render !== 'undefined') {
181
+ 'micro_template': function (template, view) {
182
+ if (!helpers.isUndefined(template.micro_render)) {
195
183
  return $(template.micro_render(view));
196
- } else {
197
- return false;
198
184
  }
185
+ return false;
199
186
  },
200
187
 
201
- 'mustache': function(template, view) {
202
- if (typeof Mustache !== 'undefined' && typeof Mustache.render !== 'undefined') {
188
+ 'mustache': function (template, view) {
189
+ if (!helpers.isUndefined(Mustache) && !helpers.isUndefined(Mustache.render)) {
203
190
  return $(Mustache.render(template.html(), view));
204
- } else {
205
- return false;
206
191
  }
192
+ return false;
207
193
  },
208
194
 
209
- 'jsrender': function(template, view) {
210
- if (typeof template.render !== 'undefined') {
195
+ 'jsrender': function (template, view) {
196
+ if (!helpers.isUndefined(template.render)) {
211
197
  return $(template.render(view));
212
- } else {
213
- return false;
214
198
  }
199
+ return false;
215
200
  },
216
201
 
217
- 'underscore': function(template, view) {
218
- if (typeof _ !== 'undefined' && typeof _.template !== 'undefined') {
202
+ 'underscore': function (template, view) {
203
+ if (!helpers.isUndefined(_) && !helpers.isUndefined(_.template)) {
219
204
  return $(_.template(template.html())(view).trim());
220
- } else {
221
- return false;
222
205
  }
206
+ return false;
223
207
  }
224
208
  };
225
209
 
@@ -231,7 +215,7 @@ define('xooie/widgets/base', ['jquery', 'xooie/xooie', 'xooie/helpers', 'xooie/s
231
215
  *
232
216
  * See [[Xooie.shared.defineWriteOnly]].
233
217
  **/
234
- Widget.defineWriteOnly = function(name) {
218
+ Widget.defineWriteOnly = function (name) {
235
219
  shared.defineWriteOnly(this, name);
236
220
  };
237
221
 
@@ -242,7 +226,7 @@ define('xooie/widgets/base', ['jquery', 'xooie/xooie', 'xooie/helpers', 'xooie/s
242
226
  *
243
227
  * See [[Xooie.shared.defineReadOnly]].
244
228
  **/
245
- Widget.defineReadOnly = function(name, defaultValue){
229
+ Widget.defineReadOnly = function (name, defaultValue) {
246
230
  shared.defineReadOnly(this, name, defaultValue);
247
231
  };
248
232
 
@@ -254,7 +238,7 @@ define('xooie/widgets/base', ['jquery', 'xooie/xooie', 'xooie/helpers', 'xooie/s
254
238
  * A method that defines a property as both readable and writable. In reality it calls both [[Xooie.Widget.defineReadOnly]]
255
239
  * and [[Xooie.Widget.defineWriteOnly]].
256
240
  **/
257
- Widget.define = function(name, defaultValue){
241
+ Widget.define = function (name, defaultValue) {
258
242
  this.defineReadOnly(name, defaultValue);
259
243
  this.defineWriteOnly(name);
260
244
  };
@@ -264,13 +248,13 @@ define('xooie/widgets/base', ['jquery', 'xooie/xooie', 'xooie/helpers', 'xooie/s
264
248
  *
265
249
  * TODO: This needs tests and documentation
266
250
  **/
267
- Widget.defineRole = function(name) {
251
+ Widget.defineRole = function (name) {
268
252
  var role = roleDetails(name);
269
253
 
270
254
  roleDispatcher(name, this.prototype);
271
255
 
272
256
  if (!helpers.isFunction(this.prototype[role.getter])) {
273
- this.prototype[role.getter] = function() {
257
+ this.prototype[role.getter] = function () {
274
258
  return this.root().find(role.selector);
275
259
  };
276
260
  }
@@ -280,10 +264,10 @@ define('xooie/widgets/base', ['jquery', 'xooie/xooie', 'xooie/helpers', 'xooie/s
280
264
  * Xooie.Widget.extend(constr) -> Widget
281
265
  * - constr (Function): The constructor for the new [[Xooie.Widget]] class.
282
266
  *
283
- * See [[Xooie.shared.extend]].
267
+ * See [[Xooie.shared.create]].
284
268
  **/
285
- Widget.extend = function(constr){
286
- return shared.extend(constr, this);
269
+ Widget.extend = function (constr, post_constr) {
270
+ return shared.create(constr, post_constr, this);
287
271
  };
288
272
 
289
273
  /**
@@ -294,10 +278,11 @@ define('xooie/widgets/base', ['jquery', 'xooie/xooie', 'xooie/helpers', 'xooie/s
294
278
  * Creates a new css rule in the Xooie stylesheet. If the rule exists, it will overwrite said rule.
295
279
  **/
296
280
  // TODO: update so that if the rule exists the properties are added to the rule
297
- Widget.createStyleRule = function(selector, properties) {
298
- if (typeof $X._stylesheet.addRule !== 'undefined') {
281
+ Widget.createStyleRule = function (selector, properties) {
282
+ if (!helpers.isUndefined($X._stylesheet.addRule)) {
299
283
  return $X._stylesheet.addRule(selector, properties);
300
284
  }
285
+ return false;
301
286
  };
302
287
 
303
288
  /**
@@ -307,12 +292,11 @@ define('xooie/widgets/base', ['jquery', 'xooie/xooie', 'xooie/helpers', 'xooie/s
307
292
  * Retrieves the css rule from the Xooie stylesheet using the provided `selector`. If the rule is not
308
293
  * present in [[$X._styleRules]] then the method will check in [[$X._stylesheet]].
309
294
  **/
310
- Widget.getStyleRule = function(selector) {
295
+ Widget.getStyleRule = function (selector) {
311
296
  if ($X._styleRules.hasOwnProperty(selector)) {
312
297
  return $X._styleRules[selector];
313
- } else {
314
- return $X._stylesheet.getRule(selector);
315
298
  }
299
+ return $X._stylesheet.getRule(selector);
316
300
  };
317
301
 
318
302
  /** internal
@@ -329,13 +313,6 @@ define('xooie/widgets/base', ['jquery', 'xooie/xooie', 'xooie/helpers', 'xooie/s
329
313
  **/
330
314
  Widget.prototype._definedRoles = [];
331
315
 
332
- /** internal, read-only
333
- * Xooie.Widget#_extendCount -> Integer | null
334
- *
335
- * Tracks the number of constructors that need to be called.
336
- **/
337
- Widget.prototype._extendCount = null;
338
-
339
316
  //PROPERTY DEFINITIONS
340
317
 
341
318
  /** internal
@@ -474,7 +451,7 @@ define('xooie/widgets/base', ['jquery', 'xooie/xooie', 'xooie/helpers', 'xooie/s
474
451
  *
475
452
  * See [[Xooie.shared.get]].
476
453
  **/
477
- Widget.prototype.get = function(name) {
454
+ Widget.prototype.get = function (name) {
478
455
  return shared.get(this, name);
479
456
  };
480
457
 
@@ -485,7 +462,7 @@ define('xooie/widgets/base', ['jquery', 'xooie/xooie', 'xooie/helpers', 'xooie/s
485
462
  *
486
463
  * See [[Xooie.shared.set]].
487
464
  **/
488
- Widget.prototype.set = function(name, value) {
465
+ Widget.prototype.set = function (name, value) {
489
466
  return shared.set(this, name, value);
490
467
  };
491
468
 
@@ -495,7 +472,7 @@ define('xooie/widgets/base', ['jquery', 'xooie/xooie', 'xooie/helpers', 'xooie/s
495
472
  * Removes the `className` and `instanceClass` classes and `data-xooie-instance` attribute from the root element.
496
473
  * Calls [[Xooie.Addon.cleanup]] for each addon. This will permit the instance to be garbage collected.
497
474
  **/
498
- Widget.prototype.cleanup = function() {
475
+ Widget.prototype.cleanup = function () {
499
476
  var name;
500
477
 
501
478
  for (name in this.addons()) {
@@ -517,15 +494,14 @@ define('xooie/widgets/base', ['jquery', 'xooie/xooie', 'xooie/helpers', 'xooie/s
517
494
  * Renders the template with the provided data by calling the method in [[Xooie.Widget.renderMethods]] based on the
518
495
  * template language specified. Returns `$('<span>Error rendering template</span>')` when an error occurs
519
496
  **/
520
- Widget.prototype.render = function(template, view) {
497
+ Widget.prototype.render = function (template, view) {
521
498
  var language = template.data('templateLanguage') || this.templateLanguage(),
522
499
  result = Widget._renderMethods[language](template, view);
523
500
 
524
501
  if (result === false) {
525
502
  return $('<span>Error rendering template</span>');
526
- } else {
527
- return result;
528
503
  }
504
+ return result;
529
505
  };
530
506
 
531
507
  /** internal
@@ -536,7 +512,7 @@ define('xooie/widgets/base', ['jquery', 'xooie/xooie', 'xooie/helpers', 'xooie/s
536
512
  * Generates an id string to be applied to an element of the specified role. The format of
537
513
  * this id string is `x-[[Xooie.Widget#id]]-{role}-{index}`.
538
514
  **/
539
- Widget.prototype._getRoleId = function(role, index) {
515
+ Widget.prototype._getRoleId = function (role, index) {
540
516
  return 'x-' + this.id() + '-' + role + '-' + index;
541
517
  };
542
518
 
@@ -545,13 +521,13 @@ define('xooie/widgets/base', ['jquery', 'xooie/xooie', 'xooie/helpers', 'xooie/s
545
521
  *
546
522
  * TODO: Test and document.
547
523
  **/
548
- Widget.prototype._applyRoles = function() {
524
+ Widget.prototype._applyRoles = function () {
549
525
  var i, j, role, elements;
550
526
 
551
- for (i=0; i < this._definedRoles.length; i+=1) {
527
+ for (i = 0; i < this._definedRoles.length; i += 1) {
552
528
  role = roleDetails(this._definedRoles[i]);
553
529
  elements = this[role.getter]();
554
-
530
+
555
531
  if (elements.length === 0 && helpers.isFunction(this[role.renderer])) {
556
532
  elements = this[role.renderer]();
557
533
  }
@@ -560,7 +536,7 @@ define('xooie/widgets/base', ['jquery', 'xooie/xooie', 'xooie/helpers', 'xooie/s
560
536
  return;
561
537
  }
562
538
 
563
- for (j=0; j < elements.length; j+=1) {
539
+ for (j = 0; j < elements.length; j += 1) {
564
540
  $(elements[j]).attr('id', this._getRoleId(this._definedRoles[i], j));
565
541
  }
566
542
 
@@ -577,8 +553,8 @@ define('xooie/widgets/base', ['jquery', 'xooie/xooie', 'xooie/helpers', 'xooie/s
577
553
  * Checks to see if the addons object has been defined. We can't define objects as
578
554
  * 'default' values for properties since the object will be the same for each instance.
579
555
  **/
580
- Widget.prototype._process_addons = function(addons){
581
- if (typeof addons === 'undefined'){
556
+ Widget.prototype._process_addons = function (addons) {
557
+ if (helpers.isUndefined(addons)) {
582
558
  addons = this._addons = {};
583
559
  }
584
560
 
@@ -591,7 +567,7 @@ define('xooie/widgets/base', ['jquery', 'xooie/xooie', 'xooie/helpers', 'xooie/s
591
567
  *
592
568
  * Adds the [[Xooie.Widget#namespace]] to the `refreshEvent`
593
569
  **/
594
- Widget.prototype._process_refreshEvent = function(refreshEvent){
570
+ Widget.prototype._process_refreshEvent = function (refreshEvent) {
595
571
  return this.namespace() === '' ? refreshEvent : refreshEvent + '.' + this.namespace();
596
572
  };
597
573
 
@@ -601,7 +577,7 @@ define('xooie/widgets/base', ['jquery', 'xooie/xooie', 'xooie/helpers', 'xooie/s
601
577
  *
602
578
  * Adds the [[Xooie.Widget#namespace]] to the `initEvent`
603
579
  **/
604
- Widget.prototype._process_initEvent = function(initEvent){
580
+ Widget.prototype._process_initEvent = function (initEvent) {
605
581
  return this.namespace() === '' ? initEvent : initEvent + '.' + this.namespace();
606
582
  };
607
583
 
@@ -611,7 +587,7 @@ define('xooie/widgets/base', ['jquery', 'xooie/xooie', 'xooie/helpers', 'xooie/s
611
587
  *
612
588
  * Adds the [[Xooie.Widget#namespace]] to the `className`
613
589
  **/
614
- Widget.prototype._process_className = function(className) {
590
+ Widget.prototype._process_className = function (className) {
615
591
  return this.namespace() === '' ? className : className + '-' + this.namespace();
616
592
  };
617
593
 
@@ -620,7 +596,7 @@ define('xooie/widgets/base', ['jquery', 'xooie/xooie', 'xooie/helpers', 'xooie/s
620
596
  *
621
597
  * Creates an instanceClass string from the [[Xooie.Widget#namespace]] and [[Xooie.Widget#id]].
622
598
  **/
623
- Widget.prototype._process_instanceClass = function() {
599
+ Widget.prototype._process_instanceClass = function () {
624
600
  return this.namespace() === '' ? 'widget-' + this.id() : this.namespace() + '-' + this.id();
625
601
  };
626
602