diff --git a/lib/raphael.draggable.js b/lib/raphael.draggable.js index 65e7128..825b5f5 100644 --- a/lib/raphael.draggable.js +++ b/lib/raphael.draggable.js @@ -75,6 +75,10 @@ lastY = event.clientY; } }); + + element.mouseup(function() { + paper.draggable.clearCurrent(); + }); }; DraggableExtension.prototype = { diff --git a/spec/raphael.draggable_spec.js b/spec/raphael.draggable_spec.js index 898f4a9..abf1193 100644 --- a/spec/raphael.draggable_spec.js +++ b/spec/raphael.draggable_spec.js @@ -73,31 +73,9 @@ Screw.Unit(function() { var paper; var rect; before(function() { - // Override Raphael's mousedown so that mousedown can be triggered - Raphael.el.mousedown = function(arg) { - if (typeof arg == 'function') { - this.mousedownHandlers = this.mousedownHandlers || []; - this.mousedownHandlers.push(arg); - } - else { - for(var i = 0; i < this.mousedownHandlers.length; i++) { - this.mousedownHandlers[i].apply(this, arg); - } - } - }; - - // Override Raphael's mousemove so that mousemove can be triggered - Raphael.el.mousemove = function(arg) { - if (typeof arg == 'function') { - this.mouseMoveHandlers = this.mouseMoveHandlers || []; - this.mouseMoveHandlers.push(arg); - } - else { - for(var i = 0; i < this.mouseMoveHandlers.length; i++) { - this.mouseMoveHandlers[i].apply(this, arg); - } - } - }; + overrideEventHandler('mousedown'); + overrideEventHandler('mousemove'); + overrideEventHandler('mouseup'); paper = Raphael(0, 0, 600, 600).draggable.enable(); rect = paper.rect(1,1,1,1).draggable.enable(); @@ -167,6 +145,14 @@ Screw.Unit(function() { expect(translateY).to(equal, moveY - startY); }); }); + + describe('mouseup', function() { + it("resets the current draggable", function() { + rect.mousedown([{}]); + rect.mouseup(); + expect(paper.draggable.current()).to(equal, null); + }); + }) }); }); }); diff --git a/spec/spec_helper.js b/spec/spec_helper.js new file mode 100644 index 0000000..d2dc6e7 --- /dev/null +++ b/spec/spec_helper.js @@ -0,0 +1,16 @@ +// Overrides a built in Raphael event handler so that event handlers can +// be triggered during testing +function overrideEventHandler(handlerName) { + var handlerCollectionName = handlerName + "handlers"; + Raphael.el[handlerName] = function(arg) { + if (typeof arg == 'function') { + this[handlerCollectionName] = this[handlerCollectionName] || []; + this[handlerCollectionName].push(arg); + } + else { + for(var i = 0; i < this[handlerCollectionName].length; i++) { + this[handlerCollectionName][i].apply(this, arg); + } + } + }; +} \ No newline at end of file diff --git a/spec/suite.html b/spec/suite.html index 000afea..a8fbac2 100644 --- a/spec/suite.html +++ b/spec/suite.html @@ -12,6 +12,7 @@ +