|
|
@ -6,9 +6,11 @@ define([
|
|
|
|
'/bower_components/alertifyjs/dist/js/alertify.js',
|
|
|
|
'/bower_components/alertifyjs/dist/js/alertify.js',
|
|
|
|
'/common/clipboard.js',
|
|
|
|
'/common/clipboard.js',
|
|
|
|
'/customize/application_config.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',
|
|
|
|
'/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
|
|
|
|
/* This file exposes functionality which is specific to Cryptpad, but not to
|
|
|
|
any particular pad type. This includes functions for committing metadata
|
|
|
|
any particular pad type. This includes functions for committing metadata
|
|
|
|
about pads to your local storage for future use and improved usability.
|
|
|
|
about pads to your local storage for future use and improved usability.
|
|
|
@ -25,6 +27,8 @@ define([
|
|
|
|
|
|
|
|
|
|
|
|
var store;
|
|
|
|
var store;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var PINNING_ENABLED = AppConfig.enablePinning;
|
|
|
|
|
|
|
|
var rpc;
|
|
|
|
|
|
|
|
|
|
|
|
var find = common.find = function (map, path) {
|
|
|
|
var find = common.find = function (map, path) {
|
|
|
|
return (map && path.reduce(function (p, n) {
|
|
|
|
return (map && path.reduce(function (p, n) {
|
|
|
@ -36,6 +40,11 @@ define([
|
|
|
|
if (store) { return store; }
|
|
|
|
if (store) { return store; }
|
|
|
|
throw new Error("Store is not ready!");
|
|
|
|
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 () {
|
|
|
|
var getNetwork = common.getNetwork = function () {
|
|
|
|
if (store) {
|
|
|
|
if (store) {
|
|
|
|
if (store.getProxy() && store.getProxy().info) {
|
|
|
|
if (store.getProxy() && store.getProxy().info) {
|
|
|
@ -563,6 +572,7 @@ define([
|
|
|
|
|
|
|
|
|
|
|
|
// STORAGE
|
|
|
|
// STORAGE
|
|
|
|
/* commit a list of pads to localStorage */
|
|
|
|
/* commit a list of pads to localStorage */
|
|
|
|
|
|
|
|
// TODO integrate pinning if enabled
|
|
|
|
var setRecentPads = common.setRecentPads = function (pads, cb) {
|
|
|
|
var setRecentPads = common.setRecentPads = function (pads, cb) {
|
|
|
|
getStore().setDrive(storageKey, pads, function (err, data) {
|
|
|
|
getStore().setDrive(storageKey, pads, function (err, data) {
|
|
|
|
cb(err, data);
|
|
|
|
cb(err, data);
|
|
|
@ -589,6 +599,7 @@ define([
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// STORAGE
|
|
|
|
// STORAGE
|
|
|
|
|
|
|
|
// TODO integrate pinning if enabled
|
|
|
|
var forgetPad = common.forgetPad = function (href, cb) {
|
|
|
|
var forgetPad = common.forgetPad = function (href, cb) {
|
|
|
|
var parsed = parsePadUrl(href);
|
|
|
|
var parsed = parsePadUrl(href);
|
|
|
|
|
|
|
|
|
|
|
@ -670,6 +681,8 @@ define([
|
|
|
|
var isNotStrongestStored = common.isNotStrongestStored = function (href, recents) {
|
|
|
|
var isNotStrongestStored = common.isNotStrongestStored = function (href, recents) {
|
|
|
|
return findStronger(href, recents);
|
|
|
|
return findStronger(href, recents);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO integrate pinning
|
|
|
|
var setPadTitle = common.setPadTitle = function (name, cb) {
|
|
|
|
var setPadTitle = common.setPadTitle = function (name, cb) {
|
|
|
|
var href = window.location.href;
|
|
|
|
var href = window.location.href;
|
|
|
|
var parsed = parsePadUrl(href);
|
|
|
|
var parsed = parsePadUrl(href);
|
|
|
@ -805,12 +818,14 @@ define([
|
|
|
|
|
|
|
|
|
|
|
|
// local name?
|
|
|
|
// local name?
|
|
|
|
common.ready = function (f) {
|
|
|
|
common.ready = function (f) {
|
|
|
|
var state = 0;
|
|
|
|
var block = 0;
|
|
|
|
|
|
|
|
|
|
|
|
var env = {};
|
|
|
|
var env = {};
|
|
|
|
|
|
|
|
|
|
|
|
var cb = function () {
|
|
|
|
var cb = function () {
|
|
|
|
f(void 0, env);
|
|
|
|
block--;
|
|
|
|
|
|
|
|
if (!block) {
|
|
|
|
|
|
|
|
f(void 0, env);
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if (sessionStorage[newPadNameKey]) {
|
|
|
|
if (sessionStorage[newPadNameKey]) {
|
|
|
@ -825,6 +840,9 @@ define([
|
|
|
|
Store.ready(function (err, storeObj) {
|
|
|
|
Store.ready(function (err, storeObj) {
|
|
|
|
store = common.store = env.store = storeObj;
|
|
|
|
store = common.store = env.store = storeObj;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var proxy = getProxy();
|
|
|
|
|
|
|
|
var network = getNetwork();
|
|
|
|
|
|
|
|
|
|
|
|
$(function() {
|
|
|
|
$(function() {
|
|
|
|
// Race condition : if document.body is undefined when alertify.js is loaded, Alertify
|
|
|
|
// 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"
|
|
|
|
// 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...
|
|
|
|
// Everything's ready, continue...
|
|
|
|
if($('#pad-iframe').length) {
|
|
|
|
if($('#pad-iframe').length) {
|
|
|
|
|
|
|
|
block++;
|
|
|
|
var $iframe = $('#pad-iframe');
|
|
|
|
var $iframe = $('#pad-iframe');
|
|
|
|
var iframe = $iframe[0];
|
|
|
|
var iframe = $iframe[0];
|
|
|
|
var iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
|
|
|
|
var iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
|
|
|
@ -860,6 +904,8 @@ define([
|
|
|
|
$iframe.load(cb);
|
|
|
|
$iframe.load(cb);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
block++;
|
|
|
|
cb();
|
|
|
|
cb();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}, common);
|
|
|
|
}, common);
|
|
|
@ -950,6 +996,7 @@ define([
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Buttons
|
|
|
|
* Buttons
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
// TODO integrate pinning if enabled
|
|
|
|
var renamePad = common.renamePad = function (title, callback) {
|
|
|
|
var renamePad = common.renamePad = function (title, callback) {
|
|
|
|
if (title === null) { return; }
|
|
|
|
if (title === null) { return; }
|
|
|
|
|
|
|
|
|
|
|
|