PageSourceSearch

https://unstoppablesiggi.com/wp-content/plugins/nextgen-gallery-pl…/nextgen_pro_tile/static/tile.js?ver=4.2.3

js unstoppablesiggi.com collected 2026-10-05 19:44:16 UTC 5,284 bytes, 128 lines download raw bytes

1(function($) {
2
3    function TiledGalleryCollection() {
4        this.galleries = [];
5        this.findAndSetupNewGalleries();
6    }
7
8    TiledGalleryCollection.prototype.findAndSetupNewGalleries = function() {
9        var self = this;
10        $('.tiled-gallery.tiled-gallery-unresized').each(function() {
11            self.galleries.push(new TiledGallery($(this)));
12        });
13    };
14
15    TiledGalleryCollection.prototype.resizeAll = function() {
16        $.each(this.galleries, function(i, gallery) {
17            gallery.resize();
18        });
19    };
20
21    function TiledGallery(galleryElem) {
22        this.gallery = galleryElem;
23
24        // Resize when initialized to fit the gallery to window dimensions
25        this.resize();
26
27        // Displays the gallery and prevents it from being initialized again
28        this.gallery.removeClass('tiled-gallery-unresized');
29    }
30
31    TiledGallery.prototype.resizeableElementsSelector = '.gallery-row, .gallery-group, .tiled-gallery-item img';
32
33    TiledGallery.prototype.getExtraDimension = function(el, attribute, mode) {
34        if (mode === 'horizontal') {
35            var left  = (attribute === 'border') ? 'borderLeftWidth'  : attribute + 'Left';
36            var right = (attribute === 'border') ? 'borderRightWidth' : attribute + 'Right';
37            return (parseInt(el.css(left), 10) || 0) + (parseInt(el.css(right), 10) || 0);
38        } else if (mode === 'vertical') {
39            var top    = (attribute === 'border') ? 'borderTopWidth'    : attribute + 'Top';
40            var bottom = (attribute === 'border') ? 'borderBottomWidth' : attribute + 'Bottom';
41            return (parseInt(el.css(top), 10) || 0) + (parseInt(el.css(bottom), 10) || 0);
42        } else {
43            return 0;
44        }
45    };
46
47    TiledGallery.prototype.resize = function() {
48        // Resize everything in the gallery based on the ratio of the current content width to the original content width
49        var originalWidth = this.gallery.data('original-width');
50        var currentWidth = this.gallery.parent().width();
51        var resizeRatio = Math.min(1, currentWidth / originalWidth);
52
53        var self = this;
54
55        this.gallery.find(this.resizeableElementsSelector).each(function () {
56            var thisGalleryElement = $(this);
57
58            var marginWidth  = self.getExtraDimension(thisGalleryElement, 'margin', 'horizontal');
59            var marginHeight = self.getExtraDimension(thisGalleryElement, 'margin', 'vertical');
60
61            var paddingWidth  = self.getExtraDimension(thisGalleryElement, 'padding', 'horizontal');
62            var paddingHeight = self.getExtraDimension(thisGalleryElement, 'padding', 'vertical');
63
64            var borderWidth  = self.getExtraDimension(thisGalleryElement, 'border', 'horizontal');
65            var borderHeight = self.getExtraDimension(thisGalleryElement, 'border', 'vertical');
66
67            // Take all outer dimensions into account when resizing so that images scale with constant empty space between them
68            var outerWidth  = thisGalleryElement.data('original-width')   + paddingWidth  + borderWidth  + marginWidth;
69            var outerHeight = thisGalleryElement.data('original-height')  + paddingHeight + borderHeight + marginHeight;
70
71            // Subtract margins so that images don't overflow on small browser windows
72            thisGalleryElement.width(Math.floor(resizeRatio * outerWidth)   - marginWidth)
73                              .height(Math.floor(resizeRatio * outerHeight) - marginHeight);
74        });
75    };
76
77    var requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
78
79    function attachResizeInAnimationFrames(tiledGalleries) {
80        var resizing = false;
81        var resizeTimeout = null;
82
83        function handleFrame() {
84            tiledGalleries.resizeAll();
85            if (resizing) {
86                requestAnimationFrame(handleFrame);
87            }
88        }
89
90        $(window).on('resize', function() {
91            clearTimeout(resizeTimeout);
92            if (! resizing) {
93                requestAnimationFrame(handleFrame);
94            }
95            resizing = true;
96            resizeTimeout = setTimeout(function() {
97                resizing = false;
98            }, 15);
99        });
100    }
101
102    function attachPlainResize(tiledGalleries) {
103        $(window).resize(function() {
104            tiledGalleries.resizeAll();
105        });
106    }
107
108    $(document).ready(function() {
109        var tiledGalleries = new TiledGalleryCollection();
110
111        $('body').on('post-load', function(e, maybeResize) {
112            if ('string' === typeof maybeResize && 'resize' === maybeResize) {
113                tiledGalleries.resizeAll();
114            } else {
115                tiledGalleries.findAndSetupNewGalleries();
116            }
117        });
118
119        // Chrome will start lagging on occasion. It helps if we only resize on animation frames.
120        // For other browsers it seems like there is no lag even if we resize every time there is an event.
121        if (window.chrome && requestAnimationFrame) {
122            attachResizeInAnimationFrames(tiledGalleries);
123        } else {
124            attachPlainResize(tiledGalleries);
125        }
126    });
127
128})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.