PluginProbe
Photonic Gallery & Lightbox for Flickr, SmugMug & Others / 3.37
Photonic Gallery & Lightbox for Flickr, SmugMug & Others v3.37
3.37 3.36 3.35 3.34 3.33 2.19 2.20 2.21 2.22 2.23 2.24 2.25 2.26 2.27 2.28 2.29 2.30 2.31 2.32 2.33 2.34 2.40 2.41 2.42 2.43 All 142 releases
photonic / include / js / front-end / src / Layouts / Masonry.js

Masonry.js in Photonic Gallery & Lightbox for Flickr, SmugMug & Others 3.37, at include/js/front-end/src/Layouts/Masonry.js

61 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Photonic Masonry Layout
3 * The Masonry layout is primarily controlled using CSS columns. The JS component is to facilitate responsive behaviour and breakpoints.
4 *
5 * License: GPL v3.0
6 */
7 import {Core} from "../Core";
8 import * as Util from "../Util";
9
10 export const Masonry = (resized, jsLoaded, selector) => {
11 if (console !== undefined && Photonic_JS.debug_on !== '0' && Photonic_JS.debug_on !== '') console.time('Masonry');
12
13 let selection = document.querySelectorAll(selector);
14 if (selector == null || selection.length === 0) {
15 selection = document.querySelectorAll('.photonic-masonry-layout');
16 }
17
18 if (!resized && selection.length > 0) {
19 Core.showSpinner();
20 }
21
22 let minWidth = (isNaN(Photonic_JS.masonry_min_width) || parseInt(Photonic_JS.masonry_min_width) <= 0) ? 200 : Photonic_JS.masonry_min_width;
23 minWidth = parseInt(minWidth);
24
25 selection.forEach((grid) => {
26 let columns = grid.getAttribute('data-photonic-gallery-columns');
27 columns = (isNaN(parseInt(columns)) || parseInt(columns) <= 0) ? 3 : parseInt(columns);
28
29 const buildLayout = (grid, fadeIn) => {
30 const viewportWidth = Math.floor(grid.getBoundingClientRect().width),
31 idealColumns = (viewportWidth / columns) > minWidth ? columns : Math.floor(viewportWidth / minWidth);
32
33 if (idealColumns !== undefined && idealColumns !== null) {
34 grid.style.columnCount = idealColumns.toString();
35 }
36
37 if (fadeIn) {
38 Array.from(grid.getElementsByTagName('img')).forEach(img => {
39 Util.fadeIn(img);
40 });
41 }
42
43 Core.showSlideupTitle();
44 if (!resized && !jsLoaded) {
45 Core.hideLoading();
46 }
47 };
48
49 if (grid.classList.contains('sizes-present')) {
50 Core.watchForImages(grid);
51 buildLayout(grid, false);
52 }
53 else {
54 Core.waitForImages(grid).then(() => {
55 buildLayout(grid, true);
56 });
57 }
58 });
59 if (console !== undefined && Photonic_JS.debug_on !== '0' && Photonic_JS.debug_on !== '') console.timeEnd('Masonry');
60 };
61