jquery-datatables-rails 1.11.2 → 1.11.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +7 -0
  2. data/lib/jquery/datatables/rails/engine.rb +1 -1
  3. data/lib/jquery/datatables/rails/version.rb +1 -1
  4. data/vendor/assets/images/dataTables/extras/button.png +0 -0
  5. data/vendor/assets/images/dataTables/extras/insert.png +0 -0
  6. data/vendor/assets/images/dataTables/foundation/sort_asc.png +0 -0
  7. data/vendor/assets/images/dataTables/foundation/sort_asc_disabled.png +0 -0
  8. data/vendor/assets/images/dataTables/foundation/sort_both.png +0 -0
  9. data/vendor/assets/images/dataTables/foundation/sort_desc.png +0 -0
  10. data/vendor/assets/images/dataTables/foundation/sort_desc_disabled.png +0 -0
  11. data/vendor/assets/images/dataTables/minus.png +0 -0
  12. data/vendor/assets/images/dataTables/plus.png +0 -0
  13. data/vendor/assets/javascripts/dataTables/extras/ColReorder.js +41 -15
  14. data/vendor/assets/javascripts/dataTables/extras/ColVis.js +1 -9
  15. data/vendor/assets/javascripts/dataTables/extras/TableTools.js +121 -69
  16. data/vendor/assets/javascripts/dataTables/extras/TableTools.min.js +50 -49
  17. data/vendor/assets/javascripts/dataTables/jquery.dataTables.bootstrap.js +2 -2
  18. data/vendor/assets/javascripts/dataTables/jquery.dataTables.bootstrap3.js +152 -0
  19. data/vendor/assets/javascripts/dataTables/jquery.dataTables.foundation.js +186 -0
  20. data/vendor/assets/javascripts/dataTables/jquery.dataTables.responsive.js +435 -0
  21. data/vendor/assets/media/dataTables/extras/as3/ZeroClipboard.as +1 -1
  22. data/vendor/assets/media/dataTables/extras/as3/ZeroClipboardPdf.as +1 -1
  23. data/vendor/assets/media/dataTables/extras/swf/copy_csv_xls.swf +0 -0
  24. data/vendor/assets/media/dataTables/extras/swf/copy_csv_xls_pdf.swf +0 -0
  25. data/vendor/assets/stylesheets/dataTables/extras/ColReorder.css.erb +21 -0
  26. data/vendor/assets/stylesheets/dataTables/extras/ColVis.css +76 -0
  27. data/vendor/assets/stylesheets/dataTables/extras/ColVisAlt.css.erb +104 -0
  28. data/vendor/assets/stylesheets/dataTables/extras/{TableTools.css → TableTools.css.erb} +39 -31
  29. data/vendor/assets/stylesheets/dataTables/jquery.dataTables.bootstrap.css.scss +5 -0
  30. data/vendor/assets/stylesheets/dataTables/jquery.dataTables.bootstrap3.css.scss +216 -0
  31. data/vendor/assets/stylesheets/dataTables/jquery.dataTables.foundation.css.scss +211 -0
  32. data/vendor/assets/stylesheets/dataTables/jquery.dataTables.responsive.css.scss +22 -0
  33. metadata +28 -15
@@ -0,0 +1,435 @@
1
+ /**
2
+ * File: datatables.responsive.js
3
+ * Version: 0.1.2
4
+ * Author: Seen Sai Yang
5
+ * Info: https://github.com/Comanche/datatables-responsive
6
+ *
7
+ * Copyright 2013 Seen Sai Yang, all rights reserved.
8
+ *
9
+ * This source file is free software, under either the GPL v2 license or a
10
+ * BSD style license.
11
+ *
12
+ * This source file is distributed in the hope that it will be useful, but
13
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the license files for details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License and the
17
+ * BSD license along with this program. These licenses are also available at:
18
+ * https://raw.github.com/Comanche/datatables-responsive/master/license-gpl2.txt
19
+ * https://raw.github.com/Comanche/datatables-responsive/master/license-bsd.txt
20
+ */
21
+
22
+ 'use strict';
23
+
24
+ /**
25
+ * Constructor for responsive datables helper.
26
+ *
27
+ * This helper class makes datatables responsive to the window size.
28
+ *
29
+ * The parameter, breakpoints, is an object for each breakpoint key/value pair
30
+ * with the following format: { breakpoint_name: pixel_width_at_breakpoint }.
31
+ *
32
+ * An example is as follows:
33
+ *
34
+ * {
35
+ * tablet: 1024,
36
+ * phone: 480
37
+ * }
38
+ *
39
+ * These breakpoint name may be used as possible values for the data-hide
40
+ * attribute. The data-hide attribute is optional and may be defined for each
41
+ * th element in the table header.
42
+ *
43
+ * @param {Object|string} tableSelector jQuery wrapped set or selector for
44
+ * datatables container element.
45
+ * @param {Object} breakpoints Object defining the responsive
46
+ * breakpoint for datatables.
47
+ */
48
+ function ResponsiveDatatablesHelper(tableSelector, breakpoints) {
49
+ if (typeof tableSelector === 'string') {
50
+ this.tableElement = $(tableSelector);
51
+ } else {
52
+ this.tableElement = tableSelector;
53
+ }
54
+
55
+ // State of column indexes and which are shown or hidden.
56
+ this.columnIndexes = [];
57
+ this.columnsShownIndexes = [];
58
+ this.columnsHiddenIndexes = [];
59
+
60
+ // Index of the th in the header tr that stores where the attribute
61
+ // data-class="expand"
62
+ // is defined.
63
+ this.expandColumn = undefined;
64
+
65
+ // Stores the break points defined in the table header.
66
+ // Each th in the header tr may contain an optional attribute like
67
+ // data-hide="phone,tablet"
68
+ // These attributes and the breakpoints object will be used to create this
69
+ // object.
70
+ this.breakpoints = {
71
+ /**
72
+ * We will be generating data in the following format:
73
+ * phone : {
74
+ * lowerLimit : undefined,
75
+ * upperLimit : 320,
76
+ * columnsToHide: []
77
+ * },
78
+ * tablet: {
79
+ * lowerLimit : 320,
80
+ * upperLimit : 724,
81
+ * columnsToHide: []
82
+ * }
83
+ */
84
+ };
85
+
86
+ // Expand icon template
87
+ this.expandIconTemplate = '<span class="responsiveExpander"></span>';
88
+
89
+ // Row template
90
+ this.rowTemplate = '<tr class="row-detail"><td><ul><!--column item--></ul></td></tr>';
91
+ this.rowLiTemplate = '<li><span class="columnTitle"><!--column title--></span>: <!--column value--></li>';
92
+
93
+ // Responsive behavior on/off flag
94
+ this.disabled = true;
95
+
96
+ // Skip next windows width change flag
97
+ this.skipNextWindowsWidthChange = false;
98
+
99
+ // Initialize settings
100
+ this.init(breakpoints);
101
+ }
102
+
103
+ /**
104
+ * Responsive datatables helper init function. Builds breakpoint limits
105
+ * for columns and begins to listen to window resize event.
106
+ *
107
+ * See constructor for the breakpoints parameter.
108
+ *
109
+ * @param {Object} breakpoints
110
+ */
111
+ ResponsiveDatatablesHelper.prototype.init = function (breakpoints) {
112
+ /** Generate breakpoints in the format we need. ***************************/
113
+ // First, we need to create a sorted array of the breakpoints given.
114
+ var breakpointsSorted = [];
115
+ _.each(breakpoints, function (value, key) {
116
+ breakpointsSorted.push({
117
+ name : key,
118
+ upperLimit : value,
119
+ columnsToHide: []
120
+ });
121
+ });
122
+ breakpointsSorted = _.sortBy(breakpointsSorted, 'upperLimit');
123
+
124
+ // Set lower and upper limits for each breakpoint.
125
+ var lowerLimit = undefined;
126
+ _.each(breakpointsSorted, function (value) {
127
+ value.lowerLimit = lowerLimit;
128
+ lowerLimit = value.upperLimit;
129
+ });
130
+
131
+ // Add the default breakpoint which shows all (has no upper limit).
132
+ breakpointsSorted.push({
133
+ name : 'default',
134
+ lowerLimit : lowerLimit,
135
+ upperLimit : undefined,
136
+ columnsToHide: []
137
+ });
138
+
139
+ // Copy the sorted breakpoint array into the breakpoints object using the
140
+ // name as the key.
141
+ for (var i = 0, l = breakpointsSorted.length; i < l; i++) {
142
+ this.breakpoints[breakpointsSorted[i].name] = breakpointsSorted[i];
143
+ }
144
+
145
+ /** Create range of possible column indexes *******************************/
146
+ // Get all visible column indexes
147
+ var columns = this.tableElement.fnSettings().aoColumns;
148
+ for (var i = 0, l = columns.length; i < l; i++) {
149
+ if (columns[i].bVisible) {
150
+ this.columnIndexes.push(i)
151
+ }
152
+ }
153
+
154
+ // We need the range of possible column indexes to calculate the columns
155
+ // to show:
156
+ // Columns to show = all columns - columns to hide
157
+ var headerElements = $('thead th', this.tableElement);
158
+
159
+ /** Add columns into breakpoints respectively *****************************/
160
+ // Read column headers' attributes and get needed info
161
+ _.each(headerElements, function (element, index) {
162
+ // Get the column with the attribute data-class="expand" so we know
163
+ // where to display the expand icon.
164
+ if ($(element).attr('data-class') === 'expand') {
165
+ this.expandColumn = index;
166
+ }
167
+
168
+ // The data-hide attribute has the breakpoints that this column
169
+ // is associated with.
170
+ // If it's defined, get the data-hide attribute and sort this
171
+ // column into the appropriate breakpoint's columnsToHide array.
172
+ var dataHide = $(element).attr('data-hide');
173
+ if (dataHide !== undefined) {
174
+ var splitBreakingPoints = dataHide.split(/,\s*/);
175
+ _.each(splitBreakingPoints, function (e) {
176
+ if (this.breakpoints[e] !== undefined) {
177
+ // Translate visible column index to internal column index.
178
+ this.breakpoints[e].columnsToHide.push(this.columnIndexes[index]);
179
+ }
180
+ }, this);
181
+ }
182
+ }, this);
183
+
184
+ // Enable responsive behavior.
185
+ this.disable(false);
186
+ };
187
+
188
+ ResponsiveDatatablesHelper.prototype.setWindowsResizeHandler = function(bindFlag) {
189
+ if (bindFlag === undefined) {
190
+ bindFlag = true;
191
+ }
192
+
193
+ if (bindFlag) {
194
+ var that = this;
195
+ $(window).bind("resize", function () {
196
+ that.respond();
197
+ });
198
+ } else {
199
+ $(window).unbind("resize");
200
+ }
201
+ }
202
+
203
+ /**
204
+ * Respond window size change. This helps make datatables responsive.
205
+ */
206
+ ResponsiveDatatablesHelper.prototype.respond = function () {
207
+ if (this.disabled) {
208
+ return;
209
+ }
210
+
211
+ // Get new windows width
212
+ var newWindowWidth = $(window).width();
213
+ var updatedHiddenColumnsCount = 0;
214
+
215
+ // Loop through breakpoints to see which columns need to be shown/hidden.
216
+ var newColumnsToHide = [];
217
+ _.each(this.breakpoints, function (element) {
218
+ if ((!element.lowerLimit || newWindowWidth > element.lowerLimit) && (!element.upperLimit || newWindowWidth <= element.upperLimit)) {
219
+ newColumnsToHide = element.columnsToHide;
220
+ }
221
+ }, this);
222
+
223
+ // Find out if a column show/hide should happen.
224
+ // Skip column show/hide if this window width change follows immediately
225
+ // after a previous column show/hide. This will help prevent a loop.
226
+ var columnShowHide = false;
227
+ if (!this.skipNextWindowsWidthChange) {
228
+ // Check difference in length
229
+ if (this.columnsHiddenIndexes.length !== newColumnsToHide.length) {
230
+ // Difference in length
231
+ columnShowHide = true;
232
+ } else {
233
+ // Same length but check difference in values
234
+ var d1 = _.difference(this.columnsHiddenIndexes, newColumnsToHide).length;
235
+ var d2 = _.difference(newColumnsToHide, this.columnsHiddenIndexes).length;
236
+ columnShowHide = d1 + d2 > 0;
237
+ }
238
+ }
239
+
240
+ if (columnShowHide) {
241
+ // Showing/hiding a column at breakpoint may cause a windows width
242
+ // change. Let's flag to skip the column show/hide that may be
243
+ // caused by the next windows width change.
244
+ this.skipNextWindowsWidthChange = true;
245
+ this.columnsHiddenIndexes = newColumnsToHide;
246
+ this.columnsShownIndexes = _.difference(this.columnIndexes, this.columnsHiddenIndexes);
247
+ this.showHideColumns();
248
+ updatedHiddenColumnsCount = this.columnsHiddenIndexes.length;
249
+ this.skipNextWindowsWidthChange = false;
250
+ }
251
+
252
+
253
+ // We don't skip this part.
254
+ // If one or more columns have been hidden, add the has-columns-hidden class to table.
255
+ // This class will show what state the table is in.
256
+ if (this.columnsHiddenIndexes.length) {
257
+ this.tableElement.addClass('has-columns-hidden');
258
+ var that = this;
259
+
260
+ // Show details for each row that is tagged with the class .detail-show.
261
+ $('tr.detail-show', this.tableElement).each(function (index, element) {
262
+ var tr = $(element);
263
+ if (tr.next('.row-detail').length === 0) {
264
+ ResponsiveDatatablesHelper.prototype.showRowDetail(that, tr);
265
+ }
266
+ });
267
+ } else {
268
+ this.tableElement.removeClass('has-columns-hidden');
269
+ $('tr.row-detail').remove();
270
+ }
271
+ };
272
+
273
+ /**
274
+ * Show/hide datatables columns.
275
+ */
276
+ ResponsiveDatatablesHelper.prototype.showHideColumns = function () {
277
+ // Calculate the columns to show
278
+ // Show columns that may have been previously hidden.
279
+ for (var i = 0, l = this.columnsShownIndexes.length; i < l; i++) {
280
+ this.tableElement.fnSetColumnVis(this.columnsShownIndexes[i], true, false);
281
+ }
282
+
283
+ // Hide columns that may have been previously shown.
284
+ for (var i = 0, l = this.columnsHiddenIndexes.length; i < l; i++) {
285
+ this.tableElement.fnSetColumnVis(this.columnsHiddenIndexes[i], false, false);
286
+ }
287
+
288
+ // Rebuild details to reflect shown/hidden column changes.
289
+ var that = this;
290
+ $('tr.row-detail').remove();
291
+ if (this.tableElement.hasClass('has-columns-hidden')) {
292
+ $('tr.detail-show', this.tableElement).each(function (index, element) {
293
+ ResponsiveDatatablesHelper.prototype.showRowDetail(that, $(element));
294
+ });
295
+ }
296
+ };
297
+
298
+ /**
299
+ * Create the expand icon on the column with the data-class="expand" attribute
300
+ * defined for it's header.
301
+ *
302
+ * @param {Object} tr table row object
303
+ */
304
+ ResponsiveDatatablesHelper.prototype.createExpandIcon = function (tr) {
305
+ if (this.disabled) {
306
+ return;
307
+ }
308
+
309
+ // Get the td for tr with the same index as the th in the header tr
310
+ // that has the data-class="expand" attribute defined.
311
+ var tds = $('td', tr);
312
+ var that = this;
313
+ // Loop through tds and create an expand icon on the td that has a column
314
+ // index equal to the expand column given.
315
+ for (var i = 0, l = tds.length; i < l; i++) {
316
+ var td = tds[i];
317
+ var tdIndex = that.tableElement.fnGetPosition(td)[2];
318
+ td = $(td);
319
+ if (tdIndex === that.expandColumn) {
320
+ // Create expand icon if there isn't one already.
321
+ if ($('span.responsiveExpander', td).length == 0) {
322
+ td.prepend(that.expandIconTemplate);
323
+
324
+ // Respond to click event on expander icon.
325
+ td.on('click', 'span.responsiveExpander', {responsiveDatatablesHelperInstance: that}, that.showRowDetailEventHandler);
326
+ }
327
+ break;
328
+ }
329
+ }
330
+ };
331
+
332
+ /**
333
+ * Show row detail event handler.
334
+ *
335
+ * This handler is used to handle the click event of the expand icon defined in
336
+ * the table row data element.
337
+ *
338
+ * @param {Object} event jQuery event object
339
+ */
340
+ ResponsiveDatatablesHelper.prototype.showRowDetailEventHandler = function (event) {
341
+ if (this.disabled) {
342
+ return;
343
+ }
344
+
345
+ // Get the parent tr of which this td belongs to.
346
+ var tr = $(this).closest('tr');
347
+
348
+ // Show/hide row details
349
+ if (tr.hasClass('detail-show')) {
350
+ ResponsiveDatatablesHelper.prototype.hideRowDetail(event.data.responsiveDatatablesHelperInstance, tr);
351
+ } else {
352
+ ResponsiveDatatablesHelper.prototype.showRowDetail(event.data.responsiveDatatablesHelperInstance, tr);
353
+ }
354
+
355
+ tr.toggleClass('detail-show');
356
+
357
+ // Prevent click event from bubbling up to higher-level DOM elements.
358
+ event.stopPropagation();
359
+ };
360
+
361
+ /**
362
+ * Show row details
363
+ *
364
+ * @param {ResponsiveDatatablesHelper} responsiveDatatablesHelperInstance instance of ResponsiveDatatablesHelper
365
+ * @param {Object} tr jQuery wrapped set
366
+ */
367
+ ResponsiveDatatablesHelper.prototype.showRowDetail = function (responsiveDatatablesHelperInstance, tr) {
368
+ // Get column because we need their titles.
369
+ var tableContainer = responsiveDatatablesHelperInstance.tableElement;
370
+ var columns = tableContainer.fnSettings().aoColumns;
371
+
372
+ // Create the new tr.
373
+ var newTr = $(responsiveDatatablesHelperInstance.rowTemplate);
374
+
375
+ // Get the ul that we'll insert li's into.
376
+ var ul = $('ul', newTr);
377
+
378
+ // Loop through hidden columns and create an li for each of them.
379
+ _.each(responsiveDatatablesHelperInstance.columnsHiddenIndexes, function (index) {
380
+ var li = $(responsiveDatatablesHelperInstance.rowLiTemplate);
381
+ $('.columnTitle', li).html(columns[index].sTitle);
382
+ li.append(tableContainer.fnGetData(tr[0], index));
383
+ ul.append(li);
384
+ });
385
+
386
+ // Create tr colspan attribute
387
+ var colspan = responsiveDatatablesHelperInstance.columnIndexes.length - responsiveDatatablesHelperInstance.columnsHiddenIndexes.length;
388
+ $('td', newTr).attr('colspan', colspan);
389
+
390
+ // Append the new tr after the current tr.
391
+ tr.after(newTr);
392
+ };
393
+
394
+ /**
395
+ * Hide row details
396
+ *
397
+ * @param {ResponsiveDatatablesHelper} responsiveDatatablesHelperInstance instance of ResponsiveDatatablesHelper
398
+ * @param {Object} tr jQuery wrapped set
399
+ */
400
+ ResponsiveDatatablesHelper.prototype.hideRowDetail = function (responsiveDatatablesHelperInstance, tr) {
401
+ tr.next('.row-detail').remove();
402
+ };
403
+
404
+ /**
405
+ * Enable/disable responsive behavior and restores changes made.
406
+ *
407
+ * @param {Boolean} disable, default is true
408
+ */
409
+ ResponsiveDatatablesHelper.prototype.disable = function (disable) {
410
+ this.disabled = (disable === undefined) || disable;
411
+
412
+ if (this.disabled) {
413
+ // Remove windows resize handler
414
+ this.setWindowsResizeHandler(false);
415
+
416
+ // Remove all trs that have row details.
417
+ $('tbody tr.row-detail', this.tableElement).remove();
418
+
419
+ // Remove all trs that are marked to have row details shown.
420
+ $('tbody tr', this.tableElement).removeClass('detail-show');
421
+
422
+ // Remove all expander icons
423
+ $('tbody tr span.responsiveExpander', this.tableElement).remove();
424
+
425
+ this.columnsHiddenIndexes = [];
426
+ this.columnsShownIndexes = this.columnIndexes;
427
+ this.showHideColumns();
428
+ this.tableElement.removeClass('has-columns-hidden');
429
+
430
+ this.tableElement.off('click', 'span.responsiveExpander', this.showRowDetailEventHandler);
431
+ } else {
432
+ // Add windows resize handler
433
+ this.setWindowsResizeHandler();
434
+ }
435
+ }
@@ -32,7 +32,7 @@ package {
32
32
 
33
33
  // import flashvars
34
34
  var flashvars:Object = LoaderInfo( this.root.loaderInfo ).parameters;
35
- domId = flashvars.id;
35
+ domId = flashvars.id.split("\\").join("\\\\");
36
36
 
37
37
  // invisible button covers entire stage
38
38
  button = new Sprite();
@@ -46,7 +46,7 @@ package {
46
46
 
47
47
  // import flashvars
48
48
  var flashvars:Object = LoaderInfo( this.root.loaderInfo ).parameters;
49
- domId = flashvars.id;
49
+ domId = flashvars.id.split("\\").join("\\\\");
50
50
 
51
51
  // invisible button covers entire stage
52
52
  button = new Sprite();