mirror of
https://github.com/Mibew/advanced-button-plugin.git
synced 2025-01-22 08:50:30 +03:00
Make plugin handle all types of buttons
This commit is contained in:
parent
d0f5b645bf
commit
9a4dd4e8f5
@ -1,12 +1,28 @@
|
|||||||
(function(Mibew) {
|
(function(Mibew) {
|
||||||
Mibew.APIFunctions.refreshButton = function(data) {
|
Mibew.APIFunctions.refreshButton = function(data) {
|
||||||
// Refresh the button image (if exists)
|
|
||||||
|
var button_object;
|
||||||
|
|
||||||
var button = document.getElementById("mibew-agent-button");
|
var button = document.getElementById("mibew-agent-button");
|
||||||
if (!button) { return; }
|
if (!button) {
|
||||||
var img = button.getElementsByTagName("img")[0];
|
// The button is operator code field
|
||||||
if (!img) { return; }
|
button_object = document.getElementById("mibew-operator-code-field");
|
||||||
var originalSrc = img.src.replace(/&dummy=\d+/, '');
|
}
|
||||||
img.src = originalSrc + "&dummy=" + (new Date()).getTime();
|
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
|
// Hide the button if all popups are open or make it visible otherwise
|
||||||
var visible = false;
|
var visible = false;
|
||||||
@ -18,20 +34,20 @@
|
|||||||
// Check whether we actually need to hide the button
|
// Check whether we actually need to hide the button
|
||||||
if (data.refreshButton.mode != 'none') {
|
if (data.refreshButton.mode != 'none') {
|
||||||
if (data.refreshButton.mode == 'visibility') {
|
if (data.refreshButton.mode == 'visibility') {
|
||||||
img.style.visibility = visible ? 'visible' : 'hidden';
|
button_object.style.visibility = visible ? 'visible' : 'hidden';
|
||||||
}
|
}
|
||||||
else if (data.refreshButton.mode == 'display') {
|
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
|
// 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) {
|
if (visible) {
|
||||||
img.className = img.className.concat(' mibew_visible');
|
button_object.className = button_object.className.concat(' mibew_visible');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
img.className = img.className.concat(' mibew_hidden');
|
button_object.className = button_object.className.concat(' mibew_hidden');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})(Mibew);
|
})(Mibew);
|
||||||
|
Loading…
Reference in New Issue
Block a user