From d82cec5446e823193846a8cfde6394475a7bb8f3 Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Mon, 23 May 2022 15:50:26 +0200 Subject: [PATCH] Handle tabbing better --- .../static/js/visual-selector.js | 50 +++++++++++++------ changedetectionio/templates/edit.html | 8 +-- 2 files changed, 39 insertions(+), 19 deletions(-) diff --git a/changedetectionio/static/js/visual-selector.js b/changedetectionio/static/js/visual-selector.js index b7d9dcdc..1ef332f6 100644 --- a/changedetectionio/static/js/visual-selector.js +++ b/changedetectionio/static/js/visual-selector.js @@ -1,30 +1,53 @@ +// Horrible proof of concept code :) + $(document).ready(function() { + $('#visualselector-tab').click(function () { + bootstrap_visualselector(); + }); + + if(!window.location.hash || window.location.hash != '#visualselector') { + $("img#selector-background").attr('src',''); + return; + } + + bootstrap_visualselector(); var current_selected_i; var state_clicked=false; - var c = document.getElementById("selector-canvas"); + var c; // greyed out fill context - var xctx = c.getContext("2d"); + var xctx; // redline highlight context - var ctx = c.getContext("2d"); + var ctx; - var current_default_xpath=$("#css_filter").val(); + var current_default_xpath; var x_scale=1; var y_scale=1; - var selector_image = document.getElementById("selector-background"); + var selector_image; var selector_image_rect; var vh; var selector_data; - if ( $("img#selector-background").is(':visible') ) { - // bootstrap it, this will trigger everything else - $("img#selector-background").bind('load', function () { - fetch_data(); - }).attr("src", screenshot_url); + function bootstrap_visualselector() { + if ( 1 ) { + // bootstrap it, this will trigger everything else + $("img#selector-background").bind('load', function () { + + c = document.getElementById("selector-canvas"); + // greyed out fill context + xctx = c.getContext("2d"); + // redline highlight context + ctx = c.getContext("2d"); + current_default_xpath =$("#css_filter").val(); + fetch_data(); + $('#selector-canvas').off("mousemove"); + // screenshot_url defined in the edit.html template + }).attr("src", screenshot_url); + } } function fetch_data() { @@ -59,10 +82,9 @@ $(document).ready(function() { // some things to check if the scaling doesnt work // - that the widths/sizes really are about the actual screen size cat elements.json |grep -o width......|sort|uniq - + selector_image = $("img#selector-background")[0]; selector_image_rect = selector_image.getBoundingClientRect(); - // make the canvas the same size as the image $('#selector-canvas').attr('height', selector_image_rect.height); $('#selector-canvas').attr('width', selector_image_rect.width); @@ -101,14 +123,10 @@ $(document).ready(function() { if(!found) { alert("unfortunately your existing CSS/xPath Filter was no longer found!"); } - } - - $('#selector-canvas').bind('mousemove', function (e) { - if(state_clicked) { return; } diff --git a/changedetectionio/templates/edit.html b/changedetectionio/templates/edit.html index 48fff036..e743db5f 100644 --- a/changedetectionio/templates/edit.html +++ b/changedetectionio/templates/edit.html @@ -6,10 +6,12 @@ @@ -22,9 +24,9 @@