mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-11-15 23:54:22 +00:00
2 lines
6.2 KiB
JavaScript
2 lines
6.2 KiB
JavaScript
/*! Widget: resizable - updated 3/25/2015 (v2.21.3) */
|
|
!function(a,b){"use strict";var c=a.tablesorter=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.$headers.eq(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=(b.$table.outerWidth(),c.hasWidget(b.table,"scroller")),f=b.$table.height(),g=d.$resizable_container.children(),h=Math.floor(g.width()/2-2*parseFloat(b.$headers.css("border-right-width")));e&&(f=0,b.$table.closest("."+c.css.scrollerWrap).children().each(function(){var b=a(this);f+=b.filter('[style*="height"]').length?b.height():b.children("table").height()})),g.each(function(){var c=a(this),e=parseInt(c.attr("data-column"),10),g=b.columns-1,i=c.data("header");(g>e||e===g&&d.resizable_addLastColumn)&&c.css({height:f,left:i.position().left+i.width()-h})})},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=e.resizable_,h=a(d.namespace+"_extra_headers"),i=a(b.target).data("header");f=parseInt(i.attr("data-column"),10),g.$target=i=i.add(h.filter('[data-column="'+f+'"]')),g.target=f,g.$next=b.shiftKey||e.resizable_targetLast?i.parent().children().not(".resizable-false").filter(":last"):i.nextAll(":not(.resizable-false)").eq(0),f=parseInt(g.$next.attr("data-column"),10),g.$next=g.$next.add(h.filter('[data-column="'+f+'"]')),g.next=f,g.mouseXPosition=b.pageX,g.storedSizes=d.$headers.map(function(){return a(this).width()}).get(),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.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.$target,h=f.$next,i=e.pageX-f.mouseXPosition;g.width()}f.fullWidth?(f.storedSizes[f.target]+=i,f.storedSizes[f.next]-=i,c.resizable.setWidths(b,d)):f.overflow?(b.$table.add(a(b.namespace+"_extra_table")).width(function(a,b){return b+i}),h.length||(f.$wrap[0].scrollLeft=b.$table.width())):(f.storedSizes[f.target]+=i,c.resizable.setWidths(b,d)),f.mouseXPosition=e.pageX}},stopResize:function(d,e){var f=e.resizable_;f.storedSizes=[],c.storage&&(f.storedSizes=d.$headers.map(function(){return a(this).width()}).get(),e.resizable!==!1&&c.storage(d.table,c.css.resizableStorage,f.storedSizes)),f.mouseXPosition=0,f.$target=f.$next=null,a(b).trigger("resize")}},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){if(e.$resizable_container){var f=d.namespace+"tsresize";d.$table.add(a(d.namespace+"_extra_table")).removeClass("hasResizable").children("thead").unbind("contextmenu"+f),e.$resizable_container.remove(),c.resizable.toggleTextSelection(d,!1),c.resizableReset(b),a(document).unbind("mousemove"+f+" mouseup"+f)}}}),c.resizableReset=function(d,e){a(d).each(function(){var f,g=this.config,h=g&&g.widgetOptions;d&&g&&(g.$headers.each(function(b){f=a(this),h.resizable_widths&&h.resizable_widths[b]?f.css("width",h.resizable_widths[b]):f.hasClass("resizable-false")||f.css("width","")}),a(b).trigger("resize"),c.storage&&!e&&c.storage(this,c.css.resizableStorage,{}))})}}(jQuery,window); |