Logic Machine Forum
Open/Close Widget - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Visualization (https://forum.logicmachine.net/forumdisplay.php?fid=9)
+--- Thread: Open/Close Widget (/showthread.php?tid=3127)



Open/Close Widget - JoseJimenez94 - 25.01.2021

Good afternoon,

I wanted to ask if it is possible to change the image of an object depending on whether the associated Widget is open or closed, without having to use Javascript.

Cheers


RE: Open/Close Widget - admin - 01.02.2021

This can't be done without Custom JS. Do you want to change the icon of the element that opens the widget or something else?


RE: Open/Close Widget - JoseJimenez94 - 11.02.2021

(01.02.2021, 07:49)admin Wrote: This can't be done without Custom JS. Do you want to change the icon of the element that opens the widget or something else?

I just want to change the icon of the element


RE: Open/Close Widget - admin - 15.02.2021

Use an object that is not connected to any control so the its value is always 0. Change widget-5 to your widget element ID, additional class for the opening element is widget-opener, change icon paths as needed.
Code:
$(function(){
  var widget = $('#widget-5');
  var img = $('.widget-opener').find('img');
  var icon_on = '/scada/resources/icons/ok-active.svg';
  var icon_off = '/scada/resources/icons/ok.svg';
  
  widget
    .on('widget-show', function() { img.attr('src', icon_on); })
    .on('widget-hide', function() { img.attr('src', icon_off); });
});