smithycms 0.6.4 → 0.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/config/initializers/refile.rb +6 -1
  3. data/lib/smithy/dependencies.rb +0 -3
  4. data/lib/smithy/version.rb +1 -1
  5. data/vendor/assets/images/datatables/favicon.ico +0 -0
  6. data/vendor/assets/images/datatables/sort_asc.png +0 -0
  7. data/vendor/assets/images/datatables/sort_asc_disabled.png +0 -0
  8. data/vendor/assets/images/datatables/sort_both.png +0 -0
  9. data/vendor/assets/images/datatables/sort_desc.png +0 -0
  10. data/vendor/assets/images/datatables/sort_desc_disabled.png +0 -0
  11. data/vendor/assets/javascripts/datatables/dataTables.bootstrap.js +220 -0
  12. data/vendor/assets/javascripts/datatables/dataTables.foundation.js +156 -0
  13. data/vendor/assets/javascripts/datatables/dataTables.jqueryui.js +164 -0
  14. data/vendor/assets/javascripts/datatables/jquery.dataTables.js +15212 -0
  15. data/vendor/assets/javascripts/datatables/jquery.js +5 -0
  16. data/vendor/assets/javascripts/datatables-responsive/dataTables.responsive.js +1190 -0
  17. data/vendor/assets/javascripts/datatables-responsive/responsive.bootstrap.js +78 -0
  18. data/vendor/assets/javascripts/datatables-responsive/responsive.foundation.js +62 -0
  19. data/vendor/assets/javascripts/datatables-responsive/responsive.jqueryui.js +63 -0
  20. data/vendor/assets/javascripts/datatables-responsive.js +1 -0
  21. data/vendor/assets/javascripts/datatables-select/dataTables.select.js +1038 -0
  22. data/vendor/assets/javascripts/datatables-select.js +1 -0
  23. data/vendor/assets/javascripts/datatables.js +1 -0
  24. data/vendor/assets/stylesheets/datatables/dataTables.bootstrap.scss +187 -0
  25. data/vendor/assets/stylesheets/datatables/dataTables.foundation.scss +117 -0
  26. data/vendor/assets/stylesheets/datatables/dataTables.jqueryui.scss +482 -0
  27. data/vendor/assets/stylesheets/datatables/jquery.dataTables.scss +453 -0
  28. data/vendor/assets/stylesheets/datatables/jquery.dataTables_themeroller.scss +416 -0
  29. data/vendor/assets/stylesheets/datatables-responsive/responsive.bootstrap.scss +4 -0
  30. data/vendor/assets/stylesheets/datatables-responsive/responsive.dataTables.scss +241 -0
  31. data/vendor/assets/stylesheets/datatables-responsive/responsive.foundation.scss +10 -0
  32. data/vendor/assets/stylesheets/datatables-responsive/responsive.jqueryui.scss +2 -0
  33. data/vendor/assets/stylesheets/datatables-responsive.scss +1 -0
  34. data/vendor/assets/stylesheets/datatables-select/select.bootstrap.scss +17 -0
  35. data/vendor/assets/stylesheets/datatables-select/select.dataTables.scss +139 -0
  36. data/vendor/assets/stylesheets/datatables-select/select.foundation.scss +18 -0
  37. data/vendor/assets/stylesheets/datatables-select/select.jqueryui.scss +4 -0
  38. data/vendor/assets/stylesheets/datatables-select.scss +1 -0
  39. data/vendor/assets/stylesheets/datatables.scss +1 -0
  40. metadata +37 -44
