From ce4a78544941eb99a12e95b9b4e535cb216f28b4 Mon Sep 17 00:00:00 2001 From: Gnome Ann <> Date: Sun, 5 Jun 2022 21:06:09 -0400 Subject: [PATCH] Allow clicking on userscripts to enable/disable them (mobile friendly) --- static/application.js | 27 +++++++++++++++++++++++---- templates/index.html | 2 +- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/static/application.js b/static/application.js index cfb25883..3b50281c 100644 --- a/static/application.js +++ b/static/application.js @@ -106,6 +106,9 @@ var using_webkit_patch = true; var shift_down = false; var do_clear_ent = false; +// Whether or not an entry in the Userscripts menu is being dragged +var us_dragging = false; + // Display vars var allowtoggle = false; var formatcount = 0; @@ -2412,9 +2415,25 @@ $(document).ready(function(){ }, 2); }); + var us_click_handler = function(ev) { + setTimeout(function() { + if (us_dragging) { + return; + } + var target = $(ev.target).closest(".uslistitem")[0]; + if ($.contains(document.getElementById("uslistunloaded"), target)) { + document.getElementById("uslistloaded").appendChild(target); + } else { + document.getElementById("uslistunloaded").appendChild(target); + } + }, 10); + } + // Make the userscripts menu sortable var us_sortable_settings = { placeholder: "ussortable-placeholder", + start: function() { us_dragging = true; }, + stop: function() { us_dragging = false; }, delay: 2, cursor: "move", tolerance: "pointer", @@ -2423,12 +2442,12 @@ $(document).ready(function(){ scrollSensitivity: 64, scrollSpeed: 10, } - $(usunloaded).sortable($.extend({ + usunloaded.sortable($.extend({ connectWith: "#uslistloaded", - }, us_sortable_settings)); - $(usloaded).sortable($.extend({ + }, us_sortable_settings)).on("click", ".uslistitem", us_click_handler); + usloaded.sortable($.extend({ connectWith: "#uslistunloaded", - }, us_sortable_settings)); + }, us_sortable_settings)).on("click", ".uslistitem", us_click_handler); // Bind actions to UI buttons button_send.on("click", function(ev) { diff --git a/templates/index.html b/templates/index.html index 07bcdcc5..a3214ffa 100644 --- a/templates/index.html +++ b/templates/index.html @@ -17,7 +17,7 @@ - +