angular-table-resize
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -50,4 +50,3 @@ angular.module("ngTableResize", []); | ||
return scope.mode; | ||
}, function(newMode) { | ||
console.log("Update!", newMode); | ||
}, function(/*newMode*/) { | ||
cleanUpAll(table); | ||
@@ -109,4 +108,3 @@ initialiseAll(table, attr, scope); | ||
resetTable(table); | ||
console.error("No settings found"); | ||
console.info("Reset table"); | ||
//console.error("No table size settings found"); | ||
return; | ||
@@ -120,3 +118,3 @@ } | ||
var cacheWidth = cache[id]; | ||
console.log("Set " + id + " to " + cacheWidth); | ||
//console.log("Set " + id + " to " + cacheWidth); | ||
$(column).css({ width: cacheWidth }); | ||
@@ -160,3 +158,2 @@ }) | ||
optional.orgWidth = $(optional).width(); | ||
console.log("Optional", optional); | ||
} | ||
@@ -243,3 +240,2 @@ | ||
resizeStorage.saveTableSizes(table, mode, cache); | ||
console.log("New cache", cache); | ||
} | ||
@@ -332,3 +328,2 @@ | ||
// By default, every handle controls the column it is placed in | ||
console.log("Fixed handle middelware"); | ||
return column; | ||
@@ -427,3 +422,2 @@ }; | ||
console.log("Total percent", totPercent); | ||
}; | ||
@@ -512,3 +506,2 @@ | ||
// Subtract difference - neightbour grows | ||
console.log("Calling fixed calculate"); | ||
return orgWidth - diffX; | ||
@@ -515,0 +508,0 @@ }; |
@@ -1,1 +0,1 @@ | ||
angular.module("ngTableResize",[]),angular.module("ngTableResize").directive("resizeable",["resizeStorage","$injector",function(t,n){function e(t,n,e){b=n,z=t.container?$(t.container):$(b).parent(),$(b).addClass("resize"),l(b,e,t),o(b,e,t),i(b,e,t)}function o(t,n,e){void 0!==e.bind&&(e.bind={update:function(){r(t),l(t,n,e)}})}function i(t,n,e){e.$watch(function(){return e.mode},function(o){console.log("Update!",o),r(t),l(t,n,e)})}function r(t){C=!0,u(t)}function s(t){$(t).width("100%"),$(t).find("th").width("auto")}function u(t){$(t).find("th").find(".handle").remove()}function l(n,e,o){w=$(n).find("th"),v=o.mode;var i=f(o);i&&(R=new i(n,w,z),console.log("Resizer",R),T=t.loadTableSizes(n,o.mode),g=R.handles(w),y=R.ctrlColumns,R.setup(),a(T),g.each(function(t,e){c(n,e)}))}function a(t){return t?($(b).width("auto"),y.each(function(n,e){var o=$(e).attr("id"),i=t[o];console.log("Set "+o+" to "+i),$(e).css({width:i})}),void R.onTableReady()):(s(b),console.error("No settings found"),void console.info("Reset table"))}function c(t,n){var e=$("<div>",{"class":"handle"});$(n).prepend(e);var o=R.handleMiddleware(e,n);d(t,e,o)}function d(t,n,e){$(n).mousedown(function(t){C&&(R.onFirstDrag(e,n),R.onTableReady(),C=!1);var o={};R.intervene&&(o=R.intervene.selector(e),o.column=o,o.orgWidth=$(o).width(),console.log("Optional",o)),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",p(n))})}function h(t,n,e,o){return function(i){var r=i.clientX,s=r-n,u=R.calculate(e,s);if(!R.restrict(u)){if(R.intervene){var l=R.intervene.calculator(o.orgWidth,s);if(R.intervene.restrict(l))return;$(o).width(l)}$(t).width(u)}}}function f(t){try{var e=n.get(t.mode);return e}catch(o){return console.error("The resizer "+t.mode+" was not found"),null}}function p(t){return function(){$(t).removeClass("active"),$(window).unbind("mousemove"),$("body").removeClass("table-resize"),R.onEndDrag(),m()}}function m(){T||(T={}),$(w).each(function(t,n){var e=$(n).attr("id");e&&(T[e]=R.saveAttr(n))}),t.saveTableSizes(b,v,T),console.log("New cache",T)}var v,w=null,y=null,g=null,b=null,z=null,R=null,C=!0,T=null;return{restrict:"A",link:e,scope:{mode:"=",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 s=JSON.stringify(i);t.localStorage.setItem(r,s)}}}]),angular.module("ngTableResize").factory("ResizerModel",[function(){function t(t,n,e){this.minWidth=25,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).width("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 console.log("Fixed handle middelware"),n},t.prototype.restrict=function(t){return t<this.minWidth},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,s){t.call(this,n,r,s),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"}),$(this.columns).first().css({width:"auto"})},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})}),console.log("Total percent",n)},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.onTableReady=function(){$(this.table).width("100%")},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 console.log("Calling fixed calculate"),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){g=n,z=t.container?$(t.container):$(g).parent(),$(g).addClass("resize"),a(g,e,t),o(g,e,t),i(g,e,t)}function o(t,n,e){void 0!==e.bind&&(e.bind={update:function(){r(t),a(t,n,e)}})}function i(t,n,e){e.$watch(function(){return e.mode},function(){r(t),a(t,n,e)})}function r(t){C=!0,s(t)}function u(t){$(t).width("100%"),$(t).find("th").width("auto")}function s(t){$(t).find("th").find(".handle").remove()}function a(n,e,o){y=$(n).find("th"),v=o.mode;var i=f(o);i&&(R=new i(n,y,z),console.log("Resizer",R),T=t.loadTableSizes(n,o.mode),b=R.handles(y),w=R.ctrlColumns,R.setup(),c(T),b.each(function(t,e){l(n,e)}))}function c(t){return t?($(g).width("auto"),w.each(function(n,e){var o=$(e).attr("id"),i=t[o];$(e).css({width:i})}),void R.onTableReady()):void u(g)}function l(t,n){var e=$("<div>",{"class":"handle"});$(n).prepend(e);var o=R.handleMiddleware(e,n);d(t,e,o)}function d(t,n,e){$(n).mousedown(function(t){C&&(R.onFirstDrag(e,n),R.onTableReady(),C=!1);var o={};R.intervene&&(o=R.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",p(n))})}function h(t,n,e,o){return function(i){var r=i.clientX,u=r-n,s=R.calculate(e,u);if(!R.restrict(s)){if(R.intervene){var a=R.intervene.calculator(o.orgWidth,u);if(R.intervene.restrict(a))return;$(o).width(a)}$(t).width(s)}}}function f(t){try{var e=n.get(t.mode);return e}catch(o){return console.error("The resizer "+t.mode+" was not found"),null}}function p(t){return function(){$(t).removeClass("active"),$(window).unbind("mousemove"),$("body").removeClass("table-resize"),R.onEndDrag(),m()}}function m(){T||(T={}),$(y).each(function(t,n){var e=$(n).attr("id");e&&(T[e]=R.saveAttr(n))}),t.saveTableSizes(g,v,T)}var v,y=null,w=null,b=null,g=null,z=null,R=null,C=!0,T=null;return{restrict:"A",link:e,scope:{mode:"=",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.minWidth=25,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).width("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 t<this.minWidth},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"}),$(this.columns).first().css({width:"auto"})},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.onTableReady=function(){$(this.table).width("100%")},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.1", | ||
"version": "1.0.2", | ||
"description": "An AngularJS module for resizing table columns!", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -34,3 +34,3 @@ # angular-table-resize | ||
```html | ||
<table resizeable mode="resizeMode"> | ||
<table resizeable mode="resizeMode" id="myTable"> | ||
... | ||
@@ -45,2 +45,5 @@ </table> | ||
#### Saving column sizes | ||
The module automatically saves the current column width to *localStorage*. This however requires that you supply your **\<table\>** with an *id* and all of your table headers **\<th\>** with and *id* as well. | ||
#### Resizing Modes | ||
@@ -47,0 +50,0 @@ The resize mode kan be set to any of theese modes. Chose the one that works best for you. |
@@ -48,4 +48,3 @@ angular.module("ngTableResize").directive('resizeable', ['resizeStorage', '$injector', function(resizeStorage, $injector) { | ||
return scope.mode; | ||
}, function(newMode) { | ||
console.log("Update!", newMode); | ||
}, function(/*newMode*/) { | ||
cleanUpAll(table); | ||
@@ -107,4 +106,3 @@ initialiseAll(table, attr, scope); | ||
resetTable(table); | ||
console.error("No settings found"); | ||
console.info("Reset table"); | ||
//console.error("No table size settings found"); | ||
return; | ||
@@ -118,3 +116,3 @@ } | ||
var cacheWidth = cache[id]; | ||
console.log("Set " + id + " to " + cacheWidth); | ||
//console.log("Set " + id + " to " + cacheWidth); | ||
$(column).css({ width: cacheWidth }); | ||
@@ -158,3 +156,2 @@ }) | ||
optional.orgWidth = $(optional).width(); | ||
console.log("Optional", optional); | ||
} | ||
@@ -241,3 +238,2 @@ | ||
resizeStorage.saveTableSizes(table, mode, cache); | ||
console.log("New cache", cache); | ||
} | ||
@@ -244,0 +240,0 @@ |
@@ -69,3 +69,2 @@ angular.module("ngTableResize").factory("BasicResizer", ["ResizerModel", function(ResizerModel) { | ||
console.log("Total percent", totPercent); | ||
}; | ||
@@ -72,0 +71,0 @@ |
@@ -73,3 +73,2 @@ angular.module("ngTableResize").factory("FixedResizer", ["ResizerModel", function(ResizerModel) { | ||
// Subtract difference - neightbour grows | ||
console.log("Calling fixed calculate"); | ||
return orgWidth - diffX; | ||
@@ -76,0 +75,0 @@ }; |
@@ -45,3 +45,2 @@ angular.module("ngTableResize").factory("ResizerModel", [function() { | ||
// By default, every handle controls the column it is placed in | ||
console.log("Fixed handle middelware"); | ||
return column; | ||
@@ -48,0 +47,0 @@ }; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
59
65042
1240