mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-11-09 02:52:00 +01:00
1 line
3.4 KiB
JavaScript
1 line
3.4 KiB
JavaScript
|
var __bind=function(a,b){return function(){return a.apply(b,arguments)}},__slice=[].slice;!function(a,b){var c,d,e;return d=function(a){return parseFloat(a.style.width.replace("%",""))},e=function(a,b){return b=b.toFixed(2),a.style.width=""+b+"%"},c=function(){function c(c,d){this.mousedown=__bind(this.mousedown,this);var e=this;this.options=a.extend({},this.defaults,d),this.$table=c,this.setHeaders(),this.restoreColumnWidths(),this.syncHandleWidths(),a(b).on("resize.rc",function(){return e.syncHandleWidths()})}return c.prototype.defaults={store:b.store,rigidSizing:!1,resizeFromBody:!0},c.prototype.getColumnId=function(a){return this.$table.data("resizable-columns-id")+"-"+a.data("resizable-column-id")},c.prototype.setHeaders=function(){return this.$tableHeaders=this.$table.find("tr th:visible"),this.assignPercentageWidths(),this.createHandles()},c.prototype.destroy=function(){return this.$handleContainer.remove(),this.$table.removeData("resizableColumns"),a(b).off(".rc")},c.prototype.assignPercentageWidths=function(){var b=this;return this.$tableHeaders.each(function(c,d){var f;return f=a(d),e(f[0],100*(f.outerWidth()/b.$table.width()))})},c.prototype.createHandles=function(){var b=this;return a(".rc-handle-container").remove(),this.$table.before(this.$handleContainer=a("<div class='rc-handle-container' />")),this.$tableHeaders.each(function(c,d){var e;if(0!==b.$tableHeaders.eq(c+1).length&&null==b.$tableHeaders.eq(c).attr("data-noresize")&&null==b.$tableHeaders.eq(c+1).attr("data-noresize"))return e=a("<div class='rc-handle' />"),e.data("th",a(d)),e.appendTo(b.$handleContainer)}),this.$handleContainer.on("mousedown",".rc-handle",this.mousedown)},c.prototype.syncHandleWidths=function(){var b=this;return this.setHeaders(),this.$handleContainer.width(this.$table.width()).find(".rc-handle").each(function(c,d){var e;return e=a(d),e.css({left:e.data("th").outerWidth()+(e.data("th").offset().left-b.$handleContainer.offset().left),height:b.options.resizeFromBody?b.$table.height():b.$table.find("thead").height()})})},c.prototype.saveColumnWidths=function(){var b=this;return this.$tableHeaders.each(function(c,e){var f;return f=a(e),null==f.attr("data-noresize")&&null!=b.options.store?store.set(b.getColumnId(f),d(f[0])):void 0})},c.prototype.restoreColumnWidths=function(){var b=this;return this.$tableHeaders.each(function(c,d){var f,g;return f=a(d),null!=b.options.store&&(g=store.get(b.getColumnId(f)))?e(f[0],g):void 0})},c.prototype.totalColumnWidths=function(){var b;return b=0,this.$tableHeaders.each(function(c,d){return b+=parseFloat(a(d)[0].style.width.replace("%",""))}),b},c.prototype.mousedown=function(b){var c,f,g,h,i,j=this;return b.preventDefault(),h=b.pageX,c=a(b.currentTarget),f=c.data("th"),g=this.$tableHeaders.eq(this.$tableHeaders.index(f)+1),i={left:d(f[0]),right:d(g[0])},this.$table.addClass("rc-table-resizing"),a(document).on("mousemove.rc",function(a){var b;return b=100*((a.pageX-h)/j.$table.width()),e(g[0],i.right-b),e(f[0],i.left+b)}),a(document).one("mouseup",function(){return a(document).off("mousemove.rc"),j.$table.removeClass("rc-table-resizing"),j.syncHandleWidths(),j.saveColumnWidths()})},c}(),a.fn.extend({resizableColumns:function(){var b,d;return d=arguments[0],b=2<=arguments.length?__slice.call(arguments,1):[],this.each(function(){var e,f;return e=a(this),f=e.data("resizableColumns"),f||e.data("resizableColumns",f=new c(e,d)),"string"==typeof d?f[d].apply(f,b):void 0})}})}(window.jQuery,window);
|