diff --git a/core/modules/startup/rootwidget.js b/core/modules/startup/rootwidget.js index 84756d11b..bf96c6fbd 100644 --- a/core/modules/startup/rootwidget.js +++ b/core/modules/startup/rootwidget.js @@ -34,6 +34,19 @@ exports.startup = function() { $tw.rootWidget.addEventListener("tm-copy-to-clipboard",function(event) { $tw.utils.copyToClipboard(event.param); }); + // Install the tm-focus-selector message + $tw.rootWidget.addEventListener("tm-focus-selector",function(event) { + var selector = event.param || "", + element; + try { + element = document.querySelector(selector); + } catch(e) { + console.log("Error in selector: ",selector) + } + if(element && element.focus) { + element.focus(); + } + }); // Install the scroller $tw.pageScroller = new $tw.utils.PageScroller(); $tw.rootWidget.addEventListener("tm-scroll",function(event) { diff --git a/editions/tw5.com/tiddlers/messages/WidgetMessage_ tm-focus-selector.tid b/editions/tw5.com/tiddlers/messages/WidgetMessage_ tm-focus-selector.tid new file mode 100644 index 000000000..dc41ad393 --- /dev/null +++ b/editions/tw5.com/tiddlers/messages/WidgetMessage_ tm-focus-selector.tid @@ -0,0 +1,12 @@ +caption: tm-focus-selector +created: 20190628162542132 +modified: 20190628162542132 +tags: Messages +title: WidgetMessage: tm-focus-selector +type: text/vnd.tiddlywiki + +The `tm-focus-selector` message sets the focus to the DOM element identified by the selector in the `param` parameter. + +|!Name |!Description | +|param |Selector identifying the DOM element to be focussed | +