angular-table-resize
Advanced tools
Comparing version 1.0.12 to 1.0.13
@@ -201,3 +201,3 @@ angular.module("ngTableResize", []); | ||
if (newWidth < getMinWidth(column)) return; | ||
if (resizer.restrict(newWidth)) return; | ||
if (resizer.restrict(newWidth, diffX)) return; | ||
@@ -208,3 +208,3 @@ // Extra optional column | ||
if (optWidth < getMinWidth(optional.column)) return; | ||
if (resizer.intervene.restrict(optWidth)) return; | ||
if (resizer.intervene.restrict(optWidth, diffX)) return; | ||
$(optional.column).width(optWidth) | ||
@@ -327,2 +327,7 @@ } | ||
ResizerModel.prototype.getMinWidth = function(column) { | ||
// "25px" -> 25 | ||
return parseInt($(column).css('min-width')) || 0; | ||
} | ||
ResizerModel.prototype.handles = function () { | ||
@@ -494,15 +499,10 @@ // By default all columns should be assigned a handle | ||
FixedResizer.prototype.restrict = function (newWidth) { | ||
if (this.bound) { | ||
if (newWidth < this.bound) { | ||
$(this.fixedColumn).width('auto'); | ||
this.bound = false; | ||
return false; | ||
} else { | ||
return true; | ||
} | ||
} else if (newWidth < this.minWidth) { | ||
return true; | ||
} else if ($(this.fixedColumn).width() <= this.minWidth) { | ||
this.bound = newWidth; | ||
FixedResizer.prototype.restrict = function (newWidth, diffX) { | ||
if (this.bound && this.bound < diffX) { | ||
this.bound = false | ||
return false | ||
} if (this.bound && this.bound > diffX) { | ||
return true | ||
} else if (this.fixedColumn.width() <= this.getMinWidth(this.fixedColumn)) { | ||
this.bound = diffX | ||
$(this.fixedColumn).width(this.minWidth); | ||
@@ -513,2 +513,6 @@ return true; | ||
FixedResizer.prototype.onEndDrag = function () { | ||
this.bound = false | ||
}; | ||
FixedResizer.prototype.calculate = function (orgWidth, diffX) { | ||
@@ -515,0 +519,0 @@ // Subtract difference - neightbour grows |
@@ -1,1 +0,1 @@ | ||
angular.module("ngTableResize",[]),angular.module("ngTableResize").directive("resizeable",["resizeStorage","$injector",function(t,n){function e(t,n,e){C=n,R=t.container?$(t.container):$(C).parent(),$(C).addClass("resize"),a(C,e,t),o(C,e,t),r(C,e,t),i(C,e,t)}function o(t,n,e){void 0!==e.bind&&(e.bind={update:function(){u(t),a(t,n,e)}})}function i(t,n,e){e.$watch(function(){return $(t).find("th").length},function(){u(t),a(t,n,e)})}function r(t,n,e){e.$watch(function(){return e.mode},function(){u(t),a(t,n,e)})}function u(t){S=!0,s(t)}function s(t){$(t).find("th").find(".handle").remove()}function a(n,e,o){w=$(n).find("th"),y=o.mode,b=!angular.isDefined(o.saveTableSizes)||o.saveTableSizes;var i=p(o,e);i&&(T=new i(n,w,R),b&&(D=t.loadTableSizes(n,o.mode)),z=T.handles(w),g=T.ctrlColumns,T.setup(),c(D),z.each(function(t,e){l(n,e)}))}function c(t){t&&($(C).width("auto"),g.each(function(n,e){var o=$(e).attr("id"),i=t[o];$(e).css({width:i})}),T.onTableReady())}function l(t,n){var e=$("<div>",{"class":"handle"});$(n).prepend(e);var o=T.handleMiddleware(e,n);d(t,e,o)}function d(t,n,e){$(n).mousedown(function(t){S&&(T.onFirstDrag(e,n),T.onTableReady(),S=!1);var o={};T.intervene&&(o=T.intervene.selector(e),o.column=o,o.orgWidth=$(o).width()),t.preventDefault(),$(n).addClass("active"),$("body").addClass("table-resize");var i=t.clientX,r=$(e).width();$(window).mousemove(h(e,i,r,o)),$(window).one("mouseup",m(n))})}function h(t,n,e,o){return function(i){var r=i.clientX,u=r-n,s=T.calculate(e,u);if(!(s<f(t)||T.restrict(s))){if(T.intervene){var a=T.intervene.calculator(o.orgWidth,u);if(a<f(o.column))return;if(T.intervene.restrict(a))return;$(o.column).width(a)}$(t).width(s)}}}function f(t){return parseInt($(t).css("min-width"))||0}function p(t,e){try{var o=e.mode?t.mode:"BasicResizer",i=n.get(o);return i}catch(r){return console.error("The resizer "+t.mode+" was not found"),null}}function m(t){return function(){$(t).removeClass("active"),$(window).unbind("mousemove"),$("body").removeClass("table-resize"),T.onEndDrag(),v()}}function v(){b&&(D||(D={}),$(w).each(function(t,n){var e=$(n).attr("id");e&&(D[e]=T.saveAttr(n))}),t.saveTableSizes(C,y,D))}var y,b,w=null,g=null,z=null,C=null,R=null,T=null,S=!0,D=null;return{restrict:"A",link:e,scope:{mode:"=",saveTableSizes:"=?",bind:"=",container:"@"}}}]),angular.module("ngTableResize").service("resizeStorage",["$window",function(t){function n(t,n){var o=t.attr("id");return o?e+"."+t.attr("id")+"."+n:void console.error("Table has no id",t)}var e="ngColumnResize";this.loadTableSizes=function(e,o){var i=n(e,o),r=t.localStorage.getItem(i);return JSON.parse(r)},this.saveTableSizes=function(e,o,i){var r=n(e,o);if(r){var u=JSON.stringify(i);t.localStorage.setItem(r,u)}}}]),angular.module("ngTableResize").factory("ResizerModel",[function(){function t(t,n,e){this.table=t,this.columns=n,this.container=e,this.handleColumns=this.handles(),this.ctrlColumns=this.ctrlColumns()}return t.prototype.setup=function(){$(this.container).css({overflowX:"hidden"})},t.prototype.onTableReady=function(){$(this.table).outerWidth("100%")},t.prototype.handles=function(){return this.columns},t.prototype.ctrlColumns=function(){return this.handleColumns},t.prototype.onFirstDrag=function(){$(this.ctrlColumns).each(function(t,n){$(n).width($(n).width())})},t.prototype.handleMiddleware=function(t,n){return n},t.prototype.restrict=function(t){return!1},t.prototype.calculate=function(t,n){return t+n},t.prototype.onEndDrag=function(){},t.prototype.saveAttr=function(t){return $(t).outerWidth()},t}]),angular.module("ngTableResize").factory("BasicResizer",["ResizerModel",function(t){function n(n,r,u){t.call(this,n,r,u),this.ctrlColumns=this.columns,this.intervene={selector:e,calculator:o,restrict:i}}function e(t){return $(t).next()}function o(t,n){return t-n}function i(t){return t<25}return n.prototype=Object.create(t.prototype),n.prototype.setup=function(){$(this.container).css({overflowX:"hidden"})},n.prototype.handles=function(){return $(this.columns).not(":last")},n.prototype.onFirstDrag=function(){this.onEndDrag()},n.prototype.onEndDrag=function(){var t=$(this.table).outerWidth(),n=[];$(this.columns).each(function(e,o){var i=$(o).outerWidth(),r=i/t*100+"%";n.push(function(){$(o).css({width:r})})}),n.map(function(t){t()})},n.prototype.saveAttr=function(t){return $(t)[0].style.width},n}]),angular.module("ngTableResize").factory("FixedResizer",["ResizerModel",function(t){function n(n,e,o){t.call(this,n,e,o),this.fixedColumn=$(n).find("th").first(),this.bound=!1}return n.prototype=Object.create(t.prototype),n.prototype.setup=function(){$(this.container).css({overflowX:"hidden"}),$(this.columns).first().css({width:"auto"})},n.prototype.handles=function(){return $(this.columns).not(":last")},n.prototype.ctrlColumns=function(){return $(this.columns).not(":first")},n.prototype.onFirstDrag=function(){$(this.ctrlColumns).each(function(t,n){$(n).width($(n).width())})},n.prototype.handleMiddleware=function(t,n){return $(n).next()},n.prototype.restrict=function(t){return this.bound?!(t<this.bound)||($(this.fixedColumn).width("auto"),this.bound=!1,!1):t<this.minWidth||($(this.fixedColumn).width()<=this.minWidth?(this.bound=t,$(this.fixedColumn).width(this.minWidth),!0):void 0)},n.prototype.calculate=function(t,n){return t-n},n}]),angular.module("ngTableResize").factory("OverflowResizer",["ResizerModel",function(t){function n(n,e,o){t.call(this,n,e,o)}return n.prototype=Object.create(t.prototype),n.prototype.setup=function(){$(this.container).css({overflow:"auto"})},n.prototype.onTableReady=function(){$(this.table).width(1)},n}]); | ||
angular.module("ngTableResize",[]),angular.module("ngTableResize").directive("resizeable",["resizeStorage","$injector",function(t,n){function e(t,n,e){C=n,R=t.container?$(t.container):$(C).parent(),$(C).addClass("resize"),a(C,e,t),o(C,e,t),r(C,e,t),i(C,e,t)}function o(t,n,e){void 0!==e.bind&&(e.bind={update:function(){u(t),a(t,n,e)}})}function i(t,n,e){e.$watch(function(){return $(t).find("th").length},function(){u(t),a(t,n,e)})}function r(t,n,e){e.$watch(function(){return e.mode},function(){u(t),a(t,n,e)})}function u(t){S=!0,s(t)}function s(t){$(t).find("th").find(".handle").remove()}function a(n,e,o){w=$(n).find("th"),y=o.mode,b=!angular.isDefined(o.saveTableSizes)||o.saveTableSizes;var i=p(o,e);i&&(T=new i(n,w,R),b&&(D=t.loadTableSizes(n,o.mode)),z=T.handles(w),g=T.ctrlColumns,T.setup(),c(D),z.each(function(t,e){l(n,e)}))}function c(t){t&&($(C).width("auto"),g.each(function(n,e){var o=$(e).attr("id"),i=t[o];$(e).css({width:i})}),T.onTableReady())}function l(t,n){var e=$("<div>",{"class":"handle"});$(n).prepend(e);var o=T.handleMiddleware(e,n);d(t,e,o)}function d(t,n,e){$(n).mousedown(function(t){S&&(T.onFirstDrag(e,n),T.onTableReady(),S=!1);var o={};T.intervene&&(o=T.intervene.selector(e),o.column=o,o.orgWidth=$(o).width()),t.preventDefault(),$(n).addClass("active"),$("body").addClass("table-resize");var i=t.clientX,r=$(e).width();$(window).mousemove(h(e,i,r,o)),$(window).one("mouseup",m(n))})}function h(t,n,e,o){return function(i){var r=i.clientX,u=r-n,s=T.calculate(e,u);if(!(s<f(t)||T.restrict(s,u))){if(T.intervene){var a=T.intervene.calculator(o.orgWidth,u);if(a<f(o.column))return;if(T.intervene.restrict(a,u))return;$(o.column).width(a)}$(t).width(s)}}}function f(t){return parseInt($(t).css("min-width"))||0}function p(t,e){try{var o=e.mode?t.mode:"BasicResizer",i=n.get(o);return i}catch(r){return console.error("The resizer "+t.mode+" was not found"),null}}function m(t){return function(){$(t).removeClass("active"),$(window).unbind("mousemove"),$("body").removeClass("table-resize"),T.onEndDrag(),v()}}function v(){b&&(D||(D={}),$(w).each(function(t,n){var e=$(n).attr("id");e&&(D[e]=T.saveAttr(n))}),t.saveTableSizes(C,y,D))}var y,b,w=null,g=null,z=null,C=null,R=null,T=null,S=!0,D=null;return{restrict:"A",link:e,scope:{mode:"=",saveTableSizes:"=?",bind:"=",container:"@"}}}]),angular.module("ngTableResize").service("resizeStorage",["$window",function(t){function n(t,n){var o=t.attr("id");return o?e+"."+t.attr("id")+"."+n:void console.error("Table has no id",t)}var e="ngColumnResize";this.loadTableSizes=function(e,o){var i=n(e,o),r=t.localStorage.getItem(i);return JSON.parse(r)},this.saveTableSizes=function(e,o,i){var r=n(e,o);if(r){var u=JSON.stringify(i);t.localStorage.setItem(r,u)}}}]),angular.module("ngTableResize").factory("ResizerModel",[function(){function t(t,n,e){this.table=t,this.columns=n,this.container=e,this.handleColumns=this.handles(),this.ctrlColumns=this.ctrlColumns()}return t.prototype.setup=function(){$(this.container).css({overflowX:"hidden"})},t.prototype.onTableReady=function(){$(this.table).outerWidth("100%")},t.prototype.getMinWidth=function(t){return parseInt($(t).css("min-width"))||0},t.prototype.handles=function(){return this.columns},t.prototype.ctrlColumns=function(){return this.handleColumns},t.prototype.onFirstDrag=function(){$(this.ctrlColumns).each(function(t,n){$(n).width($(n).width())})},t.prototype.handleMiddleware=function(t,n){return n},t.prototype.restrict=function(t){return!1},t.prototype.calculate=function(t,n){return t+n},t.prototype.onEndDrag=function(){},t.prototype.saveAttr=function(t){return $(t).outerWidth()},t}]),angular.module("ngTableResize").factory("BasicResizer",["ResizerModel",function(t){function n(n,r,u){t.call(this,n,r,u),this.ctrlColumns=this.columns,this.intervene={selector:e,calculator:o,restrict:i}}function e(t){return $(t).next()}function o(t,n){return t-n}function i(t){return t<25}return n.prototype=Object.create(t.prototype),n.prototype.setup=function(){$(this.container).css({overflowX:"hidden"})},n.prototype.handles=function(){return $(this.columns).not(":last")},n.prototype.onFirstDrag=function(){this.onEndDrag()},n.prototype.onEndDrag=function(){var t=$(this.table).outerWidth(),n=[];$(this.columns).each(function(e,o){var i=$(o).outerWidth(),r=i/t*100+"%";n.push(function(){$(o).css({width:r})})}),n.map(function(t){t()})},n.prototype.saveAttr=function(t){return $(t)[0].style.width},n}]),angular.module("ngTableResize").factory("FixedResizer",["ResizerModel",function(t){function n(n,e,o){t.call(this,n,e,o),this.fixedColumn=$(n).find("th").first(),this.bound=!1}return n.prototype=Object.create(t.prototype),n.prototype.setup=function(){$(this.container).css({overflowX:"hidden"}),$(this.columns).first().css({width:"auto"})},n.prototype.handles=function(){return $(this.columns).not(":last")},n.prototype.ctrlColumns=function(){return $(this.columns).not(":first")},n.prototype.onFirstDrag=function(){$(this.ctrlColumns).each(function(t,n){$(n).width($(n).width())})},n.prototype.handleMiddleware=function(t,n){return $(n).next()},n.prototype.restrict=function(t,n){return this.bound&&this.bound<n?(this.bound=!1,!1):!!(this.bound&&this.bound>n)||(this.fixedColumn.width()<=this.getMinWidth(this.fixedColumn)?(this.bound=n,$(this.fixedColumn).width(this.minWidth),!0):void 0)},n.prototype.onEndDrag=function(){this.bound=!1},n.prototype.calculate=function(t,n){return t-n},n}]),angular.module("ngTableResize").factory("OverflowResizer",["ResizerModel",function(t){function n(n,e,o){t.call(this,n,e,o)}return n.prototype=Object.create(t.prototype),n.prototype.setup=function(){$(this.container).css({overflow:"auto"})},n.prototype.onTableReady=function(){$(this.table).width(1)},n}]); |
{ | ||
"name": "angular-table-resize", | ||
"version": "1.0.12", | ||
"version": "1.0.13", | ||
"description": "An AngularJS module for resizing table columns!", | ||
@@ -5,0 +5,0 @@ "main": "./dist/angular-table-resize.js", |
@@ -199,3 +199,3 @@ angular.module("ngTableResize").directive('resizeable', ['resizeStorage', '$injector', function(resizeStorage, $injector) { | ||
if (newWidth < getMinWidth(column)) return; | ||
if (resizer.restrict(newWidth)) return; | ||
if (resizer.restrict(newWidth, diffX)) return; | ||
@@ -206,3 +206,3 @@ // Extra optional column | ||
if (optWidth < getMinWidth(optional.column)) return; | ||
if (resizer.intervene.restrict(optWidth)) return; | ||
if (resizer.intervene.restrict(optWidth, diffX)) return; | ||
$(optional.column).width(optWidth) | ||
@@ -209,0 +209,0 @@ } |
@@ -48,15 +48,10 @@ angular.module("ngTableResize").factory("FixedResizer", ["ResizerModel", function(ResizerModel) { | ||
FixedResizer.prototype.restrict = function (newWidth) { | ||
if (this.bound) { | ||
if (newWidth < this.bound) { | ||
$(this.fixedColumn).width('auto'); | ||
this.bound = false; | ||
return false; | ||
} else { | ||
return true; | ||
} | ||
} else if (newWidth < this.minWidth) { | ||
return true; | ||
} else if ($(this.fixedColumn).width() <= this.minWidth) { | ||
this.bound = newWidth; | ||
FixedResizer.prototype.restrict = function (newWidth, diffX) { | ||
if (this.bound && this.bound < diffX) { | ||
this.bound = false | ||
return false | ||
} if (this.bound && this.bound > diffX) { | ||
return true | ||
} else if (this.fixedColumn.width() <= this.getMinWidth(this.fixedColumn)) { | ||
this.bound = diffX | ||
$(this.fixedColumn).width(this.minWidth); | ||
@@ -67,2 +62,6 @@ return true; | ||
FixedResizer.prototype.onEndDrag = function () { | ||
this.bound = false | ||
}; | ||
FixedResizer.prototype.calculate = function (orgWidth, diffX) { | ||
@@ -69,0 +68,0 @@ // Subtract difference - neightbour grows |
@@ -24,2 +24,7 @@ angular.module("ngTableResize").factory("ResizerModel", [function() { | ||
ResizerModel.prototype.getMinWidth = function(column) { | ||
// "25px" -> 25 | ||
return parseInt($(column).css('min-width')) || 0; | ||
} | ||
ResizerModel.prototype.handles = function () { | ||
@@ -26,0 +31,0 @@ // By default all columns should be assigned a handle |
67749
1362