app/assets/javascripts/datatables/extensions/Select/dataTables.select.js in jquery-datatables-1.10.12 vs app/assets/javascripts/datatables/extensions/Select/dataTables.select.js in jquery-datatables-1.10.13

- old
+ new

@@ -1,14 +1,14 @@ -/*! Select for DataTables 1.2.0 +/*! Select for DataTables 1.2.1 * 2015-2016 SpryMedia Ltd - datatables.net/license/mit */ /** * @summary Select for DataTables * @description A collection of API methods, events and buttons for DataTables * that provides selection options of the items in a DataTable - * @version 1.2.0 + * @version 1.2.1 * @file dataTables.select.js * @author SpryMedia Ltd (www.sprymedia.co.uk) * @contact datatables.net/forums * @copyright Copyright 2015-2016 SpryMedia Ltd. * @@ -52,11 +52,11 @@ // Version information for debugger DataTable.select = {}; -DataTable.select.version = '1.2.0'; +DataTable.select.version = '1.2.1'; DataTable.select.init = function ( dt ) { var ctx = dt.settings()[0]; var init = ctx.oInit.select; var defaults = DataTable.defaults.select; @@ -69,19 +69,22 @@ var style = 'api'; var blurable = false; var info = true; var selector = 'td, th'; var className = 'selected'; + var setStyle = false; ctx._select = {}; // Initialisation customisations if ( opts === true ) { style = 'os'; + setStyle = true; } else if ( typeof opts === 'string' ) { style = opts; + setStyle = true; } else if ( $.isPlainObject( opts ) ) { if ( opts.blurable !== undefined ) { blurable = opts.blurable; } @@ -94,10 +97,11 @@ items = opts.items; } if ( opts.style !== undefined ) { style = opts.style; + setStyle = true; } if ( opts.selector !== undefined ) { selector = opts.selector; } @@ -127,11 +131,11 @@ }); }; // If the init options haven't enabled select, but there is a selectable // class name, then enable - if ( $( dt.table().node() ).hasClass( 'selectable' ) ) { + if ( ! setStyle && $( dt.table().node() ).hasClass( 'selectable' ) ) { dt.select.style( 'os' ); } }; /* @@ -299,11 +303,11 @@ function disableMouseSelection( dt ) { var ctx = dt.settings()[0]; var selector = ctx._select.selector; - $( dt.table().body() ) + $( dt.table().container() ) .off( 'mousedown.dtSelect', selector ) .off( 'mouseup.dtSelect', selector ) .off( 'click.dtSelect', selector ); $('body').off( 'click.dtSelect' ); @@ -315,30 +319,30 @@ * @param {DataTable.Api} dt DataTable to remove events from * @private */ function enableMouseSelection ( dt ) { - var body = $( dt.table().body() ); + var container = $( dt.table().container() ); var ctx = dt.settings()[0]; var selector = ctx._select.selector; - body + container .on( 'mousedown.dtSelect', selector, function(e) { // Disallow text selection for shift clicking on the table so multi // element selection doesn't look terrible! if ( e.shiftKey || e.metaKey || e.ctrlKey ) { - body + container .css( '-moz-user-select', 'none' ) .one('selectstart.dtSelect', selector, function () { return false; } ); } } ) .on( 'mouseup.dtSelect', selector, function() { // Allow text selection to occur again, Mozilla style (tested in FF // 35.0.1 - still required) - body.css( '-moz-user-select', '' ); + container.css( '-moz-user-select', '' ); } ) .on( 'click.dtSelect', selector, function ( e ) { var items = dt.select.items(); var idx; @@ -998,45 +1002,62 @@ return function (dt) { return dt.i18n( 'buttons.'+label, def ); }; } +// Common events with suitable namespaces +function namespacedEvents ( config ) { + var unique = config._eventNamespace; + + return 'draw.dt.DT'+unique+' select.dt.DT'+unique+' deselect.dt.DT'+unique; +} + +var _buttonNamespace = 0; + $.extend( DataTable.ext.buttons, { selected: { text: i18n( 'selected', 'Selected' ), className: 'buttons-selected', - init: function ( dt ) { + init: function ( dt, node, config ) { var that = this; + config._eventNamespace = '.select'+(_buttonNamespace++); // .DT namespace listeners are removed by DataTables automatically // on table destroy - dt.on( 'draw.dt.DT select.dt.DT deselect.dt.DT', function () { + dt.on( namespacedEvents(config), function () { var enable = that.rows( { selected: true } ).any() || that.columns( { selected: true } ).any() || that.cells( { selected: true } ).any(); that.enable( enable ); } ); this.disable(); + }, + destroy: function ( dt, node, config ) { + dt.off( config._eventNamespace ); } }, selectedSingle: { text: i18n( 'selectedSingle', 'Selected single' ), className: 'buttons-selected-single', - init: function ( dt ) { + init: function ( dt, node, config ) { var that = this; + config._eventNamespace = '.select'+(_buttonNamespace++); - dt.on( 'draw.dt.DT select.dt.DT deselect.dt.DT', function () { + dt.on( namespacedEvents(config), function () { var count = dt.rows( { selected: true } ).flatten().length + dt.columns( { selected: true } ).flatten().length + dt.cells( { selected: true } ).flatten().length; that.enable( count === 1 ); } ); this.disable(); + }, + destroy: function ( dt, node, config ) { + dt.off( config._eventNamespace ); } }, selectAll: { text: i18n( 'selectAll', 'Select all' ), className: 'buttons-select-all', @@ -1049,21 +1070,25 @@ text: i18n( 'selectNone', 'Deselect all' ), className: 'buttons-select-none', action: function () { clear( this.settings()[0], true ); }, - init: function ( dt ) { + init: function ( dt, node, config ) { var that = this; + config._eventNamespace = '.select'+(_buttonNamespace++); - dt.on( 'draw.dt.DT select.dt.DT deselect.dt.DT', function () { + dt.on( namespacedEvents(config), function () { var count = dt.rows( { selected: true } ).flatten().length + dt.columns( { selected: true } ).flatten().length + dt.cells( { selected: true } ).flatten().length; that.enable( count > 0 ); } ); this.disable(); + }, + destroy: function ( dt, node, config ) { + dt.off( config._eventNamespace ); } } } ); $.each( [ 'Row', 'Column', 'Cell' ], function ( i, item ) {