Debian Codegraph @

js/widgets/widget-reflow.js

raw symbols SCIP
1 /* Widget: reflow - updated 2/7/2015 (v2.19.0) *//*
2 * Requires tablesorter v2.8+ and jQuery 1.7+
3 * Also, this widget requires the following default css (modify as desired)
4
5 / * REQUIRED CSS: change your reflow breakpoint here (35em below) * /
6 @media ( max-width: 35em ) {
7 .ui-table-reflow td,
8 .ui-table-reflow th {
9 -webkit-box-sizing: border-box;
10 -moz-box-sizing: border-box;
11 box-sizing: border-box;
12 float: right;
13 / * if not using the stickyHeaders widget (not the css3 version)
14 * the "!important" flag, and "height: auto" can be removed * /
15 width: 100% !important;
16 height: auto !important;
17 }
18 / * reflow widget * /
19 .ui-table-reflow tbody td[data-title]:before {
20 color: #469;
21 font-size: .9em;
22 content: attr(data-title);
23 float: left;
24 width: 50%;
25 white-space: pre-wrap;
26 text-align: bottom;
27 display: inline-block;
28 }
29 / * reflow2 widget * /
30 table.ui-table-reflow .ui-table-cell-label.ui-table-cell-label-top {
31 display: block;
32 padding: .4em 0;
33 margin: .4em 0;
34 text-transform: uppercase;
35 font-size: .9em;
36 font-weight: 400;
37 }
38 table.ui-table-reflow .ui-table-cell-label {
39 padding: .4em;
40 min-width: 30%;
41 display: inline-block;
42 margin: -.4em 1em -.4em -.4em;
43 }
44 }
45 .ui-table-reflow .ui-table-cell-label {
46 display: none;
47 }
48
49 */
50 /*jshint browser:true, jquery:true, unused:false */
51 /*global jQuery: false */
52 ;(function($) {
53 'use strict';
54
55 var ts = $.tablesorter,
56
57 tablereflow = {
58 // simple reflow
59 // add data-attribute to each cell which shows when media query is active
60 // this widget DOES NOT WORK on a table with multiple thead rows
61 init : function(table, c, wo) {
62 var $this,
63 title = wo.reflow_dataAttrib,
64 header = wo.reflow_headerAttrib,
65 headers = [];
66 c.$table
67 .addClass(wo.reflow_className)
68 .off('refresh.tsreflow updateComplete.tsreflow2')
69 // emulate jQuery Mobile refresh
70 // https://api.jquerymobile.com/table-reflow/#method-refresh
71 .on('refresh.tsreflow updateComplete.tsreflow2', function() {
72 tablereflow.init(table, c, wo);
73 });
74 c.$headers.each(function() {
75 $this = $(this);
76 headers.push( $.trim( $this.attr(header) || $this.text() ) );
77 });
78 c.$tbodies.children().each(function() {
79 $(this).children().each(function(i) {
80 $(this).attr(title, headers[i]);
81 });
82 });
83 },
84 init2: function(table, c, wo) {
85 var $this, $tbody, i, $hdr, txt, len,
86 cols = c.columns,
87 header = wo.reflow2_headerAttrib,
88 headers = [];
89 c.$table
90 .addClass(wo.reflow2_className)
91 .off('refresh.tsreflow2 updateComplete.tsreflow2')
92 // emulate jQuery Mobile refresh
93 // https://api.jquerymobile.com/table-reflow/#method-refresh
94 .on('refresh.tsreflow2 updateComplete.tsreflow2', function() {
95 tablereflow.init2(table, c, wo);
96 });
97
98 // add <b> to every table cell with thead cell contents
99 for (i = 0; i < cols; i++) {
100 $hdr = c.$headers.filter('[data-column="' + i + '"]');
101 if ($hdr.length > 1) {
102 txt = [];
103 /*jshint loopfunc:true */
104 $hdr.each(function() {
105 $this = $(this);
106 if (!$this.hasClass(wo.reflow2_classIgnore)) {
107 txt.push( $this.attr(header) || $this.text() );
108 }
109 });
110 } else {
111 txt = [ $hdr.attr(header) || $hdr.text() ];
112 }
113 headers.push( txt );
114 }
115 // include 'remove-me' class so these additional elements are removed before updating
116 txt = '<b class="' + c.selectorRemove.slice(1) + ' ' + wo.reflow2_labelClass;
117 c.$tbodies.children().each(function() {
118 $tbody = ts.processTbody(table, $(this), true);
119 $tbody.children().each(function(j) {
120 $this = $(this);
121 len = headers[j].length;
122 i = len - 1;
123 while (i >= 0) {
124 $this.prepend(txt + (i === 0 && len > 1 ? ' ' + wo.reflow2_labelTop : '') + '">' + headers[j][i] + '</b>');
125 i--;
126 }
127 });
128 ts.processTbody(table, $tbody, false);
129 });
130 },
131 remove : function(table, c, wo) {
132 c.$table.removeClass(wo.reflow_className);
133 },
134 remove2 : function(table, c, wo) {
135 c.$table.removeClass(wo.reflow2_className);
136 }
137 };
138
139 ts.addWidget({
140 id: 'reflow',
141 options: {
142 // class name added to make it responsive (class name within media query)
143 reflow_className : 'ui-table-reflow',
144 // header attribute containing modified header name
145 reflow_headerAttrib : 'data-name',
146 // data attribute added to each tbody cell
147 reflow_dataAttrib : 'data-title'
148 },
149 init: function(table, thisWidget, c, wo) {
150 tablereflow.init(table, c, wo);
151 },
152 remove: function(table, c, wo) {
153 tablereflow.remove(table, c, wo);
154 }
155 });
156
157 ts.addWidget({
158 id: 'reflow2',
159 options: {
160 // class name added to make it responsive (class name within media query)
161 reflow2_className : 'ui-table-reflow',
162 // ignore header cell content with this class name
163 reflow2_classIgnore : 'ui-table-reflow-ignore',
164 // header attribute containing modified header name
165 reflow2_headerAttrib : 'data-name',
166 // class name applied to thead labels
167 reflow2_labelClass : 'ui-table-cell-label',
168 // class name applied to first row thead label
169 reflow2_labelTop : 'ui-table-cell-label-top'
170 },
171 init: function(table, thisWidget, c, wo) {
172 tablereflow.init2(table, c, wo);
173 },
174 remove: function(table, c, wo) {
175 tablereflow.remove2(table, c, wo);
176 }
177 });
178
179 })(jQuery);