mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-05-25 04:24:45 -04:00
Improve drag-select.
This commit is contained in:
parent
936ffaf768
commit
e3ed699260
3 changed files with 38 additions and 40 deletions
|
@ -1,9 +1,11 @@
|
||||||
|
@col-blue-200: #90caf9;
|
||||||
@col-blue-400: #42a5f5;
|
@col-blue-400: #42a5f5;
|
||||||
@col-blue-500: #2196F3;
|
@col-blue-500: #2196F3;
|
||||||
@col-blue-700: #1976D2;
|
@col-blue-700: #1976D2;
|
||||||
@col-blue-900: #0D47A1;
|
@col-blue-900: #0D47A1;
|
||||||
@col-green: #4caf50;
|
@col-green: #4caf50;
|
||||||
@col-red: #f44336;
|
@col-red: #f44336;
|
||||||
|
@col-pink-a200: #ff4081;
|
||||||
|
|
||||||
@col-light: #ffffff;
|
@col-light: #ffffff;
|
||||||
@col-lightgray: #fafafa;
|
@col-lightgray: #fafafa;
|
||||||
|
@ -71,8 +73,8 @@
|
||||||
// @max-icon-size: 24px;
|
// @max-icon-size: 24px;
|
||||||
|
|
||||||
|
|
||||||
::-moz-selection { background: @col-blue-400; color: @col-text-primary-white; text-shadow: none; }
|
::-moz-selection { background: @col-pink-a200; color: @col-text-primary-white; text-shadow: none; }
|
||||||
::selection { background: @col-blue-400; color: @col-text-primary-white; text-shadow: none; }
|
::selection { background: @col-pink-a200; color: @col-text-primary-white; text-shadow: none; }
|
||||||
|
|
||||||
.transition (@transition) {
|
.transition (@transition) {
|
||||||
-webkit-transition: @transition;
|
-webkit-transition: @transition;
|
||||||
|
@ -181,6 +183,6 @@ body {
|
||||||
height: 0;
|
height: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// *:focus {
|
*:focus {
|
||||||
// outline: 1px solid #42a5f5;
|
outline: 1px solid @col-pink-a200;
|
||||||
// }
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ modulejs.define('ext/preview', ['_', '$', 'core/settings', 'core/resource', 'cor
|
||||||
}, allsettings.preview);
|
}, allsettings.preview);
|
||||||
var $window = $(window);
|
var $window = $(window);
|
||||||
var template =
|
var template =
|
||||||
'<div id="pv-overlay" class="noSelection">' +
|
'<div id="pv-overlay">' +
|
||||||
'<div id="pv-content"/>' +
|
'<div id="pv-content"/>' +
|
||||||
'<div id="pv-spinner"><img src="' + resource.image('spinner') + '"/></div>' +
|
'<div id="pv-spinner"><img src="' + resource.image('spinner') + '"/></div>' +
|
||||||
'<div id="pv-prev-area" class="hof"><img src="' + resource.image('preview-prev') + '"/></div>' +
|
'<div id="pv-prev-area" class="hof"><img src="' + resource.image('preview-prev') + '"/></div>' +
|
||||||
|
|
|
@ -8,6 +8,7 @@ modulejs.define('ext/select', ['_', '$', 'core/settings', 'core/resource', 'core
|
||||||
var template = '<span class="selector"><img src="' + resource.image('selected') + '" alt="selected"/></span>';
|
var template = '<span class="selector"><img src="' + resource.image('selected') + '" alt="selected"/></span>';
|
||||||
var x = 0, y = 0;
|
var x = 0, y = 0;
|
||||||
var l = 0, t = 0, w = 0, h = 0;
|
var l = 0, t = 0, w = 0, h = 0;
|
||||||
|
var isDragSelect, isCtrlPressed;
|
||||||
var shrink = 1/3;
|
var shrink = 1/3;
|
||||||
var $document = $(document);
|
var $document = $(document);
|
||||||
var $selectionRect = $('<div id="selection-rect"/>');
|
var $selectionRect = $('<div id="selection-rect"/>');
|
||||||
|
@ -55,6 +56,13 @@ modulejs.define('ext/select', ['_', '$', 'core/settings', 'core/resource', 'core
|
||||||
|
|
||||||
function selectionUpdate(ev) {
|
function selectionUpdate(ev) {
|
||||||
|
|
||||||
|
if (!isDragSelect && !isCtrlPressed) {
|
||||||
|
$('#items .item').removeClass('selected');
|
||||||
|
publish();
|
||||||
|
}
|
||||||
|
|
||||||
|
isDragSelect = true;
|
||||||
|
|
||||||
l = Math.min(x, ev.pageX);
|
l = Math.min(x, ev.pageX);
|
||||||
t = Math.min(y, ev.pageY);
|
t = Math.min(y, ev.pageY);
|
||||||
w = Math.abs(x - ev.pageX);
|
w = Math.abs(x - ev.pageX);
|
||||||
|
@ -78,10 +86,15 @@ modulejs.define('ext/select', ['_', '$', 'core/settings', 'core/resource', 'core
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function selectionEnd(event) {
|
function selectionEnd(ev) {
|
||||||
|
|
||||||
event.preventDefault();
|
|
||||||
$document.off('mousemove', selectionUpdate);
|
$document.off('mousemove', selectionUpdate);
|
||||||
|
|
||||||
|
if (!isDragSelect) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ev.preventDefault();
|
||||||
$('#items .item.selecting.selected').removeClass('selecting').removeClass('selected');
|
$('#items .item.selecting.selected').removeClass('selecting').removeClass('selected');
|
||||||
$('#items .item.selecting').removeClass('selecting').addClass('selected');
|
$('#items .item.selecting').removeClass('selecting').addClass('selected');
|
||||||
publish();
|
publish();
|
||||||
|
@ -103,40 +116,21 @@ modulejs.define('ext/select', ['_', '$', 'core/settings', 'core/resource', 'core
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function selectionStart(event) {
|
function selectionStart(ev) {
|
||||||
|
|
||||||
// only on left button and don't block scrollbar
|
// only on left button and don't block scrollbar
|
||||||
if (event.button !== 0 || event.offsetX >= $('#content').width() - 14) {
|
if (ev.button !== 0 || ev.offsetX >= $('#content').width() - 14) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
x = event.pageX;
|
isDragSelect = false;
|
||||||
y = event.pageY;
|
isCtrlPressed = ev.ctrlKey || ev.metaKey;
|
||||||
|
x = ev.pageX;
|
||||||
$(':focus').blur();
|
y = ev.pageY;
|
||||||
if (!event.ctrlKey && !event.metaKey) {
|
|
||||||
$('#items .item').removeClass('selected');
|
|
||||||
publish();
|
|
||||||
}
|
|
||||||
|
|
||||||
$document
|
$document
|
||||||
.on('mousemove', selectionUpdate)
|
.on('mousemove', selectionUpdate)
|
||||||
.one('mouseup', selectionEnd);
|
.one('mouseup', selectionEnd);
|
||||||
|
|
||||||
selectionUpdate(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
function noSelection(event) {
|
|
||||||
|
|
||||||
event.stopImmediatePropagation();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function noSelectionUnlessCtrl(event) {
|
|
||||||
|
|
||||||
if (!event.ctrlKey && !event.metaKey) {
|
|
||||||
noSelection(event);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function initItem(item) {
|
function initItem(item) {
|
||||||
|
@ -144,10 +138,10 @@ modulejs.define('ext/select', ['_', '$', 'core/settings', 'core/resource', 'core
|
||||||
if (item.$view) {
|
if (item.$view) {
|
||||||
$(template)
|
$(template)
|
||||||
.appendTo(item.$view.find('a'))
|
.appendTo(item.$view.find('a'))
|
||||||
.on('click', function (event) {
|
.on('click', function (ev) {
|
||||||
|
|
||||||
event.stopImmediatePropagation();
|
ev.stopImmediatePropagation();
|
||||||
event.preventDefault();
|
ev.preventDefault();
|
||||||
|
|
||||||
item.$view.toggleClass('selected');
|
item.$view.toggleClass('selected');
|
||||||
publish();
|
publish();
|
||||||
|
@ -195,11 +189,13 @@ modulejs.define('ext/select', ['_', '$', 'core/settings', 'core/resource', 'core
|
||||||
if (settings.clickndrag) {
|
if (settings.clickndrag) {
|
||||||
$selectionRect.hide().appendTo('body');
|
$selectionRect.hide().appendTo('body');
|
||||||
|
|
||||||
// $document
|
|
||||||
$('#content')
|
$('#content')
|
||||||
.on('mousedown', '.noSelection', noSelection)
|
.on('mousedown', selectionStart)
|
||||||
.on('mousedown', '.noSelectionUnlessCtrl,input,select,a', noSelectionUnlessCtrl)
|
.on('click', function (ev) {
|
||||||
.on('mousedown', selectionStart);
|
|
||||||
|
$('#items .item').removeClass('selected');
|
||||||
|
publish();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue