This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Custom JavaScript examples
(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.
Reply
Hi,

Yes you could.

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

BR,

Erwin
Reply
Hi Erwing,
What is exactly the instruction?
Simply what you wrote
Thanks.
Reply
(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.
Reply
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
Reply
Thank you Erwin, I'll try.
Reply
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,
Reply
Can you explain what kind of task do you have?
Reply
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
Reply
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?
Reply
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
Reply
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!
Reply
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
Reply
(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
Reply
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/showthrea...298#pid298
Reply
(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/showthrea...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
Reply
Fixed value is not stored in data attributes. Why do you need this feature?
Reply
(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.
Reply
In visualization parameters you can set the button to work in start-stop mode: send 1 on press and 0 on release.
Reply
(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 
Reply


Forum Jump: