ink_ui_rails 2.1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.md +21 -0
  3. data/README.md +39 -0
  4. data/lib/ink_ui_rails.rb +8 -0
  5. data/lib/ink_ui_rails/version.rb +3 -0
  6. data/vendor/assets/fonts/font/FontAwesome.otf +0 -0
  7. data/vendor/assets/fonts/font/fontawesome-webfont.eot +0 -0
  8. data/vendor/assets/fonts/font/fontawesome-webfont.svg +399 -0
  9. data/vendor/assets/fonts/font/fontawesome-webfont.ttf +0 -0
  10. data/vendor/assets/fonts/font/fontawesome-webfont.woff +0 -0
  11. data/vendor/assets/fonts/font/ubuntu-b-webfont.eot +0 -0
  12. data/vendor/assets/fonts/font/ubuntu-b-webfont.svg +245 -0
  13. data/vendor/assets/fonts/font/ubuntu-b-webfont.ttf +0 -0
  14. data/vendor/assets/fonts/font/ubuntu-b-webfont.woff +0 -0
  15. data/vendor/assets/fonts/font/ubuntu-bi-webfont.eot +0 -0
  16. data/vendor/assets/fonts/font/ubuntu-bi-webfont.svg +245 -0
  17. data/vendor/assets/fonts/font/ubuntu-bi-webfont.ttf +0 -0
  18. data/vendor/assets/fonts/font/ubuntu-bi-webfont.woff +0 -0
  19. data/vendor/assets/fonts/font/ubuntu-c-webfont.eot +0 -0
  20. data/vendor/assets/fonts/font/ubuntu-c-webfont.svg +245 -0
  21. data/vendor/assets/fonts/font/ubuntu-c-webfont.ttf +0 -0
  22. data/vendor/assets/fonts/font/ubuntu-c-webfont.woff +0 -0
  23. data/vendor/assets/fonts/font/ubuntu-l-webfont.eot +0 -0
  24. data/vendor/assets/fonts/font/ubuntu-l-webfont.svg +245 -0
  25. data/vendor/assets/fonts/font/ubuntu-l-webfont.ttf +0 -0
  26. data/vendor/assets/fonts/font/ubuntu-l-webfont.woff +0 -0
  27. data/vendor/assets/fonts/font/ubuntu-li-webfont.eot +0 -0
  28. data/vendor/assets/fonts/font/ubuntu-li-webfont.svg +245 -0
  29. data/vendor/assets/fonts/font/ubuntu-li-webfont.ttf +0 -0
  30. data/vendor/assets/fonts/font/ubuntu-li-webfont.woff +0 -0
  31. data/vendor/assets/fonts/font/ubuntu-m-webfont.eot +0 -0
  32. data/vendor/assets/fonts/font/ubuntu-m-webfont.svg +245 -0
  33. data/vendor/assets/fonts/font/ubuntu-m-webfont.ttf +0 -0
  34. data/vendor/assets/fonts/font/ubuntu-m-webfont.woff +0 -0
  35. data/vendor/assets/fonts/font/ubuntu-mi-webfont.eot +0 -0
  36. data/vendor/assets/fonts/font/ubuntu-mi-webfont.svg +245 -0
  37. data/vendor/assets/fonts/font/ubuntu-mi-webfont.ttf +0 -0
  38. data/vendor/assets/fonts/font/ubuntu-mi-webfont.woff +0 -0
  39. data/vendor/assets/fonts/font/ubuntu-r-webfont.eot +0 -0
  40. data/vendor/assets/fonts/font/ubuntu-r-webfont.svg +245 -0
  41. data/vendor/assets/fonts/font/ubuntu-r-webfont.ttf +0 -0
  42. data/vendor/assets/fonts/font/ubuntu-r-webfont.woff +0 -0
  43. data/vendor/assets/fonts/font/ubuntu-ri-webfont.eot +0 -0
  44. data/vendor/assets/fonts/font/ubuntu-ri-webfont.svg +245 -0
  45. data/vendor/assets/fonts/font/ubuntu-ri-webfont.ttf +0 -0
  46. data/vendor/assets/fonts/font/ubuntu-ri-webfont.woff +0 -0
  47. data/vendor/assets/fonts/font/ubuntumono-b-webfont.eot +0 -0
  48. data/vendor/assets/fonts/font/ubuntumono-b-webfont.svg +242 -0
  49. data/vendor/assets/fonts/font/ubuntumono-b-webfont.ttf +0 -0
  50. data/vendor/assets/fonts/font/ubuntumono-b-webfont.woff +0 -0
  51. data/vendor/assets/fonts/font/ubuntumono-bi-webfont.eot +0 -0
  52. data/vendor/assets/fonts/font/ubuntumono-bi-webfont.svg +242 -0
  53. data/vendor/assets/fonts/font/ubuntumono-bi-webfont.ttf +0 -0
  54. data/vendor/assets/fonts/font/ubuntumono-bi-webfont.woff +0 -0
  55. data/vendor/assets/fonts/font/ubuntumono-r-webfont.eot +0 -0
  56. data/vendor/assets/fonts/font/ubuntumono-r-webfont.svg +242 -0
  57. data/vendor/assets/fonts/font/ubuntumono-r-webfont.ttf +0 -0
  58. data/vendor/assets/fonts/font/ubuntumono-r-webfont.woff +0 -0
  59. data/vendor/assets/fonts/font/ubuntumono-ri-webfont.eot +0 -0
  60. data/vendor/assets/fonts/font/ubuntumono-ri-webfont.svg +242 -0
  61. data/vendor/assets/fonts/font/ubuntumono-ri-webfont.ttf +0 -0
  62. data/vendor/assets/fonts/font/ubuntumono-ri-webfont.woff +0 -0
  63. data/vendor/assets/images/img/SAPOlogo.png +0 -0
  64. data/vendor/assets/images/img/favicon.ico +0 -0
  65. data/vendor/assets/images/img/home_bkg.png +0 -0
  66. data/vendor/assets/images/img/home_logo_IE.jpg +0 -0
  67. data/vendor/assets/images/img/icon_Sprite.png +0 -0
  68. data/vendor/assets/images/img/ink-favicon.ico +0 -0
  69. data/vendor/assets/images/img/logo_home.png +0 -0
  70. data/vendor/assets/images/img/shot_ink.png +0 -0
  71. data/vendor/assets/images/img/shot_intra.png +0 -0
  72. data/vendor/assets/images/img/shot_livebots.png +0 -0
  73. data/vendor/assets/images/img/shot_meo.png +0 -0
  74. data/vendor/assets/images/img/shot_musicbox.png +0 -0
  75. data/vendor/assets/images/img/shot_pessoa.png +0 -0
  76. data/vendor/assets/images/img/splash.1024x748.png +0 -0
  77. data/vendor/assets/images/img/splash.320x460.png +0 -0
  78. data/vendor/assets/images/img/splash.768x1004.png +0 -0
  79. data/vendor/assets/images/img/touch-icon.114.png +0 -0
  80. data/vendor/assets/images/img/touch-icon.16.png +0 -0
  81. data/vendor/assets/images/img/touch-icon.256.png +0 -0
  82. data/vendor/assets/images/img/touch-icon.57.png +0 -0
  83. data/vendor/assets/images/img/touch-icon.72.png +0 -0
  84. data/vendor/assets/javascripts/autoload.js +85 -0
  85. data/vendor/assets/javascripts/example.json +1174 -0
  86. data/vendor/assets/javascripts/holder.js +440 -0
  87. data/vendor/assets/javascripts/html5shiv-printshiv.js +496 -0
  88. data/vendor/assets/javascripts/html5shiv.js +298 -0
  89. data/vendor/assets/javascripts/ink-all.js +18015 -0
  90. data/vendor/assets/javascripts/ink-ui.js +7737 -0
  91. data/vendor/assets/javascripts/ink.aux.js +506 -0
  92. data/vendor/assets/javascripts/ink.close.js +54 -0
  93. data/vendor/assets/javascripts/ink.datepicker.js +1194 -0
  94. data/vendor/assets/javascripts/ink.datepicker.pt.js +32 -0
  95. data/vendor/assets/javascripts/ink.draggable.js +437 -0
  96. data/vendor/assets/javascripts/ink.droppable.js +193 -0
  97. data/vendor/assets/javascripts/ink.formvalidator.js +712 -0
  98. data/vendor/assets/javascripts/ink.gallery.js +757 -0
  99. data/vendor/assets/javascripts/ink.imagequery.js +259 -0
  100. data/vendor/assets/javascripts/ink.js +10278 -0
  101. data/vendor/assets/javascripts/ink.modal.js +628 -0
  102. data/vendor/assets/javascripts/ink.pagination.js +473 -0
  103. data/vendor/assets/javascripts/ink.progressbar.js +110 -0
  104. data/vendor/assets/javascripts/ink.smoothscroller.js +234 -0
  105. data/vendor/assets/javascripts/ink.sortablelist.js +338 -0
  106. data/vendor/assets/javascripts/ink.spy.js +123 -0
  107. data/vendor/assets/javascripts/ink.sticky.js +254 -0
  108. data/vendor/assets/javascripts/ink.table.js +621 -0
  109. data/vendor/assets/javascripts/ink.tabs.js +426 -0
  110. data/vendor/assets/javascripts/ink.toggle.js +218 -0
  111. data/vendor/assets/javascripts/ink.treeview.js +179 -0
  112. data/vendor/assets/javascripts/ink_ui.js +1 -0
  113. data/vendor/assets/javascripts/modernizr.js +815 -0
  114. data/vendor/assets/javascripts/prettify.js +28 -0
  115. data/vendor/assets/stylesheets/ink/_ink-ie7.css +1662 -0
  116. data/vendor/assets/stylesheets/ink/_ink.css +7496 -0
  117. data/vendor/assets/stylesheets/ink/ink_ui.scss.css +2 -0
  118. data/vendor/assets/stylesheets/ink_ui.scss.css +1 -0
  119. metadata +203 -0
