mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-18 07:44:51 +00:00
31e7dbf020
* add "delayed" option to tm-focus-selector message this delays the focussing for the time of the animation duration if delayed="yes" or delayed="true" this is useful when navigating the story river up and down with keyboard shortcuts and the shortcuts focus the title input if a navigated tiddler is in edit mode -> navigation doesn't jump but stays smooth * Update rootwidget.js * Update WidgetMessage_ tm-focus-selector.tid * add preventScroll="true" tip
82 lines
2.5 KiB
JavaScript
82 lines
2.5 KiB
JavaScript
/*\
|
|
title: $:/core/modules/startup/rootwidget.js
|
|
type: application/javascript
|
|
module-type: startup
|
|
|
|
Setup the root widget and the core root widget handlers
|
|
|
|
\*/
|
|
(function(){
|
|
|
|
/*jslint node: true, browser: true */
|
|
/*global $tw: false */
|
|
"use strict";
|
|
|
|
// Export name and synchronous status
|
|
exports.name = "rootwidget";
|
|
exports.platforms = ["browser"];
|
|
exports.after = ["startup"];
|
|
exports.before = ["story"];
|
|
exports.synchronous = true;
|
|
|
|
exports.startup = function() {
|
|
// Install the modal message mechanism
|
|
$tw.modal = new $tw.utils.Modal($tw.wiki);
|
|
$tw.rootWidget.addEventListener("tm-modal",function(event) {
|
|
$tw.modal.display(event.param,{variables: event.paramObject, event: event});
|
|
});
|
|
// Install the notification mechanism
|
|
$tw.notifier = new $tw.utils.Notifier($tw.wiki);
|
|
$tw.rootWidget.addEventListener("tm-notify",function(event) {
|
|
$tw.notifier.display(event.param,{variables: event.paramObject});
|
|
});
|
|
// Install the copy-to-clipboard mechanism
|
|
$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(event.paramObject);
|
|
}
|
|
});
|
|
// Install the scroller
|
|
$tw.pageScroller = new $tw.utils.PageScroller();
|
|
$tw.rootWidget.addEventListener("tm-scroll",function(event) {
|
|
$tw.pageScroller.handleEvent(event);
|
|
});
|
|
var fullscreen = $tw.utils.getFullScreenApis();
|
|
if(fullscreen) {
|
|
$tw.rootWidget.addEventListener("tm-full-screen",function(event) {
|
|
var fullScreenDocument = event.event ? event.event.target.ownerDocument : document;
|
|
if(event.param === "enter") {
|
|
fullScreenDocument.documentElement[fullscreen._requestFullscreen](Element.ALLOW_KEYBOARD_INPUT);
|
|
} else if(event.param === "exit") {
|
|
fullScreenDocument[fullscreen._exitFullscreen]();
|
|
} else {
|
|
if(fullScreenDocument[fullscreen._fullscreenElement]) {
|
|
fullScreenDocument[fullscreen._exitFullscreen]();
|
|
} else {
|
|
fullScreenDocument.documentElement[fullscreen._requestFullscreen](Element.ALLOW_KEYBOARD_INPUT);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
// If we're being viewed on a data: URI then give instructions for how to save
|
|
if(document.location.protocol === "data:") {
|
|
$tw.rootWidget.dispatchEvent({
|
|
type: "tm-modal",
|
|
param: "$:/language/Modals/SaveInstructions"
|
|
});
|
|
}
|
|
};
|
|
|
|
})();
|