tablesorter/dist/js/widgets/widget-resizable.min.js

2 lines
6.4 KiB
JavaScript
Raw Normal View History

/*! Widget: resizable - updated 4/2/2015 (v2.21.5) */
!function(a,b){"use strict";var c=a.tablesorter||{};a.extend(c.css,{resizableContainer:"tablesorter-resizable-container",resizableHandle:"tablesorter-resizable-handle",resizableNoSelect:"tablesorter-disableSelection",resizableStorage:"tablesorter-resizable"}),a(function(){var b="<style>body."+c.css.resizableNoSelect+" { -ms-user-select: none; -moz-user-select: -moz-none;-khtml-user-select: none; -webkit-user-select: none; user-select: none; }."+c.css.resizableContainer+" { position: relative; height: 1px; }."+c.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>";a(b).appendTo("body")}),c.resizable={init:function(b,d){if(!b.$table.hasClass("hasResizable")){b.$table.addClass("hasResizable"),c.resizableReset(b.table,!0),d.resizable_={$wrap:b.$table.parent(),mouseXPosition:0,$target:null,$next:null,overflow:"auto"===b.$table.parent().css("overflow"),fullWidth:Math.abs(b.$table.parent().width()-b.$table.width())<20,storedSizes:[]};var e,f,g,h,i=parseInt(b.$table.css("margin-top"),10);for(d.resizable_.storedSizes=h=(c.storage&&d.resizable!==!1?c.storage(b.table,c.css.resizableStorage):[])||[],c.resizable.setWidths(b,d,h),d.$resizable_container=a('<div class="'+c.css.resizableContainer+'">').css({top:i}).insertBefore(b.$table),g=0;g<b.columns;g++)f=b.$headerIndexed[g],e="false"===c.getData(f,c.getColumnData(b.table,b.headers,g),"resizable"),e||a('<div class="'+c.css.resizableHandle+'">').appendTo(d.$resizable_container).attr({"data-column":g,unselectable:"on"}).data("header",f).bind("selectstart",!1);b.$table.one("tablesorter-initialized",function(){c.resizable.setHandlePosition(b,d),c.resizable.bindings(this.config,this.config.widgetOptions)})}},setWidth:function(a,b){a.css({width:b,"min-width":"","max-width":""})},setWidths:function(b,d,e){var f,g=a(b.namespace+"_extra_headers"),h=b.$table.children("colgroup").children("col");if(e=e||d.resizable_.storedSizes||[],e.length){for(f=0;f<b.columns;f++)b.$headerIndexed[f].width(e[f]),g.length&&c.resizable.setWidth(g.eq(f).add(h.eq(f)),e[f]);a(b.namespace+"_extra_table").length&&!c.hasWidget(b.table,"scroller")&&c.resizable.setWidth(a(b.namespace+"_extra_table"),b.$table.outerWidth())}},setHandlePosition:function(b,d){var e,f=c.hasWidget(b.table,"scroller"),g=b.$table.height(),h=d.$resizable_container.children(),i=Math.floor(h.width()/2);f&&(g=0,b.$table.closest("."+c.css.scrollerWrap).children().each(function(){var b=a(this);g+=b.filter('[style*="height"]').length?b.height():b.children("table").height()})),e=b.$table.position().left,h.each(function(){var c=a(this),f=parseInt(c.attr("data-column"),10),h=b.columns-1,j=c.data("header");j&&(j.is(":visible")?(h>f||f===h&&d.resizable_addLastColumn)&&c.css({display:"inline-block",height:g,left:j.position().left-e+j.outerWidth()-i}):c.hide())})},toggleTextSelection:function(b,d){var e=b.namespace+"tsresize";b.widgetOptions.resizable_.disabled=d,a("body").toggleClass(c.css.resizableNoSelect,d),d?a("body").attr("unselectable","on").bind("selectstart"+e,!1):a("body").removeAttr("unselectable").unbind("selectstart"+e)},bindings:function(d,e){var f=d.namespace+"tsresize";e.$resizable_container.children().bind("mousedown",function(b){var f,g,h=e.resizable_,i=a(d.namespace+"_extra_headers"),j=a(b.target).data("header");for(f=parseInt(j.attr("data-column"),10),h.$target=j=j.add(i.filter('[data-column="'+f+'"]')),h.target=f,h.$next=b.shiftKey||e.resizable_targetLast?j.parent().children().not(".resizable-false").filter(":last"):j.nextAll(":not(.resizable-false)").eq(0),f=parseInt(h.$next.attr("data-column"),10),h.$next=h.$next.add(i.filter('[data-column="'+f+'"]')),h.next=f,h.mouseXPosition=b.pageX,h.storedSizes=[],f=0;f<d.columns;f++)g=d.$headerIndexed[f],h.storedSizes[f]=g.is(":visible")?g.width():0;c.resizable.toggleTextSelection(d,!0)}),a(document).bind("mousemove"+f,function(a){var b=e.resizable_;b.disabled&&0!==b.mouseXPosition&&b.$target&&(e.resizable_throttle?(clearTimeout(b.timer),b.timer=setTimeout(function(){c.resizable