@@ -0,0 +1,506 @@
1
+ /**
2
+ * @module Ink.UI.Aux_1
3
+ * @author inkdev AT sapo.pt
4
+ * @version 1
5
+ */
6
+ Ink.createModule('Ink.UI.Aux', '1', ['Ink.Net.Ajax_1','Ink.Dom.Css_1','Ink.Dom.Selector_1','Ink.Util.Url_1'], function(Ajax,Css,Selector,Url) {
7
+
8
+ 'use strict';
9
+
10
+ var instances = {};
11
+ var lastIdNum = 0;
12
+
13
+ /**
14
+ * The Aux class provides auxiliar methods to ease some of the most common/repetitive UI tasks.
15
+ *
16
+ * @class Ink.UI.Aux
17
+ * @version 1
18
+ * @uses Ink.Net.Ajax
19
+ * @uses Ink.Dom.Css
20
+ * @uses Ink.Dom.Selector
21
+ * @uses Ink.Util.Url
22
+ * @static
23
+ */
24
+ var Aux = {
25
+
26
+ /**
27
+ * Supported Ink Layouts
28
+ *
29
+ * @property Layouts
30
+ * @type Object
31
+ * @readOnly
32
+ */
33
+ Layouts: {
34
+ SMALL: 'small',
35
+ MEDIUM: 'medium',
36
+ LARGE: 'large'
37
+ },
38
+
39
+ /**
40
+ * Method to check if an item is a valid DOM Element.
41
+ *
42
+ * @method isDOMElement
43
+ * @static
44
+ * @param {Mixed} o The object to be checked.
45
+ * @return {Boolean} True if it's a valid DOM Element.
46
+ * @example
47
+ * var el = Ink.s('#element');
48
+ * if( Ink.UI.Aux.isDOMElement( el ) === true ){
49
+ * // It is a DOM Element.
50
+ * } else {
51
+ * // It is NOT a DOM Element.
52
+ * }
53
+ */
54
+ isDOMElement: function(o) {
55
+ return (typeof o === 'object' && 'nodeType' in o && o.nodeType === 1);
56
+ },
57
+
58
+ /**
59
+ * Method to check if an item is a valid integer.
60
+ *
61
+ * @method isInteger
62
+ * @static
63
+ * @param {Mixed} n The value to be checked.
64
+ * @return {Boolean} True if 'n' is a valid integer.
65
+ * @example
66
+ * var value = 1;
67
+ * if( Ink.UI.Aux.isInteger( value ) === true ){
68
+ * // It is an integer.
69
+ * } else {
70
+ * // It is NOT an integer.
71
+ * }
72
+ */
73
+ isInteger: function(n) {
74
+ return (typeof n === 'number' && n % 1 === 0);
75
+ },
76
+
77
+ /**
78
+ * Method to get a DOM Element. The first parameter should be either a DOM Element or a valid CSS Selector.
79
+ * If not, then it will throw an exception. Otherwise, it returns a DOM Element.
80
+ *
81
+ * @method elOrSelector
82
+ * @static
83
+ * @param {DOMElement|String} elOrSelector Valid DOM Element or CSS Selector
84
+ * @param {String} fieldName This field is used in the thrown Exception to identify the parameter.
85
+ * @return {DOMElement} Returns the DOMElement passed or the first result of the CSS Selector. Otherwise it throws an exception.
86
+ * @example
87
+ * // In case there are several .myInput, it will retrieve the first found
88
+ * var el = Ink.UI.Aux.elOrSelector('.myInput','My Input');
89
+ */
90
+ elOrSelector: function(elOrSelector, fieldName) {
91
+ if (!this.isDOMElement(elOrSelector)) {
92
+ var t = Selector.select(elOrSelector);
93
+ if (t.length === 0) { throw new TypeError(fieldName + ' must either be a DOM Element or a selector expression!\nThe script element must also be after the DOM Element itself.'); }
94
+ return t[0];
95
+ }
96
+ return elOrSelector;
97
+ },
98
+
99
+
100
+ /**
101
+ * Method to make a deep copy (clone) of an object.
102
+ * Note: The object cannot have loops.
103
+ *
104
+ * @method clone
105
+ * @static
106
+ * @param {Object} o The object to be cloned/copied.
107
+ * @return {Object} Returns the result of the clone/copy.
108
+ * @example
109
+ * var originalObj = {
110
+ * key1: 'value1',
111
+ * key2: 'value2',
112
+ * key3: 'value3'
113
+ * };
114
+ * var cloneObj = Ink.UI.Aux.clone( originalObj );
115
+ */
116
+ clone: function(o) {
117
+ try {
118
+ if (typeof o !== 'object') { throw new Error('Given argument is not an object!'); }
119
+ return JSON.parse( JSON.stringify(o) );
120
+ } catch (ex) {
121
+ throw new Error('Given object cannot have loops!');
122
+ }
123
+ },
124
+
125
+
126
+ /**
127
+ * Method to return the 'nth' position that an element occupies relatively to its parent.
128
+ *
129
+ * @method childIndex
130
+ * @static
131
+ * @param {DOMElement} childEl Valid DOM Element.
132
+ * @return {Number} Numerical position of an element relatively to its parent.
133
+ * @example
134
+ * <!-- Imagine the following HTML: -->
135
+ * <ul>
136
+ * <li>One</li>
137
+ * <li>Two</li>
138
+ * <li id="test">Three</li>
139
+ * <li>Four</li>
140
+ * </ul>
141
+ *
142
+ * <script>
143
+ * var testLi = Ink.s('#test');
144
+ * Ink.UI.Aux.childIndex( testLi ); // Returned value: 3
145
+ * </script>
146
+ */
147
+ childIndex: function(childEl) {
148
+ if( Aux.isDOMElement(childEl) ){
149
+ var els = Selector.select('> *', childEl.parentNode);
150
+ for (var i = 0, f = els.length; i < f; ++i) {
151
+ if (els[i] === childEl) {
152
+ return i;
153
+ }
154
+ }
155
+ }
156
+ throw 'not found!';
157
+ },
158
+
159
+
160
+ /**
161
+ * This method provides a more convenient way to do an async AJAX request and expect a JSON response.
162
+ * It offers a callback option, as third paramenter, for a better async handling.
163
+ *
164
+ * @method ajaxJSON
165
+ * @static
166
+ * @async
167
+ * @param {String} endpoint Valid URL to be used as target by the request.
168
+ * @param {Object} params This field is used in the thrown Exception to identify the parameter.
169
+ * @example
170
+ * // In case there are several .myInput, it will retrieve the first found
171
+ * var el = Ink.UI.Aux.elOrSelector('.myInput','My Input');
172
+ */
173
+ ajaxJSON: function(endpoint, params, cb) {
174
+ new Ajax(
175
+ endpoint,
176
+ {
177
+ evalJS: 'force',
178
+ method: 'POST',
179
+ parameters: params,
180
+
181
+ onSuccess: function( r) {
182
+ try {
183
+ r = r.responseJSON;
184
+ if (r.status !== 'ok') {
185
+ throw 'server error: ' + r.message;
186
+ }
187
+ cb(null, r);
188
+ } catch (ex) {
189
+ cb(ex);
190
+ }
191
+ },
192
+
193
+ onFailure: function() {
194
+ cb('communication failure');
195
+ }
196
+ }
197
+ );
198
+ },
199
+
200
+
201
+ /**
202
+ * Method to get the current Ink layout applied.
203
+ *
204
+ * @method currentLayout
205
+ * @static
206
+ * @return {String} Returns the value of one of the options of the property Layouts above defined.
207
+ * @example
208
+ * var inkLayout = Ink.UI.Aux.currentLayout();
209
+ */
210
+ currentLayout: function() {
211
+ var i, f, k, v, el, detectorEl = Selector.select('#ink-layout-detector')[0];
212
+ if (!detectorEl) {
213
+ detectorEl = document.createElement('div');
214
+ detectorEl.id = 'ink-layout-detector';
215
+ for (k in this.Layouts) {
216
+ if (this.Layouts.hasOwnProperty(k)) {
217
+ v = this.Layouts[k];
218
+ el = document.createElement('div');
219
+ el.className = 'show-' + v + ' hide-all';
220
+ el.setAttribute('data-ink-layout', v);
221
+ detectorEl.appendChild(el);
222
+ }
223
+ }
224
+ document.body.appendChild(detectorEl);
225
+ }
226
+
227
+ for (i = 0, f = detectorEl.childNodes.length; i < f; ++i) {
228
+ el = detectorEl.childNodes[i];
229
+ if (Css.getStyle(el, 'visibility') !== 'hidden') {
230
+ return el.getAttribute('data-ink-layout');
231
+ }
232
+ }
233
+ },
234
+
235
+
236
+ /**
237
+ * Method to set the location's hash (window.location.hash).
238
+ *
239
+ * @method hashSet
240
+ * @static
241
+ * @param {Object} o Object with the info to be placed in the location's hash.
242
+ * @example
243
+ * // It will set the location's hash like: <url>#key1=value1&key2=value2&key3=value3
244
+ * Ink.UI.Aux.hashSet({
245
+ * key1: 'value1',
246
+ * key2: 'value2',
247
+ * key3: 'value3'
248
+ * });
249
+ */
250
+ hashSet: function(o) {
251
+ if (typeof o !== 'object') { throw new TypeError('o should be an object!'); }
252
+ var hashParams = Url.getAnchorString();
253
+ hashParams = Ink.extendObj(hashParams, o);
254
+ window.location.hash = Url.genQueryString('', hashParams).substring(1);
255
+ },
256
+
257
+ /**
258
+ * Method to remove children nodes from a given object.
259
+ * This method was initially created to help solve a problem in Internet Explorer(s) that occurred when trying
260
+ * to set the innerHTML of some specific elements like 'table'.
261
+ *
262
+ * @method cleanChildren
263
+ * @static
264
+ * @param {DOMElement} parentEl Valid DOM Element
265
+ * @example
266
+ * <!-- Imagine the following HTML: -->
267
+ * <ul id="myUl">
268
+ * <li>One</li>
269
+ * <li>Two</li>
270
+ * <li>Three</li>
271
+ * <li>Four</li>
272
+ * </ul>
273
+ *
274
+ * <script>
275
+ * Ink.UI.Aux.cleanChildren( Ink.s( '#myUl' ) );
276
+ * </script>
277
+ *
278
+ * <!-- After running it, the HTML changes to: -->
279
+ * <ul id="myUl"></ul>
280
+ */
281
+ cleanChildren: function(parentEl) {
282
+ if( !Aux.isDOMElement(parentEl) ){
283
+ throw 'Please provide a valid DOMElement';
284
+ }
285
+ var prevEl, el = parentEl.lastChild;
286
+ while (el) {
287
+ prevEl = el.previousSibling;
288
+ parentEl.removeChild(el);
289
+ el = prevEl;
290
+ }
291
+ },
292
+
293
+ /**
294
+ * This method stores the id and/or the classes of a given element in a given object.
295
+ *
296
+ * @method storeIdAndClasses
297
+ * @static
298
+ * @param {DOMElement} fromEl Valid DOM Element to get the id and classes from.
299
+ * @param {Object} inObj Object where the id and classes will be saved.
300
+ * @example
301
+ * <div id="myDiv" class="aClass"></div>
302
+ *
303
+ * <script>
304
+ * var storageObj = {};
305
+ * Ink.UI.Aux.storeIdAndClasses( Ink.s('#myDiv'), storageObj );
306
+ * // storageObj changes to:
307
+ * {
308
+ * _id: 'myDiv',
309
+ * _classes: 'aClass'
310
+ * }
311
+ * </script>
312
+ */
313
+ storeIdAndClasses: function(fromEl, inObj) {
314
+ if( !Aux.isDOMElement(fromEl) ){
315
+ throw 'Please provide a valid DOMElement as first parameter';
316
+ }
317
+
318
+ var id = fromEl.id;
319
+ if (id) {
320
+ inObj._id = id;
321
+ }
322
+
323
+ var classes = fromEl.className;
324
+ if (classes) {
325
+ inObj._classes = classes;
326
+ }
327
+ },
328
+
329
+ /**
330
+ * This method sets the id and className properties of a given DOM Element based on a given similar object
331
+ * resultant of the previous function 'storeIdAndClasses'.
332
+ *
333
+ * @method restoreIdAndClasses
334
+ * @static
335
+ * @param {DOMElement} toEl Valid DOM Element to set the id and classes on.
336
+ * @param {Object} inObj Object where the id and classes to be set are.
337
+ * @example
338
+ * <div></div>
339
+ *
340
+ * <script>
341
+ * var storageObj = {
342
+ * _id: 'myDiv',
343
+ * _classes: 'aClass'
344
+ * };
345
+ *
346
+ * Ink.UI.Aux.storeIdAndClasses( Ink.s('div'), storageObj );
347
+ * </script>
348
+ *
349
+ * <!-- After the code runs the div element changes to: -->
350
+ * <div id="myDiv" class="aClass"></div>
351
+ */
352
+ restoreIdAndClasses: function(toEl, inObj) {
353
+
354
+ if( !Aux.isDOMElement(toEl) ){
355
+ throw 'Please provide a valid DOMElement as first parameter';
356
+ }
357
+
358
+ if (inObj._id && toEl.id !== inObj._id) {
359
+ toEl.id = inObj._id;
360
+ }
361
+
362
+ if (inObj._classes && toEl.className.indexOf(inObj._classes) === -1) {
363
+ if (toEl.className) { toEl.className += ' ' + inObj._classes; }
364
+ else { toEl.className = inObj._classes; }
365
+ }
366
+
367
+ if (inObj._instanceId && !toEl.getAttribute('data-instance')) {
368
+ toEl.setAttribute('data-instance', inObj._instanceId);
369
+ }
370
+ },
371
+
372
+ /**
373
+ * This method saves a component's instance reference for later retrieval.
374
+ *
375
+ * @method registerInstance
376
+ * @static
377
+ * @param {Object} inst Object that holds the instance.
378
+ * @param {DOMElement} el DOM Element to associate with the object.
379
+ * @param {Object} [optionalPrefix] Defaults to 'instance'
380
+ */
381
+ registerInstance: function(inst, el, optionalPrefix) {
382
+ if (inst._instanceId) { return; }
383
+
384
+ if (typeof inst !== 'object') { throw new TypeError('1st argument must be a JavaScript object!'); }
385
+
386
+ if (inst._options && inst._options.skipRegister) { return; }
387
+
388
+ if (!this.isDOMElement(el)) { throw new TypeError('2nd argument must be a DOM element!'); }
389
+ if (optionalPrefix !== undefined && typeof optionalPrefix !== 'string') { throw new TypeError('3rd argument must be a string!'); }
390
+ var id = (optionalPrefix || 'instance') + (++lastIdNum);
391
+ instances[id] = inst;
392
+ inst._instanceId = id;
393
+ var dataInst = el.getAttribute('data-instance');
394
+ dataInst = (dataInst !== null) ? [dataInst, id].join(' ') : id;
395
+ el.setAttribute('data-instance', dataInst);
396
+ },
397
+
398
+ /**
399
+ * This method deletes/destroy an instance with a given id.
400
+ *
401
+ * @method unregisterInstance
402
+ * @static
403
+ * @param {String} id Id of the instance to be destroyed.
404
+ */
405
+ unregisterInstance: function(id) {
406
+ delete instances[id];
407
+ },
408
+
409
+ /**
410
+ * This method retrieves the registered instance(s) of a given element or instance id.
411
+ *
412
+ * @method getInstance
413
+ * @static
414
+ * @param {String|DOMElement} instanceIdOrElement Instance's id or DOM Element from which we want the instances.
415
+ * @return {Object|Object[]} Returns an instance or a collection of instances.
416
+ */
417
+ getInstance: function(instanceIdOrElement) {
418
+ var ids;
419
+ if (this.isDOMElement(instanceIdOrElement)) {
420
+ ids = instanceIdOrElement.getAttribute('data-instance');
421
+ if (ids === null) { throw new Error('argument is not a DOM instance element!'); }
422
+ }
423
+ else {
424
+ ids = instanceIdOrElement;
425
+ }
426
+
427
+ ids = ids.split(' ');
428
+ var inst, id, i, l = ids.length;
429
+
430
+ var res = [];
431
+ for (i = 0; i < l; ++i) {
432
+ id = ids[i];
433
+ if (!id) { throw new Error('Element is not a JS instance!'); }
434
+ inst = instances[id];
435
+ if (!inst) { throw new Error('Instance "' + id + '" not found!'); }
436
+ res.push(inst);
437
+ }
438
+
439
+ return (l === 1) ? res[0] : res;
440
+ },
441
+
442
+ /**
443
+ * This method retrieves the registered instance(s) of an element based on the given selector.
444
+ *
445
+ * @method getInstanceFromSelector
446
+ * @static
447
+ * @param {String} selector CSS selector to define the element from which it'll get the instance(s).
448
+ * @return {Object|Object[]} Returns an instance or a collection of instances.
449
+ */
450
+ getInstanceFromSelector: function(selector) {
451
+ var el = Selector.select(selector)[0];
452
+ if (!el) { throw new Error('Element not found!'); }
453
+ return this.getInstance(el);
454
+ },
455
+
456
+ /**
457
+ * This method retrieves the registered instances' ids of all instances.
458
+ *
459
+ * @method getInstanceIds
460
+ * @static
461
+ * @return {String[]} Id or collection of ids of all existing instances.
462
+ */
463
+ getInstanceIds: function() {
464
+ var res = [];
465
+ for (var id in instances) {
466
+ if (instances.hasOwnProperty(id)) {
467
+ res.push( id );
468
+ }
469
+ }
470
+ return res;
471
+ },
472
+
473
+ /**
474
+ * This method retrieves all existing instances.
475
+ *
476
+ * @method getInstances
477
+ * @static
478
+ * @return {Object[]} Collection of existing instances.
479
+ */
480
+ getInstances: function() {
481
+ var res = [];
482
+ for (var id in instances) {
483
+ if (instances.hasOwnProperty(id)) {
484
+ res.push( instances[id] );
485
+ }
486
+ }
487
+ return res;
488
+ },
489
+
490
+ /**
491
+ * This method is not to supposed to be invoked by the Aux component.
492
+ * Components should copy this method as its destroy method.
493
+ *
494
+ * @method destroyComponent
495
+ * @static
496
+ */
497
+ destroyComponent: function() {
498
+ Ink.Util.Aux.unregisterInstance(this._instanceId);
499
+ this._element.parentNode.removeChild(this._element);
500
+ }
501
+
502
+ };
503
+
504
+ return Aux;
505
+
506
+ });