diff --git a/bower.json b/bower.json index 02edff2..a2e32d6 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "filament-tablesaw", - "version": "1.0.3", + "version": "1.0.4", "main": [ "dist/tablesaw.js", "dist/tablesaw.css", diff --git a/dist/bare/tablesaw.bare.css b/dist/bare/tablesaw.bare.css index 093ce09..82c2e1c 100644 --- a/dist/bare/tablesaw.bare.css +++ b/dist/bare/tablesaw.bare.css @@ -1,4 +1,4 @@ -/*! Tablesaw - v1.0.3 - 2015-01-27 +/*! Tablesaw - v1.0.4 - 2015-02-19 * https://github.com/filamentgroup/tablesaw * Copyright (c) 2015 Filament Group; Licensed MIT */ diff --git a/dist/stackonly/tablesaw.stackonly.css b/dist/stackonly/tablesaw.stackonly.css index b29c547..ea01ae7 100644 --- a/dist/stackonly/tablesaw.stackonly.css +++ b/dist/stackonly/tablesaw.stackonly.css @@ -1,4 +1,4 @@ -/*! Tablesaw - v1.0.3 - 2015-01-27 +/*! Tablesaw - v1.0.4 - 2015-02-19 * https://github.com/filamentgroup/tablesaw * Copyright (c) 2015 Filament Group; Licensed MIT */ diff --git a/dist/stackonly/tablesaw.stackonly.js b/dist/stackonly/tablesaw.stackonly.js index e3f2b02..a528357 100644 --- a/dist/stackonly/tablesaw.stackonly.js +++ b/dist/stackonly/tablesaw.stackonly.js @@ -1,4 +1,4 @@ -/*! Tablesaw - v1.0.3 - 2015-01-27 +/*! Tablesaw - v1.0.4 - 2015-02-19 * https://github.com/filamentgroup/tablesaw * Copyright (c) 2015 Filament Group; Licensed MIT */ ;(function( $ ) { @@ -35,7 +35,15 @@ */ if( typeof Tablesaw === "undefined" ) { - Tablesaw = {}; + Tablesaw = { + i18n: { + modes: [ 'Stack', 'Swipe', 'Toggle' ], + columns: 'Columns', + columnBtnText: 'Columns', + columnsDialogError: 'No eligible columns.', + sort: 'Sort' + } + }; } if( !Tablesaw.config ) { Tablesaw.config = {}; diff --git a/dist/stackonly/tablesaw.stackonly.scss b/dist/stackonly/tablesaw.stackonly.scss index f9b8f0a..7a2e9b2 100644 --- a/dist/stackonly/tablesaw.stackonly.scss +++ b/dist/stackonly/tablesaw.stackonly.scss @@ -1,7 +1,7 @@ -/*! Tablesaw - v1.0.3 - 2015-01-27 +/*! Tablesaw - v1.0.4 - 2015-02-19 * https://github.com/filamentgroup/tablesaw * Copyright (c) 2015 Filament Group; Licensed MIT */ -/*! Tablesaw - v1.0.3 - 2015-01-27 +/*! Tablesaw - v1.0.4 - 2015-02-19 * https://github.com/filamentgroup/tablesaw * Copyright (c) 2015 Filament Group; Licensed MIT */ diff --git a/dist/tablesaw.css b/dist/tablesaw.css index 38c004f..d0f8c7a 100644 --- a/dist/tablesaw.css +++ b/dist/tablesaw.css @@ -1,4 +1,4 @@ -/*! Tablesaw - v1.0.3 - 2015-01-27 +/*! Tablesaw - v1.0.4 - 2015-02-19 * https://github.com/filamentgroup/tablesaw * Copyright (c) 2015 Filament Group; Licensed MIT */ diff --git a/dist/tablesaw.js b/dist/tablesaw.js index 0796f0c..3a6c728 100644 --- a/dist/tablesaw.js +++ b/dist/tablesaw.js @@ -1,4 +1,4 @@ -/*! Tablesaw - v1.0.3 - 2015-01-27 +/*! Tablesaw - v1.0.4 - 2015-02-19 * https://github.com/filamentgroup/tablesaw * Copyright (c) 2015 Filament Group; Licensed MIT */ ;(function( $ ) { @@ -35,7 +35,15 @@ */ if( typeof Tablesaw === "undefined" ) { - Tablesaw = {}; + Tablesaw = { + i18n: { + modes: [ 'Stack', 'Swipe', 'Toggle' ], + columns: 'Columns', + columnBtnText: 'Columns', + columnsDialogError: 'No eligible columns.', + sort: 'Sort' + } + }; } if( !Tablesaw.config ) { Tablesaw.config = {}; @@ -366,11 +374,6 @@ if( !Tablesaw.config ) { toolbar: 'tablesaw-bar' }; - this.i18n = { - columnBtnText: 'Columns', - columnsDialogError: 'No eligible columns.' - }; - // Expose headers and allHeaders properties on the widget // headers references the THs within the first TR in the table this.headers = this.$table.find( 'tr:first > th' ); @@ -394,7 +397,7 @@ if( !Tablesaw.config ) { id = tableId + "-popup"; $btnContain = $( "
" ); $menuButton = $( "" + - "" + this.i18n.columnBtnText + "" ); + "" + Tablesaw.i18n.columnBtnText + "" ); $popup = $( "
" ); $menu = $( "
" ); @@ -417,7 +420,7 @@ if( !Tablesaw.config ) { }); if( !hasNonPersistentHeaders ) { - $menu.append( '' ); + $menu.append( '' ); } $menu.appendTo( $popup ); @@ -562,12 +565,11 @@ if( !Tablesaw.config ) { } // Calculate initial widths - var initialWidth = $table.css( 'width' ); $table.css('width', 'auto'); $headerCells.each(function() { headerWidths.push( $( this ).outerWidth() ); }); - $table.css( 'width', initialWidth ); + $table.css( 'width', '' ); $btns.appendTo( $table.prev( '.tablesaw-bar' ) ); @@ -606,7 +608,9 @@ if( !Tablesaw.config ) { function maintainWidths() { var prefix = '#' + tableId + '.tablesaw-swipe ', styles = [], - tableWidth = $table.width(); + tableWidth = $table.width(), + hash = [], + newHash; $headerCells.each(function( index ) { var width; @@ -615,14 +619,28 @@ if( !Tablesaw.config ) { // Only save width on non-greedy columns (take up less than 75% of table width) if( width < tableWidth * 0.75 ) { + hash.push( index + '-' + width ); styles.push( prefix + ' .tablesaw-cell-persist:nth-child(' + ( index + 1 ) + ') { width: ' + width + 'px; }' ); } } }); + newHash = hash.join( '_' ); - unmaintainWidths(); $table.addClass( persistWidths ); - $head.append( $( '' ).attr( 'id', tableId + '-persist' ) ); + + var $style = $( '#' + tableId + '-persist' ); + // If style element not yet added OR if the widths have changed + if( !$style.length || $style.data( 'hash' ) !== newHash ) { + // Remove existing + $style.remove(); + + if( styles.length ) { + $( '' ) + .attr( 'id', tableId + '-persist' ) + .data( 'hash', newHash ) + .appendTo( $head ); + } + } } function getNext(){ @@ -670,7 +688,7 @@ if( !Tablesaw.config ) { } var extraPaddingPixels = 20, - tableWidth = $table.width(), + containerWidth = $table.parent().width(), persist = [], sum = 0, sums = [], @@ -686,7 +704,7 @@ if( !Tablesaw.config ) { sums.push( sum ); // is persistent or is hidden - if( isPersist || sum > tableWidth ) { + if( isPersist || sum > containerWidth ) { visibleNonPersistantCount--; } }); @@ -701,7 +719,7 @@ if( !Tablesaw.config ) { return; } - if( sums[ index ] <= tableWidth || needsNonPersistentColumn ) { + if( sums[ index ] <= containerWidth || needsNonPersistentColumn ) { needsNonPersistentColumn = false; showColumn( this ); } else { @@ -847,9 +865,6 @@ if( !Tablesaw.config ) { tableToolbar: 'tablesaw-toolbar', sortButton: pluginName + "-btn" }, - i18n = { - sort: 'Sort' - }, methods = { _create: function( o ){ return $( this ).each(function() { @@ -928,7 +943,7 @@ if( !Tablesaw.config ) { }, addSwitcher = function( heads ){ $switcher = $( '
' ).addClass( classes.switcher ).addClass( classes.tableToolbar ).html(function() { - var html = [ '