angular-table-resize
Advanced tools
Comparing version 1.0.11 to 1.0.12
@@ -54,4 +54,3 @@ angular.module("ngTableResize", []); | ||
return $(table).find('th').length; | ||
}, function (newColLength) { | ||
console.log("YEH BOOOOI", newColLength) | ||
}, function (/*newColLength*/) { | ||
cleanUpAll(table); | ||
@@ -415,5 +414,3 @@ initialiseAll(table, attr, scope); | ||
// Replace all column's width with absolute measurements | ||
$(this.columns).each(function(index, column) { | ||
$(column).width($(column).width()); | ||
}) | ||
this.onEndDrag() | ||
}; | ||
@@ -425,11 +422,15 @@ | ||
var totPercent = 0; | ||
var callbacks = [] | ||
// Calculate the width of every column | ||
$(this.columns).each(function(index, column) { | ||
var colWidth = $(column).outerWidth(); | ||
var percentWidth = colWidth / totWidth * 100 + '%'; | ||
totPercent += (colWidth / totWidth * 100); | ||
$(column).css({ width: percentWidth }); | ||
callbacks.push(function() { | ||
$(column).css({ width: percentWidth }); | ||
}) | ||
}) | ||
// Apply the calculated width of every column | ||
callbacks.map(function(cb) { cb() }) | ||
}; | ||
@@ -436,0 +437,0 @@ |
@@ -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(o){console.log("YEH BOOOOI",o),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){b=$(n).find("th"),y=o.mode,w=!angular.isDefined(o.saveTableSizes)||o.saveTableSizes;var i=p(o,e);i&&(T=new i(n,b,R),w&&(O=t.loadTableSizes(n,o.mode)),z=T.handles(b),g=T.ctrlColumns,T.setup(),c(O),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(){w&&(O||(O={}),$(b).each(function(t,n){var e=$(n).attr("id");e&&(O[e]=T.saveAttr(n))}),t.saveTableSizes(C,y,O))}var y,w,b=null,g=null,z=null,C=null,R=null,T=null,S=!0,O=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.columns).each(function(t,n){$(n).width($(n).width())})},n.prototype.onEndDrag=function(){var t=$(this.table).outerWidth(),n=0;$(this.columns).each(function(e,o){var i=$(o).outerWidth(),r=i/t*100+"%";n+=i/t*100,$(o).css({width:r})})},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))){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}]); |
{ | ||
"name": "angular-table-resize", | ||
"version": "1.0.11", | ||
"version": "1.0.12", | ||
"description": "An AngularJS module for resizing table columns!", | ||
@@ -5,0 +5,0 @@ "main": "./dist/angular-table-resize.js", |
@@ -52,4 +52,3 @@ angular.module("ngTableResize").directive('resizeable', ['resizeStorage', '$injector', function(resizeStorage, $injector) { | ||
return $(table).find('th').length; | ||
}, function (newColLength) { | ||
console.log("YEH BOOOOI", newColLength) | ||
}, function (/*newColLength*/) { | ||
cleanUpAll(table); | ||
@@ -56,0 +55,0 @@ initialiseAll(table, attr, scope); |
@@ -46,5 +46,3 @@ angular.module("ngTableResize").factory("BasicResizer", ["ResizerModel", function(ResizerModel) { | ||
// Replace all column's width with absolute measurements | ||
$(this.columns).each(function(index, column) { | ||
$(column).width($(column).width()); | ||
}) | ||
this.onEndDrag() | ||
}; | ||
@@ -56,11 +54,15 @@ | ||
var totPercent = 0; | ||
var callbacks = [] | ||
// Calculate the width of every column | ||
$(this.columns).each(function(index, column) { | ||
var colWidth = $(column).outerWidth(); | ||
var percentWidth = colWidth / totWidth * 100 + '%'; | ||
totPercent += (colWidth / totWidth * 100); | ||
$(column).css({ width: percentWidth }); | ||
callbacks.push(function() { | ||
$(column).css({ width: percentWidth }); | ||
}) | ||
}) | ||
// Apply the calculated width of every column | ||
callbacks.map(function(cb) { cb() }) | ||
}; | ||
@@ -67,0 +69,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1358
67366