The problem is you call your start function before you before your bind your mouse handlers, so your stop function has nothing to unbind.
(function($) {
$.fn.ondrag = function(opt) {
//console.log("set drag");
var obj = this;
opt = $.extend({start:null,drag:null,end:null,leave:null,dropElement:document}, opt);
this.data('ondrag',opt);
opt.dragHandler = function(e){ if (opt.drag) opt.drag.call(obj); e.stopPropagation(); };
opt.leaveHandler = function(e){ if (opt.leave) opt.leave.call(obj); e.stopPropagation(); };
opt.startHandler = function(e){
$(document).on("mousemove",opt.dragHandler);
$(document.body).on("mouseleave",opt.leaveHandler);
$(document).on("mouseup",opt.endHandler);
if (opt.start) opt.start.call(obj);
e.stopPropagation();
};
opt.endHandler = function(e){
opt.stopdrag();
e.stopPropagation();
};
this.on("mousedown",opt.startHandler);
opt.stopdrag = function(){
console.log("stop dragging", opt.drag);
$(document).off("mousemove",opt.dragHandler);
$(document.body).off("mouseleave",opt.leaveHandler);
$(document).off("mouseup",opt.endHandler);
if (opt.end) opt.end.call(obj);
};
return this;
};
})(jQuery);
All you need to do is move the callbacks to start/end below the on/off calls.