@@ -0,0 +1,1190 @@
1
+ /*! Responsive 2.0.1
2
+ * 2014-2015 SpryMedia Ltd - datatables.net/license
3
+ */
4
+
5
+ /**
6
+ * @summary Responsive
7
+ * @description Responsive tables plug-in for DataTables
8
+ * @version 2.0.1
9
+ * @file dataTables.responsive.js
10
+ * @author SpryMedia Ltd (www.sprymedia.co.uk)
11
+ * @contact www.sprymedia.co.uk/contact
12
+ * @copyright Copyright 2014-2015 SpryMedia Ltd.
13
+ *
14
+ * This source file is free software, available under the following license:
15
+ * MIT license - http://datatables.net/license/mit
16
+ *
17
+ * This source file is distributed in the hope that it will be useful, but
18
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the license files for details.
20
+ *
21
+ * For details please refer to: http://www.datatables.net
22
+ */
23
+ (function( factory ){
24
+ if ( typeof define === 'function' && define.amd ) {
25
+ // AMD
26
+ define( ['jquery', 'datatables.net'], function ( $ ) {
27
+ return factory( $, window, document );
28
+ } );
29
+ }
30
+ else if ( typeof exports === 'object' ) {
31
+ // CommonJS
32
+ module.exports = function (root, $) {
33
+ if ( ! root ) {
34
+ root = window;
35
+ }
36
+
37
+ if ( ! $ || ! $.fn.dataTable ) {
38
+ $ = require('datatables.net')(root, $).$;
39
+ }
40
+
41
+ return factory( $, root, root.document );
42
+ };
43
+ }
44
+ else {
45
+ // Browser
46
+ factory( jQuery, window, document );
47
+ }
48
+ }(function( $, window, document, undefined ) {
49
+ 'use strict';
50
+ var DataTable = $.fn.dataTable;
51
+
52
+
53
+ /**
54
+ * Responsive is a plug-in for the DataTables library that makes use of
55
+ * DataTables' ability to change the visibility of columns, changing the
56
+ * visibility of columns so the displayed columns fit into the table container.
57
+ * The end result is that complex tables will be dynamically adjusted to fit
58
+ * into the viewport, be it on a desktop, tablet or mobile browser.
59
+ *
60
+ * Responsive for DataTables has two modes of operation, which can used
61
+ * individually or combined:
62
+ *
63
+ * * Class name based control - columns assigned class names that match the
64
+ * breakpoint logic can be shown / hidden as required for each breakpoint.
65
+ * * Automatic control - columns are automatically hidden when there is no
66
+ * room left to display them. Columns removed from the right.
67
+ *
68
+ * In additional to column visibility control, Responsive also has built into
69
+ * options to use DataTables' child row display to show / hide the information
70
+ * from the table that has been hidden. There are also two modes of operation
71
+ * for this child row display:
72
+ *
73
+ * * Inline - when the control element that the user can use to show / hide
74
+ * child rows is displayed inside the first column of the table.
75
+ * * Column - where a whole column is dedicated to be the show / hide control.
76
+ *
77
+ * Initialisation of Responsive is performed by:
78
+ *
79
+ * * Adding the class `responsive` or `dt-responsive` to the table. In this case
80
+ * Responsive will automatically be initialised with the default configuration
81
+ * options when the DataTable is created.
82
+ * * Using the `responsive` option in the DataTables configuration options. This
83
+ * can also be used to specify the configuration options, or simply set to
84
+ * `true` to use the defaults.
85
+ *
86
+ * @class
87
+ * @param {object} settings DataTables settings object for the host table
88
+ * @param {object} [opts] Configuration options
89
+ * @requires jQuery 1.7+
90
+ * @requires DataTables 1.10.3+
91
+ *
92
+ * @example
93
+ * $('#example').DataTable( {
94
+ * responsive: true
95
+ * } );
96
+ * } );
97
+ */
98
+ var Responsive = function ( settings, opts ) {
99
+ // Sanity check that we are using DataTables 1.10 or newer
100
+ if ( ! DataTable.versionCheck || ! DataTable.versionCheck( '1.10.3' ) ) {
101
+ throw 'DataTables Responsive requires DataTables 1.10.3 or newer';
102
+ }
103
+
104
+ this.s = {
105
+ dt: new DataTable.Api( settings ),
106
+ columns: [],
107
+ current: []
108
+ };
109
+
110
+ // Check if responsive has already been initialised on this table
111
+ if ( this.s.dt.settings()[0].responsive ) {
112
+ return;
113
+ }
114
+
115
+ // details is an object, but for simplicity the user can give it as a string
116
+ if ( opts && typeof opts.details === 'string' ) {
117
+ opts.details = { type: opts.details };
118
+ }
119
+
120
+ this.c = $.extend( true, {}, Responsive.defaults, DataTable.defaults.responsive, opts );
121
+ settings.responsive = this;
122
+ this._constructor();
123
+ };
124
+
125
+ $.extend( Responsive.prototype, {
126
+ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
127
+ * Constructor
128
+ */
129
+
130
+ /**
131
+ * Initialise the Responsive instance
132
+ *
133
+ * @private
134
+ */
135
+ _constructor: function ()
136
+ {
137
+ var that = this;
138
+ var dt = this.s.dt;
139
+ var dtPrivateSettings = dt.settings()[0];
140
+ var oldWindowWidth = $(window).width();
141
+
142
+ dt.settings()[0]._responsive = this;
143
+
144
+ // Use DataTables' throttle function to avoid processor thrashing on
145
+ // resize
146
+ $(window).on( 'resize.dtr orientationchange.dtr', DataTable.util.throttle( function () {
147
+ // iOS has a bug whereby resize can fire when only scrolling
148
+ // See: http://stackoverflow.com/questions/8898412
149
+ var width = $(window).width();
150
+
151
+ if ( width !== oldWindowWidth ) {
152
+ that._resize();
153
+ oldWindowWidth = width;
154
+ }
155
+ } ) );
156
+
157
+ // DataTables doesn't currently trigger an event when a row is added, so
158
+ // we need to hook into its private API to enforce the hidden rows when
159
+ // new data is added
160
+ dtPrivateSettings.oApi._fnCallbackReg( dtPrivateSettings, 'aoRowCreatedCallback', function (tr, data, idx) {
161
+ if ( $.inArray( false, that.s.current ) !== -1 ) {
162
+ $('td, th', tr).each( function ( i ) {
163
+ var idx = dt.column.index( 'toData', i );
164
+
165
+ if ( that.s.current[idx] === false ) {
166
+ $(this).css('display', 'none');
167
+ }
168
+ } );
169
+ }
170
+ } );
171
+
172
+ // Destroy event handler
173
+ dt.on( 'destroy.dtr', function () {
174
+ dt.off( '.dtr' );
175
+ $( dt.table().body() ).off( '.dtr' );
176
+ $(window).off( 'resize.dtr orientationchange.dtr' );
177
+
178
+ // Restore the columns that we've hidden
179
+ $.each( that.s.current, function ( i, val ) {
180
+ if ( val === false ) {
181
+ that._setColumnVis( i, true );
182
+ }
183
+ } );
184
+ } );
185
+
186
+ // Reorder the breakpoints array here in case they have been added out
187
+ // of order
188
+ this.c.breakpoints.sort( function (a, b) {
189
+ return a.width < b.width ? 1 :
190
+ a.width > b.width ? -1 : 0;
191
+ } );
192
+
193
+ this._classLogic();
194
+ this._resizeAuto();
195
+
196
+ // Details handler
197
+ var details = this.c.details;
198
+
199
+ if ( details.type !== false ) {
200
+ that._detailsInit();
201
+
202
+ // DataTables will trigger this event on every column it shows and
203
+ // hides individually
204
+ dt.on( 'column-visibility.dtr', function (e, ctx, col, vis) {
205
+ that._classLogic();
206
+ that._resizeAuto();
207
+ that._resize();
208
+ } );
209
+
210
+ // Redraw the details box on each draw which will happen if the data
211
+ // has changed. This is used until DataTables implements a native
212
+ // `updated` event for rows
213
+ dt.on( 'draw.dtr', function () {
214
+ that._redrawChildren();
215
+ } );
216
+
217
+ $(dt.table().node()).addClass( 'dtr-'+details.type );
218
+ }
219
+
220
+ dt.on( 'column-reorder.dtr', function (e, settings, details) {
221
+ // This requires ColReorder 1.2.1 or newer
222
+ if ( details.drop ) {
223
+ that._classLogic();
224
+ that._resizeAuto();
225
+ that._resize();
226
+ }
227
+ } );
228
+
229
+ // Change in column sizes means we need to calc
230
+ dt.on( 'column-sizing.dtr', function () {
231
+ that._resize();
232
+ });
233
+
234
+ dt.on( 'init.dtr', function (e, settings, details) {
235
+ that._resizeAuto();
236
+ that._resize();
237
+
238
+ // If columns were hidden, then DataTables needs to adjust the
239
+ // column sizing
240
+ if ( $.inArray( false, that.s.current ) ) {
241
+ dt.columns.adjust();
242
+ }
243
+ } );
244
+
245
+ // First pass - draw the table for the current viewport size
246
+ this._resize();
247
+ },
248
+
249
+
250
+ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
251
+ * Private methods
252
+ */
253
+
254
+ /**
255
+ * Calculate the visibility for the columns in a table for a given
256
+ * breakpoint. The result is pre-determined based on the class logic if
257
+ * class names are used to control all columns, but the width of the table
258
+ * is also used if there are columns which are to be automatically shown
259
+ * and hidden.
260
+ *
261
+ * @param {string} breakpoint Breakpoint name to use for the calculation
262
+ * @return {array} Array of boolean values initiating the visibility of each
263
+ * column.
264
+ * @private
265
+ */
266
+ _columnsVisiblity: function ( breakpoint )
267
+ {
268
+ var dt = this.s.dt;
269
+ var columns = this.s.columns;
270
+ var i, ien;
271
+
272
+ // Create an array that defines the column ordering based first on the
273
+ // column's priority, and secondly the column index. This allows the
274
+ // columns to be removed from the right if the priority matches
275
+ var order = columns
276
+ .map( function ( col, idx ) {
277
+ return {
278
+ columnIdx: idx,
279
+ priority: col.priority
280
+ };
281
+ } )
282
+ .sort( function ( a, b ) {
283
+ if ( a.priority !== b.priority ) {
284
+ return a.priority - b.priority;
285
+ }
286
+ return a.columnIdx - b.columnIdx;
287
+ } );
288
+
289
+
290
+ // Class logic - determine which columns are in this breakpoint based
291
+ // on the classes. If no class control (i.e. `auto`) then `-` is used
292
+ // to indicate this to the rest of the function
293
+ var display = $.map( columns, function ( col ) {
294
+ return col.auto && col.minWidth === null ?
295
+ false :
296
+ col.auto === true ?
297
+ '-' :
298
+ $.inArray( breakpoint, col.includeIn ) !== -1;
299
+ } );
300
+
301
+ // Auto column control - first pass: how much width is taken by the
302
+ // ones that must be included from the non-auto columns
303
+ var requiredWidth = 0;
304
+ for ( i=0, ien=display.length ; i<ien ; i++ ) {
305
+ if ( display[i] === true ) {
306
+ requiredWidth += columns[i].minWidth;
307
+ }
308
+ }
309
+
310
+ // Second pass, use up any remaining width for other columns. For
311
+ // scrolling tables we need to subtract the width of the scrollbar. It
312
+ // may not be requires which makes this sub-optimal, but it would
313
+ // require another full redraw to make complete use of those extra few
314
+ // pixels
315
+ var scrolling = dt.settings()[0].oScroll;
316
+ var bar = scrolling.sY || scrolling.sX ? scrolling.iBarWidth : 0;
317
+ var widthAvailable = dt.table().container().offsetWidth - bar;
318
+ var usedWidth = widthAvailable - requiredWidth;
319
+
320
+ // Control column needs to always be included. This makes it sub-
321
+ // optimal in terms of using the available with, but to stop layout
322
+ // thrashing or overflow. Also we need to account for the control column
323
+ // width first so we know how much width is available for the other
324
+ // columns, since the control column might not be the first one shown
325
+ for ( i=0, ien=display.length ; i<ien ; i++ ) {
326
+ if ( columns[i].control ) {
327
+ usedWidth -= columns[i].minWidth;
328
+ }
329
+ }
330
+
331
+ // Allow columns to be shown (counting by priority and then right to
332
+ // left) until we run out of room
333
+ var empty = false;
334
+ for ( i=0, ien=order.length ; i<ien ; i++ ) {
335
+ var colIdx = order[i].columnIdx;
336
+
337
+ if ( display[colIdx] === '-' && ! columns[colIdx].control && columns[colIdx].minWidth ) {
338
+ // Once we've found a column that won't fit we don't let any
339
+ // others display either, or columns might disappear in the
340
+ // middle of the table
341
+ if ( empty || usedWidth - columns[colIdx].minWidth < 0 ) {
342
+ empty = true;
343
+ display[colIdx] = false;
344
+ }
345
+ else {
346
+ display[colIdx] = true;
347
+ }
348
+
349
+ usedWidth -= columns[colIdx].minWidth;
350
+ }
351
+ }
352
+
353
+ // Determine if the 'control' column should be shown (if there is one).
354
+ // This is the case when there is a hidden column (that is not the
355
+ // control column). The two loops look inefficient here, but they are
356
+ // trivial and will fly through. We need to know the outcome from the
357
+ // first , before the action in the second can be taken
358
+ var showControl = false;
359
+
360
+ for ( i=0, ien=columns.length ; i<ien ; i++ ) {
361
+ if ( ! columns[i].control && ! columns[i].never && ! display[i] ) {
362
+ showControl = true;
363
+ break;
364
+ }
365
+ }
366
+
367
+ for ( i=0, ien=columns.length ; i<ien ; i++ ) {
368
+ if ( columns[i].control ) {
369
+ display[i] = showControl;
370
+ }
371
+ }
372
+
373
+ // Finally we need to make sure that there is at least one column that
374
+ // is visible
375
+ if ( $.inArray( true, display ) === -1 ) {
376
+ display[0] = true;
377
+ }
378
+
379
+ return display;
380
+ },
381
+
382
+
383
+ /**
384
+ * Create the internal `columns` array with information about the columns
385
+ * for the table. This includes determining which breakpoints the column
386
+ * will appear in, based upon class names in the column, which makes up the
387
+ * vast majority of this method.
388
+ *
389
+ * @private
390
+ */
391
+ _classLogic: function ()
392
+ {
393
+ var that = this;
394
+ var calc = {};
395
+ var breakpoints = this.c.breakpoints;
396
+ var dt = this.s.dt;
397
+ var columns = dt.columns().eq(0).map( function (i) {
398
+ var column = this.column(i);
399
+ var className = column.header().className;
400
+ var priority = dt.settings()[0].aoColumns[i].responsivePriority;
401
+
402
+ if ( priority === undefined ) {
403
+ var dataPriority = $(column.header()).data('priority');
404
+
405
+ priority = dataPriority !== undefined ?
406
+ dataPriority * 1 :
407
+ 10000;
408
+ }
409
+
410
+ return {
411
+ className: className,
412
+ includeIn: [],
413
+ auto: false,
414
+ control: false,
415
+ never: className.match(/\bnever\b/) ? true : false,
416
+ priority: priority
417
+ };
418
+ } );
419
+
420
+ // Simply add a breakpoint to `includeIn` array, ensuring that there are
421
+ // no duplicates
422
+ var add = function ( colIdx, name ) {
423
+ var includeIn = columns[ colIdx ].includeIn;
424
+
425
+ if ( $.inArray( name, includeIn ) === -1 ) {
426
+ includeIn.push( name );
427
+ }
428
+ };
429
+
430
+ var column = function ( colIdx, name, operator, matched ) {
431
+ var size, i, ien;
432
+
433
+ if ( ! operator ) {
434
+ columns[ colIdx ].includeIn.push( name );
435
+ }
436
+ else if ( operator === 'max-' ) {
437
+ // Add this breakpoint and all smaller
438
+ size = that._find( name ).width;
439
+
440
+ for ( i=0, ien=breakpoints.length ; i<ien ; i++ ) {
441
+ if ( breakpoints[i].width <= size ) {
442
+ add( colIdx, breakpoints[i].name );
443
+ }
444
+ }
445
+ }
446
+ else if ( operator === 'min-' ) {
447
+ // Add this breakpoint and all larger
448
+ size = that._find( name ).width;
449
+
450
+ for ( i=0, ien=breakpoints.length ; i<ien ; i++ ) {
451
+ if ( breakpoints[i].width >= size ) {
452
+ add( colIdx, breakpoints[i].name );
453
+ }
454
+ }
455
+ }
456
+ else if ( operator === 'not-' ) {
457
+ // Add all but this breakpoint
458
+ for ( i=0, ien=breakpoints.length ; i<ien ; i++ ) {
459
+ if ( breakpoints[i].name.indexOf( matched ) === -1 ) {
460
+ add( colIdx, breakpoints[i].name );
461
+ }
462
+ }
463
+ }
464
+ };
465
+
466
+ // Loop over each column and determine if it has a responsive control
467
+ // class
468
+ columns.each( function ( col, i ) {
469
+ var classNames = col.className.split(' ');
470
+ var hasClass = false;
471
+
472
+ // Split the class name up so multiple rules can be applied if needed
473
+ for ( var k=0, ken=classNames.length ; k<ken ; k++ ) {
474
+ var className = $.trim( classNames[k] );
475
+
476
+ if ( className === 'all' ) {
477
+ // Include in all
478
+ hasClass = true;
479
+ col.includeIn = $.map( breakpoints, function (a) {
480
+ return a.name;
481
+ } );
482
+ return;
483
+ }
484
+ else if ( className === 'none' || col.never ) {
485
+ // Include in none (default) and no auto
486
+ hasClass = true;
487
+ return;
488
+ }
489
+ else if ( className === 'control' ) {
490
+ // Special column that is only visible, when one of the other
491
+ // columns is hidden. This is used for the details control
492
+ hasClass = true;
493
+ col.control = true;
494
+ return;
495
+ }
496
+
497
+ $.each( breakpoints, function ( j, breakpoint ) {
498
+ // Does this column have a class that matches this breakpoint?
499
+ var brokenPoint = breakpoint.name.split('-');
500
+ var re = new RegExp( '(min\\-|max\\-|not\\-)?('+brokenPoint[0]+')(\\-[_a-zA-Z0-9])?' );
501
+ var match = className.match( re );
502
+
503
+ if ( match ) {
504
+ hasClass = true;
505
+
506
+ if ( match[2] === brokenPoint[0] && match[3] === '-'+brokenPoint[1] ) {
507
+ // Class name matches breakpoint name fully
508
+ column( i, breakpoint.name, match[1], match[2]+match[3] );
509
+ }
510
+ else if ( match[2] === brokenPoint[0] && ! match[3] ) {
511
+ // Class name matched primary breakpoint name with no qualifier
512
+ column( i, breakpoint.name, match[1], match[2] );
513
+ }
514
+ }
515
+ } );
516
+ }
517
+
518
+ // If there was no control class, then automatic sizing is used
519
+ if ( ! hasClass ) {
520
+ col.auto = true;
521
+ }
522
+ } );
523
+
524
+ this.s.columns = columns;
525
+ },
526
+
527
+
528
+ /**
529
+ * Show the details for the child row
530
+ *
531
+ * @param {DataTables.Api} row API instance for the row
532
+ * @param {boolean} update Update flag
533
+ * @private
534
+ */
535
+ _detailsDisplay: function ( row, update )
536
+ {
537
+ var that = this;
538
+ var dt = this.s.dt;
539
+ var details = this.c.details;
540
+
541
+ if ( details && details.type ) {
542
+ var res = details.display( row, update, function () {
543
+ return details.renderer(
544
+ dt, row[0], that._detailsObj(row[0])
545
+ );
546
+ } );
547
+
548
+ if ( res === true || res === false ) {
549
+ $(dt.table().node()).triggerHandler( 'responsive-display.dt', [dt, row, res, update] );
550
+ }
551
+ }
552
+ },
553
+
554
+
555
+ /**
556
+ * Initialisation for the details handler
557
+ *
558
+ * @private
559
+ */
560
+ _detailsInit: function ()
561
+ {
562
+ var that = this;
563
+ var dt = this.s.dt;
564
+ var details = this.c.details;
565
+
566
+ // The inline type always uses the first child as the target
567
+ if ( details.type === 'inline' ) {
568
+ details.target = 'td:first-child, th:first-child';
569
+ }
570
+
571
+ // Keyboard accessibility
572
+ dt.on( 'draw.dtr', function () {
573
+ that._tabIndexes();
574
+ } );
575
+ that._tabIndexes(); // Initial draw has already happened
576
+
577
+ $( dt.table().body() ).on( 'keyup.dtr', 'td, th', function (e) {
578
+ if ( e.keyCode === 13 && $(this).data('dtr-keyboard') ) {
579
+ $(this).click();
580
+ }
581
+ } );
582
+
583
+ // type.target can be a string jQuery selector or a column index
584
+ var target = details.target;
585
+ var selector = typeof target === 'string' ? target : 'td, th';
586
+
587
+ // Click handler to show / hide the details rows when they are available
588
+ $( dt.table().body() )
589
+ .on( 'click.dtr mousedown.dtr mouseup.dtr', selector, function (e) {
590
+ // If the table is not collapsed (i.e. there is no hidden columns)
591
+ // then take no action
592
+ if ( ! $(dt.table().node()).hasClass('collapsed' ) ) {
593
+ return;
594
+ }
595
+
596
+ // Check that the row is actually a DataTable's controlled node
597
+ if ( ! dt.row( $(this).closest('tr') ).length ) {
598
+ return;
599
+ }
600
+
601
+ // For column index, we determine if we should act or not in the
602
+ // handler - otherwise it is already okay
603
+ if ( typeof target === 'number' ) {
604
+ var targetIdx = target < 0 ?
605
+ dt.columns().eq(0).length + target :
606
+ target;
607
+
608
+ if ( dt.cell( this ).index().column !== targetIdx ) {
609
+ return;
610
+ }
611
+ }
612
+
613
+ // $().closest() includes itself in its check
614
+ var row = dt.row( $(this).closest('tr') );
615
+
616
+ // Check event type to do an action
617
+ if ( e.type === 'click' ) {
618
+ // The renderer is given as a function so the caller can execute it
619
+ // only when they need (i.e. if hiding there is no point is running
620
+ // the renderer)
621
+ that._detailsDisplay( row, false );
622
+ }
623
+ else if ( e.type === 'mousedown' ) {
624
+ // For mouse users, prevent the focus ring from showing
625
+ $(this).css('outline', 'none');
626
+ }
627
+ else if ( e.type === 'mouseup' ) {
628
+ // And then re-allow at the end of the click
629
+ $(this).blur().css('outline', '');
630
+ }
631
+ } );
632
+ },
633
+
634
+
635
+ /**
636
+ * Get the details to pass to a renderer for a row
637
+ * @param {int} rowIdx Row index
638
+ * @private
639
+ */
640
+ _detailsObj: function ( rowIdx )
641
+ {
642
+ var that = this;
643
+ var dt = this.s.dt;
644
+
645
+ return $.map( this.s.columns, function( col, i ) {
646
+ if ( col.never ) {
647
+ return;
648
+ }
649
+
650
+ return {
651
+ title: dt.settings()[0].aoColumns[ i ].sTitle,
652
+ data: dt.cell( rowIdx, i ).render( that.c.orthogonal ),
653
+ hidden: dt.column( i ).visible() && !that.s.current[ i ],
654
+ columnIndex: i
655
+ };
656
+ } );
657
+ },
658
+
659
+
660
+ /**
661
+ * Find a breakpoint object from a name
662
+ *
663
+ * @param {string} name Breakpoint name to find
664
+ * @return {object} Breakpoint description object
665
+ * @private
666
+ */
667
+ _find: function ( name )
668
+ {
669
+ var breakpoints = this.c.breakpoints;
670
+
671
+ for ( var i=0, ien=breakpoints.length ; i<ien ; i++ ) {
672
+ if ( breakpoints[i].name === name ) {
673
+ return breakpoints[i];
674
+ }
675
+ }
676
+ },
677
+
678
+
679
+ /**
680
+ * Re-create the contents of the child rows as the display has changed in
681
+ * some way.
682
+ *
683
+ * @private
684
+ */
685
+ _redrawChildren: function ()
686
+ {
687
+ var that = this;
688
+ var dt = this.s.dt;
689
+
690
+ dt.rows( {page: 'current'} ).iterator( 'row', function ( settings, idx ) {
691
+ var row = dt.row( idx );
692
+
693
+ that._detailsDisplay( dt.row( idx ), true );
694
+ } );
695
+ },
696
+
697
+
698
+ /**
699
+ * Alter the table display for a resized viewport. This involves first
700
+ * determining what breakpoint the window currently is in, getting the
701
+ * column visibilities to apply and then setting them.
702
+ *
703
+ * @private
704
+ */
705
+ _resize: function ()
706
+ {
707
+ var that = this;
708
+ var dt = this.s.dt;
709
+ var width = $(window).width();
710
+ var breakpoints = this.c.breakpoints;
711
+ var breakpoint = breakpoints[0].name;
712
+ var columns = this.s.columns;
713
+ var i, ien;
714
+ var oldVis = this.s.current.slice();
715
+
716
+ // Determine what breakpoint we are currently at
717
+ for ( i=breakpoints.length-1 ; i>=0 ; i-- ) {
718
+ if ( width <= breakpoints[i].width ) {
719
+ breakpoint = breakpoints[i].name;
720
+ break;
721
+ }
722
+ }
723
+
724
+ // Show the columns for that break point
725
+ var columnsVis = this._columnsVisiblity( breakpoint );
726
+ this.s.current = columnsVis;
727
+
728
+ // Set the class before the column visibility is changed so event
729
+ // listeners know what the state is. Need to determine if there are
730
+ // any columns that are not visible but can be shown
731
+ var collapsedClass = false;
732
+ for ( i=0, ien=columns.length ; i<ien ; i++ ) {
733
+ if ( columnsVis[i] === false && ! columns[i].never && ! columns[i].control ) {
734
+ collapsedClass = true;
735
+ break;
736
+ }
737
+ }
738
+
739
+ $( dt.table().node() ).toggleClass( 'collapsed', collapsedClass );
740
+
741
+ var changed = false;
742
+
743
+ dt.columns().eq(0).each( function ( colIdx, i ) {
744
+ if ( columnsVis[i] !== oldVis[i] ) {
745
+ changed = true;
746
+ that._setColumnVis( colIdx, columnsVis[i] );
747
+ }
748
+ } );
749
+
750
+ if ( changed ) {
751
+ this._redrawChildren();
752
+
753
+ // Inform listeners of the change
754
+ $(dt.table().node()).trigger( 'responsive-resize.dt', [dt, this.s.current] );
755
+ }
756
+ },
757
+
758
+
759
+ /**
760
+ * Determine the width of each column in the table so the auto column hiding
761
+ * has that information to work with. This method is never going to be 100%
762
+ * perfect since column widths can change slightly per page, but without
763
+ * seriously compromising performance this is quite effective.
764
+ *
765
+ * @private
766
+ */
767
+ _resizeAuto: function ()
768
+ {
769
+ var dt = this.s.dt;
770
+ var columns = this.s.columns;
771
+
772
+ // Are we allowed to do auto sizing?
773
+ if ( ! this.c.auto ) {
774
+ return;
775
+ }
776
+
777
+ // Are there any columns that actually need auto-sizing, or do they all
778
+ // have classes defined
779
+ if ( $.inArray( true, $.map( columns, function (c) { return c.auto; } ) ) === -1 ) {
780
+ return;
781
+ }
782
+
783
+ // Clone the table with the current data in it
784
+ var tableWidth = dt.table().node().offsetWidth;
785
+ var columnWidths = dt.columns;
786
+ var clonedTable = dt.table().node().cloneNode( false );
787
+ var clonedHeader = $( dt.table().header().cloneNode( false ) ).appendTo( clonedTable );
788
+ var clonedBody = $( dt.table().body() ).clone( false, false ).empty().appendTo( clonedTable ); // use jQuery because of IE8
789
+
790
+ // Header
791
+ var headerCells = dt.columns()
792
+ .header()
793
+ .filter( function (idx) {
794
+ return dt.column(idx).visible();
795
+ } )
796
+ .to$()
797
+ .clone( false )
798
+ .css( 'display', 'table-cell' );
799
+
800
+ // Body rows - we don't need to take account of DataTables' column
801
+ // visibility since we implement our own here (hence the `display` set)
802
+ $(clonedBody)
803
+ .append( $(dt.rows( { page: 'current' } ).nodes()).clone( false ) )
804
+ .find( 'th, td' ).css( 'display', '' );
805
+
806
+ // Footer
807
+ var footer = dt.table().footer();
808
+ if ( footer ) {
809
+ var clonedFooter = $( footer.cloneNode( false ) ).appendTo( clonedTable );
810
+ var footerCells = dt.columns()
811
+ .header()
812
+ .filter( function (idx) {
813
+ return dt.column(idx).visible();
814
+ } )
815
+ .to$()
816
+ .clone( false )
817
+ .css( 'display', 'table-cell' );
818
+
819
+ $('<tr/>')
820
+ .append( footerCells )
821
+ .appendTo( clonedFooter );
822
+ }
823
+
824
+ $('<tr/>')
825
+ .append( headerCells )
826
+ .appendTo( clonedHeader );
827
+
828
+ // In the inline case extra padding is applied to the first column to
829
+ // give space for the show / hide icon. We need to use this in the
830
+ // calculation
831
+ if ( this.c.details.type === 'inline' ) {
832
+ $(clonedTable).addClass( 'dtr-inline collapsed' );
833
+ }
834
+
835
+ var inserted = $('<div/>')
836
+ .css( {
837
+ width: 1,
838
+ height: 1,
839
+ overflow: 'hidden'
840
+ } )
841
+ .append( clonedTable );
842
+
843
+ inserted.insertBefore( dt.table().node() );
844
+
845
+ // The cloned header now contains the smallest that each column can be
846
+ headerCells.each( function (i) {
847
+ var idx = dt.column.index( 'fromVisible', i );
848
+ columns[ idx ].minWidth = this.offsetWidth || 0;
849
+ } );
850
+
851
+ inserted.remove();
852
+ },
853
+
854
+ /**
855
+ * Set a column's visibility.
856
+ *
857
+ * We don't use DataTables' column visibility controls in order to ensure
858
+ * that column visibility can Responsive can no-exist. Since only IE8+ is
859
+ * supported (and all evergreen browsers of course) the control of the
860
+ * display attribute works well.
861
+ *
862
+ * @param {integer} col Column index
863
+ * @param {boolean} showHide Show or hide (true or false)
864
+ * @private
865
+ */
866
+ _setColumnVis: function ( col, showHide )
867
+ {
868
+ var dt = this.s.dt;
869
+ var display = showHide ? '' : 'none'; // empty string will remove the attr
870
+
871
+ $( dt.column( col ).header() ).css( 'display', display );
872
+ $( dt.column( col ).footer() ).css( 'display', display );
873
+ dt.column( col ).nodes().to$().css( 'display', display );
874
+ },
875
+
876
+
877
+ /**
878
+ * Update the cell tab indexes for keyboard accessibility. This is called on
879
+ * every table draw - that is potentially inefficient, but also the least
880
+ * complex option given that column visibility can change on the fly. Its a
881
+ * shame user-focus was removed from CSS 3 UI, as it would have solved this
882
+ * issue with a single CSS statement.
883
+ *
884
+ * @private
885
+ */
886
+ _tabIndexes: function ()
887
+ {
888
+ var dt = this.s.dt;
889
+ var cells = dt.cells( { page: 'current' } ).nodes().to$();
890
+ var ctx = dt.settings()[0];
891
+ var target = this.c.details.target;
892
+
893
+ cells.filter( '[data-dtr-keyboard]' ).removeData( '[data-dtr-keyboard]' );
894
+
895
+ var selector = typeof target === 'number' ?
896
+ ':eq('+target+')' :
897
+ target;
898
+
899
+ $( selector, dt.rows( { page: 'current' } ).nodes() )
900
+ .attr( 'tabIndex', ctx.iTabIndex )
901
+ .data( 'dtr-keyboard', 1 );
902
+ }
903
+ } );
904
+
905
+
906
+ /**
907
+ * List of default breakpoints. Each item in the array is an object with two
908
+ * properties:
909
+ *
910
+ * * `name` - the breakpoint name.
911
+ * * `width` - the breakpoint width
912
+ *
913
+ * @name Responsive.breakpoints
914
+ * @static
915
+ */
916
+ Responsive.breakpoints = [
917
+ { name: 'desktop', width: Infinity },
918
+ { name: 'tablet-l', width: 1024 },
919
+ { name: 'tablet-p', width: 768 },
920
+ { name: 'mobile-l', width: 480 },
921
+ { name: 'mobile-p', width: 320 }
922
+ ];
923
+
924
+
925
+ /**
926
+ * Display methods - functions which define how the hidden data should be shown
927
+ * in the table.
928
+ *
929
+ * @namespace
930
+ * @name Responsive.defaults
931
+ * @static
932
+ */
933
+ Responsive.display = {
934
+ childRow: function ( row, update, render ) {
935
+ if ( update ) {
936
+ if ( $(row.node()).hasClass('parent') ) {
937
+ row.child( render(), 'child' ).show();
938
+
939
+ return true;
940
+ }
941
+ }
942
+ else {
943
+ if ( ! row.child.isShown() ) {
944
+ row.child( render(), 'child' ).show();
945
+ $( row.node() ).addClass( 'parent' );
946
+
947
+ return true;
948
+ }
949
+ else {
950
+ row.child( false );
951
+ $( row.node() ).removeClass( 'parent' );
952
+
953
+ return false;
954
+ }
955
+ }
956
+ },
957
+
958
+ childRowImmediate: function ( row, update, render ) {
959
+ if ( (! update && row.child.isShown()) || ! row.responsive.hasHidden() ) {
960
+ // User interaction and the row is show, or nothing to show
961
+ row.child( false );
962
+ $( row.node() ).removeClass( 'parent' );
963
+
964
+ return false;
965
+ }
966
+ else {
967
+ // Display
968
+ row.child( render(), 'child' ).show();
969
+ $( row.node() ).addClass( 'parent' );
970
+
971
+ return true;
972
+ }
973
+ },
974
+
975
+ // This is a wrapper so the modal options for Bootstrap and jQuery UI can
976
+ // have options passed into them. This specific one doesn't need to be a
977
+ // function but it is for consistency in the `modal` name
978
+ modal: function ( options ) {
979
+ return function ( row, update, render ) {
980
+ if ( ! update ) {
981
+ // Show a modal
982
+ var close = function () {
983
+ modal.remove(); // will tidy events for us
984
+ $(document).off( 'keypress.dtr' );
985
+ };
986
+
987
+ var modal = $('<div class="dtr-modal"/>')
988
+ .append( $('<div class="dtr-modal-display"/>')
989
+ .append( $('<div class="dtr-modal-content"/>')
990
+ .append( render() )
991
+ )
992
+ .append( $('<div class="dtr-modal-close">&times;</div>' )
993
+ .click( function () {
994
+ close();
995
+ } )
996
+ )
997
+ )
998
+ .append( $('<div class="dtr-modal-background"/>')
999
+ .click( function () {
1000
+ close();
1001
+ } )
1002
+ )
1003
+ .appendTo( 'body' );
1004
+
1005
+ $(document).on( 'keyup.dtr', function (e) {
1006
+ if ( e.keyCode === 27 ) {
1007
+ e.stopPropagation();
1008
+
1009
+ close();
1010
+ }
1011
+ } );
1012
+ }
1013
+ else {
1014
+ $('div.dtr-modal-content')
1015
+ .empty()
1016
+ .append( render() );
1017
+ }
1018
+
1019
+ if ( options && options.header ) {
1020
+ $('div.dtr-modal-content').prepend(
1021
+ '<h2>'+options.header( row )+'</h2>'
1022
+ );
1023
+ }
1024
+ };
1025
+ }
1026
+ };
1027
+
1028
+
1029
+ /**
1030
+ * Responsive default settings for initialisation
1031
+ *
1032
+ * @namespace
1033
+ * @name Responsive.defaults
1034
+ * @static
1035
+ */
1036
+ Responsive.defaults = {
1037
+ /**
1038
+ * List of breakpoints for the instance. Note that this means that each
1039
+ * instance can have its own breakpoints. Additionally, the breakpoints
1040
+ * cannot be changed once an instance has been creased.
1041
+ *
1042
+ * @type {Array}
1043
+ * @default Takes the value of `Responsive.breakpoints`
1044
+ */
1045
+ breakpoints: Responsive.breakpoints,
1046
+
1047
+ /**
1048
+ * Enable / disable auto hiding calculations. It can help to increase
1049
+ * performance slightly if you disable this option, but all columns would
1050
+ * need to have breakpoint classes assigned to them
1051
+ *
1052
+ * @type {Boolean}
1053
+ * @default `true`
1054
+ */
1055
+ auto: true,
1056
+
1057
+ /**
1058
+ * Details control. If given as a string value, the `type` property of the
1059
+ * default object is set to that value, and the defaults used for the rest
1060
+ * of the object - this is for ease of implementation.
1061
+ *
1062
+ * The object consists of the following properties:
1063
+ *
1064
+ * * `display` - A function that is used to show and hide the hidden details
1065
+ * * `renderer` - function that is called for display of the child row data.
1066
+ * The default function will show the data from the hidden columns
1067
+ * * `target` - Used as the selector for what objects to attach the child
1068
+ * open / close to
1069
+ * * `type` - `false` to disable the details display, `inline` or `column`
1070
+ * for the two control types
1071
+ *
1072
+ * @type {Object|string}
1073
+ */
1074
+ details: {
1075
+ display: Responsive.display.childRow,
1076
+
1077
+ renderer: function ( api, rowIdx, columns ) {
1078
+ var data = $.map( columns, function ( col, i ) {
1079
+ return col.hidden ?
1080
+ '<li data-dtr-index="'+col.columnIndex+'">'+
1081
+ '<span class="dtr-title">'+
1082
+ col.title+
1083
+ '</span> '+
1084
+ '<span class="dtr-data">'+
1085
+ col.data+
1086
+ '</span>'+
1087
+ '</li>' :
1088
+ '';
1089
+ } ).join('');
1090
+
1091
+ return data ?
1092
+ $('<ul data-dtr-index="'+rowIdx+'"/>').append( data ) :
1093
+ false;
1094
+ },
1095
+
1096
+ target: 0,
1097
+
1098
+ type: 'inline'
1099
+ },
1100
+
1101
+ /**
1102
+ * Orthogonal data request option. This is used to define the data type
1103
+ * requested when Responsive gets the data to show in the child row.
1104
+ *
1105
+ * @type {String}
1106
+ */
1107
+ orthogonal: 'display'
1108
+ };
1109
+
1110
+
1111
+ /*
1112
+ * API
1113
+ */
1114
+ var Api = $.fn.dataTable.Api;
1115
+
1116
+ // Doesn't do anything - work around for a bug in DT... Not documented
1117
+ Api.register( 'responsive()', function () {
1118
+ return this;
1119
+ } );
1120
+
1121
+ Api.register( 'responsive.index()', function ( li ) {
1122
+ li = $(li);
1123
+
1124
+ return {
1125
+ column: li.data('dtr-index'),
1126
+ row: li.parent().data('dtr-index')
1127
+ };
1128
+ } );
1129
+
1130
+ Api.register( 'responsive.rebuild()', function () {
1131
+ return this.iterator( 'table', function ( ctx ) {
1132
+ if ( ctx._responsive ) {
1133
+ ctx._responsive._classLogic();
1134
+ }
1135
+ } );
1136
+ } );
1137
+
1138
+ Api.register( 'responsive.recalc()', function () {
1139
+ return this.iterator( 'table', function ( ctx ) {
1140
+ if ( ctx._responsive ) {
1141
+ ctx._responsive._resizeAuto();
1142
+ ctx._responsive._resize();
1143
+ }
1144
+ } );
1145
+ } );
1146
+
1147
+ Api.register( 'responsive.hasHidden()', function () {
1148
+ var ctx = this.context[0];
1149
+
1150
+ return ctx._responsive ?
1151
+ $.inArray( false, ctx._responsive.s.current ) !== -1 :
1152
+ false;
1153
+ } );
1154
+
1155
+
1156
+ /**
1157
+ * Version information
1158
+ *
1159
+ * @name Responsive.version
1160
+ * @static
1161
+ */
1162
+ Responsive.version = '2.0.1';
1163
+
1164
+
1165
+ $.fn.dataTable.Responsive = Responsive;
1166
+ $.fn.DataTable.Responsive = Responsive;
1167
+
1168
+ // Attach a listener to the document which listens for DataTables initialisation
1169
+ // events so we can automatically initialise
1170
+ $(document).on( 'preInit.dt.dtr', function (e, settings, json) {
1171
+ if ( e.namespace !== 'dt' ) {
1172
+ return;
1173
+ }
1174
+
1175
+ if ( $(settings.nTable).hasClass( 'responsive' ) ||
1176
+ $(settings.nTable).hasClass( 'dt-responsive' ) ||
1177
+ settings.oInit.responsive ||
1178
+ DataTable.defaults.responsive
1179
+ ) {
1180
+ var init = settings.oInit.responsive;
1181
+
1182
+ if ( init !== false ) {
1183
+ new Responsive( settings, $.isPlainObject( init ) ? init : {} );
1184
+ }
1185
+ }
1186
+ } );
1187
+
1188
+
1189
+ return Responsive;
1190
+ }));