Skip to content

Commit

Permalink
[*] Escape key stops the drag and drop (usefull when d&d doesn't stop…
Browse files Browse the repository at this point in the history
… on mouseup)
  • Loading branch information
nsorosac committed Feb 1, 2013
1 parent b0767b4 commit 17d5772
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions sofresh.js
Expand Up @@ -318,7 +318,7 @@ require_once dirname(__FILE__).'/php/sofresh.php';
var $this = this,
initX = false,
initY = false;
$sf(document).on('mousemove.sofresh', function(event){
function onDragAndDrop(event){
if ($this.container.hasClass('sofresh-movable')) {
event.preventDefault();
if (!initX) initX = event.pageX;
Expand All @@ -329,11 +329,8 @@ require_once dirname(__FILE__).'/php/sofresh.php';
initY = event.pageY;
$sf('.sofresh-movable').css({ left: '+=' + thisX, top: '+=' + thisY });
}
});
$sf('#sofresh_header').on('mousedown', function(event){
event.preventDefault();
$this.container.addClass('sofresh-movable');
}).on('mouseup', function(){
}
function stopDragAndDrop(){
$this.container.removeClass('sofresh-movable');
initX = false;
initY = false;
Expand All @@ -343,6 +340,18 @@ require_once dirname(__FILE__).'/php/sofresh.php';
left: position.left - $sf(document).scrollLeft()
};
$this.saveState();
}
$sf(document).on('mousemove.sofresh', function(event){
onDragAndDrop(event);
});
$sf('#sofresh_header').on('mousedown', function(event){
event.preventDefault();
$this.container.addClass('sofresh-movable');
}).on('mouseup', function(){
stopDragAndDrop();
});
$sf(document).on('keyup', function(event){
if (event.which == 27) stopDragAndDrop();
});
};

Expand Down

0 comments on commit 17d5772

Please sign in to comment.