Include JS code

152 views
Skip to first unread message

Mohammad

unread,
Jul 5, 2018, 4:15:39 AM7/5/18
to TiddlyWiki
This may be redundant.

Is it possible to include this code in a Javascript tiddler and use it!


var ul = document.getElementsByClassName('incremental');
for (var i = 0; i < ul.length; i++) {
    ul[i].style.listStyleType = 'decimal';


}
var childlists = document.querySelectorAll(".incremental>li");
for (var i = 0; i < childlists.length; i++) {
    childlists[i].style.display = "none";
}
window.onkeydown = function (event) {
    var childlists = document.querySelectorAll(".incremental>li");
    var pos;

    //assigning appropirate value to pos
    for (var i = 0; i < childlists.length; i++) {

        if (childlists[i].style.display == "none") {

            pos = i;
            break;
        } else {
            pos = childlists.length ;
        }


    }
    // check whether pos is in the allowed interval
    // note that allowed interval is length of child array

    if (event.key == "ArrowRight") {

        if (pos<childlists.length) {
            childlists[pos].style.display = ""

        }

    }
    if (event.key == "ArrowLeft") {

        if (pos - 1 >= 0) {

            childlists[pos - 1].style.display = "none";
        }

    }
}



/Mohammad

PMario

unread,
Jul 5, 2018, 5:17:57 AM7/5/18
to TiddlyWiki
Hi Mohammad,

In short: No.

I think it would be easier, if you describe, what you want to achive. So we may have a solution, or could provide help.


more details:

Your code directly manipulates the "redered output" in the DOM and also keeps program state in the DOM. This is similar to what jQuery did some years ago. That's not the concept used by TW.

TiddlyWiki is built with a completely different concept in mind. Every time the tiddler store is changed, the output (DOM) is automatically rewritten by the core, if needed. So your program can and will be destroied at any time.

TiddlyWiki uses widgets to create and manipulate the rendered output.

have fun!
mario

Mohammad

unread,
Jul 5, 2018, 7:34:51 AM7/5/18
to TiddlyWiki
Hello Mario,

 Thank you for your reply!
I was playing with JavaScript and was curious to see how can I add JS code to Tiddlywiki.
I understood JS code are not allowed to directly interact with the DOM objects!

I appreciate if you introduce me some simple cases (tutorial) for learning how JS code can be included in TW.


/Mohammad

Mark S.

unread,
Jul 5, 2018, 10:54:41 AM7/5/18
to TiddlyWiki
Well, it can be used to write your own widgets, which I found really complicated and confusing, and not well-documented.

It's easier  to write your own javascript Macros or Filters. The easiest way to do that is to find a simple one (like the "now" macro) , clone it, and then modify it to use your own js code. The problem is that you will need various TW functions to get variable values, fields, etc. and you will probably have to go spelunking in the code to figure out what they are because they're not documented (if they are documented, it would be great to know where).

Coding was much easier in TWC. You could use jquery which was designed from the bottom up to be easy for coding. There's oceans of existing code out there that could be easily modified and plugged in. With TW5, not so much. I'm not sure what was gained by giving TW5 it's own tree, since the DOM based approach obviously worked in TWC.

-- Mark

Mark S.

unread,
Jul 5, 2018, 11:12:06 AM7/5/18
to TiddlyWiki
Here's a link to an interesting post on the subject by Eric S.

https://groups.google.com/forum/#!topic/tiddlywiki/M6wADVDjyTE

-- Mark

Jeremy Ruston

unread,
Jul 5, 2018, 11:14:46 AM7/5/18
to tiddl...@googlegroups.com


On 5 Jul 2018, at 15:54, 'Mark S.' via TiddlyWiki <tiddl...@googlegroups.com> wrote:

I'm not sure what was gained by giving TW5 it's own tree, since the DOM based approach obviously worked in TWC.

Well, that’s 7 years of my life wasted!

But seriously, do you not see any advantages of TW5 over TWC? To me, the success of TW5 is that it possible to do so much more without resorting to JavaScript.

Best wishes

Jeremy

Mohammad

unread,
Jul 5, 2018, 11:34:45 AM7/5/18
to TiddlyWiki
Thank you Mark!
I actually do most the job with the current TW5 features and it is amazing in preparing semantic content.

Cheers
Mohammad

Mohammad

unread,
Jul 5, 2018, 11:40:28 AM7/5/18
to TiddlyWiki
Jeremy!

 I really appreciate your great work. I love TW5 and I use it in my daily work more than any other tools! We know you put a lot of time and distribute what you did free of charge and people use it some of them even don't know who brought this amazing tool to them.

One suggestion here is:
Could we have a tiddlywiki.com/documentation and lets interested developers/contributors to help? I know there is a lot of work to be done.(This is for learning purpose)

Thank you for all your help and efforts

/Mohammad

Mark S.

unread,
Jul 5, 2018, 12:58:28 PM7/5/18
to TiddlyWiki
There's lots of great stuff about TW5.

But the kit the user is given is incomplete compared to JS. If it was a complete kit, that would be one thing.  The string operations are anemic. No logic operators. Ahem, nothing for creating new tiddlers from regular expressions (#2963).

There's a post in the forum today where someone wants to sort by the *values* from a data tiddler. But there's no operator for extracting all values. You could extract them one by one, but then you couldn't then sort them. So, there's a whole class of aggregate functionality that is missing. Any time that you can only access a value one-by-one, there's no way to put that output back into a form that can be used by the filter-driven widgets.

In JS, you could aggregate the results into an array or object, and then sort them out. It's something that comes up all the time in coding. With JS, everything is possible, most things are intuitive, and there are reams of resources including full-blown books, tutorials, examples, etc.

So ... I don't understand. What exactly is gained by keeping the users at a distance from the actual JS ? Is there some sort of performance gain?

Thanks !
-- Mark

Jed Carty

unread,
Jul 5, 2018, 2:09:15 PM7/5/18
to TiddlyWiki
There is a huge usability gain, you don't need to know any javascript to make something new and useful with tiddlywiki. I made most of my earlier plugins that I still use before I knew any javascript.
If it were just a neat javascript page that you used javascript to make things in than I never would have played with it.
The reusability and simplicity of widgets is amazing, wikitext abstracts out a lot of the overhead to give only the parts that are specifically useful. Yes there are things that are missing but that isn't a downside of the approach, that just means we aren't done making everything yet.
Also there are huge gains in security, I would never put Bob online if it had inline javascript like tiddlywiki classic.

Yes, you can do less with vanilla tiddlywiki than you can with javascript, but you can do more with assembler than you can with javascript, but I am not going to write a web server in assembly despite the potential performance gains.

Mark S.

unread,
Jul 5, 2018, 2:32:22 PM7/5/18
to TiddlyWiki
I would say there's a usability loss.

As soon as you get beyond simple list loops, there's no clear way forward.

Also, there's tons of documentation on JS. Standard procedures and techniques.

Take a look at recent post https://groups.google.com/forum/#!topic/tiddlywiki/IpKqoJbs35c and explain how you would do that with the existing toolkit.

I don't understand the security reference. What will prevent potentially malicious users from inserting their own widgets, filters, or js macros?

The analogy with assembler doesn't really work. Assembler is a lot harder to use than javascript. Javascript is possibly a little harder than TW5-code, but it has massive support and almost none of the cul-de-sacs of TW5.


Thanks!

Jed Carty

unread,
Jul 5, 2018, 2:42:27 PM7/5/18
to TiddlyWiki
Perhaps I am unique, but it took me a much longer time to learn javascript than it did to learn wikitext, so I very much disagree that javascript is only a little harder than wikitext. And usability isn't functionality, so if a specific thing can be implemented isn't relevant to it. The things that you do in wikitext are not difficult to learn and there are only a few patterns to know to understand how wikitext and widgets work.

TonyM

unread,
Jul 5, 2018, 9:21:20 PM7/5/18
to TiddlyWiki
Folks,

Jed and Mark, I agree with your apparently conflicting positions here,  here is something I have realised recently.

TiddlyWiki is mostly designed to act on its own elements, tags, tiddlers, fields etc... and it does this in the way any "High Level" programming language does, it treats them as sets. We simply state the set of items we want to process and tell it what to do with every item in the set. It also supports responding to empty sets, or single member sets. Years ago when I was a programmer I remember using a high level report generator, it was very similar. This approach has fantastic simplification and productivity benefits.

I also understand where Mark is coming from. Much of how we understand the world is procedural, and while sets are part of it we are more familiar with steps, recipes, procedural language(s). There is a wealth of solutions in the JavaScript world to help solve real world problems. This is where Mark is right on that without the ability to include sophisticate logical manipulation or non set based procedural code we are loosing some functions, and cant leverage a lot of open source code. I may add that evans formula plugin goes a long way to fixing this while blending with TiddlyWikis approach.

I started a collaborative document anyone can edit in yammer at https://www.yammer.com/tiddlywiki/#/files/140794632 It aims to Document set and procedural code structures and how to use them in tiddlywiki. You know the primitives Sequence, iteration, selection decision, recursion etc...

Not withstanding the above, Last night, I realised the HTML tags <object> and <Embed> work without alteration in a Tiddler, and also realise tiddlywiki simply renders this as a html page. Now I could have a massive HTML only site with PHP and Java Script and a given html page will include what it needs to work including php and Javascript. I do not see why we could not do this inside a tiddler. The Scripts are external, the engine is external ie the PHP server are not inside the tiddler, but as far as the user is concerned they look like they are in the tiddlyWiki.  Just as an iframe does.

Then all we need is the ability to feed these html pages info found in tiddlywiki, and let these pages return results we can store/act on in tiddlywiki, people with more skills that me could create java and php "modules" you add to these external html pages to permit these interactions. And some support plugins/widgets in tiddlywiki.

In these external solutions we should be able to use all the java-script code we want.

Now, I expect rightly that Jeremy would say here he does not want to break the single file mode of Tiddlywiki, however even Jeremy would not consider a hyperlink or iframe as breaking the single file model, I think he would understand an hope he responds here, that accessing external resources is part of tiddlywiki, and they do not live in the single file. In fact in the upcoming release he has done something that will help with using of other tiddlywikis external resources, a single tiddler.

Please tell me if this is more than a thought bubble?

Regards
Tony

passingby

unread,
Jul 5, 2018, 11:05:58 PM7/5/18
to TiddlyWiki


On Thursday, July 5, 2018 at 12:09:15 PM UTC-6, Jed Carty wrote:
There is a huge usability gain, you don't need to know any javascript to make something new and useful with tiddlywiki.

I was a hobby level programmer in javascript. I remember many years ago in TWC using Eric Schulman's code and developer tools I could do almost any kind of processing on data and render it in any way I felt like. 
I ll be nothing but honest that I have never felt like that with TW5. Many times I tried and gave up in frustration simply because I could not find either tools or documentation like I did in TWC. 

Just a few months ago I once again started to do some hacking, trying to create a simple quiz. I was out of job and was preparing for some multiple choice exam and I wanted something simple but efficient. Believe it or not after spending almost a week I started wondering if the whole effort was worth it at all. And then I gave it up and just created hand written flash cards. Whats the point? When one has put in a whole long weekend and neglected one's health and given it space in one's mind and still does not reach anywhere one feel one has made a wrong decision and wasted precious time. 

People who are creating new things in TW5 are doing it because many of them have a good programming background. Many of them are exceptionally creative and they have time. TW5 will never become a tool that common people will use. Its too complicated as well as restrictive. 

 
 
If it were just a neat javascript page that you used javascript to make things in than I never would have played with it.

If you call a javascript page just a neat thing, then TW5 is also just a neat thing. I do not understand why you find javascript as something any less valuable. It might be with you that it does not attract you, but huge part of internet runs on javascript.

 
Yes, you can do less with vanilla tiddlywiki than you can with javascript, but you can do more with assembler than you can with javascript, but I am not going to write a web server in assembly despite the potential performance gains.

That's a completely wrong comparison. I think you do not know Javascript enough. 

TonyM

unread,
Jul 5, 2018, 11:50:25 PM7/5/18
to TiddlyWiki
Passingby,

I empathise with your feelings, this happened to me initially, feeling also that TW5 "had too long a learning curve", rather than the quicker "steeper" learning curve (common misuse of the "learning curve" phrase avoided here, the horizontal on this curve is time, and the vertical knowledge, its steeper if you can acquire the knowledge quicker)

The truth is after perhaps 100s of hours I am running smooth and quickly with occasional barriers. The capabilities are now almost limitless.

100s of hours is not good enough, of course, however there are many activities and discussions working to reduce the time to learn and adopt tiddlywiki, thus increasing the slope of learning curve.

TW5, as did TWC is going through an evolutionary process. In time not only will enthusiasts adopt it, but the every person.

Regards
Tony

Mohammad

unread,
Jul 6, 2018, 12:09:52 AM7/6/18
to TiddlyWiki
Passingby!
Tony!

I agree there is limited documentation on TW5 and some of them in tiddlywiki.com are not good for learning purpose and may target developer or advanced users.
If we could improve the documentation, then I think the learning curve will be short.

For the Javascript and TWC, I think for many users (non-programmer) doing things with JS is really hard. TW5 facilitates many tasks using a high level yet simple widgets. I agree it is not complete and there are shortcomings, but its simplicity is not comparable with JS for non-programmer.

All in all what we need is good resource kit, good documentation, better collaboration

/Mohammad
Reply all
Reply to author
Forward
0 new messages