Skip to content

Instantly share code, notes, and snippets.

@Ivanca
Last active December 22, 2015 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ivanca/6531219 to your computer and use it in GitHub Desktop.
Save Ivanca/6531219 to your computer and use it in GitHub Desktop.
(function ($) {
var dragging = null;
$(".style-editor").on("mousedown.wf", ".tick", function (e) {
var $ghost = $("<div class='drag-ghost'>").appendTo('body').css(
'cursor', 'ns-resize'
);
var $input = $(this).closest('.input-control').find('input');
dragging = {
startY: e.clientY,
oldVal: $input.val(),
$ele: $(this),
$input: $input,
$ghost: $ghost
};
return false;
});
$(window).on("mouseup.wf blur.wf focusout.wf", function (e) {
if (dragging) {
dragging.$ele.closest('.input-control').find('input').change();
dragging.$ghost.remove();
dragging = null;
return false;
}
});
$(window).on("mousemove.wf", function (e) {
if (dragging) {
var delta = dragging.startY - e.clientY;
var newVal = parseInt(dragging.oldVal, 10) + delta * 2;
if (isNaN( newVal )) return;
dragging.$input.val(newVal).change();
}
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment