[TW5] How get target tiddler by title in widget

104 views
Skip to first unread message

Andrew

unread,
Feb 5, 2016, 8:01:46 PM2/5/16
to TiddlyWikiDev
Currently I'm reworking a format widget that modifies text in edit mode. The widgets I'm modifying use the following to get selected text but it means the ID had to be added to a core tiddler. I'd like to select the element by title instead of a Id if possible so that core tiddlers don't have to be overridden?

txt=document.getElementById("myTextarea");
var startPos = txt.selectionStart;
var endPos = txt.selectionEnd;
var listtext= txt.value.substr(startPos, endPos -startPos);

Maybe with something like the following. I really wish I could figure this out:

var tiddler = this.getAttribute("tiddler",this.getVariable("currentTiddler"));

Or maybe some kind of getTargetElement by title? Help.

Jed Carty

unread,
Feb 7, 2016, 8:36:14 AM2/7/16
to TiddlyWikiDev
I am not certain what you need. If you need access to the tiddler in the sense of the information the wiki uses than you can use this:

When you call the widget use this:

<$widget tiddler='Some Tiddler Name'/>

And have this in the code:

var tiddler = this.getAttribute("tiddler", this.getVariable('currentTiddler'));

then you can have this to get the text of the tiddler:

var tiddlerObject = this.getTiddler(tiddler);
if (tiddlerObject) {
tiddlerText = tiddlerObject.fields.text;

//Whatever your code is here

}

Tobias Beer

unread,
Feb 7, 2016, 11:17:13 AM2/7/16
to TiddlyWikiDev
Hi Andrew,

Unfortunately, I would argue the current TiddlySophy unduly neglects the DOM.

We very much need ways to do traversals and have selectors address DOM elements,
so as to be able to act upon an element, e.g. a text-field.

It's not "a tiddler" you wish to address but a rendered html element being a textarea.

Best wishes,

Tobias.

BJ

unread,
Feb 8, 2016, 2:16:46 AM2/8/16
to TiddlyWikiDev
you could do it like this:

        var element = window.focusedElement;
        if(element) {// only allow input[type=text]/textarea
            if (element.tagName === "TEXTAREA" ||(element.tagName === "INPUT" && element.type === "text")) {
                return element.value.substring(element.selectionStart,element.selectionEnd);
            }
        }

infurnoape

unread,
Feb 9, 2016, 8:00:34 AM2/9/16
to tiddly...@googlegroups.com
Thank you Jed, Tobias, and BJ,
I guess it is over my head. All of your suggestions may actually work but I cant figure out how to use them. In it's half unfinished state I was working on http://www.format.tiddlyspot.com if anyone would like to have a look. It has problems of overriding core tiddlers which I want to change but cant figure out how. I wish anyone could work on it directly.

Happy Connecting. Sent from my Sprint Samsung Galaxy S® 5
--
You received this message because you are subscribed to the Google Groups "TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywikide...@googlegroups.com.
To post to this group, send email to tiddly...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywikidev.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywikidev/7f44c313-8fd4-4049-8957-e9477af3da95%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

infurnoape

unread,
Feb 9, 2016, 8:14:42 AM2/9/16
to tiddly...@googlegroups.com
Sorry, the correct link 

BJ

unread,
Feb 10, 2016, 5:38:42 AM2/10/16
to TiddlyWikiDev
you can do it like this:

EditListWidget.prototype.myFunction= function (pre,post)  {
var dummy=ResetFind();
/* This function is for entries that are preceeded and followed by the entry */
    var txtarea = this.parentDomNode.getElementsByTagName("textarea")[0];
    var str=txtarea.value;

and change references from myFunction() to this.myFunction()

all the best

BJ

infurnoape

unread,
Feb 10, 2016, 8:51:46 AM2/10/16
to tiddly...@googlegroups.com
Thank you BJ. Well, I really don't know what I'm doing. Now it creates a bunch of fields with the letters of the title when I try to use bold or anything. I wish someone could just take this over.

BJ

unread,
Feb 10, 2016, 10:48:17 AM2/10/16
to TiddlyWikiDev

Hi Andrew,
sometimes we try to hard with programming and need to have a break, often I try to solve a problem without success for hours, then the next morning the answer comes to me immediately.

I will make some changes to you work and put it up on tiddyspot. - it looks it me like it is almost finished.

If you have a github account (or feel like having one) you could put your work into github which would allow myself and other to contribute easily to your work.

Cheers
BJ

infurnoape

unread,
Feb 10, 2016, 12:22:53 PM2/10/16
to tiddly...@googlegroups.com
I do have a github account but I am not familiar with how things work. You are right. I need to migrate everything to github. Thank you for taking an interest. Thank you again.

BJ

unread,
Feb 10, 2016, 1:24:33 PM2/10/16
to TiddlyWikiDev
there are some notes on how to setup github for a tiddlywiki plugin on http://tiddlywiki.com/dev - see tiddler
"Developing plugins using Node.js and GitHub"
some of my plugin are like this (but with addition build scripts),  see https://github.com/buggyj/TW5-nulleditor for an example

I have put you modified code here

http://bjformat.tiddlyspot.com/
Reply all
Reply to author
Forward
0 new messages