Refreshing and timeout for a widget (to import a textfile when clicking it in an IFrame.)

85 views
Skip to first unread message

Jan

unread,
Jul 21, 2019, 10:05:01 AM7/21/19
to TiddlyWiki
Hello,
Mark and Jed helped me to build a widget, which shall directly import a textfile with one click.
The construction is quite complex
The first function detects the click on an Iframe and the second imports the URL by XMLHttpRequest.
On the backend a php writes the clicked address into a textfile which ist read by the second function.

already worked with two flaws this workes with two flaws.
1. I works just once, so the widget shoud refresh.
2. Because the serverside appears to be slower I had to weave in a one second timeout before executing the XMLHttpRequest.

My attempt is below and on szenio.de/test you can see the working proof which suffers from the delay of the server and thus points to the click before. 

It would be great if you could help me on this issue.

Ciao Jan

/*\
title: $:/core/modules/macros/urltext.js
type: application/javascript
module-type: macro
Makro, das eine Textdatei darstellt
\*/

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

/*
Information about this macro
*/
   exports.name = "geturl";
   exports.params = [
      {name: "url"}
   ];

/*
Run the macro
*/
   exports.run = function(url) {
var monitor = setInterval(function(){
    var elem = document.activeElement;
    if(elem && elem.tagName == 'IFRAME'){
    setTimeout(TimeoutFunction, 1000);
   clearInterval(monitor);
   }
   }, 100);
   };
  function TimeoutFunction(url) {
  var client = new XMLHttpRequest();
      client.open('GET', url, false);
       client.setRequestHeader('Content-type', 'Content-Type: text/html; charset=ISO-8859-1');
      client.onreadystatechange = function() {
    if (client.readyState == 4 && client.status == 200)
    {
      var urltext = unescape(client.responseText);
      var fields = {title: '$:/Temp/URL', text: urltext}
       $tw.wiki.addTiddler(new $tw.Tiddler(fields))
    }
    }
   client.send();
}
})();



Jan

unread,
Jul 21, 2019, 2:36:23 PM7/21/19
to TiddlyWiki
Hi!
The question is just about refreshing now, the timeout-issue is solved by the code below.

-A new question arises: How can I call a modal in a widget?
-How do I refresh this widget?

You can see the mechanism working go to Szenio.de/Test

Cheers Jan

/*\
title: $:/core/modules/macros/urltext.js
type: application/javascript
module-type: macro
Makro, das eine Textdatei darstellt
\*/

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

/*
Information about this macro
*/
   exports.name
 = "geturl";
   exports.params = [
      {name: "url"}
   ];

/*
Run the macro
*/
   exports.run = function() {
   var monitor = setInterval(function(){
    var elem = document.activeElement;
    if(elem && elem.tagName == 'IFRAME'){
    setTimeout(TimeoutFunction, 300);
   clearInterval(monitor);
   }
   }, 100);
   };
  function TimeoutFunction(url) {
      var client = new XMLHttpRequest();client.open('GET', "handover.txt", false);
      client.setRequestHeader('Content-type', 'Content-Type: text/html; charset=ISO-8859-1');
      client.onreadystatechange = function() {
    if (client.readyState == 4 && client.status == 200)
    {
      var urltext = unescape(client.responseText);
      var fields = {title: '$:/Temp/URL', text: client.responseText}
       $tw.wiki.addTiddler(new $tw.Tiddler(fields))
    }
    }
   client.send();
}
})();



Am 21.07.2019 um 16:04 schrieb Jan:

TonyM

unread,
Jul 21, 2019, 9:56:55 PM7/21/19
to TiddlyWiki
Jan

Not sure I can help until you get this mechanism working but I am watching.

Regards
Tony

Jan

unread,
Jul 22, 2019, 7:10:43 AM7/22/19
to tiddl...@googlegroups.com
Hi Tony, Hi everyone,
The problems seem to be solved. You can test the mechanism if your interested.
--
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+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/12bdbcaa-d331-498e-9f71-944c88050e7e%40googlegroups.com.

TonyM

unread,
Jul 22, 2019, 8:37:26 PM7/22/19
to TiddlyWiki
Jan,

http://szenio.de/Test/ thows an error for me. Ask if you want more details.

Thus I can not see how to test it.

I copied you above code to a tiddler called 

$:/core/modules/macros/urltext.js

and set
type: application/javascript
module-type: macro

But I do not know how to activate/use it, especially since I can't access your demo.

Regards
Tony
To unsubscribe from this group and stop receiving emails from it, send an email to tiddl...@googlegroups.com.

Jan

unread,
Jul 22, 2019, 8:49:50 PM7/22/19
to tiddl...@googlegroups.com
Hi Tony,
That is strange but good to know. I have not seen red screens for quite a while. (This means for one and a half days ;-) I tidied it up a a little to avoid that it immediately calls back my server at startup.
So please try again. The klick to import mechanism is almost ready.

Thanks for testing.
Jan
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/93a9b3f3-9044-469a-abe7-2d359090a65f%40googlegroups.com.

TonyM

unread,
Jul 22, 2019, 9:20:07 PM7/22/19
to TiddlyWiki
Jan,

I am really excited however as I sad before "But I do not know how to activate/use it" could you please provide a short description how to use it?

Tony

Jan

unread,
Jul 23, 2019, 7:07:12 PM7/23/19
to tiddl...@googlegroups.com
Hi Tony,
I hope the Wiki does not throw any more errors( at least you didn#t mention).
To post to the list you need to press the button in the Tiddler called Posttester.
Scan the QR code with your phone, I hope the rest is intuitive.
I will see wether you manage to post something.
THe serverside consists of three PHPs,  I still have to do some houskeeping because you cannot import the text of tiddlers with spaces...
Have you managed to install the PHPs for exporting entire Tiddlers I mailed you?

Jan
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/1de0b60c-b68b-4e06-ac3f-2d1fb2f4afb0%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages