j1-template 2021.0.9 → 2021.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/assets/data/menu.html +0 -32
  3. data/assets/themes/j1/adapter/js/fam.js +59 -27
  4. data/assets/themes/j1/adapter/js/toccer.js +97 -18
  5. data/assets/themes/j1/core/css/themes/uno-light/bootstrap.css +78 -89
  6. data/assets/themes/j1/core/css/themes/uno-light/bootstrap.min.css +1 -1
  7. data/assets/themes/j1/modules/justifiedGallery/LICENSE +1 -1
  8. data/assets/themes/j1/modules/justifiedGallery/README.md +5 -3
  9. data/assets/themes/j1/modules/justifiedGallery/_versions/v3.8.0/js/{jquery.justifiedGallery.js → justifiedGallery.js} +145 -145
  10. data/assets/themes/j1/modules/justifiedGallery/_versions/v3.8.0/js/{jquery.justifiedGallery.min.js → justifiedGallery.min.js} +1 -2
  11. data/assets/themes/j1/modules/justifiedGallery/js/justifiedGallery.js +69 -53
  12. data/assets/themes/j1/modules/justifiedGallery/js/justifiedGallery.min.js +2 -2
  13. data/lib/j1/commands/generate.rb +1 -1
  14. data/lib/j1/version.rb +1 -1
  15. data/lib/starter_web/Gemfile +1 -1
  16. data/lib/starter_web/_config.yml +1 -1
  17. data/lib/starter_web/_data/apps/justified_gallery.yml +41 -13
  18. data/lib/starter_web/_data/blocks/banner.yml +2 -2
  19. data/lib/starter_web/_data/blocks/panel.yml +1 -1
  20. data/lib/starter_web/_data/modules/defaults/toccer.yml +2 -2
  21. data/lib/starter_web/_data/modules/navigator_menu.yml +6 -6
  22. data/lib/starter_web/_includes/attributes.asciidoc +13 -5
  23. data/lib/starter_web/_plugins/lunr_index.rb +1 -1
  24. data/lib/starter_web/assets/images/collections/blog/featured/markus-spiske-2.jpg +0 -0
  25. data/lib/starter_web/assets/images/collections/blog/featured/staticgen.jpg +0 -0
  26. data/lib/starter_web/assets/images/modules/attics/florian-olivo-1920x1280.jpg +0 -0
  27. data/lib/starter_web/assets/images/modules/attics/{runner-1920x1200-bw.jpg → runner-1920x1200.jpg} +0 -0
  28. data/lib/starter_web/assets/images/modules/attics/{the-place-1920x1280-bw.jpg → the-place-1920x1280.jpg} +0 -0
  29. data/lib/starter_web/assets/images/modules/gallery/old_times/colored/image_01.jpg +0 -0
  30. data/lib/starter_web/assets/images/modules/gallery/old_times/image_01.jpg +0 -0
  31. data/lib/starter_web/assets/images/modules/gallery/old_times/image_02.jpg +0 -0
  32. data/lib/starter_web/assets/images/modules/gallery/old_times/image_03.jpg +0 -0
  33. data/lib/starter_web/assets/images/modules/gallery/old_times/image_04.jpg +0 -0
  34. data/lib/starter_web/assets/images/modules/icons/d1/scalable/d1.svg +1 -1
  35. data/lib/starter_web/assets/images/pages/panels/florian-olivo-1920x800.jpg +0 -0
  36. data/lib/starter_web/assets/images/pages/panels/responsive-text-1920x800.jpg +0 -0
  37. data/lib/starter_web/collections/posts/public/featured/_posts/{0000-00-00-welcome-to-j1-template.adoc.erb → 0000-00-00-welcome-to-j1.adoc.erb} +29 -13
  38. data/lib/starter_web/collections/posts/public/featured/_posts/{2020-05-01-top-open-source-static-site-generators.adoc → 2020-05-01-top-site-generators.adoc} +9 -14
  39. data/lib/starter_web/collections/posts/public/featured/_posts/2020-06-01-about-cookies.adoc +53 -52
  40. data/lib/starter_web/collections/posts/public/featured/_posts/2021-01-01-welcome-to-j1.adoc +167 -0
  41. data/lib/starter_web/index.html +8 -8
  42. data/lib/starter_web/package.json +1 -1
  43. data/lib/starter_web/pages/public/asciidoc_skeletons/book/000_intro.adoc +1 -1
  44. data/lib/starter_web/pages/public/asciidoc_skeletons/book/100_chapter.adoc +1 -1
  45. data/lib/starter_web/pages/public/asciidoc_skeletons/book/200_chapter.adoc +1 -1
  46. data/lib/starter_web/pages/public/asciidoc_skeletons/book/900_references.adoc +1 -1
  47. data/lib/starter_web/pages/public/asciidoc_skeletons/book/book.adoc +1 -1
  48. data/lib/starter_web/pages/public/asciidoc_skeletons/multi-document/100_chapter.asciidoc +1 -1
  49. data/lib/starter_web/pages/public/asciidoc_skeletons/multi-document/200_chapter.asciidoc +1 -1
  50. data/lib/starter_web/pages/public/asciidoc_skeletons/multi-document/multi.adoc +1 -1
  51. data/lib/starter_web/pages/public/learn/roundtrip/100_present_images.adoc +4 -5
  52. data/lib/starter_web/pages/public/learn/roundtrip/500_themes.adoc +20 -51
  53. data/lib/starter_web/pages/public/learn/where_to_go.adoc +34 -49
  54. data/lib/starter_web/pages/public/panels/intro_panel/panel.adoc +67 -36
  55. data/lib/starter_web/pages/public/previewer/bootstrap_theme.adoc +15 -15
  56. data/lib/starter_web/pages/public/previewer/rouge.adoc +22 -53
  57. data/lib/starter_web/utilsrv/_defaults/package.json +1 -1
  58. data/lib/starter_web/utilsrv/package.json +1 -1
  59. metadata +18 -16
  60. data/assets/themes/j1/modules/justifiedGallery/_versions/v3.8.0/justifiedGallery.min.zip +0 -0
  61. data/assets/themes/j1/modules/justifiedGallery/_versions/v3.8.0/justifiedGallery.zip +0 -0
  62. data/assets/themes/j1/modules/justifiedGallery/_versions/v4.0.0/css/justifiedGallery.css +0 -110
  63. data/assets/themes/j1/modules/justifiedGallery/_versions/v4.0.0/css/justifiedGallery.min.css +0 -110
  64. data/assets/themes/j1/modules/justifiedGallery/_versions/v4.0.0/css/theme/uno.css +0 -23
  65. data/assets/themes/j1/modules/justifiedGallery/_versions/v4.0.0/js/jquery.justifiedGallery.js +0 -1229
  66. data/assets/themes/j1/modules/justifiedGallery/_versions/v4.0.0/js/jquery.justifiedGallery.min.js +0 -8
  67. data/lib/starter_web/collections/posts/public/featured/_posts/2020-04-01-confusion-about-base-url.adoc +0 -118
