From 9a4dd4e8f5a46eeb725f83d7b00f37abe72e23f0 Mon Sep 17 00:00:00 2001 From: "Fedor A. Fetisov" Date: Thu, 18 Mar 2021 03:34:07 +0300 Subject: [PATCH] Make plugin handle all types of buttons --- js/refresh.js | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/js/refresh.js b/js/refresh.js index 90ada10..2605e8e 100644 --- a/js/refresh.js +++ b/js/refresh.js @@ -1,12 +1,28 @@ (function(Mibew) { Mibew.APIFunctions.refreshButton = function(data) { - // Refresh the button image (if exists) + + var button_object; + var button = document.getElementById("mibew-agent-button"); - if (!button) { return; } - var img = button.getElementsByTagName("img")[0]; - if (!img) { return; } - var originalSrc = img.src.replace(/&dummy=\d+/, ''); - img.src = originalSrc + "&dummy=" + (new Date()).getTime(); + if (!button) { + // The button is operator code field + button_object = document.getElementById("mibew-operator-code-field"); + } + else { + button_object = button.getElementsByTagName("img")[0]; + if (!button_object) { + // The button is text link + button_object = button; + } + else { + // The button is image, refresh it + var originalSrc = button_object.src.replace(/&dummy=\d+/, ''); + button_object.src = originalSrc + "&dummy=" + (new Date()).getTime(); + } + } + + // Unable to find button of any type - nothing to do + if (!button_object) { return; } // Hide the button if all popups are open or make it visible otherwise var visible = false; @@ -18,20 +34,20 @@ // Check whether we actually need to hide the button if (data.refreshButton.mode != 'none') { if (data.refreshButton.mode == 'visibility') { - img.style.visibility = visible ? 'visible' : 'hidden'; + button_object.style.visibility = visible ? 'visible' : 'hidden'; } else if (data.refreshButton.mode == 'display') { - img.style.display = visible ? data.refreshButton.submode : 'none'; + button_object.style.display = visible ? data.refreshButton.submode : 'none'; } } // Set appropriate class for the button depending on its alleged visibility - img.className = img.className.replace(/ mibew_(visible|hidden)/, ''); + button_object.className = button_object.className.replace(/ mibew_(visible|hidden)/, ''); if (visible) { - img.className = img.className.concat(' mibew_visible'); + button_object.className = button_object.className.concat(' mibew_visible'); } else { - img.className = img.className.concat(' mibew_hidden'); + button_object.className = button_object.className.concat(' mibew_hidden'); } } })(Mibew);