> > > > On Wed, Feb 13, 2019 at 5:06 PM Simon Huber <hypnotize...@gmail.com > <javascript:>> wrote: > >> >>> >>> On Wed, Feb 13, 2019 at 3:56 PM Simon Huber <hypnotize...@gmail.com> >>> wrote: >>> >>>> Hi stefano, >>>> >>>> from within the render method it should be possible to access the >>>> parent if I recall correctly, >>>> >>>> could you post a bit of code to work with? >>>> >>>> >>> Well, it is all very rudimentary still, but the idea is the following: >>> In my plugin I import the library and instantiate it, then create the >>> div to pass to it. Then I call the constructor of my library's main object >>> with the div as its argument: >>> '''' >>> (function(){ >>> /*jslint node: true, browser: true */ >>> /*global $tw: false */ >>> "use strict"; >>> var Widget = require("$:/core/modules/widgets/widget.js").widget; >>> >>> >>> >> Stefano, here you should be able to get dimensions of the parent domnode >> by >> >> var rect = this.parentDomNode.getBoundingClientRect(); >> >> for example ... >> >> var width = rect.width; >> >> > Brilliant! > It works like a charm. > > > One day I will understand TW's data model and its relationship to the > DOM... > But that day is still far away. >
You're welcome While trying and hacking on widgets myself I think I understand the basic model, which looks like this (anybody, correct me if I'm wrong) : * all the widgets are layed out in a tree structure, like the DOM * the widget tree starts with the root widget (which is accessible through $tw.rootWidget) ROOTWIDGET first child widget child widget of first child widget ... /child widget of first child widget /first child widget sibling widget of first child widget ... /sibling widget of first child widget /ROOTWIDGET * if I make a widget and it's rendered, it will be somewhere within this tree * I can access its parent widget from within my widget with this parentWidget * I can walk up the tree until the root widget is reached (this.parentWidget.parentWidget.parentWidget ... ) * a widget that makes child widgets through this.makeChildWidgets() - most widgets call it in the execute method at the bottom I believe - has an accessible "children" array which contains its child widgets (this.parentWidget.children / this.children) * the widgets in the tiddlywiki core follow a "rule" when they create a dom node. they push that created node to the "this.domNodes" array by this.domNodes.push(myDomNode) - so that domNode becomes accessible "from outside" by walking the widget-tree up/down this is some basic information which I gathered by searching, reading and trying ... not everything must be necessarily correct, anyone, just correct me where I think we need to add some simple explanations somewhere all the best -- 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 tiddlywikidev+unsubscr...@googlegroups.com. To post to this group, send email to tiddlywikidev@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/3dfc75ed-bb34-4256-8988-40ca216a659b%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.