effective_datatables 3.2.7 → 3.3.0

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.
@@ -1,5 +1,5 @@
1
- /*! Buttons for DataTables 1.2.4
2
- * ©2016 SpryMedia Ltd - datatables.net/license
1
+ /*! Buttons for DataTables 1.4.2
2
+ * ©2016-2017 SpryMedia Ltd - datatables.net/license
3
3
  */
4
4
 
5
5
  (function( factory ){
@@ -48,6 +48,11 @@ var _dtButtons = DataTable.ext.buttons;
48
48
  */
49
49
  var Buttons = function( dt, config )
50
50
  {
51
+ // If there is no config set it to an empty object
52
+ if ( typeof( config ) === 'undefined' ) {
53
+ config = {};
54
+ }
55
+
51
56
  // Allow a boolean true for defaults
52
57
  if ( config === true ) {
53
58
  config = {};
@@ -194,7 +199,7 @@ $.extend( Buttons.prototype, {
194
199
  // needed). Take a copy as the array is modified by `remove`
195
200
  var buttons = this.s.buttons.slice();
196
201
  var i, ien;
197
-
202
+
198
203
  for ( i=0, ien=buttons.length ; i<ien ; i++ ) {
199
204
  this.remove( buttons[i].node );
200
205
  }
@@ -253,6 +258,24 @@ $.extend( Buttons.prototype, {
253
258
  return $(button.node);
254
259
  },
255
260
 
261
+ /**
262
+ * Set / get a processing class on the selected button
263
+ * @param {boolean} flag true to add, false to remove, undefined to get
264
+ * @return {boolean|Buttons} Getter value or this if a setter.
265
+ */
266
+ processing: function ( node, flag )
267
+ {
268
+ var button = this._nodeToButton( node );
269
+
270
+ if ( flag === undefined ) {
271
+ return $(button.node).hasClass( 'processing' );
272
+ }
273
+
274
+ $(button.node).toggleClass( 'processing', flag );
275
+
276
+ return this;
277
+ },
278
+
256
279
  /**
257
280
  * Remove a button.
258
281
  * @param {node} node Button node
@@ -410,6 +433,7 @@ $.extend( Buttons.prototype, {
410
433
 
411
434
  for ( var i=0, ien=buttons.length ; i<ien ; i++ ) {
412
435
  container.append( buttons[i].inserter );
436
+ container.append( ' ' );
413
437
 
414
438
  if ( buttons[i].buttons && buttons[i].buttons.length ) {
415
439
  this._draw( buttons[i].collection, buttons[i].buttons );
@@ -462,7 +486,8 @@ $.extend( Buttons.prototype, {
462
486
  if ( built.conf.buttons ) {
463
487
  var collectionDom = this.c.dom.collection;
464
488
  built.collection = $('<'+collectionDom.tag+'/>')
465
- .addClass( collectionDom.className );
489
+ .addClass( collectionDom.className )
490
+ .attr( 'role', 'menu') ;
466
491
  built.conf._collection = built.collection;
467
492
 
468
493
  this._expandButton( built.buttons, built.conf.buttons, true, attachPoint );
@@ -515,7 +540,7 @@ $.extend( Buttons.prototype, {
515
540
  config.action.call( dt.button( button ), e, dt, button, config );
516
541
 
517
542
  $(dt.table().node()).triggerHandler( 'buttons-action.dt', [
518
- dt.button( button ), dt, button, config
543
+ dt.button( button ), dt, button, config
519
544
  ] );
520
545
  };
521
546
 
@@ -569,7 +594,7 @@ $.extend( Buttons.prototype, {
569
594
  }
570
595
 
571
596
  if ( config.titleAttr ) {
572
- button.attr( 'title', config.titleAttr );
597
+ button.attr( 'title', text( config.titleAttr ) );
573
598
  }
574
599
 
575
600
  if ( ! config.namespace ) {
@@ -860,7 +885,7 @@ $.extend( Buttons.prototype, {
860
885
  /**
861
886
  * Show / hide a background layer behind a collection
862
887
  * @param {boolean} Flag to indicate if the background should be shown or
863
- * hidden
888
+ * hidden
864
889
  * @param {string} Class to assign to the background
865
890
  * @static
866
891
  */
@@ -938,7 +963,7 @@ Buttons.instanceSelector = function ( group, buttons )
938
963
  ret.push( buttons[ input ].inst );
939
964
  }
940
965
  };
941
-
966
+
942
967
  process( group );
943
968
 
944
969
  return ret;
@@ -1118,7 +1143,7 @@ Buttons.defaults = {
1118
1143
  * @type {string}
1119
1144
  * @static
1120
1145
  */
1121
- Buttons.version = '1.2.4';
1146
+ Buttons.version = '1.4.2';
1122
1147
 
1123
1148
 
1124
1149
  $.extend( _dtButtons, {
@@ -1159,6 +1184,21 @@ $.extend( _dtButtons, {
1159
1184
  left: hostOffset.left
1160
1185
  } );
1161
1186
 
1187
+ // calculate overflow when positioned beneath
1188
+ var tableBottom = tableContainer.offset().top + tableContainer.height();
1189
+ var listBottom = hostOffset.top + host.outerHeight() + config._collection.outerHeight();
1190
+ var bottomOverflow = listBottom - tableBottom;
1191
+
1192
+ // calculate overflow when positioned above
1193
+ var listTop = hostOffset.top - config._collection.outerHeight();
1194
+ var tableTop = tableContainer.offset().top;
1195
+ var topOverflow = tableTop - listTop;
1196
+
1197
+ // if bottom overflow is larger, move to the top because it fits better
1198
+ if (bottomOverflow > topOverflow) {
1199
+ config._collection.css( 'top', hostOffset.top - config._collection.outerHeight() - 5);
1200
+ }
1201
+
1162
1202
  var listRight = hostOffset.left + config._collection.outerWidth();
1163
1203
  var tableRight = tableContainer.offset().left + tableContainer.width();
1164
1204
  if ( listRight > tableRight ) {
@@ -1399,6 +1439,19 @@ DataTable.Api.registerPlural( 'buttons().nodes()', 'button().node()', function (
1399
1439
  return jq;
1400
1440
  } );
1401
1441
 
1442
+ // Get / set button processing state
1443
+ DataTable.Api.registerPlural( 'buttons().processing()', 'button().processing()', function ( flag ) {
1444
+ if ( flag === undefined ) {
1445
+ return this.map( function ( set ) {
1446
+ return set.inst.processing( set.node );
1447
+ } );
1448
+ }
1449
+
1450
+ return this.each( function ( set ) {
1451
+ set.inst.processing( set.node, flag );
1452
+ } );
1453
+ } );
1454
+
1402
1455
  // Get / set button text (i.e. the button labels)
1403
1456
  DataTable.Api.registerPlural( 'buttons().text()', 'button().text()', function ( label ) {
1404
1457
  if ( label === undefined ) {
@@ -1522,6 +1575,118 @@ DataTable.Api.register( 'buttons.exportData()', function ( options ) {
1522
1575
  }
1523
1576
  } );
1524
1577
 
1578
+ // Get information about the export that is common to many of the export data
1579
+ // types (DRY)
1580
+ DataTable.Api.register( 'buttons.exportInfo()', function ( conf ) {
1581
+ if ( ! conf ) {
1582
+ conf = {};
1583
+ }
1584
+
1585
+ return {
1586
+ filename: _filename( conf ),
1587
+ title: _title( conf ),
1588
+ messageTop: _message(this, conf.messageTop || conf.message, 'top'),
1589
+ messageBottom: _message(this, conf.messageBottom, 'bottom')
1590
+ };
1591
+ } );
1592
+
1593
+
1594
+
1595
+ /**
1596
+ * Get the file name for an exported file.
1597
+ *
1598
+ * @param {object} config Button configuration
1599
+ * @param {boolean} incExtension Include the file name extension
1600
+ */
1601
+ var _filename = function ( config )
1602
+ {
1603
+ // Backwards compatibility
1604
+ var filename = config.filename === '*' && config.title !== '*' && config.title !== undefined ?
1605
+ config.title :
1606
+ config.filename;
1607
+
1608
+ if ( typeof filename === 'function' ) {
1609
+ filename = filename();
1610
+ }
1611
+
1612
+ if ( filename === undefined || filename === null ) {
1613
+ return null;
1614
+ }
1615
+
1616
+ if ( filename.indexOf( '*' ) !== -1 ) {
1617
+ filename = $.trim( filename.replace( '*', $('title').text() ) );
1618
+ }
1619
+
1620
+ // Strip characters which the OS will object to
1621
+ filename = filename.replace(/[^a-zA-Z0-9_\u00A1-\uFFFF\.,\-_ !\(\)]/g, "");
1622
+
1623
+ var extension = _stringOrFunction( config.extension );
1624
+ if ( ! extension ) {
1625
+ extension = '';
1626
+ }
1627
+
1628
+ return filename + extension;
1629
+ };
1630
+
1631
+ /**
1632
+ * Simply utility method to allow parameters to be given as a function
1633
+ *
1634
+ * @param {undefined|string|function} option Option
1635
+ * @return {null|string} Resolved value
1636
+ */
1637
+ var _stringOrFunction = function ( option )
1638
+ {
1639
+ if ( option === null || option === undefined ) {
1640
+ return null;
1641
+ }
1642
+ else if ( typeof option === 'function' ) {
1643
+ return option();
1644
+ }
1645
+ return option;
1646
+ };
1647
+
1648
+ /**
1649
+ * Get the title for an exported file.
1650
+ *
1651
+ * @param {object} config Button configuration
1652
+ */
1653
+ var _title = function ( config )
1654
+ {
1655
+ var title = _stringOrFunction( config.title );
1656
+
1657
+ return title === null ?
1658
+ null : title.indexOf( '*' ) !== -1 ?
1659
+ title.replace( '*', $('title').text() || 'Exported data' ) :
1660
+ title;
1661
+ };
1662
+
1663
+ var _message = function ( dt, option, position )
1664
+ {
1665
+ var message = _stringOrFunction( option );
1666
+ if ( message === null ) {
1667
+ return null;
1668
+ }
1669
+
1670
+ var caption = $('caption', dt.table().container()).eq(0);
1671
+ if ( message === '*' ) {
1672
+ var side = caption.css( 'caption-side' );
1673
+ if ( side !== position ) {
1674
+ return null;
1675
+ }
1676
+
1677
+ return caption.length ?
1678
+ caption.text() :
1679
+ '';
1680
+ }
1681
+
1682
+ return message;
1683
+ };
1684
+
1685
+
1686
+
1687
+
1688
+
1689
+
1525
1690
 
1526
1691
  var _exportTextarea = $('<textarea/>')[0];
1527
1692
  var _exportData = function ( dt, inOpts )
@@ -1556,6 +1721,9 @@ var _exportData = function ( dt, inOpts )
1556
1721
  return str;
1557
1722
  }
1558
1723
 
1724
+ // Always remove script tags
1725
+ str = str.replace( /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, '' );
1726
+
1559
1727
  if ( config.stripHtml ) {
1560
1728
  str = str.replace( /<[^>]*>/g, '' );
1561
1729
  }
@@ -155,7 +155,7 @@ DataTable.ext.renderer.pageButton.bootstrap = function ( settings, host, idx, bu
155
155
  };
156
156
 
157
157
  // IE9 throws an 'unknown error' if document.activeElement is used
158
- // inside an iframe or frame.
158
+ // inside an iframe or frame.
159
159
  var activeEl;
160
160
 
161
161
  try {