PageSourceSearch

https://codius.ru/Scripts/manual/adaptiveblocks.js

js codius.ru collected 2026-10-07 00:30:10 UTC 3,032 bytes, 87 lines download raw bytes

1
2var minBlockWidth = 240;
3
4$(document).ready(function () {
5    initBlocks(true);
6    window.onresize = initBlocks;
7})
8
9var _count = -1; // дефолтное кол-во колонок, генерируемое на сервере
10//var ptables; //= $("");
11
12function initBlocks(manual){
13    var ptables = $("table.products");
14
15    var lastemptycolumn = true; // Дополнять ли таблицу пустым столбцом
16
17    for (var i = 0; i < $(ptables).length; i++) {
18        var actualTbl = $(ptables)[i];
19        if ($(actualTbl).attr("emptycolumn") != null) {
20            lastemptycolumn = $(actualTbl).attr("emptycolumn") == 'true';
21        }
22
23        resizeTable($(ptables)[i], manual, lastemptycolumn);
24    }
25}
26
27function getColumnsCount(table) {
28    var parent = $(table).parent();
29    var minWidth = document.documentElement.scrollWidth > $(parent).width() ? $(parent).width() : document.documentElement.scrollWidth
30
31    var parentWidth = minWidth > $(table).width() ? minWidth : $(table).width();
32    var minwidth = minBlockWidth;
33
34    if ($(table).attr("minwidth") != undefined) {
35        minwidth = parseInt( $(table).attr("minwidth"));
36    }
37
38    var c = Math.floor(parentWidth / (minwidth));
39    return c > 0 ? c : 1;
40}
41
42function resizeTable(table, manual, lastemptycolumn) {
43    var _count = parseInt($(table).attr("colscount"));
44    var colsCount = getColumnsCount($(table));          // кол-во столбцов в таблице
45    if (_count == colsCount && !manual) { return; }     //ничего не делать, если кол-во колонок то же, что и ранее
46
47    var blocks = $(table).find("td.product");
48    var rows = $(blocks).length / colsCount;
49    var blockWidth = 100 / colsCount; // ширина каждой ячейки в процентах
50
51    $(table).find("tr").remove();
52
53    var actualRow;
54    var rowscount = 0;
55    var actualBlock = 0;
56    for (var i = 0; i < $(blocks).length; i++) {
57        if (actualBlock == 0) {
58            $(table).find("tbody").append("<tr></tr>");
59            actualRow = $(table).find("tr:last");
60            rowscount++;
61        }
62        var block = $(blocks)[i];
63        $(block).width(blockWidth + "%");
64        actualRow.append($(blocks)[i]);
65
66        actualBlock++;
67        if (actualBlock >= colsCount) { actualBlock = 0;}
68    }
69
70    if (lastemptycolumn && (actualBlock < colsCount && blocks.length < colsCount)) { // Ячеек меньше чем нужно - восполняем
71        var block = "<td></td>";
72        actualRow.append($(block));
73        block = $(actualRow).find("td:last");
74        $(block).width(blockWidth * (colsCount - actualBlock) + "%");
75    }
76
77    if (rowscount > 1) {
78        var block = "<td></td>";
79        actualRow.append($(block));
80        block = $(actualRow).find("td:last");
81        $(block).attr("colspan",colsCount - actualBlock);
82    }
83
84
85    $(table).attr("colscount", colsCount);
86}
87

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.