Skip to content

Commit

Permalink
Fixes some cursor craziness on Chrome. Breaks Firefox.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyckahn committed Mar 25, 2012
1 parent b2c9ea0 commit 8189983
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/jquery.dragon.js
@@ -1,6 +1,7 @@
;(function ($) {

var $win = $(window);
var $doc = $(document);

/**
* Options:
Expand All @@ -15,7 +16,7 @@
$els.css('position', 'absolute');

if (!opts.noCursor) {
$els.css('cursor', 'pointer');
$els.css('cursor', 'move');
}

$els.each(function (i, el) {
Expand All @@ -24,9 +25,12 @@
var top = position.top;
var left = position.left;

$el.css('top', top);
$el.css('left', left);
$el.on('mousedown', $.proxy(onMouseDown, $el));
$el
.css({
'top': top
,'left': left
})
.on('mousedown', $.proxy(onMouseDown, $el));
});
}

Expand All @@ -47,13 +51,16 @@
.on('mouseup', onMouseUpInstance)
.on('blur', onMouseUpInstance)
.on('mousemove', onMouseMoveInstance);

$doc.on('selectstart', preventSelect);
}

function onMouseUp (evt) {
var data = this.data('dragon');
$win.off('mouseup', data.onMouseUp);
$win.off('blur', data.onMouseUp);
$win.off('mousemove', data.onMouseMove);
$doc.off('selectstart', preventSelect);
delete data.onMouseUp;
delete data.onMouseMove;
}
Expand All @@ -66,4 +73,16 @@
});
}

// This event handler fixes some craziness with the startselect event breaking
// the cursor CSS setting.
// http://forum.jquery.com/topic/chrome-text-select-cursor-on-drag
function preventSelect(evt) {
evt.preventDefault();
if (window.getSelection) {
window.getSelection().removeAllRanges();
} else if (document.selection) {
document.selection.clear();
}
}

} (jQuery));

0 comments on commit 8189983

Please sign in to comment.