[tw5] Re: How do I periodically update specific page elements?

2018-09-17 Thread Lost Admin
Hi Mat,

It would certainly be possible to do so but, I agree with what Jed said, if 
the macro gets called multiple times it will create multiple instances of 
the timer event. This is probably not what what you want (and certainly not 
what I want).

The relevant bit of code (from above) that creates the timer event is this 
...

setInterval(function() {
  /* Put your code here, it gets triggered every 30 milliseconds (5 
minutes) */
   }, 30); /* 30 for 5 minutes */

Jed had also suggested (in an earlier thread) that it would probably be 
better to put it into a startup module. I'll be figuring out how to create 
a startup module and moving the logic there. If I have time, I'll figure 
out how to add to the settings so that people can define the trigger period 
and class name.

On Sunday, September 16, 2018 at 4:47:15 PM UTC-4, Mat wrote:
>
> @Lost Admin
>
> This is of great interest for a thing I'm working on for TWederation, 
> hopefully soon to be published. As you may know Jed has built a special 
> server (Bob) and also a plugin (TWederBob) that enables a wiki to fetch 
> tiddlers from the remote server. I would like for this fetching (an action 
> widget) to trigger periodically.
>
> Would it be possible to use your creation for that? I.e to trigger an 
> action widget at set time intervals?
>
> <:-)
>

On Monday, September 17, 2018 at 8:37:10 AM UTC-4, Jed Carty wrote:
>
> The biggest problem I see with a macro based solution like this is that it 
> may get called multiple times (and start multiple timers that all do the 
> same thing) because it runs unconditionally when rendered and nothing 
> removes the setInterval.
>>
>>
> I think that a much better solution would be to make a startup module that 
> starts a background daemon that will run a set of action widgets at 
> configurable intervals. It shouldn't be too difficult to make, if I have 
> the time I will try and put something together.
>

I agree. That's my next step. 

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to tiddlywiki+unsubscr...@googlegroups.com.
To post to this group, send email to tiddlywiki@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/977a8df1-d1ac-4baf-9db7-1a4fd3507cad%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[tw5] Re: How do I periodically update specific page elements?

2018-09-16 Thread Mat
@Lost Admin

This is of great interest for a thing I'm working on for TWederation, 
hopefully soon to be published. As you may know Jed has built a special 
server (Bob) and also a plugin (TWederBob) that enables a wiki to fetch 
tiddlers from the remote server. I would like for this fetching (an action 
widget) to trigger periodically.

Would it be possible to use your creation for that? I.e to trigger an 
action widget at set time intervals?

<:-)

>

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to tiddlywiki+unsubscr...@googlegroups.com.
To post to this group, send email to tiddlywiki@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/98751d9d-d1bd-4afd-bb3a-277efb62e0f9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[tw5] Re: How do I periodically update specific page elements?

2018-09-16 Thread Lost Admin
After much fiddling, I have a working update macro.

/*\
title: $:/macros/ek/imageupdate.js
type: application/javascript
module-type: macro

embed images with class='u5m'
put <> at the bottom
all images with that class will be updated every 5 minutes

\*/
(function(){

/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";

exports.name = "imageupdate";

exports.params = [];

/*
Run the macro
*/
exports.run = function() {

   setInterval(function() {
  var imgElements = document.getElementsByClassName('u5m');
  /* var srclist = ''; */
  for (var i = 0; i < imgElements.length; i++) {
 var img = imgElements[i];
 img.src = ( (img.src.indexOf('?') == -1) ? img.src : 
img.src.substr(0,img.src.indexOf('?')) ) + '?c=' + Math.random();
 /* srclist = srclist + " " + img.src; */
 }
 document.getElementById('iuon').innerHTML = 'Refreshed ' + Date(); /*+ 
"" + srclist; */
   }, 30); /* 30 for 5 minutes */

   /* for debugging, print the source list once */
   var imgElements = document.getElementsByClassName('u5m');
   var output = 'Img Urls:';
   for (var i = 0; i < imgElements.length; i++) {
  var img = imgElements[i];
  output = output + " " + img.src;
   }

   return 'Refreshed ' + Date() /* + output */ + '';
};

})();

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to tiddlywiki+unsubscr...@googlegroups.com.
To post to this group, send email to tiddlywiki@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/b7004d02-e992-43c5-a0fc-189486781df8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[tw5] Re: How do I periodically update specific page elements?

2018-09-16 Thread Lost Admin
I had at first thought of doing it by class name but I don't know how to 
insert a class name into:

[img[/path/to/file.png]]

is it as simple as

[img class=5min [/path/to/file.png]]

?

On Sunday, September 16, 2018 at 1:10:33 PM UTC-4, Jed Carty wrote:
>
> I think that the easiest way to do it would be to give each image a unique 
> class name, or each group that is supposed to be updated on a specific 
> interval the same class name, then use getElementsByClassName instead of by 
> tag.
>
> I think that an alternative method for doing this that may be a bit more 
> flexible for your future plans is to make a daemon process in a startup 
> module that triggers once ever n minutes and then runs a script then. The 
> startup actions in the core is an example and the trigger actions plugin I 
> made does a similar thing but the trigger is a change to a tiddler instead 
> of a timer.
>

My trigger actions plugin is here if you want it as a reference 
> https://ooktech.com/jed/ExampleWikis/TriggerActions/
> I am not sure if there is a way to use it directly. Eventually I need to 
> rewrite it using the same logic as the startup actions in the core, but it 
> works.
>
> If the data comes from server-side components that you can access than you 
> could use websockets to update it but that may take a bit more work. It 
> would give you much more control over how and when things up date though.
>

I will look into the startup action once I've got a macro working. That 
does sound like a better idea.

Websockets would be good, but that will require that I figure out how to 
make websockets work.

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to tiddlywiki+unsubscr...@googlegroups.com.
To post to this group, send email to tiddlywiki@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/ad2b2bb7-59ad-47c7-a6a3-7c7f2e35bb92%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[tw5] Re: How do I periodically update specific page elements?

2018-09-16 Thread Jed Carty
I think that the easiest way to do it would be to give each image a unique 
class name, or each group that is supposed to be updated on a specific 
interval the same class name, then use getElementsByClassName instead of by 
tag.

I think that an alternative method for doing this that may be a bit more 
flexible for your future plans is to make a daemon process in a startup 
module that triggers once ever n minutes and then runs a script then. The 
startup actions in the core is an example and the trigger actions plugin I 
made does a similar thing but the trigger is a change to a tiddler instead 
of a timer.

My trigger actions plugin is here if you want it as a 
reference https://ooktech.com/jed/ExampleWikis/TriggerActions/
I am not sure if there is a way to use it directly. Eventually I need to 
rewrite it using the same logic as the startup actions in the core, but it 
works.

If the data comes from server-side components that you can access than you 
could use websockets to update it but that may take a bit more work. It 
would give you much more control over how and when things up date though.

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to tiddlywiki+unsubscr...@googlegroups.com.
To post to this group, send email to tiddlywiki@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/3c061555-be67-456e-ab0e-c43ad61ee954%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.