PageSourceSearch

https://grupadino.pl/wp-content/themes/dino/js/stacktable.js

js grupadino.pl collected 2026-10-02 16:49:34 UTC 8,134 bytes, 208 lines download raw bytes

vendor: 8,134 bytes, lines 1-208
1/**
2 * stacktable.js
3 * Author & copyright (c) 2012: John Polacek
4 * CardTable by: Justin McNally (2015)
5 * Dual MIT & GPL license
6 *
7 * Page: http://johnpolacek.github.com/stacktable.js
8 * Repo: https://github.com/johnpolacek/stacktable.js/
9 *
10 * jQuery plugin for stacking tables on small screens
11 * Requires jQuery version 1.7 or above
12 *
13 */
14;(function($) {
15  $.fn.cardtable = function(options) {
16    var $tables = this,
17        defaults = {headIndex:0},
18        settings = $.extend({}, defaults, options),
19        headIndex;
20
21    // checking the "headIndex" option presence... or defaults it to 0
22    if(options && options.headIndex)
23      headIndex = options.headIndex;
24    else
25      headIndex = 0;
26
27    return $tables.each(function() {
28      var $table = $(this);
29      if ($table.hasClass('stacktable')) {
30        return;
31      }
32      var table_css = $(this).prop('class');
33      var $stacktable = $('<div></div>');
34      if (typeof settings.myClass !== 'undefined') $stacktable.addClass(settings.myClass);
35      var markup = '';
36      var $caption, $topRow, headMarkup, bodyMarkup, tr_class;
37
38      $table.addClass('stacktable large-only');
39
40      $caption = $table.find(">caption").clone();
41      $topRow = $table.find('>thead>tr,>tbody>tr,>tfoot>tr,>tr').eq(0);
42
43      // avoid duplication when paginating
44      $table.siblings().filter('.small-only').remove();
45
46      // using rowIndex and cellIndex in order to reduce ambiguity
47      $table.find('>tbody>tr').each(function() {
48
49        // declaring headMarkup and bodyMarkup, to be used for separately head and body of single records
50        headMarkup = '';
51        bodyMarkup = '';
52        tr_class = $(this).prop('class');
53        // for the first row, "headIndex" cell is the head of the table
54        // for the other rows, put the "headIndex" cell as the head for that row
55        // then iterate through the key/values
56        $(this).find('>td,>th').each(function(cellIndex) {
57          if ($(this).html() !== ''){
58            bodyMarkup += '<tr class="' + tr_class +'">';
59            if ($topRow.find('>td,>th').eq(cellIndex).html()){
60              bodyMarkup += '<td class="st-key">'+$topRow.find('>td,>th').eq(cellIndex).html()+'</td>';
61            } else {
62              bodyMarkup += '<td class="st-key"></td>';
63            }
64            bodyMarkup += '<td class="st-val '+$(this).prop('class')  +'">'+$(this).html()+'</td>';
65            bodyMarkup += '</tr>';
66          }
67        });
68
69        markup += '<table class=" '+ table_css +' stacktable small-only"><tbody>' + headMarkup + bodyMarkup + '</tbody></table>';
70      });
71
72      $table.find('>tfoot>tr>td').each(function(rowIndex,value) {
73        if ($.trim($(value).text()) !== '') {
74          markup += '<table class="'+ table_css + ' stacktable small-only"><tbody><tr><td>' + $(value).html() + '</td></tr></tbody></table>';
75        }
76      });
77
78      $stacktable.prepend($caption);
79      $stacktable.append($(markup));
80      $table.before($stacktable);
81    });
82  };
83
84  $.fn.stacktable = function(options) {
85    var $tables = this,
86        defaults = {headIndex:0,displayHeader:true},
87        settings = $.extend({}, defaults, options),
88        headIndex;
89
90    // checking the "headIndex" option presence... or defaults it to 0
91    if(options && options.headIndex)
92      headIndex = options.headIndex;
93    else
94      headIndex = 0;
95
96    return $tables.each(function() {
97      var table_css = $(this).prop('class');
98      var $stacktable = $('<table class="'+ table_css +' stacktable small-only"><tbody></tbody></table>');
99      if (typeof settings.myClass !== 'undefined') $stacktable.addClass(settings.myClass);
100      var markup = '';
101      var $table, $caption, $topRow, headMarkup, bodyMarkup, tr_class, displayHeader;
102
103      $table = $(this);
104      $table.addClass('stacktable large-only');
105      $caption = $table.find(">caption").clone();
106      $topRow = $table.find('>thead>tr,>tbody>tr,>tfoot>tr').eq(0);
107
108      displayHeader = $table.data('display-header') === undefined ? settings.displayHeader : $table.data('display-header');
109
110      // using rowIndex and cellIndex in order to reduce ambiguity
111      $table.find('>tbody>tr').each(function(rowIndex) {
112
113        // declaring headMarkup and bodyMarkup, to be used for separately head and body of single records
114        headMarkup = '';
115        bodyMarkup = '';
116        tr_class = $(this).prop('class');
117        
118        // for the first row, "headIndex" cell is the head of the table
119        if (rowIndex === 0) {
120          // the main heading goes into the markup variable
121          if (displayHeader) {
122            markup += '<tr class=" '+tr_class +' "><th class="st-head-row st-head-row-main" colspan="2">'+$(this).find('>th,>td').eq(headIndex).html()+'</th></tr>';
123          }
124        } else {
125          // for the other rows, put the "headIndex" cell as the head for that row
126          // then iterate through the key/values
127          $(this).find('>td,>th').each(function(cellIndex) {
128            if (cellIndex === headIndex) {
129              headMarkup = '<tr class="'+ tr_class+'"><th class="st-head-row" colspan="2">'+$(this).html()+'</th></tr>';
130            } else {
131              if ($(this).html() !== ''){
132                bodyMarkup += '<tr class="' + tr_class +'">';
133                if ($topRow.find('>td,>th').eq(cellIndex).html()){
134                  bodyMarkup += '<td class="st-key">'+$topRow.find('>td,>th').eq(cellIndex).html()+'</td>';
135                } else {
136                  bodyMarkup += '<td class="st-key"></td>';
137                }
138                bodyMarkup += '<td class="st-val '+$(this).prop('class')  +'">'+$(this).html()+'</td>';
139                bodyMarkup += '</tr>';
140              }
141            }
142          });
143
144          markup += headMarkup + bodyMarkup;
145        }
146      });
147
148      $stacktable.prepend($caption);
149      $stacktable.append($(markup));
150      $table.before($stacktable);
151    });
152  };
153
154 $.fn.stackcolumns = function(options) {
155    var $tables = this,
156        defaults = {},
157        settings = $.extend({}, defaults, options);
158
159    return $tables.each(function() {
160      var $table = $(this);
161      var num_cols = $table.find('>thead>tr,>tbody>tr,>tfoot>tr').eq(0).find('>td,>th').length; //first table <tr> must not contain colspans, or add sum(colspan-1) here.
162      if(num_cols<3) //stackcolumns has no effect on tables with less than 3 columns
163        return;
164
165      var $stackcolumns = $('<table class="stacktable small-only"></table>');
166      if (typeof settings.myClass !== 'undefined') $stackcolumns.addClass(settings.myClass);
167      $table.addClass('stacktable large-only');
168      var tb = $('<tbody></tbody>');
169      var col_i = 1; //col index starts at 0 -> start copy at second column.
170
171      while (col_i < num_cols) {
172        $table.find('>thead>tr,>tbody>tr,>tfoot>tr').each(function(index) {
173          var tem = $('<tr></tr>'); // todo opt. copy styles of $this; todo check if parent is thead or tfoot to handle accordingly
174          if(index === 0) tem.addClass("st-head-row st-head-row-main");
175          var first = $(this).find('>td,>th').eq(0).clone().addClass("st-key");
176          var target = col_i;
177          // if colspan apply, recompute target for second cell.
178          if ($(this).find("*[colspan]").length) {
179            var i =0;
180            $(this).find('>td,>th').each(function() {
181                var cs = $(this).attr("colspan");
182                if (cs) {
183                  cs = parseInt(cs, 10);
184                  target -= cs-1;
185                  if ((i+cs) > (col_i)) //out of current bounds
186                    target += i + cs - col_i -1;
187                  i += cs;
188                } else {
189                  i++;
190                }
191
192                if (i > col_i)
193                  return false; //target is set; break.
194            });
195          }
196          var second = $(this).find('>td,>th').eq(target).clone().addClass("st-val").removeAttr("colspan");
197          tem.append(first, second);
198          tb.append(tem);
199        });
200        ++col_i;
201      }
202
203      $stackcolumns.append($(tb));
204      $table.before($stackcolumns);
205    });
206  };
207
208}(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.