PageSourceSearch

https://www.energy-ind.com/wp-content/plugins/portfolio-wp/js/crp-tiled-layer.js?ver=7.1.2

js energy-ind.com collected 2026-10-06 16:22:22 UTC 14,642 bytes, 431 lines download raw bytes

1CRPTiledLayerType = {};
2CRPTiledLayerType.Puzzle = 1;
3CRPTiledLayerType.Masonry = 2;
4CRPTiledLayerType.Square = 3;
5CRPTiledLayerType.Justified = 4;
6
7;(function ($) {
8    $.crpTiledLayer = function (element, options) {
9        if(options.approxTileWidth < options.minTileWidth){
10            options.approxTileWidth = options.minTileWidth;
11        }
12
13        var Slot = function (width, height) {
14            this.position = { x: 0, y: 0 };
15            this.blocks = { h: width, v: height };
16            this.size = { width: this.blocks.h, height: this.blocks.v };
17            this.px = { width: width, height: height };
18            this.edge_right = false;
19        }
20
21        Slot.prototype.resize = function (blocks, onlyWidth) {
22            //nw : nh = w : h => nh = nw * h / w
23            var new_width = blocks;
24            var new_height = (new_width * this.px.height) / this.px.width;
25            var bv = this.blocks.v;
26            this.blocks.h = blocks;
27            if(!onlyWidth && plugin.settings.layoutType != CRPTiledLayerType.Square)
28                this.blocks.v = new_height;
29        }
30
31        var Grid = function (margin, min_tile_width, width) {
32            this.slots = [];
33            this.cells = [];
34            this.margin = margin;
35            this.min_tile_width = min_tile_width;
36            this.width = width;
37            this.hor_size = width;
38            this.init();
39        }
40
41        Grid.prototype.init = function () {
42            this.slots.length = 0;
43            this.cells.length = 0;
44            for (var i = 0; i < this.hor_size * 1000; i++) {
45                this.cells[i] = 0;
46            }
47        }
48
49        Grid.prototype.add_slot = function (slot) {
50            for (var j = 0; j < slot.blocks.v; j++) {
51                for (var i = 0; i < slot.blocks.h; i++) {
52                    var row = slot.position.y + j;
53                    var column = slot.position.x + i;
54                    //if (this.cells.length < row * this.hor_size + column)
55
56                    this.cells[row * this.hor_size + column] = 1;
57                    this.cells.push(0);
58                }
59            }
60
61            this.slots.push(slot);
62        }
63
64        Grid.prototype.count_free_cells_on_right = function (index) {
65            var line = Math.floor(index / this.hor_size);
66            var line_end = (line + 1) * this.hor_size;
67
68            var length = 0;
69
70            for (; index < line_end; index++, length++) {
71                if (this.cells[index] == 1) {
72                    break;
73                }
74            }
75
76            return length;
77        }
78
79        Grid.prototype.insert = function (width, height, allowEnlargement) {
80
81            /* Hack for square and masonry styles */
82            var sW = width;
83            var sH = height;
84            if(plugin.settings.layoutType == CRPTiledLayerType.Masonry || plugin.settings.layoutType == CRPTiledLayerType.Square){
85                var _slotWidth = plugin.settings.approxTileWidth + plugin.settings.margin;
86                var _wrapperWidth = $element.width() + plugin.settings.margin;
87                if(_slotWidth > _wrapperWidth - plugin.settings.margin){
88                    _slotWidth = _wrapperWidth - plugin.settings.margin;
89                }
90
91                var _itemsPerRow = parseInt( _wrapperWidth / _slotWidth );
92                var _delta = _wrapperWidth - _itemsPerRow * _slotWidth;
93                var _deltaPerCell = Math.floor(_delta / _itemsPerRow);
94                _slotWidth += _deltaPerCell;
95
96                sW = _slotWidth;
97
98                var _ratio = plugin.settings.approxTileHeight / plugin.settings.approxTileWidth;
99                if(plugin.settings.layoutType == CRPTiledLayerType.Masonry){
100                    _ratio = height / width;
101                }
102
103                sH = Math.ceil(sW * _ratio);
104
105            } else {
106                var _wrapperWidth = $element.width() + plugin.settings.margin;
107                var step = parseInt( _wrapperWidth / 4 );
108
109                var ratios = [
110                    {w: 1, h:1},
111                    {w: 2, h:2},
112                ];
113                var ratio = ratios[(Math.floor(Math.random() * (ratios.length - 0)) + 0)];
114
115                sW = ratio.w * step;
116                sH = ratio.h * step;
117            }
118
119            var newsH = sH;
120            if (plugin.settings.addBlock1Height != false) {
121                newsH += plugin.settings.addBlock1Height;
122            }
123            if (plugin.settings.addBlock2Height != false) {
124                newsH += plugin.settings.addBlock2Height;
125            }
126            var slot = new Slot(sW, newsH);
127            var av_blocks = 0;
128            var free_cell = 0;
129            var line = 0;
130
131            if (this.slots.length == 0) {
132                av_blocks = this.hor_size;
133                slot.position.x = 0;
134                slot.position.y = 0;
135            } else {
136
137                //find first available cell
138                var exit = false;
139                for (; free_cell < this.cells.length; free_cell++) {
140                    if (this.cells[free_cell] == 0) {
141
142                        line = Math.floor(free_cell / this.hor_size);
143                        var line_end = (line + 1) * this.hor_size;
144
145                        //available blocks
146                        av_blocks = 0;
147                        for (var k = 0; k <= line_end - free_cell; k++) {
148                            av_blocks = k;
149                            if (this.cells[free_cell + k] == 1) {
150                                //there's another slot on the right
151                                break;
152                            }
153                        }
154                        break;
155                    }
156                }
157            }
158            //the slot need to be shrinked
159            if (av_blocks < slot.blocks.h) {
160                slot.resize(av_blocks);
161            } else {
162                var free_on_right = this.count_free_cells_on_right(free_cell + slot.blocks.h);
163                if (free_on_right - plugin.settings.margin < this.min_tile_width &&
164                    free_on_right > 0) {
165                    slot.resize(av_blocks, !allowEnlargement);
166                    slot.enlarged = true;
167                }
168                if (free_on_right == 0)
169                    slot.edge_right = true;
170            }
171
172            slot.position.x = free_cell % this.hor_size;
173            slot.position.y = Math.floor(free_cell / this.hor_size);
174
175            this.add_slot(slot);
176            return slot;
177        }
178
179        var defaults = {
180            layoutType: CRPTiledLayerType.Square,
181            approxTileWidth: 200,
182            approxTileHeight: 200,
183            minTileWidth: 200,
184            margin: 10,
185            addBlock1Height: false,
186            addBlock2Height: false,
187            allowEnlargement: false,
188            onComplete: function () { },
189            onUpdate: function () { },
190        }
191
192        var plugin = this;
193        var grid = null;
194        var maxHeight = 0;
195
196        plugin.settings = {}
197
198        var $element = $(element),
199            element = element;
200
201        var currentWidth = $element.width();
202
203        var completed = false;
204        var busy = false;
205
206        var tilesForFilter = function(ft) {
207            $tiles =  $element.find(".tile");
208            return $tiles;
209        }
210
211        var doFiltration = function() {
212            busy = true;
213
214            var $tiles = tilesForFilter(null);
215            maxHeight = 0;
216            grid = null;
217
218            $tiles.css({visibility: 'invisible'});
219            entile($tiles);
220            $tiles.css({visibility: 'visible'});
221
222            busy = false;
223        }
224
225        plugin.init = function () {
226            plugin.settings = $.extend({}, defaults, options);
227
228            $element.find(".ftg-items").css({
229                position: "relative",
230                minWidth: plugin.settings.minTileWidth,
231            });
232
233            var $tiles = $element.find(".tile");
234            styleTiles($tiles);
235            assignImagesSize($tiles);
236            var category = window.location.hash;
237            if (category != '' && category != '#') {
238                var current = jQuery(".ftg-filters a[href='" + category + "']");
239                if (current.length != 0) {
240                    jQuery("a", current.closest(".ftg-filters")).removeClass('selected');
241                    current.addClass('selected');
242                }
243            }
244            doFiltration();
245
246            $(window).resize(function () {
247                if(busy) return;
248
249                if (currentWidth != $element.width())
250                {
251                    busy = true;
252                    currentWidth = $element.width();
253
254                    resTo = setTimeout(function () {
255                        grid = null;
256                        maxHeight = 0;
257
258                        var $filteredTiles = tilesForFilter(null);
259                        entile($filteredTiles);
260
261                        busy = false;
262                    }, 700);
263                }
264            });
265        }
266
267        var styleTiles = function ($tiles) {
268            $tiles.css({
269                position: "absolute",
270                visibility: 'hidden',
271            });
272
273            $tiles.find('.tile-inner').css({
274                position: "relative",
275                display: "block",
276                overflow: "hidden",
277            });
278
279            $tiles.find('.crp-item').css({
280                position: "relative",
281                display: "block",
282                fontSize: 10, //against weird rules in some reset.css
283                maxWidth: "9999em",
284            });
285        }
286
287        var assignImagesSize = function ($tiles) {
288            $tiles.each(function () {
289                var $item = $(this).find(".crp-item");
290
291                var size = {
292                    width: $item.data("width"),
293                    height: $item.data("height")
294                };
295
296                $item.data("size", size);
297            });
298        }
299
300        var entile = function ($tiles) {
301            if (!grid)
302                grid = new Grid(plugin.settings.margin, plugin.settings.minTileWidth, Math.floor($element.width() + plugin.settings.margin));
303
304            $tiles.each(function () {
305                if ($(this).hasClass("ftg-hidden"))
306                    return;
307
308                var size = $(this).find(".crp-item").data("size");
309
310                var slot = grid.insert(
311                    size.width + plugin.settings.margin,
312                    size.height + plugin.settings.margin,
313                    plugin.settings.allowEnlargement);
314
315                $(this).data("enlarged", slot.enlarged);
316
317
318                var top = slot.position.y;
319                var height = slot.blocks.v;
320
321                var tileWidth = slot.blocks.h - plugin.settings.margin;
322                var tileHeight = slot.blocks.v - plugin.settings.margin;
323
324                if (top + tileHeight > maxHeight)
325                    maxHeight = top + height + plugin.settings.margin;
326
327                if (plugin.settings.addBlock1Height != false) {
328                    tileHeight -= plugin.settings.addBlock1Height;
329                }
330
331                if (plugin.settings.addBlock2Height != false) {
332                    tileHeight -= plugin.settings.addBlock2Height;
333                }
334
335
336                $(this).css({
337                    top: top,
338                    left: slot.position.x,
339                    width: slot.blocks.h,
340                    height: height
341                });
342                $(this).find('.tile-inner').css({
343                    width: tileWidth,
344                    height: tileHeight
345                })
346                    .data("width", tileWidth)
347                    .data("height", tileHeight);
348
349                if (plugin.settings.addBlock1Height != false) {
350                    $(this).find('.tile-inner').css({
351                        top: plugin.settings.addBlock1Height
352                    });
353                    $(this).find('.crp-additional-block1').css({
354                        width: tileWidth,
355                        height: plugin.settings.addBlock1Height
356                    });
357                }
358                if (plugin.settings.addBlock2Height != false) {
359                    $(this).find('.crp-additional-block2').css({
360                        bottom: plugin.settings.margin,
361                        width: tileWidth,
362                        height: plugin.settings.addBlock2Height
363                    });
364                }
365
366                $element.find(".ftg-items").height(maxHeight);
367            });
368
369            $tiles.find("img.crp-item").each(function (i, item) {
370                var $item = $(item);
371                var size = $item.data("size");
372
373                var ratioImg = size.width / size.height;
374                var ratioTile = $item.parent().data("width") / $item.parent().data("height");
375
376                var bugFixDiff = 0;
377                if (ratioImg >= ratioTile) {
378                    $item.attr("case", "2");
379
380                    var $h = $item.parent().data("height") + bugFixDiff;
381                    var $w = ratioImg * $h;
382
383                    $item.css({
384                        width: $w,
385                        height: $h
386                    });
387
388                    var diff = $w - $item.parent().data("width");
389                    $item.css({
390                        "margin-left": diff / -2,
391                        "margin-top": bugFixDiff / -2,
392                    });
393                } else {
394                    $item.attr("case", "4");
395
396                    var $w = $item.parent().data("width") + bugFixDiff;
397                    var $h = $w / ratioImg;
398
399                    $item.css({
400                        width: $w,
401                        height: $h
402                    });
403
404                    var diff = $h - $item.parent().data("height");
405                    $item.css({
406                        "margin-top": diff / -2,
407                        "margin-left": bugFixDiff / -2,
408                    });
409                }
410            });
411
412            if (!completed) {
413                completed = true;
414                plugin.settings.onComplete.call(plugin);
415            } else {
416                plugin.settings.onUpdate.call(plugin);
417            }
418        }
419
420        plugin.init();
421    }
422
423    $.fn.crpTiledLayer = function (options) {
424        return this.each(function () {
425            if (undefined == $(this).data('crpTiledLayer')) {
426                var plugin = new $.crpTiledLayer(this, options);
427                $(this).data('crpTiledLayer', plugin);
428            }
429        });
430    }
431})(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.