From 642c3a4b44fef0fab0ffff056f90ce184abfb1db Mon Sep 17 00:00:00 2001 From: Davit Vardanyan Date: Fri, 12 Dec 2014 12:35:17 +0300 Subject: [PATCH 1/2] Added bottom style fix for removing height expanding bug of elements, which and they have bottom style positioning. --- draggabilly.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/draggabilly.js b/draggabilly.js index b513673..81e3bcc 100644 --- a/draggabilly.js +++ b/draggabilly.js @@ -131,6 +131,8 @@ Draggabilly.prototype._create = function() { this.element.style.position = 'relative'; } + this._fixBottomPosition(); + this.enable(); this.setHandles(); @@ -166,6 +168,20 @@ Draggabilly.prototype.setHandles = function() { } }; +// bottom style fix, added for removing height expanding bug +// of elements, which position is absolute +Draggabilly.prototype._fixBottomPosition = function(){ + var style = getStyle(this.element); + var bottom = parseInt(style.bottom, 10); + if( !isNaN(bottom) ) + { + var element_height = this.element.offsetHeight; + var window_height = Math.max(document.documentElement.clientHeight, window.innerHeight || 0); + this.element.style.top = String(window_height - element_height + bottom) + 'px'; + this.element.style.bottom = 'auto'; + } +}; + // remove default dragging interaction on all images in IE8 // IE8 does its own drag thing on images, which messes stuff up From 0aa93da1d469f90d8443ee720b3d6bfced2778aa Mon Sep 17 00:00:00 2001 From: Davit Date: Sat, 13 Dec 2014 09:18:55 +0300 Subject: [PATCH 2/2] Fixed my previously fixed function) Just noticed, that same thing happens, when element positioned also with right style. --- draggabilly.js | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/draggabilly.js b/draggabilly.js index 81e3bcc..02d91c0 100644 --- a/draggabilly.js +++ b/draggabilly.js @@ -113,7 +113,6 @@ extend( Draggabilly.prototype, EventEmitter.prototype ); Draggabilly.prototype.options = { }; - Draggabilly.prototype._create = function() { // properties @@ -131,8 +130,8 @@ Draggabilly.prototype._create = function() { this.element.style.position = 'relative'; } - this._fixBottomPosition(); - + this._fixBottomRightPosition(); + this.enable(); this.setHandles(); @@ -170,18 +169,31 @@ Draggabilly.prototype.setHandles = function() { // bottom style fix, added for removing height expanding bug // of elements, which position is absolute -Draggabilly.prototype._fixBottomPosition = function(){ - var style = getStyle(this.element); - var bottom = parseInt(style.bottom, 10); - if( !isNaN(bottom) ) - { - var element_height = this.element.offsetHeight; - var window_height = Math.max(document.documentElement.clientHeight, window.innerHeight || 0); - this.element.style.top = String(window_height - element_height + bottom) + 'px'; - this.element.style.bottom = 'auto'; - } +Draggabilly.prototype._fixBottomRightPosition = function(){ + var style = getStyle(this.element); + var parent_node = this.element.parentNode; + + var bottom = parseInt(style.bottom, 10); + if( !isNaN(bottom) ) + { + var element_height = this.element.offsetHeight; + + var parent_height = Math.max(parent_node.clientHeight, parent_node.innerHeight || 0); + this.element.style.top = String(parent_height - element_height + bottom) + 'px'; + this.element.style.bottom = 'auto'; + } + + var right = parseInt(style.right, 10); + if( !isNaN(right) ) + { + var element_width = this.element.offsetWidth; + var parent_width = Math.max(parent_node.clientWidth, parent_node.innerWidth || 0); + this.element.style.left = String(parent_width - element_width + right) + 'px'; + this.element.style.right = 'auto'; + } }; + // remove default dragging interaction on all images in IE8 // IE8 does its own drag thing on images, which messes stuff up