2014-05-05 13:41:46 +00:00
|
|
|
/*\
|
|
|
|
title: $:/core/modules/startup/rootwidget.js
|
|
|
|
type: application/javascript
|
|
|
|
module-type: startup
|
|
|
|
|
2014-05-05 14:25:51 +00:00
|
|
|
Setup the root widget and the core root widget handlers
|
2014-05-05 13:41:46 +00:00
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
// Export name and synchronous status
|
|
|
|
exports.name = "rootwidget";
|
|
|
|
exports.platforms = ["browser"];
|
2014-08-13 19:20:58 +00:00
|
|
|
exports.after = ["startup"];
|
2014-05-05 14:25:51 +00:00
|
|
|
exports.before = ["story"];
|
2014-05-05 13:41:46 +00:00
|
|
|
exports.synchronous = true;
|
|
|
|
|
|
|
|
exports.startup = function() {
|
2023-06-13 09:35:55 +00:00
|
|
|
// Install the HTTP client event handler
|
|
|
|
$tw.httpClient = new $tw.utils.HttpClient();
|
|
|
|
var getPropertiesWithPrefix = function(properties,prefix) {
|
|
|
|
var result = Object.create(null);
|
|
|
|
$tw.utils.each(properties,function(value,name) {
|
|
|
|
if(name.indexOf(prefix) === 0) {
|
|
|
|
result[name.substring(prefix.length)] = properties[name];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
$tw.rootWidget.addEventListener("tm-http-request",function(event) {
|
|
|
|
var params = event.paramObject || {};
|
|
|
|
$tw.httpClient.initiateHttpRequest({
|
|
|
|
wiki: event.widget.wiki,
|
|
|
|
url: params.url,
|
|
|
|
method: params.method,
|
|
|
|
body: params.body,
|
2023-07-17 11:15:20 +00:00
|
|
|
binary: params.binary,
|
2024-05-30 16:53:22 +00:00
|
|
|
useDefaultHeaders: params.useDefaultHeaders,
|
2023-06-13 09:35:55 +00:00
|
|
|
oncompletion: params.oncompletion,
|
|
|
|
onprogress: params.onprogress,
|
|
|
|
bindStatus: params["bind-status"],
|
|
|
|
bindProgress: params["bind-progress"],
|
|
|
|
variables: getPropertiesWithPrefix(params,"var-"),
|
|
|
|
headers: getPropertiesWithPrefix(params,"header-"),
|
|
|
|
passwordHeaders: getPropertiesWithPrefix(params,"password-header-"),
|
|
|
|
queryStrings: getPropertiesWithPrefix(params,"query-"),
|
2024-06-03 18:20:12 +00:00
|
|
|
passwordQueryStrings: getPropertiesWithPrefix(params,"password-query-"),
|
|
|
|
basicAuthUsername: params["basic-auth-username"],
|
|
|
|
basicAuthUsernameFromStore: params["basic-auth-username-from-store"],
|
|
|
|
basicAuthPassword: params["basic-auth-password"],
|
|
|
|
basicAuthPasswordFromStore: params["basic-auth-password-from-store"]
|
2023-06-13 09:35:55 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
$tw.rootWidget.addEventListener("tm-http-cancel-all-requests",function(event) {
|
|
|
|
$tw.httpClient.cancelAllHttpRequests();
|
|
|
|
});
|
2014-05-05 13:41:46 +00:00
|
|
|
// Install the modal message mechanism
|
|
|
|
$tw.modal = new $tw.utils.Modal($tw.wiki);
|
2014-08-28 20:43:44 +00:00
|
|
|
$tw.rootWidget.addEventListener("tm-modal",function(event) {
|
2018-11-18 20:57:04 +00:00
|
|
|
$tw.modal.display(event.param,{variables: event.paramObject, event: event});
|
2014-05-05 13:41:46 +00:00
|
|
|
});
|
2020-11-23 17:06:24 +00:00
|
|
|
$tw.rootWidget.addEventListener("tm-show-switcher",function(event) {
|
|
|
|
$tw.modal.display("$:/core/ui/SwitcherModal",{variables: event.paramObject, event: event});
|
2021-05-30 18:20:17 +00:00
|
|
|
});
|
2014-05-05 13:41:46 +00:00
|
|
|
// Install the notification mechanism
|
|
|
|
$tw.notifier = new $tw.utils.Notifier($tw.wiki);
|
2014-08-28 20:43:44 +00:00
|
|
|
$tw.rootWidget.addEventListener("tm-notify",function(event) {
|
2016-07-03 13:55:41 +00:00
|
|
|
$tw.notifier.display(event.param,{variables: event.paramObject});
|
2014-05-05 13:41:46 +00:00
|
|
|
});
|
2017-12-15 15:08:18 +00:00
|
|
|
// Install the copy-to-clipboard mechanism
|
|
|
|
$tw.rootWidget.addEventListener("tm-copy-to-clipboard",function(event) {
|
2024-05-29 14:06:33 +00:00
|
|
|
$tw.utils.copyToClipboard(event.param,{
|
2024-05-30 16:58:07 +00:00
|
|
|
successNotification: event.paramObject && event.paramObject.successNotification,
|
|
|
|
failureNotification: event.paramObject && event.paramObject.failureNotification
|
2024-05-29 14:06:33 +00:00
|
|
|
});
|
2017-12-15 15:08:18 +00:00
|
|
|
});
|
2019-06-28 16:27:36 +00:00
|
|
|
// Install the tm-focus-selector message
|
|
|
|
$tw.rootWidget.addEventListener("tm-focus-selector",function(event) {
|
|
|
|
var selector = event.param || "",
|
2021-06-06 11:42:28 +00:00
|
|
|
element,
|
2023-05-06 10:54:54 +00:00
|
|
|
baseElement = event.event && event.event.target ? event.event.target.ownerDocument : document;
|
|
|
|
element = $tw.utils.querySelectorSafe(selector,baseElement);
|
2019-06-28 16:27:36 +00:00
|
|
|
if(element && element.focus) {
|
2019-08-06 12:12:21 +00:00
|
|
|
element.focus(event.paramObject);
|
2019-06-28 16:27:36 +00:00
|
|
|
}
|
|
|
|
});
|
2022-02-19 09:38:48 +00:00
|
|
|
// Install the tm-rename-tiddler and tm-relink-tiddler messages
|
|
|
|
var makeRenameHandler = function(method) {
|
|
|
|
return function(event) {
|
|
|
|
var options = {},
|
|
|
|
paramObject = event.paramObject || {},
|
|
|
|
from = paramObject.from || event.tiddlerTitle,
|
|
|
|
to = paramObject.to;
|
|
|
|
options.dontRenameInTags = (paramObject.renameInTags === "false" || paramObject.renameInTags === "no") ? true : false;
|
|
|
|
options.dontRenameInLists = (paramObject.renameInLists === "false" || paramObject.renameInLists === "no") ? true : false;
|
|
|
|
$tw.wiki[method](from,to,options);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
$tw.rootWidget.addEventListener("tm-rename-tiddler",makeRenameHandler("renameTiddler"));
|
|
|
|
$tw.rootWidget.addEventListener("tm-relink-tiddler",makeRenameHandler("relinkTiddler"));
|
2014-05-05 13:41:46 +00:00
|
|
|
// Install the scroller
|
|
|
|
$tw.pageScroller = new $tw.utils.PageScroller();
|
2014-08-28 20:43:44 +00:00
|
|
|
$tw.rootWidget.addEventListener("tm-scroll",function(event) {
|
2014-05-05 13:41:46 +00:00
|
|
|
$tw.pageScroller.handleEvent(event);
|
|
|
|
});
|
2014-08-01 15:52:12 +00:00
|
|
|
var fullscreen = $tw.utils.getFullScreenApis();
|
2014-08-03 11:35:53 +00:00
|
|
|
if(fullscreen) {
|
2014-08-28 20:43:44 +00:00
|
|
|
$tw.rootWidget.addEventListener("tm-full-screen",function(event) {
|
2019-03-09 17:09:34 +00:00
|
|
|
var fullScreenDocument = event.event ? event.event.target.ownerDocument : document;
|
2018-08-14 21:53:53 +00:00
|
|
|
if(event.param === "enter") {
|
2019-03-09 17:09:34 +00:00
|
|
|
fullScreenDocument.documentElement[fullscreen._requestFullscreen](Element.ALLOW_KEYBOARD_INPUT);
|
2018-08-14 21:53:53 +00:00
|
|
|
} else if(event.param === "exit") {
|
2019-03-09 17:09:34 +00:00
|
|
|
fullScreenDocument[fullscreen._exitFullscreen]();
|
2014-08-03 11:35:53 +00:00
|
|
|
} else {
|
2019-03-09 17:09:34 +00:00
|
|
|
if(fullScreenDocument[fullscreen._fullscreenElement]) {
|
|
|
|
fullScreenDocument[fullscreen._exitFullscreen]();
|
2018-08-14 21:53:53 +00:00
|
|
|
} else {
|
2019-03-09 17:09:34 +00:00
|
|
|
fullScreenDocument.documentElement[fullscreen._requestFullscreen](Element.ALLOW_KEYBOARD_INPUT);
|
2021-05-30 18:20:17 +00:00
|
|
|
}
|
2014-08-03 11:35:53 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-05-05 13:41:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
})();
|