fix some interactions between click-to-select and drag
This commit is contained in:
parent
fc73c872ed
commit
7e01b0aad0
|
|
@ -164,6 +164,9 @@ $(function (){
|
||||||
square.on('click.destination', squareClickDestination);
|
square.on('click.destination', squareClickDestination);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (event === 'drag') {
|
||||||
|
cbSquare(from).droppable('enable');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function pieceEndMove(piece, to) {
|
function pieceEndMove(piece, to) {
|
||||||
|
|
@ -193,7 +196,12 @@ $(function (){
|
||||||
}
|
}
|
||||||
|
|
||||||
function squareDropDestination(ev, ui) {
|
function squareDropDestination(ev, ui) {
|
||||||
pieceEndMove(ui.draggable, cbSquareLocation(this));
|
const droppedAt = cbSquareLocation(this);
|
||||||
|
if ($(ui.draggable).data('location') == droppedAt) {
|
||||||
|
squareClickSelect.call(cbSquare(droppedAt));
|
||||||
|
} else {
|
||||||
|
pieceEndMove(ui.draggable, droppedAt);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function squareClickUnselect(ev, ui) {
|
function squareClickUnselect(ev, ui) {
|
||||||
|
|
@ -201,6 +209,7 @@ $(function (){
|
||||||
}
|
}
|
||||||
|
|
||||||
function squareClickSelect(ev, ui) {
|
function squareClickSelect(ev, ui) {
|
||||||
|
renderBoard();
|
||||||
const clicked = $(this).children('.cb-piece.ui-draggable').not('.ui-draggable-disabled');
|
const clicked = $(this).children('.cb-piece.ui-draggable').not('.ui-draggable-disabled');
|
||||||
clicked.addClass('cb-selected');
|
clicked.addClass('cb-selected');
|
||||||
$('#cb_board .cb-square').off('click.select');
|
$('#cb_board .cb-square').off('click.select');
|
||||||
|
|
@ -209,13 +218,22 @@ $(function (){
|
||||||
}
|
}
|
||||||
|
|
||||||
function pieceStartDrag(ev, ui) {
|
function pieceStartDrag(ev, ui) {
|
||||||
|
const dragged = $(this);
|
||||||
$('#cb_board .cb-selected').removeClass('cb-selected');
|
$('#cb_board .cb-selected').removeClass('cb-selected');
|
||||||
$('#cb_board .cb-square').off('click.destination');
|
$('#cb_board .cb-legal').removeClass('cb-legal');
|
||||||
pieceStartMove($(this), 'drag');
|
dragged.data('saved-style', dragged.attr('style'));
|
||||||
|
$('#cb_board').data('dragging_from', dragged.data('location'));
|
||||||
|
pieceStartMove(dragged, 'drag');
|
||||||
}
|
}
|
||||||
|
|
||||||
function pieceStopDrag(ev, ui) {
|
function pieceStopDrag(ev, ui) {
|
||||||
renderBoard();
|
const dragged = $(this);
|
||||||
|
dragged.attr('style', dragged.data('saved-style'));
|
||||||
|
dragged.removeData('saved-style');
|
||||||
|
dragged.css('z-index', '');
|
||||||
|
if ($('#cb_board').data('dragging_from') === dragged.data('location')) {
|
||||||
|
renderBoard();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function placePiece(where, side, type, suffix) {
|
function placePiece(where, side, type, suffix) {
|
||||||
|
|
@ -235,7 +253,7 @@ $(function (){
|
||||||
piece.draggable({
|
piece.draggable({
|
||||||
disabled: true,
|
disabled: true,
|
||||||
containment: '#cb_inner',
|
containment: '#cb_inner',
|
||||||
revert: 'invalid',
|
revert: true,
|
||||||
zIndex: 100,
|
zIndex: 100,
|
||||||
start: pieceStartDrag,
|
start: pieceStartDrag,
|
||||||
stop: pieceStopDrag,
|
stop: pieceStopDrag,
|
||||||
|
|
@ -244,6 +262,7 @@ $(function (){
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderBoard(animate) {
|
function renderBoard(animate) {
|
||||||
|
$('#cb_board').removeData('dragging_from');
|
||||||
$('#cb_board .cb-piece').stop(true);
|
$('#cb_board .cb-piece').stop(true);
|
||||||
$('#cb_board .cb-square').off('click.select');
|
$('#cb_board .cb-square').off('click.select');
|
||||||
$('#cb_board .cb-square').off('click.unselect');
|
$('#cb_board .cb-square').off('click.unselect');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue