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

2 lines
6.5 KiB
JavaScript

/*! Widget: resizable - updated 5/17/2015 (v2.22.0) */
!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.mouseMove(d,e,a)},isNaN(e.resizable_throttle)?5:e.resizable_throttle)):c.resizable.mouseMove(d,e,a))}).bind("mouseup"+f,function(){e.resizable_.disabled&&(c.resizable.toggleTextSelection(d,!1),c.resizable.stopResize(d,e),c.resizable.setHandlePosition(d,e))}),a(b).bind("resize"+f+" resizeEnd"+f,function(){c.resizable.setHandlePosition(d,e)}),d.$table.bind("columnUpdate"+f,function(){c.resizable.setHandlePosition(d,e)}).find("thead:first").add(a(d.namespace+"_extra_table").find("thead:first")).bind("contextmenu"+f,function(){var a=0===e.resizable_.storedSizes.length;return c.resizableReset(d.table),c.resizable.setHandlePosition(d,e),e.resizable_.storedSizes=[],a})},mouseMove:function(b,d,e){if(0!==d.resizable_.mouseXPosition&&d.resizable_.$target){var f=d.resizable_,g=f.$next,h=e.pageX-f.mouseXPosition;f.fullWidth?(f.storedSizes[f.target]+=h,f.storedSizes[f.next]-=h,c.resizable.setWidths(b,d)):f.overflow?(b.$table.add(a(b.namespace+"_extra_table")).width(function(a,b){return b+h}),g.length||(f.$wrap[0].scrollLeft=b.$table.width())):(f.storedSizes[f.target]+=h,c.resizable.setWidths(b,d)),f.mouseXPosition=e.pageX,b.$table.trigger("stickyHeadersUpdate")}},stopResize:function(a,b){var d,e,f=b.resizable_;if(f.storedSizes=[],c.storage){for(f.storedSizes=[],e=0;e<a.columns;e++)d=a.$headerIndexed[e],f.storedSizes[e]=d.is(":visible")?d.width():0;b.resizable!==!1&&c.storage(a.table,c.css.resizableStorage,f.storedSizes)}f.mouseXPosition=0,f.$target=f.$next=null,a.$table.trigger("stickyHeadersUpdate")}},c.addWidget({id:"resizable",priority:40,options:{resizable:!0,resizable_addLastColumn:!1,resizable_widths:[],resizable_throttle:!1,resizable_targetLast:!1},init:function(a,b,d,e){c.resizable.init(d,e)},remove:function(b,d,e,f){if(e.$resizable_container){var g=d.namespace+"tsresize";d.$table.add(a(d.namespace+"_extra_table")).removeClass("hasResizable").children("thead").unbind("contextmenu"+g),e.$resizable_container.remove(),c.resizable.toggleTextSelection(d,!1),c.resizableReset(b,f),a(document).unbind("mousemove"+g+" mouseup"+g)}}}),c.resizableReset=function(b,d){a(b).each(function(){var a,e,f=this.config,g=f&&f.widgetOptions;if(b&&f&&f.$headerIndexed.length){for(a=0;a<f.columns;a++)e=f.$headerIndexed[a],g.resizable_widths&&g.resizable_widths[a]?e.css("width",g.resizable_widths[a]):e.hasClass("resizable-false")||e.css("width","");f.$table.trigger("stickyHeadersUpdate"),c.storage&&!d&&c.storage(this,c.css.resizableStorage,{})}})}}(jQuery,window);