angular-table-resize
Advanced tools
Comparing version 1.0.13 to 1.0.14
@@ -10,2 +10,4 @@ var devapp = angular.module("DemoApp", ["ngTableResize"]); | ||
$scope.profile = 'one' | ||
var i = 1; | ||
@@ -12,0 +14,0 @@ |
@@ -7,2 +7,3 @@ angular.module("ngTableResize", []); | ||
var saveTableSizes; | ||
var profile; | ||
@@ -40,4 +41,13 @@ var columns = null; | ||
watchTableChanges(table, attr, scope) | ||
// Watch for scope bindings | ||
setUpWatchers(table, attr, scope) | ||
} | ||
function setUpWatchers(table, attr, scope) { | ||
scope.$watch('profile', function(newVal, oldVal) { | ||
console.log("Hey man") | ||
}) | ||
} | ||
function bindUtilityFunctions(table, attr, scope) { | ||
@@ -91,2 +101,3 @@ if (scope.bind === undefined) return; | ||
saveTableSizes = angular.isDefined(scope.saveTableSizes) ? scope.saveTableSizes : true; | ||
profile = scope.profile; | ||
@@ -100,3 +111,3 @@ // Get the resizer object for the current mode | ||
// Load column sizes from saved storage | ||
cache = resizeStorage.loadTableSizes(table, scope.mode) | ||
cache = resizeStorage.loadTableSizes(table, scope.mode, scope.profile) | ||
} | ||
@@ -260,3 +271,3 @@ | ||
resizeStorage.saveTableSizes(table, mode, cache); | ||
resizeStorage.saveTableSizes(table, mode, profile, cache); | ||
} | ||
@@ -270,2 +281,3 @@ | ||
mode: '=', | ||
profile: '=?', | ||
// whether to save table sizes; default true | ||
@@ -284,4 +296,4 @@ saveTableSizes: '=?', | ||
this.loadTableSizes = function(table, model) { | ||
var key = getStorageKey(table, model); | ||
this.loadTableSizes = function(table, mode, profile) { | ||
var key = getStorageKey(table, mode, profile); | ||
var object = $window.localStorage.getItem(key); | ||
@@ -291,4 +303,4 @@ return JSON.parse(object); | ||
this.saveTableSizes = function(table, model, sizes) { | ||
var key = getStorageKey(table, model); | ||
this.saveTableSizes = function(table, mode, profile, sizes) { | ||
var key = getStorageKey(table, mode, profile); | ||
if (!key) return; | ||
@@ -299,3 +311,3 @@ var string = JSON.stringify(sizes); | ||
function getStorageKey(table, mode) { | ||
function getStorageKey(table, mode, profile) { | ||
var id = table.attr('id'); | ||
@@ -306,3 +318,3 @@ if (!id) { | ||
} | ||
return prefix + '.' + table.attr('id') + '.' + mode; | ||
return prefix + '.' + table.attr('id') + '.' + mode + (profile ? '.' + profile : ''); | ||
} | ||
@@ -419,2 +431,6 @@ | ||
}) | ||
$(this.table).css({ | ||
width: '100%' | ||
}) | ||
}; | ||
@@ -479,2 +495,6 @@ | ||
$(this.table).css({ | ||
width: '100%' | ||
}) | ||
// First column is auto to compensate for 100% table width | ||
@@ -481,0 +501,0 @@ $(this.columns).first().css({ |
@@ -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,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}]); | ||
angular.module("ngTableResize",[]),angular.module("ngTableResize").directive("resizeable",["resizeStorage","$injector",function(t,n){function e(t,n,e){T=n,S=t.container?$(t.container):$(T).parent(),$(T).addClass("resize"),c(T,e,t),i(T,e,t),u(T,e,t),r(T,e,t),o(T,e,t)}function o(t,n,e){e.$watch("profile",function(t,n){console.log("Hey man")})}function i(t,n,e){void 0!==e.bind&&(e.bind={update:function(){s(t),c(t,n,e)}})}function r(t,n,e){e.$watch(function(){return $(t).find("th").length},function(){s(t),c(t,n,e)})}function u(t,n,e){e.$watch(function(){return e.mode},function(){s(t),c(t,n,e)})}function s(t){M=!0,a(t)}function a(t){$(t).find("th").find(".handle").remove()}function c(n,e,o){z=$(n).find("th"),b=o.mode,w=!angular.isDefined(o.saveTableSizes)||o.saveTableSizes,g=o.profile;var i=m(o,e);i&&(D=new i(n,z,S),w&&(W=t.loadTableSizes(n,o.mode,o.profile)),R=D.handles(z),C=D.ctrlColumns,D.setup(),l(W),R.each(function(t,e){d(n,e)}))}function l(t){t&&($(T).width("auto"),C.each(function(n,e){var o=$(e).attr("id"),i=t[o];$(e).css({width:i})}),D.onTableReady())}function d(t,n){var e=$("<div>",{"class":"handle"});$(n).prepend(e);var o=D.handleMiddleware(e,n);h(t,e,o)}function h(t,n,e){$(n).mousedown(function(t){M&&(D.onFirstDrag(e,n),D.onTableReady(),M=!1);var o={};D.intervene&&(o=D.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(f(e,i,r,o)),$(window).one("mouseup",v(n))})}function f(t,n,e,o){return function(i){var r=i.clientX,u=r-n,s=D.calculate(e,u);if(!(s<p(t)||D.restrict(s,u))){if(D.intervene){var a=D.intervene.calculator(o.orgWidth,u);if(a<p(o.column))return;if(D.intervene.restrict(a,u))return;$(o.column).width(a)}$(t).width(s)}}}function p(t){return parseInt($(t).css("min-width"))||0}function m(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 v(t){return function(){$(t).removeClass("active"),$(window).unbind("mousemove"),$("body").removeClass("table-resize"),D.onEndDrag(),y()}}function y(){w&&(W||(W={}),$(z).each(function(t,n){var e=$(n).attr("id");e&&(W[e]=D.saveAttr(n))}),t.saveTableSizes(T,b,g,W))}var b,w,g,z=null,C=null,R=null,T=null,S=null,D=null,M=!0,W=null;return{restrict:"A",link:e,scope:{mode:"=",profile:"=?",saveTableSizes:"=?",bind:"=",container:"@"}}}]),angular.module("ngTableResize").service("resizeStorage",["$window",function(t){function n(t,n,o){var i=t.attr("id");return i?e+"."+t.attr("id")+"."+n+(o?"."+o:""):void console.error("Table has no id",t)}var e="ngColumnResize";this.loadTableSizes=function(e,o,i){var r=n(e,o,i),u=t.localStorage.getItem(r);return JSON.parse(u)},this.saveTableSizes=function(e,o,i,r){var u=n(e,o,i);if(u){var s=JSON.stringify(r);t.localStorage.setItem(u,s)}}}]),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"}),$(this.table).css({width:"100%"})},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.table).css({width:"100%"}),$(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}]); |
@@ -40,3 +40,5 @@ /*jshint esversion: 6 */ | ||
gulp.task('watch', function() { | ||
gulp.watch(['index.html', 'css/**', 'scripts/**', 'views/**', 'demo/**'], browsersync.reload); | ||
gulp.watch(['index.html', 'css/**', 'scripts/**', 'views/**', 'demo/**'], function() { | ||
runSequence('build', browsersync.reload) | ||
}); | ||
}); | ||
@@ -43,0 +45,0 @@ |
{ | ||
"name": "angular-table-resize", | ||
"version": "1.0.13", | ||
"version": "1.0.14", | ||
"description": "An AngularJS module for resizing table columns!", | ||
@@ -5,0 +5,0 @@ "main": "./dist/angular-table-resize.js", |
@@ -5,2 +5,3 @@ angular.module("ngTableResize").directive('resizeable', ['resizeStorage', '$injector', function(resizeStorage, $injector) { | ||
var saveTableSizes; | ||
var profile; | ||
@@ -38,4 +39,13 @@ var columns = null; | ||
watchTableChanges(table, attr, scope) | ||
// Watch for scope bindings | ||
setUpWatchers(table, attr, scope) | ||
} | ||
function setUpWatchers(table, attr, scope) { | ||
scope.$watch('profile', function(newVal, oldVal) { | ||
console.log("Hey man") | ||
}) | ||
} | ||
function bindUtilityFunctions(table, attr, scope) { | ||
@@ -89,2 +99,3 @@ if (scope.bind === undefined) return; | ||
saveTableSizes = angular.isDefined(scope.saveTableSizes) ? scope.saveTableSizes : true; | ||
profile = scope.profile; | ||
@@ -98,3 +109,3 @@ // Get the resizer object for the current mode | ||
// Load column sizes from saved storage | ||
cache = resizeStorage.loadTableSizes(table, scope.mode) | ||
cache = resizeStorage.loadTableSizes(table, scope.mode, scope.profile) | ||
} | ||
@@ -258,3 +269,3 @@ | ||
resizeStorage.saveTableSizes(table, mode, cache); | ||
resizeStorage.saveTableSizes(table, mode, profile, cache); | ||
} | ||
@@ -268,2 +279,3 @@ | ||
mode: '=', | ||
profile: '=?', | ||
// whether to save table sizes; default true | ||
@@ -270,0 +282,0 @@ saveTableSizes: '=?', |
@@ -37,2 +37,6 @@ angular.module("ngTableResize").factory("BasicResizer", ["ResizerModel", function(ResizerModel) { | ||
}) | ||
$(this.table).css({ | ||
width: '100%' | ||
}) | ||
}; | ||
@@ -39,0 +43,0 @@ |
@@ -20,2 +20,6 @@ angular.module("ngTableResize").factory("FixedResizer", ["ResizerModel", function(ResizerModel) { | ||
$(this.table).css({ | ||
width: '100%' | ||
}) | ||
// First column is auto to compensate for 100% table width | ||
@@ -22,0 +26,0 @@ $(this.columns).first().css({ |
@@ -5,4 +5,4 @@ angular.module("ngTableResize").service('resizeStorage', ['$window', function($window) { | ||
this.loadTableSizes = function(table, model) { | ||
var key = getStorageKey(table, model); | ||
this.loadTableSizes = function(table, mode, profile) { | ||
var key = getStorageKey(table, mode, profile); | ||
var object = $window.localStorage.getItem(key); | ||
@@ -12,4 +12,4 @@ return JSON.parse(object); | ||
this.saveTableSizes = function(table, model, sizes) { | ||
var key = getStorageKey(table, model); | ||
this.saveTableSizes = function(table, mode, profile, sizes) { | ||
var key = getStorageKey(table, mode, profile); | ||
if (!key) return; | ||
@@ -20,3 +20,3 @@ var string = JSON.stringify(sizes); | ||
function getStorageKey(table, mode) { | ||
function getStorageKey(table, mode, profile) { | ||
var id = table.attr('id'); | ||
@@ -27,5 +27,5 @@ if (!id) { | ||
} | ||
return prefix + '.' + table.attr('id') + '.' + mode; | ||
return prefix + '.' + table.attr('id') + '.' + mode + (profile ? '.' + profile : ''); | ||
} | ||
}]); |
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
69521
1397