2015-04-02 14:56:05 +00:00
|
|
|
/*! Widget: resizable - updated 4/2/2015 (v2.21.5) */
|
2015-02-13 03:10:38 +00:00
|
|
|
;(function ($, window) {
|
|
|
|
'use strict';
|
2015-04-09 14:26:49 +00:00
|
|
|
var ts = $.tablesorter || {};
|
2015-02-13 03:10:38 +00:00
|
|
|
|
|
|
|
$.extend(ts.css, {
|
2015-03-25 20:21:12 +00:00
|
|
|
resizableContainer : 'tablesorter-resizable-container',
|
|
|
|
resizableHandle : 'tablesorter-resizable-handle',
|
|
|
|
resizableNoSelect : 'tablesorter-disableSelection',
|
|
|
|
resizableStorage : 'tablesorter-resizable'
|
2015-02-13 03:10:38 +00:00
|
|
|
});
|
|
|
|
|
2015-03-25 20:21:12 +00:00
|
|
|
// Add extra scroller css
|
|
|
|
$(function(){
|
|
|
|
var s = '<style>' +
|
|
|
|
'body.' + ts.css.resizableNoSelect + ' { -ms-user-select: none; -moz-user-select: -moz-none;' +
|
|
|
|
'-khtml-user-select: none; -webkit-user-select: none; user-select: none; }' +
|
|
|
|
'.' + ts.css.resizableContainer + ' { position: relative; height: 1px; }' +
|
|
|
|
// make handle z-index > than stickyHeader z-index, so the handle stays above sticky header
|
|
|
|
'.' + ts.css.resizableHandle + ' { position: absolute; display: inline-block; width: 8px; top: 1px;' +
|
|
|
|
'cursor: ew-resize; z-index: 3; user-select: none; -moz-user-select: none; }' +
|
|
|
|
'</style>';
|
|
|
|
$(s).appendTo('body');
|
|
|
|
});
|
|
|
|
|
|
|
|
ts.resizable = {
|
|
|
|
init : function( c, wo ) {
|
|
|
|
if ( c.$table.hasClass( 'hasResizable' ) ) { return; }
|
|
|
|
c.$table.addClass( 'hasResizable' );
|
|
|
|
ts.resizableReset( c.table, true ); // set default widths
|
|
|
|
|
|
|
|
// internal variables
|
|
|
|
wo.resizable_ = {
|
|
|
|
$wrap : c.$table.parent(),
|
|
|
|
mouseXPosition : 0,
|
|
|
|
$target : null,
|
|
|
|
$next : null,
|
|
|
|
overflow : c.$table.parent().css('overflow') === 'auto',
|
|
|
|
fullWidth : Math.abs(c.$table.parent().width() - c.$table.width()) < 20,
|
|
|
|
storedSizes : []
|
|
|
|
};
|
|
|
|
|
|
|
|
var noResize, $header, column, storedSizes,
|
|
|
|
marginTop = parseInt( c.$table.css( 'margin-top' ), 10 );
|
|
|
|
|
|
|
|
wo.resizable_.storedSizes = storedSizes = ( ( ts.storage && wo.resizable !== false ) ?
|
|
|
|
ts.storage( c.table, ts.css.resizableStorage ) :
|
|
|
|
[] ) || [];
|
|
|
|
ts.resizable.setWidths( c, wo, storedSizes );
|
|
|
|
|
|
|
|
wo.$resizable_container = $( '<div class="' + ts.css.resizableContainer + '">' )
|
|
|
|
.css({ top : marginTop })
|
|
|
|
.insertBefore( c.$table );
|
|
|
|
// add container
|
|
|
|
for ( column = 0; column < c.columns; column++ ) {
|
|
|
|
$header = c.$headerIndexed[ column ];
|
|
|
|
noResize = ts.getData( $header, ts.getColumnData( c.table, c.headers, column ), 'resizable' ) === 'false';
|
|
|
|
if ( !noResize ) {
|
|
|
|
$( '<div class="' + ts.css.resizableHandle + '">' )
|
|
|
|
.appendTo( wo.$resizable_container )
|
|
|
|
.attr({
|
|
|
|
'data-column' : column,
|
|
|
|
'unselectable' : 'on'
|
|
|
|
})
|
|
|
|
.data( 'header', $header )
|
|
|
|
.bind( 'selectstart', false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c.$table.one('tablesorter-initialized', function() {
|
|
|
|
ts.resizable.setHandlePosition( c, wo );
|
|
|
|
ts.resizable.bindings( this.config, this.config.widgetOptions );
|
|
|
|
});
|
2015-02-13 03:10:38 +00:00
|
|
|
},
|
2015-03-25 20:21:12 +00:00
|
|
|
|
|
|
|
setWidth : function( $el, width ) {
|
|
|
|
$el.css({
|
|
|
|
'width' : width,
|
|
|
|
'min-width' : '',
|
|
|
|
'max-width' : ''
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
setWidths : function( c, wo, storedSizes ) {
|
|
|
|
var column,
|
|
|
|
$extra = $( c.namespace + '_extra_headers' ),
|
|
|
|
$col = c.$table.children( 'colgroup' ).children( 'col' );
|
|
|
|
storedSizes = storedSizes || wo.resizable_.storedSizes || [];
|
2015-02-13 03:10:38 +00:00
|
|
|
// process only if table ID or url match
|
2015-03-25 20:21:12 +00:00
|
|
|
if ( storedSizes.length ) {
|
|
|
|
for ( column = 0; column < c.columns; column++ ) {
|
|
|
|
// set saved resizable widths
|
2015-04-02 14:56:05 +00:00
|
|
|
c.$headerIndexed[ column ].width( storedSizes[ column ] );
|
2015-03-25 20:21:12 +00:00
|
|
|
if ( $extra.length ) {
|
|
|
|
// stickyHeaders needs to modify min & max width as well
|
|
|
|
ts.resizable.setWidth( $extra.eq( column ).add( $col.eq( column ) ), storedSizes[ column ] );
|
2015-02-13 03:10:38 +00:00
|
|
|
}
|
|
|
|
}
|
2015-03-25 20:21:12 +00:00
|
|
|
if ( $( c.namespace + '_extra_table' ).length && !ts.hasWidget( c.table, 'scroller' ) ) {
|
|
|
|
ts.resizable.setWidth( $( c.namespace + '_extra_table' ), c.$table.outerWidth() );
|
|
|
|
}
|
2015-02-13 03:10:38 +00:00
|
|
|
}
|
2015-03-25 20:21:12 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
setHandlePosition : function( c, wo ) {
|
2015-04-08 04:50:22 +00:00
|
|
|
var startPosition,
|
2015-03-25 20:21:12 +00:00
|
|
|
hasScroller = ts.hasWidget( c.table, 'scroller' ),
|
|
|
|
tableHeight = c.$table.height(),
|
|
|
|
$handles = wo.$resizable_container.children(),
|
2015-04-08 04:50:22 +00:00
|
|
|
handleCenter = Math.floor( $handles.width() / 2 );
|
2015-03-25 20:21:12 +00:00
|
|
|
|
|
|
|
if ( hasScroller ) {
|
|
|
|
tableHeight = 0;
|
|
|
|
c.$table.closest( '.' + ts.css.scrollerWrap ).children().each(function(){
|
|
|
|
var $this = $(this);
|
|
|
|
// center table has a max-height set
|
|
|
|
tableHeight += $this.filter('[style*="height"]').length ? $this.height() : $this.children('table').height();
|
|
|
|
});
|
|
|
|
}
|
2015-04-08 04:50:22 +00:00
|
|
|
// subtract out table left position from resizable handles. Fixes #864
|
|
|
|
startPosition = c.$table.position().left;
|
2015-03-25 20:21:12 +00:00
|
|
|
$handles.each( function() {
|
|
|
|
var $this = $(this),
|
|
|
|
column = parseInt( $this.attr( 'data-column' ), 10 ),
|
|
|
|
columns = c.columns - 1,
|
|
|
|
$header = $this.data( 'header' );
|
2015-04-02 23:49:52 +00:00
|
|
|
if ( !$header ) { return; } // see #859
|
2015-04-02 14:56:05 +00:00
|
|
|
if ( !$header.is(':visible') ) {
|
|
|
|
$this.hide();
|
|
|
|
} else if ( column < columns || column === columns && wo.resizable_addLastColumn ) {
|
2015-03-25 20:21:12 +00:00
|
|
|
$this.css({
|
2015-04-02 14:56:05 +00:00
|
|
|
display: 'inline-block',
|
2015-03-25 20:21:12 +00:00
|
|
|
height : tableHeight,
|
2015-04-08 04:50:22 +00:00
|
|
|
left : $header.position().left - startPosition + $header.outerWidth() - handleCenter
|
2015-03-25 20:21:12 +00:00
|
|
|
});
|
2015-02-13 03:10:38 +00:00
|
|
|
}
|
|
|
|
});
|
2015-03-25 20:21:12 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// prevent text selection while dragging resize bar
|
|
|
|
toggleTextSelection : function( c, toggle ) {
|
|
|
|
var namespace = c.namespace + 'tsresize';
|
|
|
|
c.widgetOptions.resizable_.disabled = toggle;
|
|
|
|
$( 'body' ).toggleClass( ts.css.resizableNoSelect, toggle );
|
|
|
|
if ( toggle ) {
|
|
|
|
$( 'body' )
|
|
|
|
.attr( 'unselectable', 'on' )
|
|
|
|
.bind( 'selectstart' + namespace, false );
|
|
|
|
} else {
|
|
|
|
$( 'body' )
|
|
|
|
.removeAttr( 'unselectable' )
|
|
|
|
.unbind( 'selectstart' + namespace );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
bindings : function( c, wo ) {
|
|
|
|
var namespace = c.namespace + 'tsresize';
|
|
|
|
wo.$resizable_container.children().bind( 'mousedown', function( event ) {
|
2015-02-13 03:10:38 +00:00
|
|
|
// save header cell and mouse position
|
2015-04-02 14:56:05 +00:00
|
|
|
var column, $this,
|
2015-03-25 20:21:12 +00:00
|
|
|
vars = wo.resizable_,
|
|
|
|
$extras = $( c.namespace + '_extra_headers' ),
|
|
|
|
$header = $( event.target ).data( 'header' );
|
|
|
|
|
|
|
|
column = parseInt( $header.attr( 'data-column' ), 10 );
|
|
|
|
vars.$target = $header = $header.add( $extras.filter('[data-column="' + column + '"]') );
|
|
|
|
vars.target = column;
|
|
|
|
|
2015-02-13 03:10:38 +00:00
|
|
|
// if table is not as wide as it's parent, then resize the table
|
2015-03-25 20:21:12 +00:00
|
|
|
vars.$next = event.shiftKey || wo.resizable_targetLast ?
|
|
|
|
$header.parent().children().not( '.resizable-false' ).filter( ':last' ) :
|
|
|
|
$header.nextAll( ':not(.resizable-false)' ).eq( 0 );
|
|
|
|
|
|
|
|
column = parseInt( vars.$next.attr( 'data-column' ), 10 );
|
|
|
|
vars.$next = vars.$next.add( $extras.filter('[data-column="' + column + '"]') );
|
|
|
|
vars.next = column;
|
|
|
|
|
|
|
|
vars.mouseXPosition = event.pageX;
|
2015-04-02 14:56:05 +00:00
|
|
|
vars.storedSizes = [];
|
|
|
|
for ( column = 0; column < c.columns; column++ ) {
|
|
|
|
$this = c.$headerIndexed[ column ];
|
|
|
|
vars.storedSizes[ column ] = $this.is(':visible') ? $this.width() : 0;
|
|
|
|
}
|
2015-03-25 20:21:12 +00:00
|
|
|
ts.resizable.toggleTextSelection( c, true );
|
2015-02-13 03:10:38 +00:00
|
|
|
});
|
2015-03-25 20:21:12 +00:00
|
|
|
|
|
|
|
$( document )
|
|
|
|
.bind( 'mousemove' + namespace, function( event ) {
|
|
|
|
var vars = wo.resizable_;
|
|
|
|
// ignore mousemove if no mousedown
|
|
|
|
if ( !vars.disabled || vars.mouseXPosition === 0 || !vars.$target ) { return; }
|
|
|
|
if ( wo.resizable_throttle ) {
|
|
|
|
clearTimeout( vars.timer );
|
|
|
|
vars.timer = setTimeout( function() {
|
|
|
|
ts.resizable.mouseMove( c, wo, event );
|
|
|
|
}, isNaN( wo.resizable_throttle ) ? 5 : wo.resizable_throttle );
|
|
|
|
} else {
|
|
|
|
ts.resizable.mouseMove( c, wo, event );
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.bind( 'mouseup' + namespace, function() {
|
|
|
|
if (!wo.resizable_.disabled) { return; }
|
|
|
|
ts.resizable.toggleTextSelection( c, false );
|
|
|
|
ts.resizable.stopResize( c, wo );
|
|
|
|
ts.resizable.setHandlePosition( c, wo );
|
|
|
|
});
|
|
|
|
|
|
|
|
// resizeEnd event triggered by scroller widget
|
|
|
|
$( window ).bind( 'resize' + namespace + ' resizeEnd' + namespace, function() {
|
|
|
|
ts.resizable.setHandlePosition( c, wo );
|
2015-02-13 03:10:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// right click to reset columns to default widths
|
2015-04-02 14:56:05 +00:00
|
|
|
c.$table
|
|
|
|
.bind( 'columnUpdate' + namespace, function() {
|
|
|
|
ts.resizable.setHandlePosition( c, wo );
|
|
|
|
})
|
|
|
|
.find( 'thead:first' )
|
|
|
|
.add( $( c.namespace + '_extra_table' ).find( 'thead:first' ) )
|
|
|
|
.bind( 'contextmenu' + namespace, function() {
|
|
|
|
// $.isEmptyObject() needs jQuery 1.4+; allow right click if already reset
|
|
|
|
var allowClick = wo.resizable_.storedSizes.length === 0;
|
|
|
|
ts.resizableReset( c.table );
|
|
|
|
ts.resizable.setHandlePosition( c, wo );
|
|
|
|
wo.resizable_.storedSizes = [];
|
|
|
|
return allowClick;
|
|
|
|
});
|
2015-03-25 20:21:12 +00:00
|
|
|
|
2015-02-13 03:10:38 +00:00
|
|
|
},
|
2015-03-25 20:21:12 +00:00
|
|
|
|
|
|
|
mouseMove : function( c, wo, event ) {
|
|
|
|
if ( wo.resizable_.mouseXPosition === 0 || !wo.resizable_.$target ) { return; }
|
|
|
|
// resize columns
|
|
|
|
var vars = wo.resizable_,
|
|
|
|
$next = vars.$next,
|
2015-04-08 04:50:22 +00:00
|
|
|
leftEdge = event.pageX - vars.mouseXPosition;
|
2015-03-25 20:21:12 +00:00
|
|
|
if ( vars.fullWidth ) {
|
|
|
|
vars.storedSizes[ vars.target ] += leftEdge;
|
|
|
|
vars.storedSizes[ vars.next ] -= leftEdge;
|
|
|
|
ts.resizable.setWidths( c, wo );
|
|
|
|
|
|
|
|
} else if ( vars.overflow ) {
|
|
|
|
c.$table.add( $( c.namespace + '_extra_table' ) ).width(function(i, w){
|
|
|
|
return w + leftEdge;
|
|
|
|
});
|
|
|
|
if ( !$next.length ) {
|
|
|
|
// if expanding right-most column, scroll the wrapper
|
|
|
|
vars.$wrap[0].scrollLeft = c.$table.width();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
vars.storedSizes[ vars.target ] += leftEdge;
|
|
|
|
ts.resizable.setWidths( c, wo );
|
|
|
|
}
|
|
|
|
vars.mouseXPosition = event.pageX;
|
|
|
|
},
|
|
|
|
|
|
|
|
stopResize : function( c, wo ) {
|
2015-04-02 14:56:05 +00:00
|
|
|
var $this, column,
|
|
|
|
vars = wo.resizable_;
|
2015-03-25 20:21:12 +00:00
|
|
|
vars.storedSizes = [];
|
|
|
|
if ( ts.storage ) {
|
2015-04-02 14:56:05 +00:00
|
|
|
vars.storedSizes = [];
|
|
|
|
for ( column = 0; column < c.columns; column++ ) {
|
|
|
|
$this = c.$headerIndexed[ column ];
|
|
|
|
vars.storedSizes[ column ] = $this.is(':visible') ? $this.width() : 0;
|
|
|
|
}
|
2015-03-25 20:21:12 +00:00
|
|
|
if ( wo.resizable !== false ) {
|
|
|
|
// save all column widths
|
|
|
|
ts.storage( c.table, ts.css.resizableStorage, vars.storedSizes );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
vars.mouseXPosition = 0;
|
|
|
|
vars.$target = vars.$next = null;
|
|
|
|
$(window).trigger('resize'); // will update stickyHeaders, just in case
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// this widget saves the column widths if
|
|
|
|
// $.tablesorter.storage function is included
|
|
|
|
// **************************
|
|
|
|
ts.addWidget({
|
|
|
|
id: "resizable",
|
|
|
|
priority: 40,
|
|
|
|
options: {
|
|
|
|
resizable : true,
|
|
|
|
resizable_addLastColumn : false,
|
|
|
|
resizable_widths : [],
|
|
|
|
resizable_throttle : false, // set to true (5ms) or any number 0-10 range
|
|
|
|
resizable_targetLast : false
|
|
|
|
},
|
|
|
|
init: function(table, thisWidget, c, wo) {
|
|
|
|
ts.resizable.init( c, wo );
|
|
|
|
},
|
2015-04-16 15:07:25 +00:00
|
|
|
remove: function( table, c, wo, refreshing ) {
|
2015-03-25 20:21:12 +00:00
|
|
|
if (wo.$resizable_container) {
|
|
|
|
var namespace = c.namespace + 'tsresize';
|
|
|
|
c.$table.add( $( c.namespace + '_extra_table' ) )
|
|
|
|
.removeClass('hasResizable')
|
|
|
|
.children( 'thead' ).unbind( 'contextmenu' + namespace );
|
|
|
|
|
|
|
|
wo.$resizable_container.remove();
|
|
|
|
ts.resizable.toggleTextSelection( c, false );
|
2015-04-16 15:07:25 +00:00
|
|
|
ts.resizableReset( table, refreshing );
|
2015-03-25 20:21:12 +00:00
|
|
|
$( document ).unbind( 'mousemove' + namespace + ' mouseup' + namespace );
|
|
|
|
}
|
2015-02-13 03:10:38 +00:00
|
|
|
}
|
|
|
|
});
|
2015-03-25 20:21:12 +00:00
|
|
|
|
2015-04-16 15:07:25 +00:00
|
|
|
ts.resizableReset = function( table, refreshing ) {
|
2015-03-25 20:21:12 +00:00
|
|
|
$( table ).each(function(){
|
2015-04-02 14:56:05 +00:00
|
|
|
var index, $t,
|
2015-02-13 03:10:38 +00:00
|
|
|
c = this.config,
|
|
|
|
wo = c && c.widgetOptions;
|
2015-04-02 14:56:05 +00:00
|
|
|
if ( table && c && c.$headerIndexed.length ) {
|
|
|
|
for ( index = 0; index < c.columns; index++ ) {
|
|
|
|
$t = c.$headerIndexed[ index ];
|
|
|
|
if ( wo.resizable_widths && wo.resizable_widths[ index ] ) {
|
|
|
|
$t.css( 'width', wo.resizable_widths[ index ] );
|
2015-03-25 20:21:12 +00:00
|
|
|
} else if ( !$t.hasClass( 'resizable-false' ) ) {
|
2015-02-13 03:10:38 +00:00
|
|
|
// don't clear the width of any column that is not resizable
|
2015-03-25 20:21:12 +00:00
|
|
|
$t.css( 'width', '' );
|
2015-02-13 03:10:38 +00:00
|
|
|
}
|
2015-04-02 14:56:05 +00:00
|
|
|
}
|
2015-03-25 20:21:12 +00:00
|
|
|
// reset stickyHeader widths
|
|
|
|
$( window ).trigger( 'resize' );
|
2015-04-16 15:07:25 +00:00
|
|
|
if ( ts.storage && !refreshing ) {
|
2015-03-25 20:21:12 +00:00
|
|
|
ts.storage( this, ts.css.resizableStorage, {} );
|
|
|
|
}
|
2015-02-13 03:10:38 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-03-25 20:21:12 +00:00
|
|
|
})( jQuery, window );
|