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,757 @@
1
+ /**
2
+ * @module Ink.UI.Gallery_1
3
+ * @author inkdev AT sapo.pt
4
+ * @version 1
5
+ */
6
+ Ink.createModule('Ink.UI.Gallery', '1', ['Ink.UI.Aux_1','Ink.Dom.Event_1','Ink.Dom.Css_1','Ink.Dom.Element_1','Ink.Dom.Selector_1','Ink.Util.Array_1','Ink.Util.Swipe_1'], function(Aux, Event, Css, Element, Selector, InkArray, Swipe ) {
7
+ 'use strict';
8
+
9
+ /**
10
+ * Function to calculate the size based on a given max. size and image size.
11
+ *
12
+ * @function maximizeBox
13
+ * @param {Number} maxSz
14
+ * @param {Number} imageSz
15
+ * @param {Boolean} forceMaximize
16
+ * @return {Number}
17
+ * @private
18
+ */
19
+ var maximizeBox = function(maxSz, imageSz, forceMaximize) {
20
+ var w = imageSz[0];
21
+ var h = imageSz[1];
22
+
23
+ if (forceMaximize || (w > maxSz[0] || h > maxSz[1]) ) {
24
+ var arImg = w / h;
25
+ var arMax = maxSz[0] / maxSz[1];
26
+ var s = (arImg > arMax) ? maxSz[0] / w : maxSz[1] / h;
27
+ return [parseInt(w * s + 0.5, 10), parseInt(h * s + 0.5, 10)];
28
+ }
29
+
30
+ return imageSz;
31
+ };
32
+
33
+ /**
34
+ * @function maximizeBox
35
+ * @param {Object} o
36
+ * @param {Function} cb Callback function to run on each image loaded.
37
+ * @private
38
+ */
39
+ var getDimsAsync = function(o, cb) {
40
+ cb = Ink.bind(cb,o);
41
+
42
+ var dims = [o.img.offsetWidth, o.img.offsetHeight];
43
+ if (dims[0] && dims[1]) {
44
+ cb(dims);
45
+ }
46
+ o.img.onload = Ink.bindEvent(function() {
47
+ cb([this.img.offsetWidth, this.img.offsetHeight]);
48
+ },o);
49
+ };
50
+
51
+ /**
52
+ * @class Ink.UI.Gallery
53
+ * @constructor
54
+ * @version 1
55
+ * @uses Ink.UI.Aux
56
+ * @uses Ink.Dom.Event
57
+ * @uses Ink.Dom.Css
58
+ * @uses Ink.Dom.Element
59
+ * @uses Ink.Dom.Selector
60
+ * @uses Ink.Util.Array
61
+ * @uses Ink.Util.Swipe
62
+ * @param {String|DOMElement} selector
63
+ * @param {Object} [options] Options for the gallery
64
+ * @param {Number} [options.fullImageMaxWidth] Default value is 400.
65
+ * @param {Number} [options.thumbnailMaxWidth] Max. width of the thumbnail. Default value is 106.
66
+ * @param {Number} [options.layout] This determines what layout the gallery will have. Numeric value between 0 and 3.
67
+ * @param {Boolean} [options.circular] Determines if the gallery behaves in a circular never ending cycle.
68
+ * @param {Boolean} [options.fixImageSizes] Specifies if the images should be forced to have the gallery size.
69
+ * @example
70
+ * <ul class="ink-gallery-source">
71
+ * <li class="hentry hmedia">
72
+ * <a rel="enclosure" href="http://imgs.sapo.pt/ink/assets/imgs_gal/1.1.png">
73
+ * <img alt="s1" src="http://imgs.sapo.pt/ink/assets/imgs_gal/thumb1.png">
74
+ * </a>
75
+ * <a class="bookmark" href="http://imgs.sapo.pt/ink/assets/imgs_gal/1.1.png">
76
+ * <span class="entry-title">s1</span>
77
+ * </a>
78
+ * <span class="entry-content"><p>hello world 1</p></span>
79
+ * </li>
80
+ * <li class="hentry hmedia">
81
+ * <a rel="enclosure" href="http://imgs.sapo.pt/ink/assets/imgs_gal/1.2.png">
82
+ * <img alt="s1" src="http://imgs.sapo.pt/ink/assets/imgs_gal/thumb2.png">
83
+ * </a>
84
+ * <a class="bookmark" href="http://imgs.sapo.pt/ink/assets/imgs_gal/1.2.png">
85
+ * <span class="entry-title">s2</span>
86
+ * </a>
87
+ * <span class="entry-content"><p>hello world 2</p></span>
88
+ * </li>
89
+ * </ul>
90
+ * <script>
91
+ * Ink.requireModules(['Ink.Dom.Selector_1','Ink.UI.Gallery_1'],function( Selector, Gallery ){
92
+ * var galleryElement = Ink.s('ul.ink-gallery-source');
93
+ * var galleryObj = new Gallery( galleryElement );
94
+ * });
95
+ * </script>
96
+ */
97
+ var Gallery = function(selector, options) {
98
+
99
+ this._element = Aux.elOrSelector(selector, '1st argument');
100
+
101
+ this._options = Ink.extendObj({
102
+ fullImageMaxWidth: 600,
103
+ fullImageMaxHeight: 400,
104
+ thumbnailMaxWidth: 106,
105
+ layout: 0,
106
+ circular: false,
107
+ fixImageSizes: false
108
+ }, Element.data(this._element));
109
+
110
+ this._options = Ink.extendObj(this._options, options || {});
111
+
112
+ this._handlers = {
113
+ navClick: Ink.bindEvent(this._onNavClick,this),
114
+ paginationClick: Ink.bindEvent(this._onPaginationClick,this),
115
+ thumbsClick: Ink.bindEvent(this._onThumbsClick,this),
116
+ focusBlur: Ink.bindEvent(this._onFocusBlur,this),
117
+ keyDown: Ink.bindEvent(this._onKeyDown,this)
118
+ };
119
+
120
+ this._isFocused = false;
121
+ this._model = [];
122
+
123
+ if (this._options.model instanceof Array) {
124
+ this._model = this._options.model;
125
+ this._createdFrom = 'JSON';
126
+ }
127
+ else if (this._element.nodeName.toLowerCase() === 'ul') {
128
+ this._createdFrom = 'DOM';
129
+ }
130
+ else {
131
+ throw new TypeError('You must pass a selector expression/DOM element as 1st option or provide a model on 2nd argument!');
132
+ }
133
+
134
+ this._index = 0;
135
+ this._thumbIndex = 0;
136
+
137
+ if( !isNaN(this._options.layout) ){
138
+
139
+ this._options.layout = parseInt(this._options.layout,10);
140
+ if (this._options.layout === 0) {
141
+ this._showThumbs = false;
142
+ this._showDescription = false;
143
+ this._paginationHasPrevNext = false;
144
+ }
145
+ else if (this._options.layout === 1 || this._options.layout === 2 || this._options.layout === 3) {
146
+ this._showThumbs = true;
147
+ this._showDescription = true;
148
+ this._paginationHasPrevNext = true;
149
+ }
150
+ else {
151
+ throw new TypeError('supported layouts are 0-3!');
152
+ }
153
+ }
154
+
155
+ if (this._element.getAttribute('data-fix-image-sizes') !== null) {
156
+ this._options.fixImageSizes = true;
157
+ }
158
+
159
+ this._init();
160
+ };
161
+
162
+ Gallery.prototype = {
163
+
164
+ /**
165
+ * Init function called from the constructor.
166
+ *
167
+ * @method _init
168
+ * @private
169
+ */
170
+ _init: function() {
171
+ // extract model
172
+ if (this._createdFrom === 'DOM') {
173
+ this._extractModelFromDOM();
174
+ }
175
+
176
+ // generate and apply DOM
177
+ var el = this._generateMarkup();
178
+ var parentEl = this._element.parentNode;
179
+
180
+ if (!this._notFirstInit) {
181
+ Aux.storeIdAndClasses(this._element, this);
182
+ this._notFirstInit = true;
183
+ }
184
+
185
+ parentEl.insertBefore(el, this._element);
186
+ parentEl.removeChild(this._element);
187
+ this._element = el;
188
+
189
+ Aux.restoreIdAndClasses(this._element, this);
190
+
191
+ // subscribe events
192
+ Event.observe(this._paginationEl, 'click', this._handlers.paginationClick);
193
+ Event.observe(this._navEl, 'click', this._handlers.navClick);
194
+
195
+ if (this._showThumbs) {
196
+ Event.observe(this._thumbsUlEl, 'click', this._handlers.thumbsClick);
197
+ }
198
+
199
+ Event.observe(this._element, 'mouseover', this._handlers.focusBlur);
200
+ Event.observe(this._element, 'mouseout', this._handlers.focusBlur);
201
+ Event.observe(document, 'keydown', this._handlers.keyDown);
202
+
203
+ Aux.registerInstance(this, this._element, 'gallery');
204
+ },
205
+
206
+ /**
207
+ * Updates the model from the UL representation
208
+ *
209
+ * @method _extractModelFromDOM
210
+ * @private
211
+ */
212
+ _extractModelFromDOM: function() {
213
+ /*global console:false */
214
+ var m = [];
215
+ var dims;
216
+
217
+ var liEls = Selector.select('> li', this._element);
218
+ InkArray.each(liEls,function(liEl) {
219
+ try {
220
+ var d = {
221
+ image_full: '',
222
+ image_thumb: '',
223
+ title_text: '',
224
+ title_link: '',
225
+ description: '',
226
+ content_overlay: document.createDocumentFragment()
227
+ };
228
+
229
+ var enclosureAEl = Selector.select('> a[rel=enclosure]', liEl)[0];
230
+ var thumbImgEl = Selector.select('> img', enclosureAEl)[0];
231
+ var bookmarkAEl = Selector.select('> a[class=bookmark]', liEl)[0];
232
+ var titleSpanEl = Selector.select('span[class=entry-title]', liEl)[0];
233
+ var entryContentSpanEl = Selector.select('> span[class=entry-content]', liEl)[0];
234
+ var contentOverlayEl = Selector.select('> .content-overlay', liEl)[0];
235
+
236
+ dims = enclosureAEl.getAttribute('data-dims');
237
+ if (dims !== null) {
238
+ dims = dims.split(',');
239
+ dims[0] = parseInt(dims[0], 10);
240
+ dims[1] = parseInt(dims[1], 10);
241
+ }
242
+ if (dims && !isNaN(dims[0]) && !isNaN(dims[1])) { d.dims = dims; }
243
+
244
+ d.image_full = enclosureAEl.getAttribute('href');
245
+ d.image_thumb = thumbImgEl.getAttribute('src');
246
+ if (bookmarkAEl) {
247
+ d.title_link = bookmarkAEl.getAttribute('href');
248
+ }
249
+ d.title_text = titleSpanEl.innerHTML;
250
+ if (entryContentSpanEl) {
251
+ d.description = entryContentSpanEl.innerHTML;
252
+ }
253
+
254
+ if(contentOverlayEl){
255
+ d.content_overlay.appendChild(contentOverlayEl);
256
+ }
257
+
258
+ m.push(d);
259
+ } catch(ex) {
260
+ console.error('problematic element:');
261
+ console.error(liEl);
262
+ console.error(ex);
263
+ throw new Error('Problem parsing gallery data from DOM!');
264
+ }
265
+ });
266
+
267
+ this._model = m;
268
+ },
269
+
270
+ /**
271
+ * Returns the top element for the gallery DOM representation
272
+ *
273
+ * @method _generateMarkup
274
+ * @private
275
+ * @return {DOMElement} Returns the Gallery element totally rendered.
276
+ */
277
+ _generateMarkup: function() {
278
+ /*jshint maxstatements:80 */
279
+ var el = document.createElement('div');
280
+ el.className = 'ink-gallery';
281
+
282
+ var stageEl = document.createElement('div');
283
+ stageEl.className = 'stage';
284
+
285
+ // nav
286
+ var navEl = document.createElement('nav');
287
+ navEl.innerHTML = [
288
+ '<ul class="unstyled">',
289
+ '<li><a href="#" class="next"></a></li>',
290
+ '<li><a href="#" class="previous"></a></li>',
291
+ '</ul>'
292
+ ].join('');
293
+ this._navEl = navEl;
294
+
295
+ // slider
296
+ var sliderEl = document.createElement('div');
297
+ sliderEl.className = 'slider';
298
+
299
+ var ulEl = document.createElement('ul');
300
+ this._sliderUlEl = ulEl;
301
+
302
+ var that = this;
303
+
304
+ var W = this._options.fullImageMaxWidth;
305
+ var H = this._options.fullImageMaxHeight;
306
+
307
+ InkArray.each(this._model,function(d, i) {
308
+ var liEl = document.createElement('li');
309
+ var imgEl = document.createElement('img');
310
+ imgEl.setAttribute('name', 'image ' + (i + 1));
311
+ imgEl.setAttribute('src', d.image_full);
312
+ imgEl.setAttribute('alt', d.title_text);
313
+ //imgEl.style.maxWidth = that._options.fullImageMaxWidth + 'px';
314
+ //imgEl.setAttribute('width', that._options.fullImageMaxWidth); // TODO?
315
+ liEl.appendChild(imgEl);
316
+
317
+ if(d.content_overlay){
318
+ if(d.content_overlay.nodeType === 1 || d.content_overlay.nodeType === 11){
319
+ d.content_overlay = liEl.appendChild(d.content_overlay);
320
+ } else if(typeof d.content_overlay === 'string'){
321
+ var contentOverlayEl = document.createElement('div');
322
+
323
+ contentOverlayEl.className = 'content-overlay';
324
+ contentOverlayEl.innerHTML = d.content_overlay;
325
+
326
+ d.content_overlay = liEl.appendChild(contentOverlayEl);
327
+ }
328
+ }
329
+
330
+ ulEl.appendChild(liEl);
331
+
332
+ if (that._options.fixImageSizes) {
333
+ var dimsCb = function(dims) {
334
+ //console.log(this, dims);
335
+ var imgEl = this.img;
336
+ var data = this.data;
337
+
338
+ if (!data.dims) { data.dims = dims; }
339
+
340
+ var dims2 = maximizeBox([W, H], dims);
341
+
342
+ var w = dims2[0];
343
+ var h = dims2[1];
344
+ var dw = Math.floor( (W - w)/2 );
345
+ var dh = Math.floor( (H - h)/2 );
346
+
347
+ if (w !== W || h !== H) {
348
+ imgEl.setAttribute('width', w);
349
+ imgEl.setAttribute('height', h);
350
+
351
+ var s = imgEl.style;
352
+ if (dw > 0) { s.paddingLeft = dw + 'px'; }
353
+ if (dh > 0) { s.paddingBottom = dh + 'px'; }
354
+ }
355
+ };
356
+
357
+ if (d.dims) { dimsCb.call( {img:imgEl, data:d}, d.dims); }
358
+ else { getDimsAsync({img:imgEl, data:d}, dimsCb); }
359
+ }
360
+ });
361
+
362
+ sliderEl.appendChild(ulEl);
363
+ this._sliderEl = sliderEl;
364
+
365
+ // description
366
+ var articleTextDivEl;
367
+ if (this._showDescription) {
368
+ var d = this._model[this._index];
369
+ articleTextDivEl = document.createElement('div');
370
+ articleTextDivEl.className = ['article_text', 'example' + (this._options.layout === 3 ? 2 : this._options.layout)].join(' ');
371
+ if (d.title_link) {
372
+ articleTextDivEl.innerHTML = ['<h1><a href="', d.title_link, '">', d.title_text, '</a></h1>', d.description].join('');
373
+ }
374
+ else {
375
+ articleTextDivEl.innerHTML = ['<h1>', d.title_text, '</h1>', d.description].join('');
376
+ }
377
+ this._articleTextDivEl = articleTextDivEl;
378
+ }
379
+
380
+ // thumbs
381
+ var thumbsDivEl;
382
+ if (this._showThumbs) {
383
+ thumbsDivEl = document.createElement('div');
384
+ thumbsDivEl.className = 'thumbs';
385
+ ulEl = document.createElement('ul');
386
+ ulEl.className = 'unstyled';
387
+
388
+ InkArray.each(this._model,function(d, i) {
389
+ var liEl = document.createElement('li');
390
+ var aEl = document.createElement('a');
391
+ aEl.setAttribute('href', '#');
392
+ var imgEl = document.createElement('img');
393
+ imgEl.setAttribute('name', 'thumb ' + (i + 1));
394
+ imgEl.setAttribute('src', d.image_thumb);
395
+ imgEl.setAttribute('alt', (i + 1));
396
+ var spanEl = document.createElement('span');
397
+ spanEl.innerHTML = d.title_text;
398
+ aEl.appendChild(imgEl);
399
+ aEl.appendChild(spanEl);
400
+ liEl.appendChild(aEl);
401
+ ulEl.appendChild(liEl);
402
+ });
403
+ thumbsDivEl.appendChild(ulEl);
404
+
405
+ this._thumbsDivEl = thumbsDivEl;
406
+ this._thumbsUlEl = ulEl;
407
+ }
408
+
409
+
410
+ // pagination
411
+ var paginationEl = document.createElement('div');
412
+ paginationEl.className = 'pagination';
413
+
414
+ var aEl;
415
+ if (this._paginationHasPrevNext) {
416
+ aEl = document.createElement('a');
417
+ aEl.setAttribute('href', '#');
418
+ aEl.className = 'previous';
419
+ paginationEl.appendChild(aEl);
420
+ }
421
+
422
+ InkArray.each(this._model,function(d, i) {
423
+ var aEl = document.createElement('a');
424
+ aEl.setAttribute('href', '#');
425
+ aEl.setAttribute('data-index', i);
426
+ if (i === that._index) { aEl.className = 'active'; }
427
+ paginationEl.appendChild(aEl);
428
+ });
429
+
430
+ if (this._paginationHasPrevNext) {
431
+ aEl = document.createElement('a');
432
+ aEl.setAttribute('href', '#');
433
+ aEl.className = 'next';
434
+ paginationEl.appendChild(aEl);
435
+ }
436
+
437
+ this._paginationEl = paginationEl;
438
+
439
+ // last appends...
440
+ if (this._options.layout === 0) {
441
+ stageEl.appendChild(navEl);
442
+ stageEl.appendChild(sliderEl);
443
+ stageEl.appendChild(paginationEl);
444
+ el.appendChild(stageEl);
445
+ }
446
+ else if (this._options.layout === 1 || this._options.layout === 2 || this._options.layout === 3) {
447
+ stageEl.appendChild(navEl);
448
+ stageEl.appendChild(sliderEl);
449
+ stageEl.appendChild(articleTextDivEl);
450
+ el.appendChild(stageEl);
451
+
452
+ if (this._options.layout === 3) {
453
+ //this._thumbsUlEl.appendChild(paginationEl);
454
+ this._thumbsUlEl.className = 'thumbs unstyled';
455
+ Css.addClassName(el, 'rightNav');
456
+ el.appendChild(this._thumbsUlEl);
457
+ }
458
+ else {
459
+ thumbsDivEl.appendChild(paginationEl);
460
+ el.appendChild(thumbsDivEl);
461
+ }
462
+ }
463
+
464
+ this._swipeDir = 'x';
465
+ this._swipeThumbsDir = this._options.layout === 0 ? '' : (this._options.layout === 3 ? 'y' : 'x');
466
+
467
+ if (Swipe._supported) {
468
+ new Swipe(el, {
469
+ callback: Ink.bind(function(sw, o) {
470
+ var th = this._isMeOrParent(o.target, this._thumbsUlEl);
471
+ var sl = th ? false : this._isMeOrParent(o.target, el);//this._sliderUlEl);
472
+ if ( (!th && !sl) || (th && !this._swipeThumbsDir) ) { return; }
473
+ if ( (sl && o.axis !== this._swipeDir) || (th && o.axis !== this._swipeThumbsDir) ) { return; }
474
+ if (o.dr[0] < 0) { if (th) { this.thumbNext(); } else { this.next(); } }
475
+ else { if (th) { this.thumbPrevious(); } else { this.previous(); } }
476
+ },this),
477
+ maxDuration: 0.4,
478
+ minDist: 50
479
+ });
480
+ }
481
+
482
+ return el;
483
+ },
484
+
485
+ /**
486
+ * Verifies if a given element is equals to its parent
487
+ *
488
+ * @method _isMeOrParent
489
+ * @param {DOMElement} el Element to be compared with the parent element
490
+ * @param {DOMElement} parentEl Parent element to be compared with the element
491
+ * @return {Boolean|undefined} In case the 'el' variable is not defined, it returns undefined. Otherwise, it will return true or false depending on the comparison.
492
+ * @private
493
+ */
494
+ _isMeOrParent: function(el, parentEl) {
495
+ if (!el) {return;}
496
+ do {
497
+ if (el === parentEl) { return true; }
498
+ el = el.parentNode;
499
+ } while (el);
500
+ return false;
501
+ },
502
+
503
+ /**
504
+ * Navigation click handler
505
+ *
506
+ * @method _onNavClick
507
+ * @param {Event} ev
508
+ * @private
509
+ */
510
+ _onNavClick: function(ev) {
511
+ var tgtEl = Event.element(ev);
512
+ var delta;
513
+ if (Css.hasClassName(tgtEl, 'previous')) { delta = -1; }
514
+ else if (Css.hasClassName(tgtEl, 'next')) { delta = 1; }
515
+ else { return; }
516
+
517
+ Event.stop(ev);
518
+ this.goTo(delta, true);
519
+ },
520
+
521
+ /**
522
+ * Pagination click handler
523
+ *
524
+ * @method _onPaginationClick
525
+ * @param {Event} ev
526
+ * @private
527
+ */
528
+ _onPaginationClick: function(ev) {
529
+ var tgtEl = Event.element(ev);
530
+ var i = tgtEl.getAttribute('data-index');
531
+ var isRelative = false;
532
+ if (Css.hasClassName(tgtEl, 'previous')) { i = -1; isRelative = true; }
533
+ else if (Css.hasClassName(tgtEl, 'next')) { i = 1; isRelative = true; }
534
+ else if (i === null) { return; }
535
+ else { i = parseInt(i, 10); }
536
+ Event.stop(ev);
537
+
538
+ if (isRelative) { this.thumbGoTo(i, true); }
539
+ else { this.goTo(i); }
540
+ },
541
+
542
+ /**
543
+ * Thumbs click handler
544
+ *
545
+ * @method _onThumbsClick
546
+ * @param {Event} ev
547
+ * @private
548
+ */
549
+ _onThumbsClick: function(ev) {
550
+ var tgtEl = Event.element(ev);
551
+ if (tgtEl.nodeName.toLowerCase() === 'img') {}
552
+ else if (tgtEl.nodeName.toLowerCase() === 'span') {
553
+ tgtEl = Selector.select('> img', tgtEl.parentNode)[0];
554
+ }
555
+ else { return; }
556
+
557
+ Event.stop(ev);
558
+ var i = parseInt(tgtEl.getAttribute('alt'), 10) - 1;
559
+ this.goTo(i);
560
+ },
561
+
562
+ /**
563
+ * Focus handler
564
+ *
565
+ * @method _onFocusBlur
566
+ * @param {Event} ev
567
+ * @private
568
+ */
569
+ _onFocusBlur: function(ev) {
570
+ this._isFocused = (ev.type === 'mouseover');
571
+ },
572
+
573
+ /**
574
+ * Key handler
575
+ *
576
+ * @method _onKeyDown
577
+ * @param {Event} ev
578
+ * @private
579
+ */
580
+ _onKeyDown: function(ev) {
581
+ if (!this._isFocused) { return; }
582
+ var kc = ev.keyCode;
583
+ if (kc === 37) { this.previous(); }
584
+ else if (kc === 39) { this.next(); }
585
+ else { return; }
586
+ Event.stop(ev);
587
+ },
588
+
589
+ /**
590
+ * Validates the number of the item against the gallery items.
591
+ *
592
+ * @method _validateValue
593
+ * @param {Number} i The number of the item being validated
594
+ * @param {Boolean} [isRelative]
595
+ * @param {Boolean} [isThumb]
596
+ * @return {Number|Boolean}
597
+ * @private
598
+ */
599
+ _validateValue: function(i, isRelative, isThumb) {
600
+ // check arguments
601
+ if (!Aux.isInteger(i)) {
602
+ throw new TypeError('1st parameter must be an integer number!');
603
+ }
604
+ if ( isRelative !== undefined &&
605
+ isRelative !== false &&
606
+ isRelative !== true ) {
607
+ throw new TypeError('2nd parameter must either be boolean or ommitted!');
608
+ }
609
+
610
+ var val = isThumb ? this._thumbIndex : this._index;
611
+
612
+ // compute new index
613
+ if (isRelative) { i += val; }
614
+
615
+ if (this._options.circular) {
616
+ if (i < 0) { i = this._model.length - 1; }
617
+ else if (i >= this._model.length) { i = 0; }
618
+ }
619
+ else {
620
+ if (i < 0 || i >= this._model.length || i === val) { return false; }
621
+ }
622
+
623
+ return i;
624
+ },
625
+
626
+
627
+
628
+ /**************
629
+ * PUBLIC API *
630
+ **************/
631
+
632
+ /**
633
+ * Returns the index of the current image
634
+ *
635
+ * @method getIndex
636
+ * @return {Number} Index of the current image
637
+ * @public
638
+ */
639
+ getIndex: function() {
640
+ return this._index;
641
+ },
642
+
643
+ /**
644
+ * Returns the number of images in the gallery
645
+ *
646
+ * @method getLength
647
+ * @return {Number} Number of images in the gallery
648
+ * @public
649
+ */
650
+ getLength: function() {
651
+ return this._model.length;
652
+ },
653
+
654
+ /**
655
+ * Moves gallery to the nth - 1 image
656
+ *
657
+ * @method goTo
658
+ * @param {Number} i Absolute or relative index
659
+ * @param {Boolean} [isRelative] pass true for relative movement, otherwise absolute
660
+ * @public
661
+ */
662
+ goTo: function(i, isRelative) {
663
+ i = this._validateValue(i, isRelative, false);
664
+ if (i === false) { return; }
665
+ this._index = i;
666
+
667
+ // update DOM representation
668
+ var paginationAEls = Selector.select('> a', this._paginationEl);
669
+ var that = this;
670
+ InkArray.each(paginationAEls,function(aEl, i) {
671
+ Css.setClassName(aEl, 'active', (i - (that._paginationHasPrevNext ? 1 : 0)) === that._index);
672
+ });
673
+
674
+ this._sliderUlEl.style.marginLeft = ['-', this._options.fullImageMaxWidth * this._index, 'px'].join('');
675
+
676
+ if (this._showDescription) {
677
+ var d = this._model[this._index];
678
+ if (d.title_link) {
679
+ this._articleTextDivEl.innerHTML = ['<h1><a href="', d.title_link, '">', d.title_text, '</a></h1>', d.description].join('');
680
+ }
681
+ else {
682
+ this._articleTextDivEl.innerHTML = ['<h1>', d.title_text, '</h1>', d.description].join('');
683
+ }
684
+ }
685
+ },
686
+
687
+ /**
688
+ * Moves gallery to the nth - 1 thumb
689
+ *
690
+ * @method thumbGoTo
691
+ * @param {Number} i Absolute or relative index
692
+ * @param {Boolean} [isRelative] pass true for relative movement, otherwise absolute
693
+ * @public
694
+ */
695
+ thumbGoTo: function(i, isRelative) {
696
+ i = this._validateValue(i, isRelative, true);
697
+ if (i === false) { return; }
698
+ this._thumbIndex = i;
699
+
700
+ // update DOM representation
701
+ var prop = 'margin' + (this._swipeThumbsDir === 'x' ? 'Left' : 'Top');
702
+ this._thumbsUlEl.style[prop] = ['-', this._options.thumbnailMaxWidth * this._thumbIndex, 'px'].join('');
703
+ },
704
+
705
+ /**
706
+ * Move to the previous image
707
+ *
708
+ * @method previous
709
+ * @public
710
+ */
711
+ previous: function() {
712
+ this.goTo(-1, true);
713
+ },
714
+
715
+ /**
716
+ * Move to the next image
717
+ *
718
+ * @method next
719
+ * @public
720
+ */
721
+ next: function() {
722
+ this.goTo(1, true);
723
+ },
724
+
725
+ /**
726
+ * Move to the previous thumb
727
+ *
728
+ * @method thumbPrevious
729
+ * @public
730
+ */
731
+ thumbPrevious: function() {
732
+ this.thumbGoTo(-1, true);
733
+ },
734
+
735
+ /**
736
+ * Move to the next thumb
737
+ *
738
+ * @method thumbNext
739
+ * @public
740
+ */
741
+ thumbNext: function() {
742
+ this.thumbGoTo(1, true);
743
+ },
744
+
745
+ /**
746
+ * Unregisters the component and removes its markup from the DOM
747
+ *
748
+ * @method destroy
749
+ * @public
750
+ */
751
+ destroy: Aux.destroyComponent
752
+
753
+ };
754
+
755
+ return Gallery;
756
+
757
+ });