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-05-05 16:06:24 +00:00
|
|
|
exports.after = ["load-modules"];
|
2014-05-05 14:25:51 +00:00
|
|
|
exports.before = ["story"];
|
2014-05-05 13:41:46 +00:00
|
|
|
exports.synchronous = true;
|
|
|
|
|
|
|
|
var widget = require("$:/core/modules/widgets/widget.js");
|
|
|
|
|
|
|
|
exports.startup = function() {
|
|
|
|
// Create a root widget for attaching event handlers. By using it as the parentWidget for another widget tree, one can reuse the event handlers
|
|
|
|
$tw.rootWidget = new widget.widget({
|
|
|
|
type: "widget",
|
|
|
|
children: []
|
|
|
|
},{
|
|
|
|
wiki: $tw.wiki,
|
|
|
|
document: document
|
|
|
|
});
|
|
|
|
// Install the modal message mechanism
|
|
|
|
$tw.modal = new $tw.utils.Modal($tw.wiki);
|
|
|
|
$tw.rootWidget.addEventListener("tw-modal",function(event) {
|
|
|
|
$tw.modal.display(event.param);
|
|
|
|
});
|
|
|
|
// Install the notification mechanism
|
|
|
|
$tw.notifier = new $tw.utils.Notifier($tw.wiki);
|
|
|
|
$tw.rootWidget.addEventListener("tw-notify",function(event) {
|
|
|
|
$tw.notifier.display(event.param);
|
|
|
|
});
|
|
|
|
// Install the scroller
|
|
|
|
$tw.pageScroller = new $tw.utils.PageScroller();
|
|
|
|
$tw.rootWidget.addEventListener("tw-scroll",function(event) {
|
|
|
|
$tw.pageScroller.handleEvent(event);
|
|
|
|
});
|
|
|
|
// Install the save action handlers
|
|
|
|
$tw.rootWidget.addEventListener("tw-save-wiki",function(event) {
|
|
|
|
$tw.syncer.saveWiki({
|
|
|
|
template: event.param,
|
|
|
|
downloadType: "text/plain"
|
|
|
|
});
|
|
|
|
});
|
|
|
|
$tw.rootWidget.addEventListener("tw-auto-save-wiki",function(event) {
|
|
|
|
$tw.syncer.saveWiki({
|
|
|
|
method: "autosave",
|
|
|
|
template: event.param,
|
|
|
|
downloadType: "text/plain"
|
|
|
|
});
|
|
|
|
});
|
|
|
|
$tw.rootWidget.addEventListener("tw-download-file",function(event) {
|
|
|
|
$tw.syncer.saveWiki({
|
|
|
|
method: "download",
|
|
|
|
template: event.param,
|
|
|
|
downloadType: "text/plain"
|
|
|
|
});
|
|
|
|
});
|
2014-08-01 15:52:12 +00:00
|
|
|
var fullscreen = $tw.utils.getFullScreenApis();
|
2014-08-03 11:35:53 +00:00
|
|
|
if(fullscreen) {
|
|
|
|
$tw.rootWidget.addEventListener("tw-full-screen",function(event) {
|
|
|
|
if(document[fullscreen._fullscreenElement]) {
|
|
|
|
document[fullscreen._exitFullscreen]();
|
|
|
|
} else {
|
|
|
|
document.documentElement[fullscreen._requestFullscreen](Element.ALLOW_KEYBOARD_INPUT);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-05-05 13:41:46 +00:00
|
|
|
// 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: "tw-modal",
|
|
|
|
param: "$:/language/Modals/SaveInstructions"
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
})();
|