advanced-button-plugin/js/refresh.js

35 lines
1.4 KiB
JavaScript
Raw Permalink Normal View History

2018-10-16 17:21:08 +03:00
(function(Mibew) {
Mibew.APIFunctions.refreshButton = function(data) {
// Refresh the button image
var img = document.getElementById("mibew-agent-button").getElementsByTagName("img")[0];
var originalSrc = img.src.replace(/&dummy=\d+/, '');
img.src = originalSrc + "&dummy=" + (new Date()).getTime();
// Hide the button if all popups are open or make it visible otherwise
var visible = false;
for(var key in Mibew.Objects.ChatPopups) {
var popup = Mibew.Objects.ChatPopups[key];
visible = visible || !popup.isOpened;
}
// Check whether we actually need to hide the button
2018-10-17 18:04:39 +03:00
if (data.refreshButton.mode != 'none') {
if (data.refreshButton.mode == 'visibility') {
img.style.visibility = visible ? 'visible' : 'hidden';
}
else if (data.refreshButton.mode == 'display') {
img.style.display = visible ? data.refreshButton.submode : 'none';
}
2018-10-16 17:21:08 +03:00
}
// Set appropriate class for the button depending on its alleged visibility
img.className = img.className.replace(/ mibew_(visible|hidden)/, '');
if (visible) {
img.className = img.className.concat(' mibew_visible');
}
else {
img.className = img.className.concat(' mibew_hidden');
}
2018-10-16 17:21:08 +03:00
}
})(Mibew);