PageSourceSearch

https://www.scrippscollege.edu/wp-content/themes/scrippscollege/as…/johnpolacek-stacktable/stacktable.js?v=001

js scrippscollege.edu collected 2026-10-02 03:51:11 UTC 8,560 bytes, 219 lines download raw bytes

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