From 17d57724696fbb50111bb1c36b838e9d62cf3c3a Mon Sep 17 00:00:00 2001 From: Nicolas Sorosac Date: Fri, 1 Feb 2013 13:51:34 +0100 Subject: [PATCH] [*] Escape key stops the drag and drop (usefull when d&d doesn't stop on mouseup) --- sofresh.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/sofresh.js b/sofresh.js index b6479ad..fe54389 100644 --- a/sofresh.js +++ b/sofresh.js @@ -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; @@ -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; @@ -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(); }); };