Logic Machine Forum
Custom JavaScript examples - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Custom JavaScript examples (/showthread.php?tid=275)

Pages: 1 2 3 4 5 6 7 8 9 10 11


RE: Custom JavaScript examples - Domoticatorino - 09.03.2018

(15.04.2016, 21:32)Erwin van der Zwart Wrote: Another nice custom Javascript feature: Back to startpage after x seconds when there is no user input:

The startpage will be automaticly linked to the first page of the visu that is loaded.

Paste this code into your custom Javascript and adjust time (SE_Timeout) if needed.

Code:
$(function() {
 
 // Back to Start after x seconds (in miliseconds)
 var SE_Timeout = 90000; // adjust this timer value if needed (90 seconds in miliseconds)
 var SE_Startpage = currentPlanId; // First page that is loaded
 var eventlist = 'vclick vmousedown vmouseout touchend';
 
 // Timer function no usage detected
 function No_Usage_Detected(callback, timeout, _this) {
   var timer;
   return function(e) {
       var _that = this;
       if (timer)
           clearTimeout(timer);
       timer = setTimeout(function() {
           callback.call(_this || _that, e);
       }, timeout);
   }
 }

 // Back to start function when timer elapsed
   var SE_Goto_Startpage = No_Usage_Detected(function(e) {
   if ( currentPlanId != SE_Startpage ) {
    showPlan(SE_Startpage);
   }
 }, SE_Timeout);
 
 // Add event listener to document to detect user input
 $(document)
 .on(eventlist, function() {
   SE_Goto_Startpage();
 });

 // Add event listener to all iframes to detect user input inside iframes
 $('iframe').load(function() {
   var iframe = $('iframe').contents().find('html');
   iframe.on(eventlist, function(event) {
    SE_Goto_Startpage();
   });
 });

});

BR,

Erwin van der Zwart
Hi Erwin,
further to this above. It is possible to log out as well.
What do you suggest?
Thanks.


RE: Custom JavaScript examples - Erwin van der Zwart - 09.03.2018

Hi,

Yes you could.

Add after line 24 a redirect to /logout  (after showPlan)

BR,

Erwin


RE: Custom JavaScript examples - Domoticatorino - 16.03.2018

Hi Erwing,
What is exactly the instruction?
Simply what you wrote
Thanks.


RE: Custom JavaScript examples - Domoticatorino - 17.03.2018

(09.03.2018, 07:23)Erwin van der Zwart Wrote: Hi,

Yes you could.

Add after line 24 a redirect to /logout  (after showPlan)

BR,

Erwin

So instruction is the following?

showPlan (redirect to /logout)

Thanks.


RE: Custom JavaScript examples - Erwin van der Zwart - 17.03.2018

Hi,

No, that would be to easy (:

Add this after line 24:
Code:
$(location).attr("href", "/logout");
So result looks like:
Code:
 var SE_Goto_Startpage = No_Usage_Detected(function(e) {
    if ( currentPlanId != SE_Startpage ) {
        showPlan(SE_Startpage);
        $(location).attr("href", "/logout");
    }
  }, SE_Timeout);
BR,

Erwin


RE: Custom JavaScript examples - Domoticatorino - 17.03.2018

Thank you Erwin, I'll try.


RE: Custom JavaScript examples - Mrinj - 24.03.2018

Hi,
Please excuse the question but I’m newbie who’s been reading and testing and still can not connect the dotts:
How to read/write % value to a virtual object 32/1/1 from a custom created java script (in notepad), saved as html, uploaded as image to Wizer and imported in frame/url in a visualization? Do I need to have a starage.lp for multiple addresses?
Can someone please replay with a short step by step guide or a simple js example?
Best,


RE: Custom JavaScript examples - admin - 25.03.2018

Can you explain what kind of task do you have?


RE: Custom JavaScript examples - Erwin van der Zwart - 25.03.2018

Hi,

HTML files with embedded JS uploaded to the images folder and added to the visu by using a frame is a very old way to include custom JS to the visu.

Now we have (quite a while already) Custom JS so the old methode above is not needed anymore.

Just like Admin asked, what do you need to do?

BR,

Erwin


RE: Custom JavaScript examples - Mrinj - 25.03.2018

I've been reading post (probably old), testing and maybe that's why is confusing for me. Excuse me please!
My plan was to enter a number and save/read the value to an object (in %) from an image (probably with script) that is embedded in visualization, frame and via /scada/resources/icons/image.html. I know this can be done in visualization, object and then by choosing the object address, but the idea is that multiple objects can be saved.
How can this be done with Custom JS?


RE: Custom JavaScript examples - Erwin van der Zwart - 25.03.2018

Hi,

Why don't you just add a normal value or string object(s) to the visu? Can you explain why you are thinking that you need to do this by using JS?

BR,

Erwin


RE: Custom JavaScript examples - Mrinj - 25.03.2018

Probably it will be best and easiest with normal value in visu.
And probably I've been reading & trying to hard to understand the principles of JS and Wiser.
Thanks for your time, advice and help!


RE: Custom JavaScript examples - suporte.arqtech - 06.08.2018

Hello

Is it possible to repeat a command while I hold down a button with the short / long press script?

I need a volume button for a TV in witch the user doesn´t need to press several times to achieve the desired level.


BR,

Jefferson


RE: Custom JavaScript examples - DGrandes - 29.04.2019

(06.08.2018, 20:31)suporte.arqtech Wrote: Hello

Is it possible to repeat a command while I hold down a button with the short / long press script?

I need a volume button for a TV in witch the user doesn´t need to press several times to achieve the desired level.


BR,

Jefferson

Hi,
I want to do it too.

I need to send a byte number continually while i press + or - button.

For example, while I press +, send "30" to group address 1/1/1, and when I press -, sen "31" to 1/1/1

Thanks


RE: Custom JavaScript examples - admin - 29.04.2019

You don't need custom JS for this. Use binary objects in start/stop mode and this script for conversion to 1-byte scaled: https://forum.logicmachine.net/showthread.php?tid=51&pid=298#pid298


RE: Custom JavaScript examples - DGrandes - 30.04.2019

(29.04.2019, 17:00)admin Wrote: You don't need custom JS for this. Use binary objects in start/stop mode and this script for conversion to 1-byte scaled: https://forum.logicmachine.net/showthread.php?tid=51&pid=298#pid298

Thanks! It works.

I have another question.
I want to get "send fixed value" data from object when i click on element.
I know that to know the object, the code is el.data("object"), and for status object, el.data("status-object"), but i don't know others.

Is there any documentation about this?

Thanks


RE: Custom JavaScript examples - admin - 30.04.2019

Fixed value is not stored in data attributes. Why do you need this feature?


RE: Custom JavaScript examples - DGrandes - 30.04.2019

(30.04.2019, 11:59)admin Wrote: Fixed value is not stored in data attributes. Why do you need this feature?

For the same example that I explained before. 
I have seen that by modifying the example code for dimming lights, I can use it for my case. But I wanted to make a generic code, because the same object is used for many actions. I wanted to put the sending value in "send fixed value" in each object and take it in JS.



The button's to control the volume are in the LM visualisation, and i the solution that you give me, I have to create a JS to simulate the push button (1 on press, 0 on release) too.


RE: Custom JavaScript examples - admin - 30.04.2019

In visualization parameters you can set the button to work in start-stop mode: send 1 on press and 0 on release.


RE: Custom JavaScript examples - DGrandes - 30.04.2019

(30.04.2019, 14:04)admin Wrote: In visualization parameters you can set the button to work in start-stop mode: send 1 on press and 0 on release.


Ok, thanks!

I didn't know it  Confused