mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-12-05 05:04:20 +00:00
2 lines
7.5 KiB
JavaScript
2 lines
7.5 KiB
JavaScript
/*! Widget: resizable - updated 4/18/2017 (v2.28.8) */
|
|
!function(e,t){"use strict";var s=e.tablesorter||{};e.extend(s.css,{resizableContainer:"tablesorter-resizable-container",resizableHandle:"tablesorter-resizable-handle",resizableNoSelect:"tablesorter-disableSelection",resizableStorage:"tablesorter-resizable"}),e(function(){var t="<style>body."+s.css.resizableNoSelect+" { -ms-user-select: none; -moz-user-select: -moz-none;-khtml-user-select: none; -webkit-user-select: none; user-select: none; }."+s.css.resizableContainer+" { position: relative; height: 1px; }."+s.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>";e("head").append(t)}),s.resizable={init:function(t,a){if(!t.$table.hasClass("hasResizable")){t.$table.addClass("hasResizable");var i,r,l,o,n=t.$table,d=n.parent(),b=parseInt(n.css("margin-top"),10),c=a.resizable_vars={useStorage:s.storage&&!1!==a.resizable,$wrap:d,mouseXPosition:0,$target:null,$next:null,overflow:"auto"===d.css("overflow")||"scroll"===d.css("overflow")||"auto"===d.css("overflow-x")||"scroll"===d.css("overflow-x"),storedSizes:[]};for(s.resizableReset(t.table,!0),c.tableWidth=n.width(),c.fullWidth=Math.abs(d.width()-c.tableWidth)<20,c.useStorage&&c.overflow&&(s.storage(t.table,"tablesorter-table-original-css-width",c.tableWidth),o=s.storage(t.table,"tablesorter-table-resized-width")||"auto",s.resizable.setWidth(n,o,!0)),a.resizable_vars.storedSizes=l=(c.useStorage?s.storage(t.table,s.css.resizableStorage):[])||[],s.resizable.setWidths(t,a,l),s.resizable.updateStoredSizes(t,a),a.$resizable_container=e('<div class="'+s.css.resizableContainer+'">').css({top:b}).insertBefore(n),r=0;r<t.columns;r++)i=t.$headerIndexed[r],o=s.getColumnData(t.table,t.headers,r),"false"===s.getData(i,o,"resizable")||e('<div class="'+s.css.resizableHandle+'">').appendTo(a.$resizable_container).attr({"data-column":r,unselectable:"on"}).data("header",i).bind("selectstart",!1);s.resizable.bindings(t,a)}},updateStoredSizes:function(e,t){var s,a,i=e.columns,r=t.resizable_vars;for(r.storedSizes=[],s=0;s<i;s++)a=e.$headerIndexed[s],r.storedSizes[s]=a.is(":visible")?a.width():0},setWidth:function(e,t,s){e.css({width:t,"min-width":s?t:"","max-width":s?t:""})},setWidths:function(t,a,i){var r,l,o=a.resizable_vars,n=e(t.namespace+"_extra_headers"),d=t.$table.children("colgroup").children("col");if((i=i||o.storedSizes||[]).length){for(r=0;r<t.columns;r++)s.resizable.setWidth(t.$headerIndexed[r],i[r],o.overflow),n.length&&(l=n.eq(r).add(d.eq(r)),s.resizable.setWidth(l,i[r],o.overflow));(l=e(t.namespace+"_extra_table")).length&&!s.hasWidget(t.table,"scroller")&&s.resizable.setWidth(l,t.$table.outerWidth(),o.overflow)}},setHandlePosition:function(t,a){var i,r=t.$table.height(),l=a.$resizable_container.children(),o=Math.floor(l.width()/2);s.hasWidget(t.table,"scroller")&&(r=0,t.$table.closest("."+s.css.scrollerWrap).children().each(function(){var t=e(this);r+=t.filter('[style*="height"]').length?t.height():t.children("table").height()})),!a.resizable_includeFooter&&t.$table.children("tfoot").length&&(r-=t.$table.children("tfoot").height()),i=t.$table.position().left,l.each(function(){var s=e(this),l=parseInt(s.attr("data-column"),10),n=t.columns-1,d=s.data("header");d&&(d.is(":visible")?(l<n||l===n&&a.resizable_addLastColumn)&&s.css({display:"inline-block",height:r,left:d.position().left-i+d.outerWidth()-o}):s.hide())})},toggleTextSelection:function(t,a,i){var r=t.namespace+"tsresize";a.resizable_vars.disabled=i,e("body").toggleClass(s.css.resizableNoSelect,i),i?e("body").attr("unselectable","on").bind("selectstart"+r,!1):e("body").removeAttr("unselectable").unbind("selectstart"+r)},bindings:function(a,i){var r=a.namespace+"tsresize";i.$resizable_container.children().bind("mousedown",function(t){var r,l=i.resizable_vars,o=e(a.namespace+"_extra_headers"),n=e(t.target).data("header");r=parseInt(n.attr("data-column"),10),l.$target=n=n.add(o.filter('[data-column="'+r+'"]')),l.target=r,l.$next=t.shiftKey||i.resizable_targetLast?n.parent().children().not(".resizable-false").filter(":last"):n.nextAll(":not(.resizable-false)").eq(0),r=parseInt(l.$next.attr("data-column"),10),l.$next=l.$next.add(o.filter('[data-column="'+r+'"]')),l.next=r,l.mouseXPosition=t.pageX,s.resizable.updateStoredSizes(a,i),s.resizable.toggleTextSelection(a,i,!0)}),e(document).bind("mousemove"+r,function(e){var t=i.resizable_vars;t.disabled&&0!==t.mouseXPosition&&t.$target&&(i.resizable_throttle?(clearTimeout(t.timer),t.timer=setTimeout(function(){s.resizable.mouseMove(a,i,e)},isNaN(i.resizable_throttle)?5:i.resizable_throttle)):s.resizable.mouseMove(a,i,e))}).bind("mouseup"+r,function(){i.resizable_vars.disabled&&(s.resizable.toggleTextSelection(a,i,!1),s.resizable.stopResize(a,i),s.resizable.setHandlePosition(a,i))}),e(t).bind("resize"+r+" resizeEnd"+r,function(){s.resizable.setHandlePosition(a,i)}),a.$table.bind("columnUpdate pagerComplete resizableUpdate ".split(" ").join(r+" "),function(){s.resizable.setHandlePosition(a,i)}).bind("resizableReset"+r,function(){s.resizableReset(a.table)}).find("thead:first").add(e(a.namespace+"_extra_table").find("thead:first")).bind("contextmenu"+r,function(){var e=0===i.resizable_vars.storedSizes.length;return s.resizableReset(a.table),s.resizable.setHandlePosition(a,i),i.resizable_vars.storedSizes=[],e})},mouseMove:function(t,a,i){if(0!==a.resizable_vars.mouseXPosition&&a.resizable_vars.$target){var r,l=0,o=a.resizable_vars,n=o.$next,d=o.storedSizes[o.target],b=i.pageX-o.mouseXPosition;if(o.overflow){if(d+b>0){for(o.storedSizes[o.target]+=b,s.resizable.setWidth(o.$target,o.storedSizes[o.target],!0),r=0;r<t.columns;r++)l+=o.storedSizes[r];s.resizable.setWidth(t.$table.add(e(t.namespace+"_extra_table")),l)}n.length||(o.$wrap[0].scrollLeft=t.$table.width())}else o.fullWidth?(o.storedSizes[o.target]+=b,o.storedSizes[o.next]-=b,s.resizable.setWidths(t,a)):(o.storedSizes[o.target]+=b,s.resizable.setWidths(t,a));o.mouseXPosition=i.pageX,t.$table.triggerHandler("stickyHeadersUpdate")}},stopResize:function(e,t){var a=t.resizable_vars;s.resizable.updateStoredSizes(e,t),a.useStorage&&(s.storage(e.table,s.css.resizableStorage,a.storedSizes),s.storage(e.table,"tablesorter-table-resized-width",e.$table.width())),a.mouseXPosition=0,a.$target=a.$next=null,e.$table.triggerHandler("stickyHeadersUpdate")}},s.addWidget({id:"resizable",priority:40,options:{resizable:!0,resizable_addLastColumn:!1,resizable_includeFooter:!0,resizable_widths:[],resizable_throttle:!1,resizable_targetLast:!1},init:function(e,t,a,i){s.resizable.init(a,i)},format:function(e,t,a){s.resizable.setHandlePosition(t,a)},remove:function(t,a,i,r){if(i.$resizable_container){var l=a.namespace+"tsresize";a.$table.add(e(a.namespace+"_extra_table")).removeClass("hasResizable").children("thead").unbind("contextmenu"+l),i.$resizable_container.remove(),s.resizable.toggleTextSelection(a,i,!1),s.resizableReset(t,r),e(document).unbind("mousemove"+l+" mouseup"+l)}}}),s.resizableReset=function(t,a){e(t).each(function(){var e,i,r=this.config,l=r&&r.widgetOptions,o=l.resizable_vars;if(t&&r&&r.$headerIndexed.length){for(o.overflow&&o.tableWidth&&(s.resizable.setWidth(r.$table,o.tableWidth,!0),o.useStorage&&s.storage(t,"tablesorter-table-resized-width","auto")),e=0;e<r.columns;e++)i=r.$headerIndexed[e],l.resizable_widths&&l.resizable_widths[e]?s.resizable.setWidth(i,l.resizable_widths[e],o.overflow):i.hasClass("resizable-false")||s.resizable.setWidth(i,"",o.overflow);r.$table.triggerHandler("stickyHeadersUpdate"),s.storage&&!a&&s.storage(this,s.css.resizableStorage,{})}})}}(jQuery,window); |