mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-12-30 20:10:28 +00:00
Refactoring more of startup.js into modules
This commit is contained in:
parent
519e1b4a44
commit
a0022a1cd6
25
boot/boot.js
25
boot/boot.js
@ -1783,24 +1783,37 @@ console.log(s.join(" "));
|
||||
return false;
|
||||
};
|
||||
|
||||
$tw.boot.isStartupTaskEligible = function(taskModule) {
|
||||
var t;
|
||||
// Check that the platform is correct
|
||||
/*
|
||||
Returns true if we are running on one platforms specified in a task modules `platforms` array
|
||||
*/
|
||||
$tw.boot.doesTaskMatchPlatform = function(taskModule) {
|
||||
var platforms = taskModule.platforms;
|
||||
if(platforms) {
|
||||
for(t=0; t<platforms.length; t++) {
|
||||
for(var t=0; t<platforms.length; t++) {
|
||||
if((platforms[t] === "browser" && !$tw.browser) || (platforms[t] === "node" && !$tw.node)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
$tw.boot.isStartupTaskEligible = function(taskModule) {
|
||||
var t;
|
||||
// Check that the platform is correct
|
||||
if(!$tw.boot.doesTaskMatchPlatform(taskModule)) {
|
||||
return false;
|
||||
}
|
||||
// Check that no other outstanding tasks must be executed before this one
|
||||
var name = taskModule.name,
|
||||
remaining = $tw.boot.remainingStartupModules;
|
||||
if(name) {
|
||||
for(t=0; t<remaining.length; t++) {
|
||||
if(remaining[t].before && remaining[t].before.indexOf(name) !== -1) {
|
||||
return false;
|
||||
var task = remaining[t];
|
||||
if(task.before && task.before.indexOf(name) !== -1) {
|
||||
if($tw.boot.doesTaskMatchPlatform(task)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -119,40 +119,6 @@ exports.startup = function() {
|
||||
downloadType: "text/plain"
|
||||
});
|
||||
});
|
||||
// Listen out for login/logout/refresh events in the browser
|
||||
$tw.rootWidget.addEventListener("tw-login",function() {
|
||||
$tw.syncer.handleLoginEvent();
|
||||
});
|
||||
$tw.rootWidget.addEventListener("tw-logout",function() {
|
||||
$tw.syncer.handleLogoutEvent();
|
||||
});
|
||||
$tw.rootWidget.addEventListener("tw-server-refresh",function() {
|
||||
$tw.syncer.handleRefreshEvent();
|
||||
});
|
||||
// Install the crypto event handlers
|
||||
$tw.rootWidget.addEventListener("tw-set-password",function(event) {
|
||||
$tw.passwordPrompt.createPrompt({
|
||||
serviceName: "Set a new password for this TiddlyWiki",
|
||||
noUserName: true,
|
||||
submitText: "Set password",
|
||||
canCancel: true,
|
||||
callback: function(data) {
|
||||
if(data) {
|
||||
$tw.crypto.setPassword(data.password);
|
||||
}
|
||||
return true; // Get rid of the password prompt
|
||||
}
|
||||
});
|
||||
});
|
||||
$tw.rootWidget.addEventListener("tw-clear-password",function(event) {
|
||||
$tw.crypto.setPassword(null);
|
||||
});
|
||||
// Ensure that $:/isEncrypted is maintained properly
|
||||
$tw.wiki.addEventListener("change",function(changes) {
|
||||
if($tw.utils.hop(changes,"$:/isEncrypted")) {
|
||||
$tw.crypto.updateCryptoStateTiddler();
|
||||
}
|
||||
});
|
||||
// If we're being viewed on a data: URI then give instructions for how to save
|
||||
if(document.location.protocol === "data:") {
|
||||
$tw.utils.dispatchCustomEvent(document,"tw-modal",{
|
||||
|
@ -3,7 +3,7 @@ title: $:/core/modules/startup/favicon.js
|
||||
type: application/javascript
|
||||
module-type: startup
|
||||
|
||||
Load core modules
|
||||
Favicon handling
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
47
core/modules/startup/password.js
Normal file
47
core/modules/startup/password.js
Normal file
@ -0,0 +1,47 @@
|
||||
/*\
|
||||
title: $:/core/modules/startup/password.js
|
||||
type: application/javascript
|
||||
module-type: startup
|
||||
|
||||
Password handling
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
// Export name and synchronous status
|
||||
exports.name = "password";
|
||||
exports.platforms = ["browser"];
|
||||
exports.after = ["startup"];
|
||||
exports.synchronous = true;
|
||||
|
||||
exports.startup = function() {
|
||||
$tw.rootWidget.addEventListener("tw-set-password",function(event) {
|
||||
$tw.passwordPrompt.createPrompt({
|
||||
serviceName: "Set a new password for this TiddlyWiki",
|
||||
noUserName: true,
|
||||
submitText: "Set password",
|
||||
canCancel: true,
|
||||
callback: function(data) {
|
||||
if(data) {
|
||||
$tw.crypto.setPassword(data.password);
|
||||
}
|
||||
return true; // Get rid of the password prompt
|
||||
}
|
||||
});
|
||||
});
|
||||
$tw.rootWidget.addEventListener("tw-clear-password",function(event) {
|
||||
$tw.crypto.setPassword(null);
|
||||
});
|
||||
// Ensure that $:/isEncrypted is maintained properly
|
||||
$tw.wiki.addEventListener("change",function(changes) {
|
||||
if($tw.utils.hop(changes,"$:/isEncrypted")) {
|
||||
$tw.crypto.updateCryptoStateTiddler();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
})();
|
34
core/modules/startup/syncer-browser.js
Normal file
34
core/modules/startup/syncer-browser.js
Normal file
@ -0,0 +1,34 @@
|
||||
/*\
|
||||
title: $:/core/modules/startup/syncer-browser.js
|
||||
type: application/javascript
|
||||
module-type: startup
|
||||
|
||||
Startup handling
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
// Export name and synchronous status
|
||||
exports.name = "syncer-browser";
|
||||
exports.platforms = ["browser"];
|
||||
exports.after = ["main-render"];
|
||||
exports.synchronous = true;
|
||||
|
||||
exports.startup = function() {
|
||||
// Listen out for login/logout/refresh events in the browser
|
||||
$tw.rootWidget.addEventListener("tw-login",function() {
|
||||
$tw.syncer.handleLoginEvent();
|
||||
});
|
||||
$tw.rootWidget.addEventListener("tw-logout",function() {
|
||||
$tw.syncer.handleLogoutEvent();
|
||||
});
|
||||
$tw.rootWidget.addEventListener("tw-server-refresh",function() {
|
||||
$tw.syncer.handleRefreshEvent();
|
||||
});
|
||||
};
|
||||
|
||||
})();
|
@ -13,7 +13,7 @@ Message handler for full screen mode
|
||||
"use strict";
|
||||
|
||||
// Export name and synchronous status
|
||||
exports.name = "full-screen-startup";
|
||||
exports.name = "full-screen";
|
||||
exports.platforms = ["browser"];
|
||||
exports.after = ["startup"];
|
||||
exports.synchronous = true;
|
||||
|
Loading…
Reference in New Issue
Block a user