|
|
|
@ -6,9 +6,11 @@ define([
|
|
|
|
|
'/bower_components/alertifyjs/dist/js/alertify.js',
|
|
|
|
|
'/common/clipboard.js',
|
|
|
|
|
'/customize/application_config.js',
|
|
|
|
|
'/common/pinpad.js', /* TODO
|
|
|
|
|
load pinpad dynamically only after you know that it will be needed */
|
|
|
|
|
|
|
|
|
|
'/bower_components/jquery/dist/jquery.min.js',
|
|
|
|
|
], function (Config, Messages, Store, Crypto, Alertify, Clipboard, AppConfig) {
|
|
|
|
|
], function (Config, Messages, Store, Crypto, Alertify, Clipboard, Pinpad, AppConfig) {
|
|
|
|
|
/* This file exposes functionality which is specific to Cryptpad, but not to
|
|
|
|
|
any particular pad type. This includes functions for committing metadata
|
|
|
|
|
about pads to your local storage for future use and improved usability.
|
|
|
|
@ -25,6 +27,8 @@ define([
|
|
|
|
|
|
|
|
|
|
var store;
|
|
|
|
|
|
|
|
|
|
var PINNING_ENABLED = AppConfig.enablePinning;
|
|
|
|
|
var rpc;
|
|
|
|
|
|
|
|
|
|
var find = common.find = function (map, path) {
|
|
|
|
|
return (map && path.reduce(function (p, n) {
|
|
|
|
@ -36,6 +40,11 @@ define([
|
|
|
|
|
if (store) { return store; }
|
|
|
|
|
throw new Error("Store is not ready!");
|
|
|
|
|
};
|
|
|
|
|
var getProxy = common.getProxy = function () {
|
|
|
|
|
if (store && store.getProxy()) {
|
|
|
|
|
return store.getProxy().proxy;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
var getNetwork = common.getNetwork = function () {
|
|
|
|
|
if (store) {
|
|
|
|
|
if (store.getProxy() && store.getProxy().info) {
|
|
|
|
@ -563,6 +572,7 @@ define([
|
|
|
|
|
|
|
|
|
|
// STORAGE
|
|
|
|
|
/* commit a list of pads to localStorage */
|
|
|
|
|
// TODO integrate pinning if enabled
|
|
|
|
|
var setRecentPads = common.setRecentPads = function (pads, cb) {
|
|
|
|
|
getStore().setDrive(storageKey, pads, function (err, data) {
|
|
|
|
|
cb(err, data);
|
|
|
|
@ -589,6 +599,7 @@ define([
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// STORAGE
|
|
|
|
|
// TODO integrate pinning if enabled
|
|
|
|
|
var forgetPad = common.forgetPad = function (href, cb) {
|
|
|
|
|
var parsed = parsePadUrl(href);
|
|
|
|
|
|
|
|
|
@ -670,6 +681,8 @@ define([
|
|
|
|
|
var isNotStrongestStored = common.isNotStrongestStored = function (href, recents) {
|
|
|
|
|
return findStronger(href, recents);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// TODO integrate pinning
|
|
|
|
|
var setPadTitle = common.setPadTitle = function (name, cb) {
|
|
|
|
|
var href = window.location.href;
|
|
|
|
|
var parsed = parsePadUrl(href);
|
|
|
|
@ -805,12 +818,14 @@ define([
|
|
|
|
|
|
|
|
|
|
// local name?
|
|
|
|
|
common.ready = function (f) {
|
|
|
|
|
var state = 0;
|
|
|
|
|
|
|
|
|
|
var block = 0;
|
|
|
|
|
var env = {};
|
|
|
|
|
|
|
|
|
|
var cb = function () {
|
|
|
|
|
f(void 0, env);
|
|
|
|
|
block--;
|
|
|
|
|
if (!block) {
|
|
|
|
|
f(void 0, env);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (sessionStorage[newPadNameKey]) {
|
|
|
|
@ -825,6 +840,9 @@ define([
|
|
|
|
|
Store.ready(function (err, storeObj) {
|
|
|
|
|
store = common.store = env.store = storeObj;
|
|
|
|
|
|
|
|
|
|
var proxy = getProxy();
|
|
|
|
|
var network = getNetwork();
|
|
|
|
|
|
|
|
|
|
$(function() {
|
|
|
|
|
// Race condition : if document.body is undefined when alertify.js is loaded, Alertify
|
|
|
|
|
// won't work. We have to reset it now to make sure it uses a correct "body"
|
|
|
|
@ -848,8 +866,34 @@ define([
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (PINNING_ENABLED && isLoggedIn()) {
|
|
|
|
|
console.log("logged in. pads will be pinned");
|
|
|
|
|
block++;
|
|
|
|
|
|
|
|
|
|
// TODO setTimeout in case rpc doesn't
|
|
|
|
|
// activate in reasonable time?
|
|
|
|
|
Pinpad.create(network, proxy, function (e, call) {
|
|
|
|
|
if (e) {
|
|
|
|
|
console.error(e);
|
|
|
|
|
return cb();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log('RPC handshake complete');
|
|
|
|
|
rpc = env.rpc = call;
|
|
|
|
|
|
|
|
|
|
// TODO check if pin list is up to date
|
|
|
|
|
// if not, reset
|
|
|
|
|
cb();
|
|
|
|
|
});
|
|
|
|
|
} else if (PINNING_ENABLED) {
|
|
|
|
|
console.log('not logged in. pads will not be pinned');
|
|
|
|
|
} else {
|
|
|
|
|
console.log('pinning disabled');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Everything's ready, continue...
|
|
|
|
|
if($('#pad-iframe').length) {
|
|
|
|
|
block++;
|
|
|
|
|
var $iframe = $('#pad-iframe');
|
|
|
|
|
var iframe = $iframe[0];
|
|
|
|
|
var iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
|
|
|
|
@ -860,6 +904,8 @@ define([
|
|
|
|
|
$iframe.load(cb);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
block++;
|
|
|
|
|
cb();
|
|
|
|
|
});
|
|
|
|
|
}, common);
|
|
|
|
@ -950,6 +996,7 @@ define([
|
|
|
|
|
/*
|
|
|
|
|
* Buttons
|
|
|
|
|
*/
|
|
|
|
|
// TODO integrate pinning if enabled
|
|
|
|
|
var renamePad = common.renamePad = function (title, callback) {
|
|
|
|
|
if (title === null) { return; }
|
|
|
|
|
|
|
|
|
|