@@ -1,110 +0,0 @@
1
- /*!
2
- * justifiedGallery - v4.0.0-alpha
3
- * http://miromannino.github.io/Justified-Gallery/
4
- * Copyright (c) 2019 Miro Mannino
5
- * Licensed under the MIT license.
6
- */
7
- .justified-gallery {
8
- width: 100%;
9
- position: relative;
10
- overflow: hidden;
11
- }
12
- .justified-gallery > a,
13
- .justified-gallery > div,
14
- .justified-gallery > figure {
15
- position: absolute;
16
- display: inline-block;
17
- overflow: hidden;
18
- /* background: #888888; To have gray placeholders while the gallery is loading with waitThumbnailsLoad = false */
19
- filter: "alpha(opacity=10)";
20
- opacity: 0.1;
21
- margin: 0;
22
- padding: 0;
23
- }
24
- .justified-gallery > a > img,
25
- .justified-gallery > div > img,
26
- .justified-gallery > figure > img,
27
- .justified-gallery > a > a > img,
28
- .justified-gallery > div > a > img,
29
- .justified-gallery > figure > a > img,
30
- .justified-gallery > a > svg,
31
- .justified-gallery > div > svg,
32
- .justified-gallery > figure > svg,
33
- .justified-gallery > a > a > svg,
34
- .justified-gallery > div > a > svg,
35
- .justified-gallery > figure > a > svg {
36
- position: absolute;
37
- top: 50%;
38
- left: 50%;
39
- margin: 0;
40
- padding: 0;
41
- border: none;
42
- filter: "alpha(opacity=0)";
43
- opacity: 0;
44
- }
45
- .justified-gallery > a > .caption,
46
- .justified-gallery > div > .caption,
47
- .justified-gallery > figure > .caption {
48
- display: none;
49
- position: absolute;
50
- bottom: 0;
51
- padding: 5px;
52
- background-color: #000000;
53
- left: 0;
54
- right: 0;
55
- margin: 0;
56
- color: white;
57
- font-size: 12px;
58
- font-weight: 300;
59
- font-family: sans-serif;
60
- }
61
- .justified-gallery > a > .caption.caption-visible,
62
- .justified-gallery > div > .caption.caption-visible,
63
- .justified-gallery > figure > .caption.caption-visible {
64
- display: initial;
65
- filter: "alpha(opacity=70)";
66
- opacity: 0.7;
67
- -webkit-transition: opacity 500ms ease-in;
68
- -moz-transition: opacity 500ms ease-in;
69
- -o-transition: opacity 500ms ease-in;
70
- transition: opacity 500ms ease-in;
71
- }
72
- .justified-gallery > .jg-entry-visible {
73
- filter: "alpha(opacity=100)";
74
- opacity: 1;
75
- background: none;
76
- }
77
- .justified-gallery > .jg-entry-visible > img,
78
- .justified-gallery > .jg-entry-visible > a > img,
79
- .justified-gallery > .jg-entry-visible > svg,
80
- .justified-gallery > .jg-entry-visible > a > svg {
81
- filter: "alpha(opacity=100)";
82
- opacity: 1;
83
- -webkit-transition: opacity 500ms ease-in;
84
- -moz-transition: opacity 500ms ease-in;
85
- -o-transition: opacity 500ms ease-in;
86
- transition: opacity 500ms ease-in;
87
- }
88
- .justified-gallery > .jg-filtered {
89
- display: none;
90
- }
91
- .justified-gallery > .spinner {
92
- position: absolute;
93
- bottom: 0;
94
- margin-left: -24px;
95
- padding: 10px 0 10px 0;
96
- left: 50%;
97
- filter: "alpha(opacity=100)";
98
- opacity: 1;
99
- overflow: initial;
100
- }
101
- .justified-gallery > .spinner > span {
102
- display: inline-block;
103
- filter: "alpha(opacity=0)";
104
- opacity: 0;
105
- width: 8px;
106
- height: 8px;
107
- margin: 0 4px 0 4px;
108
- background-color: #000;
109
- border-radius: 6px;
110
- }
@@ -1,23 +0,0 @@
1
- /*
2
- # -----------------------------------------------------------------------------
3
- # ~/assets/themes/j1/modules/justified_gallery/css/theme/uno.css
4
- # Provides J1 JustifiedGallery styles for J1 Theme Uno
5
- #
6
- # Product/Info:
7
- # https://jekyll.one
8
- #
9
- # Copyright (C) 2021 Juergen Adams
10
- #
11
- # J1 Template is licensed under the MIT License.
12
- # See: https://github.com/jekyll-one-org/J1 Template/blob/master/LICENSE
13
- #
14
- # -----------------------------------------------------------------------------
15
- */
16
-
17
- /* Gallery title */
18
- .jg-gallery-title {
19
- font-style: italic;
20
- font-weight: 400;
21
- color: rgba(0, 0, 0, 0.5);
22
- overflow: hidden;
23
- }
@@ -1,1229 +0,0 @@
1
- /*!
2
- * justifiedGallery - v4.0.0-alpha
3
- * http://miromannino.github.io/Justified-Gallery/
4
- * Copyright (c) 2019 Miro Mannino
5
- * Licensed under the MIT license.
6
- */
7
- (function (factory) {
8
- if (typeof define === 'function' && define.amd) {
9
- // AMD. Register as an anonymous module.
10
- define(['jquery'], factory);
11
- } else if (typeof module === 'object' && module.exports) {
12
- // Node/CommonJS
13
- module.exports = function( root, jQuery ) {
14
- if ( jQuery === undefined ) {
15
- // require('jQuery') returns a factory that requires window to
16
- // build a jQuery instance, we normalize how we use modules
17
- // that require this pattern but the window provided is a noop
18
- // if it's defined (how jquery works)
19
- if ( typeof window !== 'undefined' ) {
20
- jQuery = require('jquery');
21
- }
22
- else {
23
- jQuery = require('jquery')(root);
24
- }
25
- }
26
- factory(jQuery);
27
- return jQuery;
28
- };
29
- } else {
30
- // Browser globals
31
- factory(jQuery);
32
- }
33
- }(function ($) {
34
-
35
- /**
36
- * Justified Gallery controller constructor
37
- *
38
- * @param $gallery the gallery to build
39
- * @param settings the settings (the defaults are in JustifiedGallery.defaults)
40
- * @constructor
41
- */
42
- var JustifiedGallery = function ($gallery, settings) {
43
-
44
- this.settings = settings;
45
- this.checkSettings();
46
-
47
- this.imgAnalyzerTimeout = null;
48
- this.entries = null;
49
- this.buildingRow = {
50
- entriesBuff : [],
51
- width : 0,
52
- height : 0,
53
- aspectRatio : 0
54
- };
55
- this.lastFetchedEntry = null;
56
- this.lastAnalyzedIndex = -1;
57
- this.yield = {
58
- every : 2, // do a flush every n flushes (must be greater than 1)
59
- flushed : 0 // flushed rows without a yield
60
- };
61
- this.border = settings.border >= 0 ? settings.border : settings.margins;
62
- this.maxRowHeight = this.retrieveMaxRowHeight();
63
- this.suffixRanges = this.retrieveSuffixRanges();
64
- this.offY = this.border;
65
- this.rows = 0;
66
- this.spinner = {
67
- phase : 0,
68
- timeSlot : 150,
69
- $el : $('<div class="spinner"><span></span><span></span><span></span></div>'),
70
- intervalId : null
71
- };
72
- this.scrollBarOn = false;
73
- this.checkWidthIntervalId = null;
74
- this.galleryWidth = $gallery.width();
75
- this.$gallery = $gallery;
76
-
77
- };
78
-
79
- /** @returns {String} the best suffix given the width and the height */
80
- JustifiedGallery.prototype.getSuffix = function (width, height) {
81
- var longestSide, i;
82
- longestSide = (width > height) ? width : height;
83
- for (i = 0; i < this.suffixRanges.length; i++) {
84
- if (longestSide <= this.suffixRanges[i]) {
85
- return this.settings.sizeRangeSuffixes[this.suffixRanges[i]];
86
- }
87
- }
88
- return this.settings.sizeRangeSuffixes[this.suffixRanges[i - 1]];
89
- };
90
-
91
- /**
92
- * Remove the suffix from the string
93
- *
94
- * @returns {string} a new string without the suffix
95
- */
96
- JustifiedGallery.prototype.removeSuffix = function (str, suffix) {
97
- return str.substring(0, str.length - suffix.length);
98
- };
99
-
100
- /**
101
- * @returns {boolean} a boolean to say if the suffix is contained in the str or not
102
- */
103
- JustifiedGallery.prototype.endsWith = function (str, suffix) {
104
- return str.indexOf(suffix, str.length - suffix.length) !== -1;
105
- };
106
-
107
- /**
108
- * Get the used suffix of a particular url
109
- *
110
- * @param str
111
- * @returns {String} return the used suffix
112
- */
113
- JustifiedGallery.prototype.getUsedSuffix = function (str) {
114
- for (var si in this.settings.sizeRangeSuffixes) {
115
- if (this.settings.sizeRangeSuffixes.hasOwnProperty(si)) {
116
- if (this.settings.sizeRangeSuffixes[si].length === 0) continue;
117
- if (this.endsWith(str, this.settings.sizeRangeSuffixes[si])) return this.settings.sizeRangeSuffixes[si];
118
- }
119
- }
120
- return '';
121
- };
122
-
123
- /**
124
- * Given an image src, with the width and the height, returns the new image src with the
125
- * best suffix to show the best quality thumbnail.
126
- *
127
- * @returns {String} the suffix to use
128
- */
129
- JustifiedGallery.prototype.newSrc = function (imageSrc, imgWidth, imgHeight, image) {
130
- var newImageSrc;
131
-
132
- if (this.settings.thumbnailPath) {
133
- newImageSrc = this.settings.thumbnailPath(imageSrc, imgWidth, imgHeight, image);
134
- } else {
135
- var matchRes = imageSrc.match(this.settings.extension);
136
- var ext = (matchRes !== null) ? matchRes[0] : '';
137
- newImageSrc = imageSrc.replace(this.settings.extension, '');
138
- newImageSrc = this.removeSuffix(newImageSrc, this.getUsedSuffix(newImageSrc));
139
- newImageSrc += this.getSuffix(imgWidth, imgHeight) + ext;
140
- }
141
-
142
- return newImageSrc;
143
- };
144
-
145
- /**
146
- * Shows the images that is in the given entry
147
- *
148
- * @param $entry the entry
149
- * @param callback the callback that is called when the show animation is finished
150
- */
151
- JustifiedGallery.prototype.showImg = function ($entry, callback) {
152
- if (this.settings.cssAnimation) {
153
- $entry.addClass('jg-entry-visible');
154
- if (callback) callback();
155
- } else {
156
- $entry.stop().fadeTo(this.settings.imagesAnimationDuration, 1.0, callback);
157
- $entry.find(this.settings.imgSelector).stop().fadeTo(this.settings.imagesAnimationDuration, 1.0, callback);
158
- }
159
- };
160
-
161
- /**
162
- * Extract the image src form the image, looking from the 'safe-src', and if it can't be found, from the
163
- * 'src' attribute. It saves in the image data the 'jg.originalSrc' field, with the extracted src.
164
- *
165
- * @param $image the image to analyze
166
- * @returns {String} the extracted src
167
- */
168
- JustifiedGallery.prototype.extractImgSrcFromImage = function ($image) {
169
- var imageSrc = $image.data('safe-src');
170
- var imageSrcLoc = 'date-safe-src';
171
- if (typeof imageSrc === 'undefined') {
172
- imageSrc = $image.attr('src');
173
- imageSrcLoc = 'src';
174
- }
175
- $image.data('jg.originalSrc', imageSrc); // this is saved for the destroy method
176
- $image.data('jg.src', imageSrc); // this will change overtime
177
- $image.data('jg.originalSrcLoc', imageSrcLoc); // this is saved for the destroy method
178
- return imageSrc;
179
- };
180
-
181
- /** @returns {jQuery} the image in the given entry */
182
- JustifiedGallery.prototype.imgFromEntry = function ($entry) {
183
- var $img = $entry.find(this.settings.imgSelector);
184
- return $img.length === 0 ? null : $img;
185
- };
186
-
187
- /** @returns {jQuery} the caption in the given entry */
188
- JustifiedGallery.prototype.captionFromEntry = function ($entry) {
189
- var $caption = $entry.find('> .caption');
190
- return $caption.length === 0 ? null : $caption;
191
- };
192
-
193
- /**
194
- * Display the entry
195
- *
196
- * @param {jQuery} $entry the entry to display
197
- * @param {int} x the x position where the entry must be positioned
198
- * @param y the y position where the entry must be positioned
199
- * @param imgWidth the image width
200
- * @param imgHeight the image height
201
- * @param rowHeight the row height of the row that owns the entry
202
- */
203
- JustifiedGallery.prototype.displayEntry = function ($entry, x, y, imgWidth, imgHeight, rowHeight) {
204
- $entry.width(imgWidth);
205
- $entry.height(rowHeight);
206
- $entry.css('top', y);
207
- $entry.css('left', x);
208
-
209
- var $image = this.imgFromEntry($entry);
210
- if ($image !== null) {
211
- $image.css('width', imgWidth);
212
- $image.css('height', imgHeight);
213
- $image.css('margin-left', - imgWidth / 2);
214
- $image.css('margin-top', - imgHeight / 2);
215
-
216
- // Image reloading for an high quality of thumbnails
217
- var imageSrc = $image.data('jg.src');
218
- if (imageSrc) {
219
- imageSrc = this.newSrc(imageSrc, imgWidth, imgHeight, $image[0]);
220
-
221
- $image.one('error', function () {
222
- this.resetImgSrc($image); //revert to the original thumbnail
223
- });
224
-
225
- var loadNewImage = function () {
226
- // if (imageSrc !== newImageSrc) {
227
- $image.attr('src', imageSrc);
228
- // }
229
- };
230
-
231
- if ($entry.data('jg.loaded') === 'skipped') {
232
- this.onImageEvent(imageSrc, (function() {
233
- this.showImg($entry, loadNewImage); //load the new image after the fadeIn
234
- $entry.data('jg.loaded', true);
235
- }).bind(this));
236
- } else {
237
- this.showImg($entry, loadNewImage); //load the new image after the fadeIn
238
- }
239
-
240
- }
241
-
242
- } else {
243
- this.showImg($entry);
244
- }
245
-
246
- this.displayEntryCaption($entry);
247
- };
248
-
249
- /**
250
- * Display the entry caption. If the caption element doesn't exists, it creates the caption using the 'alt'
251
- * or the 'title' attributes.
252
- *
253
- * @param {jQuery} $entry the entry to process
254
- */
255
- JustifiedGallery.prototype.displayEntryCaption = function ($entry) {
256
- var $image = this.imgFromEntry($entry);
257
- if ($image !== null && this.settings.captions) {
258
- var $imgCaption = this.captionFromEntry($entry);
259
-
260
- // Create it if it doesn't exists
261
- if ($imgCaption === null) {
262
- var caption = $image.attr('alt');
263
- if (!this.isValidCaption(caption)) caption = $entry.attr('title');
264
- if (this.isValidCaption(caption)) { // Create only we found something
265
- $imgCaption = $('<div class="caption">' + caption + '</div>');
266
- $entry.append($imgCaption);
267
- $entry.data('jg.createdCaption', true);
268
- }
269
- }
270
-
271
- // Create events (we check again the $imgCaption because it can be still inexistent)
272
- if ($imgCaption !== null) {
273
- if (!this.settings.cssAnimation) $imgCaption.stop().fadeTo(0, this.settings.captionSettings.nonVisibleOpacity);
274
- this.addCaptionEventsHandlers($entry);
275
- }
276
- } else {
277
- this.removeCaptionEventsHandlers($entry);
278
- }
279
- };
280
-
281
- /**
282
- * Validates the caption
283
- *
284
- * @param caption The caption that should be validated
285
- * @return {boolean} Validation result
286
- */
287
- JustifiedGallery.prototype.isValidCaption = function (caption) {
288
- return (typeof caption !== 'undefined' && caption.length > 0);
289
- };
290
-
291
- /**
292
- * The callback for the event 'mouseenter'. It assumes that the event currentTarget is an entry.
293
- * It shows the caption using jQuery (or using CSS if it is configured so)
294
- *
295
- * @param {Event} eventObject the event object
296
- */
297
- JustifiedGallery.prototype.onEntryMouseEnterForCaption = function (eventObject) {
298
- var $caption = this.captionFromEntry($(eventObject.currentTarget));
299
- if (this.settings.cssAnimation) {
300
- $caption.addClass('caption-visible').removeClass('caption-hidden');
301
- } else {
302
- $caption.stop().fadeTo(this.settings.captionSettings.animationDuration,
303
- this.settings.captionSettings.visibleOpacity);
304
- }
305
- };
306
-
307
- /**
308
- * The callback for the event 'mouseleave'. It assumes that the event currentTarget is an entry.
309
- * It hides the caption using jQuery (or using CSS if it is configured so)
310
- *
311
- * @param {Event} eventObject the event object
312
- */
313
- JustifiedGallery.prototype.onEntryMouseLeaveForCaption = function (eventObject) {
314
- var $caption = this.captionFromEntry($(eventObject.currentTarget));
315
- if (this.settings.cssAnimation) {
316
- $caption.removeClass('caption-visible').removeClass('caption-hidden');
317
- } else {
318
- $caption.stop().fadeTo(this.settings.captionSettings.animationDuration,
319
- this.settings.captionSettings.nonVisibleOpacity);
320
- }
321
- };
322
-
323
- /**
324
- * Add the handlers of the entry for the caption
325
- *
326
- * @param $entry the entry to modify
327
- */
328
- JustifiedGallery.prototype.addCaptionEventsHandlers = function ($entry) {
329
- var captionMouseEvents = $entry.data('jg.captionMouseEvents');
330
- if (typeof captionMouseEvents === 'undefined') {
331
- captionMouseEvents = {
332
- mouseenter: $.proxy(this.onEntryMouseEnterForCaption, this),
333
- mouseleave: $.proxy(this.onEntryMouseLeaveForCaption, this)
334
- };
335
- $entry.on('mouseenter', undefined, undefined, captionMouseEvents.mouseenter);
336
- $entry.on('mouseleave', undefined, undefined, captionMouseEvents.mouseleave);
337
- $entry.data('jg.captionMouseEvents', captionMouseEvents);
338
- }
339
- };
340
-
341
- /**
342
- * Remove the handlers of the entry for the caption
343
- *
344
- * @param $entry the entry to modify
345
- */
346
- JustifiedGallery.prototype.removeCaptionEventsHandlers = function ($entry) {
347
- var captionMouseEvents = $entry.data('jg.captionMouseEvents');
348
- if (typeof captionMouseEvents !== 'undefined') {
349
- $entry.off('mouseenter', undefined, captionMouseEvents.mouseenter);
350
- $entry.off('mouseleave', undefined, captionMouseEvents.mouseleave);
351
- $entry.removeData('jg.captionMouseEvents');
352
- }
353
- };
354
-
355
- /**
356
- * Clear the building row data to be used for a new row
357
- */
358
- JustifiedGallery.prototype.clearBuildingRow = function () {
359
- this.buildingRow.entriesBuff = [];
360
- this.buildingRow.aspectRatio = 0;
361
- this.buildingRow.width = 0;
362
- };
363
-
364
- /**
365
- * Justify the building row, preparing it to
366
- *
367
- * @param isLastRow
368
- * @returns a boolean to know if the row has been justified or not
369
- */
370
- JustifiedGallery.prototype.prepareBuildingRow = function (isLastRow) {
371
- var i, $entry, imgAspectRatio, newImgW, newImgH, justify = true;
372
- var minHeight = 0;
373
- var availableWidth = this.galleryWidth - 2 * this.border - (
374
- (this.buildingRow.entriesBuff.length - 1) * this.settings.margins);
375
- var rowHeight = availableWidth / this.buildingRow.aspectRatio;
376
- var defaultRowHeight = this.settings.rowHeight;
377
- var justifiable = this.buildingRow.width / availableWidth > this.settings.justifyThreshold;
378
-
379
- //Skip the last row if we can't justify it and the lastRow == 'hide'
380
- if (isLastRow && this.settings.lastRow === 'hide' && !justifiable) {
381
- for (i = 0; i < this.buildingRow.entriesBuff.length; i++) {
382
- $entry = this.buildingRow.entriesBuff[i];
383
- if (this.settings.cssAnimation)
384
- $entry.removeClass('jg-entry-visible');
385
- else {
386
- $entry.stop().fadeTo(0, 0.1);
387
- $entry.find('> img, > a > img').fadeTo(0, 0);
388
- }
389
- }
390
- return -1;
391
- }
392
-
393
- // With lastRow = nojustify, justify if is justificable (the images will not become too big)
394
- if (isLastRow && !justifiable && this.settings.lastRow !== 'justify' && this.settings.lastRow !== 'hide') {
395
- justify = false;
396
-
397
- if (this.rows > 0) {
398
- defaultRowHeight = (this.offY - this.border - this.settings.margins * this.rows) / this.rows;
399
- justify = defaultRowHeight * this.buildingRow.aspectRatio / availableWidth > this.settings.justifyThreshold;
400
- }
401
- }
402
-
403
- for (i = 0; i < this.buildingRow.entriesBuff.length; i++) {
404
- $entry = this.buildingRow.entriesBuff[i];
405
- imgAspectRatio = $entry.data('jg.width') / $entry.data('jg.height');
406
-
407
- if (justify) {
408
- newImgW = (i === this.buildingRow.entriesBuff.length - 1) ? availableWidth : rowHeight * imgAspectRatio;
409
- newImgH = rowHeight;
410
- } else {
411
- newImgW = defaultRowHeight * imgAspectRatio;
412
- newImgH = defaultRowHeight;
413
- }
414
-
415
- availableWidth -= Math.round(newImgW);
416
- $entry.data('jg.jwidth', Math.round(newImgW));
417
- $entry.data('jg.jheight', Math.ceil(newImgH));
418
- if (i === 0 || minHeight > newImgH) minHeight = newImgH;
419
- }
420
-
421
- this.buildingRow.height = minHeight;
422
- return justify;
423
- };
424
-
425
- /**
426
- * Flush a row: justify it, modify the gallery height accordingly to the row height
427
- *
428
- * @param isLastRow
429
- */
430
- JustifiedGallery.prototype.flushRow = function (isLastRow) {
431
- var settings = this.settings;
432
- var $entry, buildingRowRes, offX = this.border, i;
433
-
434
- buildingRowRes = this.prepareBuildingRow(isLastRow);
435
- if (isLastRow && settings.lastRow === 'hide' && buildingRowRes === -1) {
436
- this.clearBuildingRow();
437
- return;
438
- }
439
-
440
- if(this.maxRowHeight) {
441
- if(this.maxRowHeight < this.buildingRow.height) this.buildingRow.height = this.maxRowHeight;
442
- }
443
-
444
- //Align last (unjustified) row
445
- if (isLastRow && (settings.lastRow === 'center' || settings.lastRow === 'right')) {
446
- var availableWidth = this.galleryWidth - 2 * this.border - (this.buildingRow.entriesBuff.length - 1) * settings.margins;
447
-
448
- for (i = 0; i < this.buildingRow.entriesBuff.length; i++) {
449
- $entry = this.buildingRow.entriesBuff[i];
450
- availableWidth -= $entry.data('jg.jwidth');
451
- }
452
-
453
- if (settings.lastRow === 'center')
454
- offX += availableWidth / 2;
455
- else if (settings.lastRow === 'right')
456
- offX += availableWidth;
457
- }
458
-
459
- var lastEntryIdx = this.buildingRow.entriesBuff.length - 1;
460
- for (i = 0; i <= lastEntryIdx; i++) {
461
- $entry = this.buildingRow.entriesBuff[ this.settings.rtl ? lastEntryIdx - i : i ];
462
- this.displayEntry($entry, offX, this.offY, $entry.data('jg.jwidth'), $entry.data('jg.jheight'), this.buildingRow.height);
463
- offX += $entry.data('jg.jwidth') + settings.margins;
464
- }
465
-
466
- //Gallery Height
467
- this.galleryHeightToSet = this.offY + this.buildingRow.height + this.border;
468
- this.setGalleryTempHeight(this.galleryHeightToSet + this.getSpinnerHeight());
469
-
470
- if (!isLastRow || (this.buildingRow.height <= settings.rowHeight && buildingRowRes)) {
471
- //Ready for a new row
472
- this.offY += this.buildingRow.height + settings.margins;
473
- this.rows += 1;
474
- this.clearBuildingRow();
475
- this.settings.triggerEvent.call(this, 'jg.rowflush');
476
- }
477
- };
478
-
479
-
480
- // Scroll position not restoring: https://github.com/miromannino/Justified-Gallery/issues/221
481
- var galleryPrevStaticHeight = 0;
482
-
483
- JustifiedGallery.prototype.rememberGalleryHeight = function () {
484
- galleryPrevStaticHeight = this.$gallery.height();
485
- this.$gallery.height(galleryPrevStaticHeight);
486
- };
487
-
488
- // grow only
489
- JustifiedGallery.prototype.setGalleryTempHeight = function (height) {
490
- galleryPrevStaticHeight = Math.max(height, galleryPrevStaticHeight);
491
- this.$gallery.height(galleryPrevStaticHeight);
492
- };
493
-
494
- JustifiedGallery.prototype.setGalleryFinalHeight = function (height) {
495
- galleryPrevStaticHeight = height;
496
- this.$gallery.height(height);
497
- };
498
-
499
- /**
500
- * Checks the width of the gallery container, to know if a new justification is needed
501
- */
502
- JustifiedGallery.prototype.checkWidth = function () {
503
- this.checkWidthIntervalId = setInterval($.proxy(function () {
504
-
505
- // if the gallery is not currently visible, abort.
506
- if (!this.$gallery.is(":visible")) return;
507
-
508
- var galleryWidth = parseFloat(this.$gallery.width());
509
- if (Math.abs(galleryWidth - this.galleryWidth) > this.settings.refreshSensitivity) {
510
- this.galleryWidth = galleryWidth;
511
- this.rewind();
512
-
513
- this.rememberGalleryHeight();
514
-
515
- // Restart to analyze
516
- this.startImgAnalyzer(true);
517
- }
518
- }, this), this.settings.refreshTime);
519
- };
520
-
521
- /**
522
- * @returns {boolean} a boolean saying if the spinner is active or not
523
- */
524
- JustifiedGallery.prototype.isSpinnerActive = function () {
525
- return this.spinner.intervalId !== null;
526
- };
527
-
528
- /**
529
- * @returns {int} the spinner height
530
- */
531
- JustifiedGallery.prototype.getSpinnerHeight = function () {
532
- return this.spinner.$el.innerHeight();
533
- };
534
-
535
- /**
536
- * Stops the spinner animation and modify the gallery height to exclude the spinner
537
- */
538
- JustifiedGallery.prototype.stopLoadingSpinnerAnimation = function () {
539
- clearInterval(this.spinner.intervalId);
540
- this.spinner.intervalId = null;
541
- this.setGalleryTempHeight(this.$gallery.height() - this.getSpinnerHeight());
542
- this.spinner.$el.detach();
543
- };
544
-
545
- /**
546
- * Starts the spinner animation
547
- */
548
- JustifiedGallery.prototype.startLoadingSpinnerAnimation = function () {
549
- var spinnerContext = this.spinner;
550
- var $spinnerPoints = spinnerContext.$el.find('span');
551
- clearInterval(spinnerContext.intervalId);
552
- this.$gallery.append(spinnerContext.$el);
553
- this.setGalleryTempHeight(this.offY + this.buildingRow.height + this.getSpinnerHeight());
554
- spinnerContext.intervalId = setInterval(function () {
555
- if (spinnerContext.phase < $spinnerPoints.length) {
556
- $spinnerPoints.eq(spinnerContext.phase).fadeTo(spinnerContext.timeSlot, 1);
557
- } else {
558
- $spinnerPoints.eq(spinnerContext.phase - $spinnerPoints.length).fadeTo(spinnerContext.timeSlot, 0);
559
- }
560
- spinnerContext.phase = (spinnerContext.phase + 1) % ($spinnerPoints.length * 2);
561
- }, spinnerContext.timeSlot);
562
- };
563
-
564
- /**
565
- * Rewind the image analysis to start from the first entry.
566
- */
567
- JustifiedGallery.prototype.rewind = function () {
568
- this.lastFetchedEntry = null;
569
- this.lastAnalyzedIndex = -1;
570
- this.offY = this.border;
571
- this.rows = 0;
572
- this.clearBuildingRow();
573
- };
574
-
575
- /**
576
- * @returns {Array} all entries matched by `settings.selector`
577
- */
578
- JustifiedGallery.prototype.getAllEntries = function () {
579
- return this.$gallery.children(this.settings.selector).toArray();
580
- };
581
-
582
- /**
583
- * Update the entries searching it from the justified gallery HTML element
584
- *
585
- * @param norewind if norewind only the new entries will be changed (i.e. randomized, sorted or filtered)
586
- * @returns {boolean} true if some entries has been founded
587
- */
588
- JustifiedGallery.prototype.updateEntries = function (norewind) {
589
- var newEntries;
590
-
591
- if (norewind && this.lastFetchedEntry != null) {
592
- newEntries = $(this.lastFetchedEntry).nextAll(this.settings.selector).toArray();
593
- } else {
594
- this.entries = [];
595
- newEntries = this.getAllEntries();
596
- }
597
-
598
- if (newEntries.length > 0) {
599
-
600
- // Sort or randomize
601
- if ($.isFunction(this.settings.sort)) {
602
- newEntries = this.sortArray(newEntries);
603
- } else if (this.settings.randomize) {
604
- newEntries = this.shuffleArray(newEntries);
605
- }
606
- this.lastFetchedEntry = newEntries[newEntries.length - 1];
607
-
608
- // Filter
609
- if (this.settings.filter) {
610
- newEntries = this.filterArray(newEntries);
611
- } else {
612
- this.resetFilters(newEntries);
613
- }
614
-
615
- }
616
-
617
- this.entries = this.entries.concat(newEntries);
618
- return true;
619
- };
620
-
621
- /**
622
- * Apply the entries order to the DOM, iterating the entries and appending the images
623
- *
624
- * @param entries the entries that has been modified and that must be re-ordered in the DOM
625
- */
626
- JustifiedGallery.prototype.insertToGallery = function (entries) {
627
- var that = this;
628
- $.each(entries, function () {
629
- $(this).appendTo(that.$gallery);
630
- });
631
- };
632
-
633
- /**
634
- * Shuffle the array using the Fisher-Yates shuffle algorithm
635
- *
636
- * @param a the array to shuffle
637
- * @return the shuffled array
638
- */
639
- JustifiedGallery.prototype.shuffleArray = function (a) {
640
- var i, j, temp;
641
- for (i = a.length - 1; i > 0; i--) {
642
- j = Math.floor(Math.random() * (i + 1));
643
- temp = a[i];
644
- a[i] = a[j];
645
- a[j] = temp;
646
- }
647
- this.insertToGallery(a);
648
- return a;
649
- };
650
-
651
- /**
652
- * Sort the array using settings.comparator as comparator
653
- *
654
- * @param a the array to sort (it is sorted)
655
- * @return the sorted array
656
- */
657
- JustifiedGallery.prototype.sortArray = function (a) {
658
- a.sort(this.settings.sort);
659
- this.insertToGallery(a);
660
- return a;
661
- };
662
-
663
- /**
664
- * Reset the filters removing the 'jg-filtered' class from all the entries
665
- *
666
- * @param a the array to reset
667
- */
668
- JustifiedGallery.prototype.resetFilters = function (a) {
669
- for (var i = 0; i < a.length; i++) $(a[i]).removeClass('jg-filtered');
670
- };
671
-
672
- /**
673
- * Filter the entries considering theirs classes (if a string has been passed) or using a function for filtering.
674
- *
675
- * @param a the array to filter
676
- * @return the filtered array
677
- */
678
- JustifiedGallery.prototype.filterArray = function (a) {
679
- var settings = this.settings;
680
- if ($.type(settings.filter) === 'string') {
681
- // Filter only keeping the entries passed in the string
682
- return a.filter(function (el) {
683
- var $el = $(el);
684
- if ($el.is(settings.filter)) {
685
- $el.removeClass('jg-filtered');
686
- return true;
687
- } else {
688
- $el.addClass('jg-filtered').removeClass('jg-visible');
689
- return false;
690
- }
691
- });
692
- } else if ($.isFunction(settings.filter)) {
693
- // Filter using the passed function
694
- var filteredArr = a.filter(settings.filter);
695
- for (var i = 0; i < a.length; i++) {
696
- if (filteredArr.indexOf(a[i]) === -1) {
697
- $(a[i]).addClass('jg-filtered').removeClass('jg-visible');
698
- } else {
699
- $(a[i]).removeClass('jg-filtered');
700
- }
701
- }
702
- return filteredArr;
703
- }
704
- };
705
-
706
- /**
707
- * Revert the image src to the default value.
708
- */
709
- JustifiedGallery.prototype.resetImgSrc = function ($img) {
710
- if ($img.data('jg.originalSrcLoc') == 'src') {
711
- $img.attr('src', $img.data('jg.originalSrc'));
712
- } else {
713
- $img.attr('src', '');
714
- }
715
- }
716
-
717
- /**
718
- * Destroy the Justified Gallery instance.
719
- *
720
- * It clears all the css properties added in the style attributes. We doesn't backup the original
721
- * values for those css attributes, because it costs (performance) and because in general one
722
- * shouldn't use the style attribute for an uniform set of images (where we suppose the use of
723
- * classes). Creating a backup is also difficult because JG could be called multiple times and
724
- * with different style attributes.
725
- */
726
- JustifiedGallery.prototype.destroy = function () {
727
- clearInterval(this.checkWidthIntervalId);
728
- this.stopImgAnalyzerStarter();
729
-
730
- // Get fresh entries list since filtered entries are absent in `this.entries`
731
- $.each(this.getAllEntries(), $.proxy(function(_, entry) {
732
- var $entry = $(entry);
733
-
734
- // Reset entry style
735
- $entry.css('width', '');
736
- $entry.css('height', '');
737
- $entry.css('top', '');
738
- $entry.css('left', '');
739
- $entry.data('jg.loaded', undefined);
740
- $entry.removeClass('jg-entry jg-filtered jg-entry-visible');
741
-
742
- // Reset image style
743
- var $img = this.imgFromEntry($entry);
744
- if ($img) {
745
- $img.css('width', '');
746
- $img.css('height', '');
747
- $img.css('margin-left', '');
748
- $img.css('margin-top', '');
749
- this.resetImgSrc($img);
750
- $img.data('jg.originalSrc', undefined);
751
- $img.data('jg.originalSrcLoc', undefined);
752
- $img.data('jg.src', undefined);
753
- }
754
-
755
- // Remove caption
756
- this.removeCaptionEventsHandlers($entry);
757
- var $caption = this.captionFromEntry($entry);
758
- if ($entry.data('jg.createdCaption')) {
759
- // remove also the caption element (if created by jg)
760
- $entry.data('jg.createdCaption', undefined);
761
- if ($caption !== null) $caption.remove();
762
- } else {
763
- if ($caption !== null) $caption.fadeTo(0, 1);
764
- }
765
-
766
- }, this));
767
-
768
- this.$gallery.css('height', '');
769
- this.$gallery.removeClass('justified-gallery');
770
- this.$gallery.data('jg.controller', undefined);
771
- this.settings.triggerEvent.call(this, 'jg.destroy');
772
- };
773
-
774
- /**
775
- * Analyze the images and builds the rows. It returns if it found an image that is not loaded.
776
- *
777
- * @param isForResize if the image analyzer is called for resizing or not, to call a different callback at the end
778
- */
779
- JustifiedGallery.prototype.analyzeImages = function (isForResize) {
780
- for (var i = this.lastAnalyzedIndex + 1; i < this.entries.length; i++) {
781
- var $entry = $(this.entries[i]);
782
- if ($entry.data('jg.loaded') === true || $entry.data('jg.loaded') === 'skipped') {
783
- var availableWidth = this.galleryWidth - 2 * this.border - (
784
- (this.buildingRow.entriesBuff.length - 1) * this.settings.margins);
785
- var imgAspectRatio = $entry.data('jg.width') / $entry.data('jg.height');
786
-
787
- this.buildingRow.entriesBuff.push($entry);
788
- this.buildingRow.aspectRatio += imgAspectRatio;
789
- this.buildingRow.width += imgAspectRatio * this.settings.rowHeight;
790
- this.lastAnalyzedIndex = i;
791
-
792
- if (availableWidth / (this.buildingRow.aspectRatio + imgAspectRatio) < this.settings.rowHeight) {
793
- this.flushRow(false);
794
-
795
- if(++this.yield.flushed >= this.yield.every) {
796
- this.startImgAnalyzer(isForResize);
797
- return;
798
- }
799
- }
800
- } else if ($entry.data('jg.loaded') !== 'error') {
801
- return;
802
- }
803
- }
804
-
805
- // Last row flush (the row is not full)
806
- if (this.buildingRow.entriesBuff.length > 0) this.flushRow(true);
807
-
808
- if (this.isSpinnerActive()) {
809
- this.stopLoadingSpinnerAnimation();
810
- }
811
-
812
- /* Stop, if there is, the timeout to start the analyzeImages.
813
- This is because an image can be set loaded, and the timeout can be set,
814
- but this image can be analyzed yet.
815
- */
816
- this.stopImgAnalyzerStarter();
817
-
818
- //On complete callback
819
- this.settings.triggerEvent.call(this, isForResize ? 'jg.resize' : 'jg.complete');
820
- this.setGalleryFinalHeight(this.galleryHeightToSet);
821
- };
822
-
823
- /**
824
- * Stops any ImgAnalyzer starter (that has an assigned timeout)
825
- */
826
- JustifiedGallery.prototype.stopImgAnalyzerStarter = function () {
827
- this.yield.flushed = 0;
828
- if (this.imgAnalyzerTimeout !== null) {
829
- clearTimeout(this.imgAnalyzerTimeout);
830
- this.imgAnalyzerTimeout = null;
831
- }
832
- };
833
-
834
- /**
835
- * Starts the image analyzer. It is not immediately called to let the browser to update the view
836
- *
837
- * @param isForResize specifies if the image analyzer must be called for resizing or not
838
- */
839
- JustifiedGallery.prototype.startImgAnalyzer = function (isForResize) {
840
- var that = this;
841
- this.stopImgAnalyzerStarter();
842
- this.imgAnalyzerTimeout = setTimeout(function () {
843
- that.analyzeImages(isForResize);
844
- }, 0.001); // we can't start it immediately due to a IE different behaviour
845
- };
846
-
847
- /**
848
- * Checks if the image is loaded or not using another image object. We cannot use the 'complete' image property,
849
- * because some browsers, with a 404 set complete = true.
850
- *
851
- * @param imageSrc the image src to load
852
- * @param onLoad callback that is called when the image has been loaded
853
- * @param onError callback that is called in case of an error
854
- */
855
- JustifiedGallery.prototype.onImageEvent = function (imageSrc, onLoad, onError) {
856
- if (!onLoad && !onError) return;
857
-
858
- var memImage = new Image();
859
- var $memImage = $(memImage);
860
- if (onLoad) {
861
- $memImage.one('load', function () {
862
- $memImage.off('load error');
863
- onLoad(memImage);
864
- });
865
- }
866
- if (onError) {
867
- $memImage.one('error', function() {
868
- $memImage.off('load error');
869
- onError(memImage);
870
- });
871
- }
872
- memImage.src = imageSrc;
873
- };
874
-
875
- /**
876
- * Init of Justified Gallery controlled
877
- * It analyzes all the entries starting theirs loading and calling the image analyzer (that works with loaded images)
878
- */
879
- JustifiedGallery.prototype.init = function () {
880
- var imagesToLoad = false, skippedImages = false, that = this;
881
- $.each(this.entries, function (index, entry) {
882
- var $entry = $(entry);
883
- var $image = that.imgFromEntry($entry);
884
-
885
- $entry.addClass('jg-entry');
886
-
887
- if ($entry.data('jg.loaded') !== true && $entry.data('jg.loaded') !== 'skipped') {
888
-
889
- // Link Rel global overwrite
890
- if (that.settings.rel !== null) $entry.attr('rel', that.settings.rel);
891
-
892
- // Link Target global overwrite
893
- if (that.settings.target !== null) $entry.attr('target', that.settings.target);
894
-
895
- if ($image !== null) {
896
-
897
- // Image src
898
- var imageSrc = that.extractImgSrcFromImage($image);
899
-
900
- /* If we have the height and the width, we don't wait that the image is loaded,
901
- but we start directly with the justification */
902
- if (that.settings.waitThumbnailsLoad === false || !imageSrc) {
903
- var width = parseFloat($image.attr('width'));
904
- var height = parseFloat($image.attr('height'));
905
- if ($image.prop('tagName') === 'svg') {
906
- width = parseFloat($image[0].getBBox().width);
907
- height = parseFloat($image[0].getBBox().height);
908
- }
909
- if (!isNaN(width) && !isNaN(height)) {
910
- $entry.data('jg.width', width);
911
- $entry.data('jg.height', height);
912
- $entry.data('jg.loaded', 'skipped');
913
- skippedImages = true;
914
- that.startImgAnalyzer(false);
915
- return true; // continue
916
- }
917
- }
918
-
919
- $entry.data('jg.loaded', false);
920
- imagesToLoad = true;
921
-
922
- // Spinner start
923
- if (!that.isSpinnerActive()) that.startLoadingSpinnerAnimation();
924
-
925
- that.onImageEvent(imageSrc, function (loadImg) { // image loaded
926
- $entry.data('jg.width', loadImg.width);
927
- $entry.data('jg.height', loadImg.height);
928
- $entry.data('jg.loaded', true);
929
- that.startImgAnalyzer(false);
930
- }, function () { // image load error
931
- $entry.data('jg.loaded', 'error');
932
- that.startImgAnalyzer(false);
933
- });
934
-
935
- } else {
936
- $entry.data('jg.loaded', true);
937
- $entry.data('jg.width', $entry.width() | parseFloat($entry.css('width')) | 1);
938
- $entry.data('jg.height', $entry.height() | parseFloat($entry.css('height')) | 1);
939
- }
940
-
941
- }
942
-
943
- });
944
-
945
- if (!imagesToLoad && !skippedImages) this.startImgAnalyzer(false);
946
- this.checkWidth();
947
- };
948
-
949
- /**
950
- * Checks that it is a valid number. If a string is passed it is converted to a number
951
- *
952
- * @param settingContainer the object that contains the setting (to allow the conversion)
953
- * @param settingName the setting name
954
- */
955
- JustifiedGallery.prototype.checkOrConvertNumber = function (settingContainer, settingName) {
956
- if ($.type(settingContainer[settingName]) === 'string') {
957
- settingContainer[settingName] = parseFloat(settingContainer[settingName]);
958
- }
959
-
960
- if ($.type(settingContainer[settingName]) === 'number') {
961
- if (isNaN(settingContainer[settingName])) throw 'invalid number for ' + settingName;
962
- } else {
963
- throw settingName + ' must be a number';
964
- }
965
- };
966
-
967
- /**
968
- * Checks the sizeRangeSuffixes and, if necessary, converts
969
- * its keys from string (e.g. old settings with 'lt100') to int.
970
- */
971
- JustifiedGallery.prototype.checkSizeRangesSuffixes = function () {
972
- if ($.type(this.settings.sizeRangeSuffixes) !== 'object') {
973
- throw 'sizeRangeSuffixes must be defined and must be an object';
974
- }
975
-
976
- var suffixRanges = [];
977
- for (var rangeIdx in this.settings.sizeRangeSuffixes) {
978
- if (this.settings.sizeRangeSuffixes.hasOwnProperty(rangeIdx)) suffixRanges.push(rangeIdx);
979
- }
980
-
981
- var newSizeRngSuffixes = {0: ''};
982
- for (var i = 0; i < suffixRanges.length; i++) {
983
- if ($.type(suffixRanges[i]) === 'string') {
984
- try {
985
- var numIdx = parseInt(suffixRanges[i].replace(/^[a-z]+/, ''), 10);
986
- newSizeRngSuffixes[numIdx] = this.settings.sizeRangeSuffixes[suffixRanges[i]];
987
- } catch (e) {
988
- throw 'sizeRangeSuffixes keys must contains correct numbers (' + e + ')';
989
- }
990
- } else {
991
- newSizeRngSuffixes[suffixRanges[i]] = this.settings.sizeRangeSuffixes[suffixRanges[i]];
992
- }
993
- }
994
-
995
- this.settings.sizeRangeSuffixes = newSizeRngSuffixes;
996
- };
997
-
998
- /**
999
- * check and convert the maxRowHeight setting
1000
- * requires rowHeight to be already set
1001
- * TODO: should be always called when only rowHeight is changed
1002
- * @return number or null
1003
- */
1004
- JustifiedGallery.prototype.retrieveMaxRowHeight = function () {
1005
- var newMaxRowHeight = null;
1006
- var rowHeight = this.settings.rowHeight;
1007
-
1008
- if ($.type(this.settings.maxRowHeight) === 'string') {
1009
- if (this.settings.maxRowHeight.match(/^[0-9]+%$/)) {
1010
- newMaxRowHeight = rowHeight * parseFloat(this.settings.maxRowHeight.match(/^([0-9]+)%$/)[1]) / 100;
1011
- } else {
1012
- newMaxRowHeight = parseFloat(this.settings.maxRowHeight);
1013
- }
1014
- } else if ($.type(this.settings.maxRowHeight) === 'number') {
1015
- newMaxRowHeight = this.settings.maxRowHeight;
1016
- } else if (this.settings.maxRowHeight === false || this.settings.maxRowHeight == null) {
1017
- return null;
1018
- } else {
1019
- throw 'maxRowHeight must be a number or a percentage';
1020
- }
1021
-
1022
- // check if the converted value is not a number
1023
- if (isNaN(newMaxRowHeight)) throw 'invalid number for maxRowHeight';
1024
-
1025
- // check values, maxRowHeight must be >= rowHeight
1026
- if (newMaxRowHeight < rowHeight) newMaxRowHeight = rowHeight;
1027
-
1028
- return newMaxRowHeight;
1029
- };
1030
-
1031
- /**
1032
- * Checks the settings
1033
- */
1034
- JustifiedGallery.prototype.checkSettings = function () {
1035
- this.checkSizeRangesSuffixes();
1036
-
1037
- this.checkOrConvertNumber(this.settings, 'rowHeight');
1038
- this.checkOrConvertNumber(this.settings, 'margins');
1039
- this.checkOrConvertNumber(this.settings, 'border');
1040
-
1041
- var lastRowModes = [
1042
- 'justify',
1043
- 'nojustify',
1044
- 'left',
1045
- 'center',
1046
- 'right',
1047
- 'hide'
1048
- ];
1049
- if (lastRowModes.indexOf(this.settings.lastRow) === -1) {
1050
- throw 'lastRow must be one of: ' + lastRowModes.join(', ');
1051
- }
1052
-
1053
- this.checkOrConvertNumber(this.settings, 'justifyThreshold');
1054
- if (this.settings.justifyThreshold < 0 || this.settings.justifyThreshold > 1) {
1055
- throw 'justifyThreshold must be in the interval [0,1]';
1056
- }
1057
- if ($.type(this.settings.cssAnimation) !== 'boolean') {
1058
- throw 'cssAnimation must be a boolean';
1059
- }
1060
-
1061
- if ($.type(this.settings.captions) !== 'boolean') throw 'captions must be a boolean';
1062
- this.checkOrConvertNumber(this.settings.captionSettings, 'animationDuration');
1063
-
1064
- this.checkOrConvertNumber(this.settings.captionSettings, 'visibleOpacity');
1065
- if (this.settings.captionSettings.visibleOpacity < 0 ||
1066
- this.settings.captionSettings.visibleOpacity > 1) {
1067
- throw 'captionSettings.visibleOpacity must be in the interval [0, 1]';
1068
- }
1069
-
1070
- this.checkOrConvertNumber(this.settings.captionSettings, 'nonVisibleOpacity');
1071
- if (this.settings.captionSettings.nonVisibleOpacity < 0 ||
1072
- this.settings.captionSettings.nonVisibleOpacity > 1) {
1073
- throw 'captionSettings.nonVisibleOpacity must be in the interval [0, 1]';
1074
- }
1075
-
1076
- this.checkOrConvertNumber(this.settings, 'imagesAnimationDuration');
1077
- this.checkOrConvertNumber(this.settings, 'refreshTime');
1078
- this.checkOrConvertNumber(this.settings, 'refreshSensitivity');
1079
- if ($.type(this.settings.randomize) !== 'boolean') throw 'randomize must be a boolean';
1080
- if ($.type(this.settings.selector) !== 'string') throw 'selector must be a string';
1081
-
1082
- if (this.settings.sort !== false && !$.isFunction(this.settings.sort)) {
1083
- throw 'sort must be false or a comparison function';
1084
- }
1085
-
1086
- if (this.settings.filter !== false && !$.isFunction(this.settings.filter) &&
1087
- $.type(this.settings.filter) !== 'string') {
1088
- throw 'filter must be false, a string or a filter function';
1089
- }
1090
- };
1091
-
1092
- /**
1093
- * It brings all the indexes from the sizeRangeSuffixes and it orders them. They are then sorted and returned.
1094
- * @returns {Array} sorted suffix ranges
1095
- */
1096
- JustifiedGallery.prototype.retrieveSuffixRanges = function () {
1097
- var suffixRanges = [];
1098
- for (var rangeIdx in this.settings.sizeRangeSuffixes) {
1099
- if (this.settings.sizeRangeSuffixes.hasOwnProperty(rangeIdx)) suffixRanges.push(parseInt(rangeIdx, 10));
1100
- }
1101
- suffixRanges.sort(function (a, b) { return a > b ? 1 : a < b ? -1 : 0; });
1102
- return suffixRanges;
1103
- };
1104
-
1105
- /**
1106
- * Update the existing settings only changing some of them
1107
- *
1108
- * @param newSettings the new settings (or a subgroup of them)
1109
- */
1110
- JustifiedGallery.prototype.updateSettings = function (newSettings) {
1111
- // In this case Justified Gallery has been called again changing only some options
1112
- this.settings = $.extend({}, this.settings, newSettings);
1113
- this.checkSettings();
1114
-
1115
- // As reported in the settings: negative value = same as margins, 0 = disabled
1116
- this.border = this.settings.border >= 0 ? this.settings.border : this.settings.margins;
1117
-
1118
- this.maxRowHeight = this.retrieveMaxRowHeight();
1119
- this.suffixRanges = this.retrieveSuffixRanges();
1120
- };
1121
-
1122
- JustifiedGallery.prototype.defaults = {
1123
- sizeRangeSuffixes: { }, /* e.g. Flickr configuration
1124
- {
1125
- 100: '_t', // used when longest is less than 100px
1126
- 240: '_m', // used when longest is between 101px and 240px
1127
- 320: '_n', // ...
1128
- 500: '',
1129
- 640: '_z',
1130
- 1024: '_b' // used as else case because it is the last
1131
- }
1132
- */
1133
- thumbnailPath: undefined, /* If defined, sizeRangeSuffixes is not used, and this function is used to determine the
1134
- path relative to a specific thumbnail size. The function should accept respectively three arguments:
1135
- current path, width and height */
1136
- rowHeight: 120, // required? required to be > 0?
1137
- maxRowHeight: false, // false or negative value to deactivate. Positive number to express the value in pixels,
1138
- // A string '[0-9]+%' to express in percentage (e.g. 300% means that the row height
1139
- // can't exceed 3 * rowHeight)
1140
- margins: 1,
1141
- border: -1, // negative value = same as margins, 0 = disabled, any other value to set the border
1142
-
1143
- lastRow: 'nojustify', // … which is the same as 'left', or can be 'justify', 'center', 'right' or 'hide'
1144
-
1145
- justifyThreshold: 0.90, /* if row width / available space > 0.90 it will be always justified
1146
- * (i.e. lastRow setting is not considered) */
1147
- waitThumbnailsLoad: true,
1148
- captions: true,
1149
- cssAnimation: true,
1150
- imagesAnimationDuration: 500, // ignored with css animations
1151
- captionSettings: { // ignored with css animations
1152
- animationDuration: 500,
1153
- visibleOpacity: 0.7,
1154
- nonVisibleOpacity: 0.0
1155
- },
1156
- rel: null, // rewrite the rel of each analyzed links
1157
- target: null, // rewrite the target of all links
1158
- extension: /\.[^.\\/]+$/, // regexp to capture the extension of an image
1159
- refreshTime: 200, // time interval (in ms) to check if the page changes its width
1160
- refreshSensitivity: 0, // change in width allowed (in px) without re-building the gallery
1161
- randomize: false,
1162
- rtl: false, // right-to-left mode
1163
- sort: false, /*
1164
- - false: to do not sort
1165
- - function: to sort them using the function as comparator (see Array.prototype.sort())
1166
- */
1167
- filter: false, /*
1168
- - false, null or undefined: for a disabled filter
1169
- - a string: an entry is kept if entry.is(filter string) returns true
1170
- see jQuery's .is() function for further information
1171
- - a function: invoked with arguments (entry, index, array). Return true to keep the entry, false otherwise.
1172
- It follows the specifications of the Array.prototype.filter() function of JavaScript.
1173
- */
1174
- selector: 'a, div:not(.spinner)', // The selector that is used to know what are the entries of the gallery
1175
- imgSelector: '> img, > a > img, > svg, > a > svg', // The selector that is used to know what are the images of each entry
1176
- triggerEvent: function (event) { // This is called to trigger events, the default behavior is to call $.trigger
1177
- this.$gallery.trigger(event); // Consider that 'this' is this set to the JustifiedGallery object, so it can
1178
- } // access to fields such as $gallery, useful to trigger events with jQuery.
1179
- };
1180
-
1181
-
1182
- /**
1183
- * Justified Gallery plugin for jQuery
1184
- *
1185
- * Events
1186
- * - jg.complete : called when all the gallery has been created
1187
- * - jg.resize : called when the gallery has been resized
1188
- * - jg.rowflush : when a new row appears
1189
- *
1190
- * @param arg the action (or the settings) passed when the plugin is called
1191
- * @returns {*} the object itself
1192
- */
1193
- $.fn.justifiedGallery = function (arg) {
1194
- return this.each(function (index, gallery) {
1195
-
1196
- var $gallery = $(gallery);
1197
- $gallery.addClass('justified-gallery');
1198
-
1199
- var controller = $gallery.data('jg.controller');
1200
- if (typeof controller === 'undefined') {
1201
- // Create controller and assign it to the object data
1202
- if (typeof arg !== 'undefined' && arg !== null && $.type(arg) !== 'object') {
1203
- if (arg === 'destroy') return; // Just a call to an unexisting object
1204
- throw 'The argument must be an object';
1205
- }
1206
- controller = new JustifiedGallery($gallery, $.extend({}, JustifiedGallery.prototype.defaults, arg));
1207
- $gallery.data('jg.controller', controller);
1208
- } else if (arg === 'norewind') {
1209
- // In this case we don't rewind: we analyze only the latest images (e.g. to complete the last unfinished row
1210
- // ... left to be more readable
1211
- } else if (arg === 'destroy') {
1212
- controller.destroy();
1213
- return;
1214
- } else {
1215
- // In this case Justified Gallery has been called again changing only some options
1216
- controller.updateSettings(arg);
1217
- controller.rewind();
1218
- }
1219
-
1220
- // Update the entries list
1221
- if (!controller.updateEntries(arg === 'norewind')) return;
1222
-
1223
- // Init justified gallery
1224
- controller.init();
1225
-
1226
- });
1227
- };
1228
-
1229
- }));