added a isMobile() function that adds a shift and ctrl key to the files view, which can be clicked to fake a shift or ctrl key selection event on a tablet/mobile - first pass at this, its fairly usable. I might allow de-selecting the shift or ctrl key if they are pressed again before a selection is used, otherwise this is all functional. Note, I also changed the contextmenu to a click not mouse down on selection of an item in the menu. This is allows me to stop the propagation of the click event which was being trapped by the $(document).on( "click" ... and which we dont want - also exposes a BUG that when I click the context menu onto a different image it does not highlight the new image and some menu items process the original highlight, others the image under the context menu

This commit is contained in:
2024-01-21 23:07:31 +11:00
parent 7e25c33f1a
commit 53ef671d34
2 changed files with 27 additions and 4 deletions

View File

@@ -223,12 +223,14 @@ function ChangeSize(clicked_button,sz)
// whether you click after highlight or before // whether you click after highlight or before
function DoSel(e, el) function DoSel(e, el)
{ {
if( e.ctrlKey ) if( e.ctrlKey || document.fake_ctrl === 1 )
{ {
$(el).toggleClass('highlight') $(el).toggleClass('highlight')
if( document.fake_ctrl === 1 )
document.fake_ctrl=0
return return
} }
if( e.shiftKey ) if( e.shiftKey || document.fake_shift === 1 )
{ {
st=Number($('.highlight').first().attr('ecnt')) st=Number($('.highlight').first().attr('ecnt'))
end=Number($('.highlight').last().attr('ecnt')) end=Number($('.highlight').last().attr('ecnt'))
@@ -243,6 +245,9 @@ function DoSel(e, el)
$('.entry').slice( end, clicked+1 ).addClass('highlight') $('.entry').slice( end, clicked+1 ).addClass('highlight')
else else
$('.entry').slice( clicked, st ).addClass('highlight') $('.entry').slice( clicked, st ).addClass('highlight')
if( document.fake_shift === 1 )
document.fake_shift=0
return return
} }
$('.highlight').removeClass('highlight') $('.highlight').removeClass('highlight')

View File

@@ -5,6 +5,8 @@
<script src="{{ url_for( 'internal', filename='js/files_transform.js')}}"></script> <script src="{{ url_for( 'internal', filename='js/files_transform.js')}}"></script>
<script> <script>
document.fake_shift=0
document.fake_ctrl=0
var move_paths=[] var move_paths=[]
{% for p in move_paths %} {% for p in move_paths %}
p = new Object() p = new Object()
@@ -83,6 +85,8 @@
<svg width="16" height="16" fill="currentColor"><use xlink:href="{{url_for('internal', filename='icons.svg')}}#trash-fill"/></svg> <svg width="16" height="16" fill="currentColor"><use xlink:href="{{url_for('internal', filename='icons.svg')}}#trash-fill"/></svg>
{% endif %} {% endif %}
</button> </button>
<button style="visibility:hidden" class="btn btn-outline-secondary" aria-label="shift-key" id="shift-key" onclick="document.fake_shift=1-document.fake_shift; event.stopPropagation(); return false">shift</button>
<button style="visibility:hidden" class="btn btn-outline-secondary" aria-label="ctrl-key" id="ctrl-key" onclick="document.fake_ctrl=1-document.fake_ctrl; event.stopPropagation(); return false">ctrl</button>
</div> </div>
<div class="d-flex col col-auto justify-content-end"> <div class="d-flex col col-auto justify-content-end">
<div class="btn-group"> <div class="btn-group">
@@ -306,6 +310,7 @@ $('.figure').dblclick( CallViewRouteWrapper )
// different context menu on files // different context menu on files
$.contextMenu({ $.contextMenu({
selector: '.entry', selector: '.entry',
itemClickEvent: "click",
build: function($triggerElement, e) { build: function($triggerElement, e) {
// when right-clicking & no selection add one OR deal with ctrl/shift right-lick as it always changes seln // when right-clicking & no selection add one OR deal with ctrl/shift right-lick as it always changes seln
if( NoSel() || e.ctrlKey || e.shiftKey ) if( NoSel() || e.ctrlKey || e.shiftKey )
@@ -375,6 +380,8 @@ $.contextMenu({
if( key == "fliph" ) { Transform("fliph") } if( key == "fliph" ) { Transform("fliph") }
if( key == "flipv" ) { Transform("flipv") } if( key == "flipv" ) { Transform("flipv") }
if( key.startsWith("ai")) { RunAIOnSeln(key) } if( key.startsWith("ai")) { RunAIOnSeln(key) }
// dont flow this event through the dom
e.stopPropagation()
}, },
items: item_list items: item_list
}; };
@@ -401,7 +408,18 @@ $( document ).keydown(function(event) {
if( ! NoSel() ) DelDBox('Delete'); if( ! NoSel() ) DelDBox('Delete');
{% endif %} {% endif %}
break; break;
} } })
});
function isMobile() {
try{ document.createEvent("TouchEvent"); return true; }
catch(e){ return false; }
}
if( isMobile() )
{
$('#shift-key').css('visibility', 'visible');
$('#ctrl-key').css('visibility', 'visible');
}
</script> </script>
{% endblock script_content %} {% endblock script_content %}