PageSourceSearch

https://www.autohuset-hoersholm.dk/designs/general/portals/themes/light/js/lib/stacktable.js

js autohuset-hoersholm.dk collected 2026-10-08 16:17:24 UTC 3,985 bytes, 111 lines download raw bytes

1/**
2 * stacktable.js
3 * Author & copyright (c) 2012: John Polacek
4 * Dual MIT & GPL license
5 *
6 * Page: http://johnpolacek.github.com/stacktable.js
7 * Repo: https://github.com/johnpolacek/stacktable.js/
8 *
9 * jQuery plugin for stacking tables on small screens
10 *
11 */
12(function($) {
13
14  $.fn.stacktable = function(options) {
15    var $tables = this,
16        defaults = {id:'stacktable',hideOriginal:false},
17        settings = $.extend({}, defaults, options),
18        stacktable;
19
20    return $tables.each(function() {
21      var $stacktable = $('<table class="table '+settings.id+'"></table>');
22      if (typeof settings.myClass !== undefined) $stacktable.addClass(settings.myClass);
23      var headMarkup = '';
24      var markup = '';
25      $table = $(this);
26      $topRow = $table.find('tr').eq(0);
27
28
29
30      // for tables th cells in every table row
31      if (settings.tableType == "vertical") {
32
33        $table.find('tr').each(function(index,value) {
34
35          markup += '<tbody>';
36            $(this).find('th,td').each(function(index,value) {
37              if (index===0) {
38                markup += '<tr class="row-header"><th colspan="2">'+$(this).html()+'</th></tr>';
39              } else {
40                if ($(this).html() !== ''){
41                  markup += '<tr>';
42                  if ($topRow.find('td,th').eq(index).html()){
43                    //markup += '<td>'+$topRow.find('td,th').eq(index).html()+'</td>';
44                    //console.log($topRow.find('td,th').eq(index).html());
45                  } else {
46                    markup += '<td></td>';
47                  }
48                  markup += '<td class="'+ $(this).attr('class') +'">'+$(this).html()+'</td>';
49                  markup += '</tr>';
50                }
51              }
52            });
53            markup += '</tbody>';
54        });        
55        $stacktable.append($(markup));
56        $table.before($stacktable);
57        if (settings.hideOriginal) $table.hide();
58      }
59
60
61      else {
62        $table.find('tr').each(function(index,value) {
63          // for the first row, top left table cell is the head of the table
64          if (index===0) {
65            headMarkup += '<thead><tr><th colspan="2">'+$(this).find('th,td').eq(0).html()+'</th></tr></thead>';
66          }
67          // for the other rows, put the left table cell as the head for that row
68          // then iterate through the key/values
69          else {
70            markup += '<tbody>';
71            $(this).find('th,td').each(function(index,value) {
72              if (index===0) {
73
74                  // copy class names different from "odd" and "even"
75                  var classes = $(this).closest('tr').attr('class').split(' ');
76
77                  if($.inArray('odd', classes) > -1) {
78                    classes.splice($.inArray('odd', classes), 1);
79                  }
80                  if($.inArray('even', classes) > -1) {
81                    classes.splice($.inArray('even', classes), 1);
82                  }
83
84
85                markup += '<tr class="row-header ' + classes.join(' ') + '"><th colspan="2">'+$(this).html()+'</th></tr>';
86              } else {
87                if ($(this).html() !== ''){
88                  markup += '<tr>';
89                  if ($topRow.find('td,th').eq(index).html()){
90                    markup += '<td>'+$topRow.find('td,th').eq(index).html()+'</td>';
91                  } else {
92                    markup += '<td></td>';
93                  }
94                  markup += '<td class="'+ $(this).attr('class') +'">'+$(this).html()+'</td>';
95                  markup += '</tr>';
96                }
97              }
98            });
99            markup += '</tbody>';
100          }
101        });
102        $stacktable.append($(headMarkup));
103        $stacktable.append($(markup));
104        $table.before($stacktable);
105        if (settings.hideOriginal) $table.hide();
106      }
107
108    });
109  };
110
111}(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.