Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@
ehthumbs.db
Thumbs.db

node_modules
node_modules
*.bak
2 changes: 1 addition & 1 deletion angular-resizable.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
},
"homepage": "https://github.com/Reklino/angular-resizable",
"devDependencies": {
"gulp": "^3.8.11",
"gulp-minify-css": "^1.1.1",
"gulp": "^3.9.0",
"gulp-minify-css": "^1.2.0",
"gulp-rename": "^1.2.2",
"gulp-uglify": "^1.2.0"
}
Expand Down
49 changes: 40 additions & 9 deletions src/angular-resizable.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ angular.module('angularResizable', [])
rHeight: "=",
rFlex: "=",
rGrabber: "@",
rDisabled: "@"
rDisabled: "@",
rGrid: "=",
rLimitResizeTo: '=?'
},
link: function(scope, element, attr) {

Expand All @@ -37,6 +39,8 @@ angular.module('angularResizable', [])
element.addClass('resizable');

var style = window.getComputedStyle(element[0], null),
originalW,
originalH,
w,
h,
dir = scope.rDirections,
Expand All @@ -50,34 +54,54 @@ angular.module('angularResizable', [])

var updateInfo = function(e) {
info.width = false; info.height = false;
if(axis == 'x')
if(axis == 'x')
info.width = scope.rFlex ? parseInt(element[0].style.flexBasis) : parseInt(element[0].style.width);
else
info.height = scope.rFlex ? parseInt(element[0].style.flexBasis) : parseInt(element[0].style.height);
info.id = element[0].id;
info.evt = e;
}
info.originalWidth = originalW;
info.originalHeight = originalH;
};

var dragging = function(e) {
var offset = axis == 'x' ? start - e.clientX : start - e.clientY;
switch(dragDir) {
var offset = (axis == 'x') ? start - e.clientX : start - e.clientY,
gridX = scope.rGrid[0] || 1,
gridY = scope.rGrid[1] || 1,
limitResizeTo = scope.rLimitResizeTo,
futureDimension;

offset = (axis == 'x')
? Math.round(offset / gridX) * gridX
: Math.round(offset / gridY) * gridY;

switch(dragDir) {
case 'top':
futureDimension = h + (offset * vy);
if ( angular.isDefined(limitResizeTo) && futureDimension > originalH+(gridY*limitResizeTo) ) return;
if(scope.rFlex) { element[0].style.flexBasis = h + (offset * vy) + 'px'; }
else { element[0].style.height = h + (offset * vy) + 'px'; }
break;
case 'right':
if(scope.rFlex) { element[0].style.flexBasis = w - (offset * vx) + 'px'; }
else { element[0].style.width = w - (offset * vx) + 'px'; }
futureDimension = w - (offset * vx);
if ( angular.isDefined(limitResizeTo) && futureDimension > originalW+(gridX*limitResizeTo) ) return;
if(scope.rFlex) { element[0].style.flexBasis = futureDimension + 'px'; }
else { element[0].style.width = futureDimension + 'px'; }
break;
case 'bottom':
futureDimension = h - (offset * vy);
if ( angular.isDefined(limitResizeTo) && futureDimension < originalH-(gridY*limitResizeTo) ) return;
if(scope.rFlex) { element[0].style.flexBasis = h - (offset * vy) + 'px'; }
else { element[0].style.height = h - (offset * vy) + 'px'; }
break;
case 'left':
futureDimension = w + (offset * vx);
if ( angular.isDefined(limitResizeTo) && futureDimension < originalW-(gridX*limitResizeTo) ) return;
if(scope.rFlex) { element[0].style.flexBasis = w + (offset * vx) + 'px'; }
else { element[0].style.width = w + (offset * vx) + 'px'; }
break;
}

updateInfo(e);
throttle(function() { scope.$emit("angular-resizable.resizing", info);});
};
Expand All @@ -93,8 +117,15 @@ angular.module('angularResizable', [])
dragDir = direction;
axis = dragDir == 'left' || dragDir == 'right' ? 'x' : 'y';
start = axis == 'x' ? e.clientX : e.clientY;
w = parseInt(style.getPropertyValue("width"));
h = parseInt(style.getPropertyValue("height"));

// IE returns different values using "style.getPropertyValue"
//w = parseInt(style.getPropertyValue("width"));
//h = parseInt(style.getPropertyValue("height"));
var elRect = element[0].getBoundingClientRect();
w = parseInt(elRect.width);
h = parseInt(elRect.height);
originalW = w;
originalH = h;

//prevent transition while dragging
element.addClass('no-transition');
Expand Down