remove unused variables
This commit is contained in:
@@ -3,7 +3,7 @@ define(['jquery'], function ($) {
|
||||
|
||||
// copy arbitrary text to the clipboard
|
||||
// return boolean indicating success
|
||||
var copy = Clipboard.copy = function (text) {
|
||||
Clipboard.copy = function (text) {
|
||||
var $ta = $('<input>', {
|
||||
type: 'text',
|
||||
}).val(text);
|
||||
|
||||
@@ -49,7 +49,7 @@ define([
|
||||
return ret;
|
||||
}
|
||||
|
||||
var hash = href.replace(patt, function (a, domain, type, hash) {
|
||||
var hash = href.replace(patt, function (a, domain, type) {
|
||||
ret.domain = domain;
|
||||
ret.type = type;
|
||||
return '';
|
||||
@@ -70,7 +70,7 @@ define([
|
||||
* - no argument: use the URL hash or create one if it doesn't exist
|
||||
* - secretHash provided: use secretHash to find the keys
|
||||
*/
|
||||
var getSecrets = Hash.getSecrets = function (secretHash) {
|
||||
Hash.getSecrets = function (secretHash) {
|
||||
var secret = {};
|
||||
var generate = function () {
|
||||
secret.keys = Crypto.createEditCryptor();
|
||||
@@ -130,7 +130,7 @@ define([
|
||||
return secret;
|
||||
};
|
||||
|
||||
var getHashes = Hash.getHashes = function (channel, secret) {
|
||||
Hash.getHashes = function (channel, secret) {
|
||||
var hashes = {};
|
||||
if (secret.keys.editKeyStr) {
|
||||
hashes.editHash = getEditHashFromKeys(channel, secret.keys);
|
||||
@@ -152,7 +152,7 @@ define([
|
||||
return id;
|
||||
};
|
||||
|
||||
var createRandomHash = Hash.createRandomHash = function () {
|
||||
Hash.createRandomHash = function () {
|
||||
// 16 byte channel Id
|
||||
var channelId = Util.hexToBase64(createChannelId());
|
||||
// 18 byte encryption key
|
||||
@@ -197,7 +197,7 @@ Version 2
|
||||
};
|
||||
|
||||
// STORAGE
|
||||
var findWeaker = Hash.findWeaker = function (href, recents) {
|
||||
Hash.findWeaker = function (href, recents) {
|
||||
var rHref = href || getRelativeHref(window.location.href);
|
||||
var parsed = parsePadUrl(rHref);
|
||||
if (!parsed.hash) { return false; }
|
||||
@@ -241,11 +241,11 @@ Version 2
|
||||
});
|
||||
return stronger;
|
||||
};
|
||||
var isNotStrongestStored = Hash.isNotStrongestStored = function (href, recents) {
|
||||
Hash.isNotStrongestStored = function (href, recents) {
|
||||
return findStronger(href, recents);
|
||||
};
|
||||
|
||||
var hrefToHexChannelId = Hash.hrefToHexChannelId = function (href) {
|
||||
Hash.hrefToHexChannelId = function (href) {
|
||||
var parsed = Hash.parsePadUrl(href);
|
||||
if (!parsed || !parsed.hash) { return; }
|
||||
|
||||
@@ -266,11 +266,11 @@ Version 2
|
||||
return hex;
|
||||
};
|
||||
|
||||
var getBlobPath = Hash.getBlobPathFromHex = function (id) {
|
||||
Hash.getBlobPathFromHex = function (id) {
|
||||
return '/blob/' + id.slice(0,2) + '/' + id;
|
||||
};
|
||||
|
||||
var serializeHash = Hash.serializeHash = function (hash) {
|
||||
Hash.serializeHash = function (hash) {
|
||||
if (hash && hash.slice(-1) !== "/") { hash += "/"; }
|
||||
return hash;
|
||||
};
|
||||
|
||||
@@ -25,7 +25,7 @@ define([
|
||||
var wcId = common.hrefToHexChannelId(config.href || window.location.href);
|
||||
|
||||
console.log(wcId);
|
||||
var createRealtime = function(chan) {
|
||||
var createRealtime = function () {
|
||||
return ChainPad.create({
|
||||
userName: 'history',
|
||||
initialState: '',
|
||||
@@ -68,14 +68,14 @@ define([
|
||||
}
|
||||
};
|
||||
|
||||
network.on('message', function (msg, sender) {
|
||||
network.on('message', function (msg) {
|
||||
onMsg(msg);
|
||||
});
|
||||
|
||||
network.sendto(hkn, JSON.stringify(['GET_FULL_HISTORY', wcId, secret.keys.validateKey]));
|
||||
};
|
||||
|
||||
var create = History.create = function (common, config) {
|
||||
History.create = function (common, config) {
|
||||
if (!config.$toolbar) { return void console.error("config.$toolbar is undefined");}
|
||||
if (History.loading) { return void console.error("History is already being loaded..."); }
|
||||
History.loading = true;
|
||||
@@ -145,7 +145,7 @@ define([
|
||||
title: Messages.history_next
|
||||
}).appendTo($hist);
|
||||
|
||||
var $label = $('<label>').text(Messages.history_version).appendTo($nav);
|
||||
$('<label>').text(Messages.history_version).appendTo($nav);
|
||||
var $cur = $('<input>', {
|
||||
'class' : 'gotoInput',
|
||||
'type' : 'number',
|
||||
|
||||
@@ -48,7 +48,7 @@ define([
|
||||
UI.alert = function (msg, cb, force) {
|
||||
cb = cb || function () {};
|
||||
if (force !== true) { msg = Util.fixHTML(msg); }
|
||||
var close = function (e) {
|
||||
var close = function () {
|
||||
findOKButton().click();
|
||||
};
|
||||
var keyHandler = listenForKeys(close, close);
|
||||
@@ -66,9 +66,9 @@ define([
|
||||
cb = cb || function () {};
|
||||
if (force !== true) { msg = Util.fixHTML(msg); }
|
||||
|
||||
var keyHandler = listenForKeys(function (e) { // yes
|
||||
var keyHandler = listenForKeys(function () { // yes
|
||||
findOKButton().click();
|
||||
}, function (e) { // no
|
||||
}, function () { // no
|
||||
findCancelButton().click();
|
||||
});
|
||||
|
||||
@@ -90,9 +90,9 @@ define([
|
||||
cb = cb || function () {};
|
||||
if (force !== true) { msg = Util.fixHTML(msg); }
|
||||
|
||||
var keyHandler = listenForKeys(function (e) {
|
||||
var keyHandler = listenForKeys(function () {
|
||||
findOKButton().click();
|
||||
}, function (e) {
|
||||
}, function () {
|
||||
findCancelButton().click();
|
||||
});
|
||||
|
||||
@@ -183,7 +183,7 @@ define([
|
||||
}
|
||||
if (Messages.tips && !hideTips) {
|
||||
var $loadingTip = $('<div>', {'id': 'loadingTip'});
|
||||
var $tip = $('<span>', {'class': 'tips'}).text(getRandomTip()).appendTo($loadingTip);
|
||||
$('<span>', {'class': 'tips'}).text(getRandomTip()).appendTo($loadingTip);
|
||||
$loadingTip.css({
|
||||
'top': $('body').height()/2 + $container.height()/2 + 20 + 'px'
|
||||
});
|
||||
@@ -204,7 +204,7 @@ define([
|
||||
$('#' + LOADING).find('p').html(error || Messages.error);
|
||||
};
|
||||
|
||||
var importContent = UI.importContent = function (type, f) {
|
||||
UI.importContent = function (type, f) {
|
||||
return function () {
|
||||
var $files = $('<input type="file">').click();
|
||||
$files.on('change', function (e) {
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
define([], function () {
|
||||
var Util = {};
|
||||
|
||||
var find = Util.find = function (map, path) {
|
||||
Util.find = function (map, path) {
|
||||
return (map && path.reduce(function (p, n) {
|
||||
return typeof(p[n]) !== 'undefined' && p[n];
|
||||
}, map));
|
||||
};
|
||||
|
||||
var fixHTML = Util.fixHTML = function (str) {
|
||||
Util.fixHTML = function (str) {
|
||||
if (!str) { return ''; }
|
||||
return str.replace(/[<>&"']/g, function (x) {
|
||||
return ({ "<": "<", ">": ">", "&": "&", '"': """, "'": "'" })[x];
|
||||
});
|
||||
};
|
||||
|
||||
var hexToBase64 = Util.hexToBase64 = function (hex) {
|
||||
Util.hexToBase64 = function (hex) {
|
||||
var hexArray = hex
|
||||
.replace(/\r|\n/g, "")
|
||||
.replace(/([\da-fA-F]{2}) ?/g, "0x$1 ")
|
||||
@@ -24,7 +24,7 @@ define([], function () {
|
||||
return window.btoa(byteString).replace(/\//g, '-').slice(0,-2);
|
||||
};
|
||||
|
||||
var base64ToHex = Util.base64ToHex = function (b64String) {
|
||||
Util.base64ToHex = function (b64String) {
|
||||
var hexArray = [];
|
||||
atob(b64String.replace(/-/g, '/')).split("").forEach(function(e){
|
||||
var h = e.charCodeAt(0).toString(16);
|
||||
@@ -34,9 +34,9 @@ define([], function () {
|
||||
return hexArray.join("");
|
||||
};
|
||||
|
||||
var uint8ArrayToHex = Util.uint8ArrayToHex = function (a) {
|
||||
Util.uint8ArrayToHex = function (a) {
|
||||
// call slice so Uint8Arrays work as expected
|
||||
return Array.prototype.slice.call(a).map(function (e, i) {
|
||||
return Array.prototype.slice.call(a).map(function (e) {
|
||||
var n = Number(e & 0xff).toString(16);
|
||||
if (n === 'NaN') {
|
||||
throw new Error('invalid input resulted in NaN');
|
||||
@@ -51,7 +51,7 @@ define([], function () {
|
||||
}).join('');
|
||||
};
|
||||
|
||||
var deduplicateString = Util.deduplicateString = function (array) {
|
||||
Util.deduplicateString = function (array) {
|
||||
var a = array.slice();
|
||||
for(var i=0; i<a.length; i++) {
|
||||
for(var j=i+1; j<a.length; j++) {
|
||||
@@ -61,11 +61,11 @@ define([], function () {
|
||||
return a;
|
||||
};
|
||||
|
||||
var getHash = Util.getHash = function () {
|
||||
Util.getHash = function () {
|
||||
return window.location.hash.slice(1);
|
||||
};
|
||||
|
||||
var replaceHash = Util.replaceHash = function (hash) {
|
||||
Util.replaceHash = function (hash) {
|
||||
if (window.history && window.history.replaceState) {
|
||||
if (!/^#/.test(hash)) { hash = '#' + hash; }
|
||||
return void window.history.replaceState({}, window.document.title, hash);
|
||||
@@ -76,16 +76,16 @@ define([], function () {
|
||||
/*
|
||||
* Saving files
|
||||
*/
|
||||
var fixFileName = Util.fixFileName = function (filename) {
|
||||
Util.fixFileName = function (filename) {
|
||||
return filename.replace(/ /g, '-').replace(/[\/\?]/g, '_')
|
||||
.replace(/_+/g, '_');
|
||||
};
|
||||
|
||||
var bytesToMegabytes = Util.bytesToMegabytes = function (bytes) {
|
||||
Util.bytesToMegabytes = function (bytes) {
|
||||
return Math.floor((bytes / (1024 * 1024) * 100)) / 100;
|
||||
};
|
||||
|
||||
var bytesToKilobytes = Util.bytesToKilobytes = function (bytes) {
|
||||
Util.bytesToKilobytes = function (bytes) {
|
||||
return Math.floor(bytes / 1024 * 100) / 100;
|
||||
};
|
||||
|
||||
|
||||
@@ -8,20 +8,19 @@ define([
|
||||
return typeof(x) === 'string';
|
||||
};
|
||||
|
||||
var isValidUsername = Cred.isValidUsername = function (name) {
|
||||
Cred.isValidUsername = function (name) {
|
||||
return !!(name && isString(name));
|
||||
};
|
||||
|
||||
var isValidPassword = Cred.isValidPassword = function (passwd) {
|
||||
Cred.isValidPassword = function (passwd) {
|
||||
return !!(passwd && isString(passwd));
|
||||
};
|
||||
|
||||
var passwordsMatch = Cred.passwordsMatch = function (a, b) {
|
||||
Cred.passwordsMatch = function (a, b) {
|
||||
return isString(a) && isString(b) && a === b;
|
||||
};
|
||||
|
||||
var deriveFromPassphrase = Cred.deriveFromPassphrase = function
|
||||
(username, password, len, cb) {
|
||||
Cred.deriveFromPassphrase = function (username, password, len, cb) {
|
||||
Scrypt(password,
|
||||
username,
|
||||
8, // memoryCost (n)
|
||||
@@ -32,7 +31,7 @@ define([
|
||||
undefined); // format, could be 'base64'
|
||||
};
|
||||
|
||||
var dispenser = Cred.dispenser = function (bytes) {
|
||||
Cred.dispenser = function (bytes) {
|
||||
var entropy = {
|
||||
used: 0,
|
||||
};
|
||||
|
||||
@@ -5,8 +5,8 @@ define([
|
||||
'/common/cryptpad-common.js',
|
||||
'/bower_components/textpatcher/TextPatcher.js'
|
||||
], function ($, Crypto, Realtime, Cryptpad, TextPatcher) {
|
||||
var Messages = Cryptpad.Messages;
|
||||
var noop = function () {};
|
||||
//var Messages = Cryptpad.Messages;
|
||||
//var noop = function () {};
|
||||
var finish = function (S, err, doc) {
|
||||
if (S.done) { return; }
|
||||
S.cb(err, doc);
|
||||
@@ -50,14 +50,14 @@ define([
|
||||
var Session = { cb: cb, };
|
||||
var config = makeConfig(hash);
|
||||
|
||||
var onReady = config.onReady = function (info) {
|
||||
config.onReady = function (info) {
|
||||
var rt = Session.session = info.realtime;
|
||||
Session.network = info.network;
|
||||
finish(Session, void 0, rt.getUserDoc());
|
||||
};
|
||||
overwrite(config, opt);
|
||||
|
||||
var realtime = Session.realtime = Realtime.start(config);
|
||||
Session.realtime = Realtime.start(config);
|
||||
};
|
||||
|
||||
var put = function (hash, doc, cb, opt) {
|
||||
@@ -87,7 +87,7 @@ define([
|
||||
};
|
||||
overwrite(config, opt);
|
||||
|
||||
var realtime = Session.session = Realtime.start(config);
|
||||
Session.session = Realtime.start(config);
|
||||
};
|
||||
|
||||
return {
|
||||
|
||||
@@ -29,7 +29,7 @@ define([
|
||||
var userHashKey = common.userHashKey = 'User_hash';
|
||||
var userNameKey = common.userNameKey = 'User_name';
|
||||
var fileHashKey = common.fileHashKey = 'FS_hash';
|
||||
var displayNameKey = common.displayNameKey = 'cryptpad.username';
|
||||
common.displayNameKey = 'cryptpad.username';
|
||||
var newPadNameKey = common.newPadNameKey = "newPadName";
|
||||
var newPadPathKey = common.newPadPathKey = "newPadPath";
|
||||
var storageKey = common.storageKey = 'CryptPad_RECENTPADS';
|
||||
@@ -39,10 +39,10 @@ define([
|
||||
var rpc;
|
||||
|
||||
// import UI elements
|
||||
var findCancelButton = common.findCancelButton = UI.findCancelButton;
|
||||
var findOKButton = common.findOKButton = UI.findOKButton;
|
||||
var listenForKeys = common.listenForKeys = UI.listenForKeys;
|
||||
var stopListening = common.stopListening = UI.stopListening;
|
||||
common.findCancelButton = UI.findCancelButton;
|
||||
common.findOKButton = UI.findOKButton;
|
||||
common.listenForKeys = UI.listenForKeys;
|
||||
common.stopListening = UI.stopListening;
|
||||
common.prompt = UI.prompt;
|
||||
common.confirm = UI.confirm;
|
||||
common.alert = UI.alert;
|
||||
@@ -54,15 +54,15 @@ define([
|
||||
common.errorLoadingScreen = UI.errorLoadingScreen;
|
||||
|
||||
// import common utilities for export
|
||||
var find = common.find = Util.find;
|
||||
common.find = Util.find;
|
||||
var fixHTML = common.fixHTML = Util.fixHTML;
|
||||
var hexToBase64 = common.hexToBase64 = Util.hexToBase64;
|
||||
var base64ToHex = common.base64ToHex = Util.base64ToHex;
|
||||
common.hexToBase64 = Util.hexToBase64;
|
||||
common.base64ToHex = Util.base64ToHex;
|
||||
var deduplicateString = common.deduplicateString = Util.deduplicateString;
|
||||
var uint8ArrayToHex = common.uint8ArrayToHex = Util.uint8ArrayToHex;
|
||||
var replaceHash = common.replaceHash = Util.replaceHash;
|
||||
common.uint8ArrayToHex = Util.uint8ArrayToHex;
|
||||
common.replaceHash = Util.replaceHash;
|
||||
var getHash = common.getHash = Util.getHash;
|
||||
var fixFileName = common.fixFileName = Util.fixFileName;
|
||||
common.fixFileName = Util.fixFileName;
|
||||
common.bytesToMegabytes = Util.bytesToMegabytes;
|
||||
common.bytesToKilobytes = Util.bytesToKilobytes;
|
||||
|
||||
@@ -121,13 +121,13 @@ define([
|
||||
});
|
||||
};
|
||||
|
||||
var reportAppUsage = common.reportAppUsage = function () {
|
||||
common.reportAppUsage = function () {
|
||||
var pattern = window.location.pathname.split('/')
|
||||
.filter(function (x) { return x; }).join('.');
|
||||
feedback(pattern);
|
||||
};
|
||||
|
||||
var getUid = common.getUid = function () {
|
||||
common.getUid = function () {
|
||||
if (store && store.getProxy() && store.getProxy().proxy) {
|
||||
return store.getProxy().proxy.uid;
|
||||
}
|
||||
@@ -152,7 +152,7 @@ define([
|
||||
}, 0);
|
||||
};
|
||||
|
||||
var getWebsocketURL = common.getWebsocketURL = function () {
|
||||
common.getWebsocketURL = function () {
|
||||
if (!Config.websocketPath) { return Config.websocketURL; }
|
||||
var path = Config.websocketPath;
|
||||
if (/^ws{1,2}:\/\//.test(path)) { return path; }
|
||||
@@ -164,7 +164,7 @@ define([
|
||||
return url;
|
||||
};
|
||||
|
||||
var login = common.login = function (hash, name, cb) {
|
||||
common.login = function (hash, name, cb) {
|
||||
if (!hash) { throw new Error('expected a user hash'); }
|
||||
if (!name) { throw new Error('expected a user name'); }
|
||||
hash = common.serializeHash(hash);
|
||||
@@ -188,7 +188,7 @@ define([
|
||||
};
|
||||
|
||||
var logoutHandlers = [];
|
||||
var logout = common.logout = function (cb) {
|
||||
common.logout = function (cb) {
|
||||
[
|
||||
userNameKey,
|
||||
userHashKey,
|
||||
@@ -211,7 +211,7 @@ define([
|
||||
|
||||
if (cb) { cb(); }
|
||||
};
|
||||
var onLogout = common.onLogout = function (h) {
|
||||
common.onLogout = function (h) {
|
||||
if (typeof (h) !== "function") { return; }
|
||||
if (logoutHandlers.indexOf(h) !== -1) { return; }
|
||||
logoutHandlers.push(h);
|
||||
@@ -232,7 +232,7 @@ define([
|
||||
return typeof getUserHash() === "string";
|
||||
};
|
||||
|
||||
var hasSigningKeys = common.hasSigningKeys = function (proxy) {
|
||||
common.hasSigningKeys = function (proxy) {
|
||||
return typeof(proxy) === 'object' &&
|
||||
typeof(proxy.edPrivate) === 'string' &&
|
||||
typeof(proxy.edPublic) === 'string';
|
||||
@@ -308,7 +308,7 @@ define([
|
||||
};
|
||||
|
||||
// Get the pads from localStorage to migrate them to the object store
|
||||
var getLegacyPads = common.getLegacyPads = function (cb) {
|
||||
common.getLegacyPads = function (cb) {
|
||||
require(['/customize/store.js'], function(Legacy) { // TODO DEPRECATE_F
|
||||
Legacy.ready(function (err, legacy) {
|
||||
if (err) { cb(err, null); return; }
|
||||
@@ -328,7 +328,6 @@ define([
|
||||
// Create untitled documents when no name is given
|
||||
var getDefaultName = common.getDefaultName = function (parsed) {
|
||||
var type = parsed.type;
|
||||
var untitledIndex = 1;
|
||||
var name = (Messages.type)[type] + ' - ' + new Date().toString().split(' ').slice(0,4).join(' ');
|
||||
return name;
|
||||
};
|
||||
@@ -348,37 +347,37 @@ define([
|
||||
};
|
||||
|
||||
/* Sort pads according to how recently they were accessed */
|
||||
var mostRecent = common.mostRecent = function (a, b) {
|
||||
common.mostRecent = function (a, b) {
|
||||
return new Date(b.atime).getTime() - new Date(a.atime).getTime();
|
||||
};
|
||||
|
||||
// STORAGE
|
||||
var setPadAttribute = common.setPadAttribute = function (attr, value, cb) {
|
||||
common.setPadAttribute = function (attr, value, cb) {
|
||||
getStore().setDrive([getHash(), attr].join('.'), value, function (err, data) {
|
||||
cb(err, data);
|
||||
});
|
||||
};
|
||||
var setAttribute = common.setAttribute = function (attr, value, cb) {
|
||||
common.setAttribute = function (attr, value, cb) {
|
||||
getStore().set(["cryptpad", attr].join('.'), value, function (err, data) {
|
||||
cb(err, data);
|
||||
});
|
||||
};
|
||||
var setLSAttribute = common.setLSAttribute = function (attr, value) {
|
||||
common.setLSAttribute = function (attr, value) {
|
||||
localStorage[attr] = value;
|
||||
};
|
||||
|
||||
// STORAGE
|
||||
var getPadAttribute = common.getPadAttribute = function (attr, cb) {
|
||||
common.getPadAttribute = function (attr, cb) {
|
||||
getStore().getDrive([getHash(), attr].join('.'), function (err, data) {
|
||||
cb(err, data);
|
||||
});
|
||||
};
|
||||
var getAttribute = common.getAttribute = function (attr, cb) {
|
||||
common.getAttribute = function (attr, cb) {
|
||||
getStore().get(["cryptpad", attr].join('.'), function (err, data) {
|
||||
cb(err, data);
|
||||
});
|
||||
};
|
||||
var getLSAttribute = common.getLSAttribute = function (attr) {
|
||||
common.getLSAttribute = function (attr) {
|
||||
return localStorage[attr];
|
||||
};
|
||||
|
||||
@@ -393,19 +392,19 @@ define([
|
||||
});
|
||||
return templates;
|
||||
};
|
||||
var addTemplate = common.addTemplate = function (data) {
|
||||
common.addTemplate = function (data) {
|
||||
getStore().pushData(data);
|
||||
getStore().addPad(data.href, ['template']);
|
||||
};
|
||||
|
||||
var isTemplate = common.isTemplate = function (href) {
|
||||
common.isTemplate = function (href) {
|
||||
var rhref = getRelativeHref(href);
|
||||
var templates = listTemplates();
|
||||
return templates.some(function (t) {
|
||||
return t.href === rhref;
|
||||
});
|
||||
};
|
||||
var selectTemplate = common.selectTemplate = function (type, rt, Crypt) {
|
||||
common.selectTemplate = function (type, rt, Crypt) {
|
||||
if (!AppConfig.enableTemplates) { return; }
|
||||
var temps = listTemplates(type);
|
||||
if (temps.length === 0) { return; }
|
||||
@@ -423,7 +422,7 @@ define([
|
||||
Crypt.get(parsed.hash, function (err, val) {
|
||||
if (err) { throw new Error(err); }
|
||||
var p = parsePadUrl(window.location.href);
|
||||
Crypt.put(p.hash, val, function (e) {
|
||||
Crypt.put(p.hash, val, function () {
|
||||
common.findOKButton().click();
|
||||
common.removeLoadingScreen();
|
||||
});
|
||||
@@ -448,28 +447,28 @@ define([
|
||||
};
|
||||
|
||||
// STORAGE: Display Name
|
||||
var getLastName = common.getLastName = function (cb) {
|
||||
common.getLastName = function (cb) {
|
||||
common.getAttribute('username', function (err, userName) {
|
||||
cb(err, userName);
|
||||
});
|
||||
};
|
||||
var _onDisplayNameChanged = [];
|
||||
var onDisplayNameChanged = common.onDisplayNameChanged = function (h) {
|
||||
common.onDisplayNameChanged = function (h) {
|
||||
if (typeof(h) !== "function") { return; }
|
||||
if (_onDisplayNameChanged.indexOf(h) !== -1) { return; }
|
||||
_onDisplayNameChanged.push(h);
|
||||
};
|
||||
var changeDisplayName = common.changeDisplayName = function (newName) {
|
||||
common.changeDisplayName = function (newName) {
|
||||
_onDisplayNameChanged.forEach(function (h) {
|
||||
h(newName);
|
||||
});
|
||||
};
|
||||
|
||||
// STORAGE
|
||||
var forgetPad = common.forgetPad = function (href, cb) {
|
||||
common.forgetPad = function (href, cb) {
|
||||
var parsed = parsePadUrl(href);
|
||||
|
||||
var callback = function (err, data) {
|
||||
var callback = function (err) {
|
||||
if (err) {
|
||||
cb(err);
|
||||
return;
|
||||
@@ -511,7 +510,7 @@ define([
|
||||
}
|
||||
});
|
||||
};
|
||||
var setPadTitle = common.setPadTitle = function (name, cb) {
|
||||
common.setPadTitle = function (name, cb) {
|
||||
var href = window.location.href;
|
||||
var parsed = parsePadUrl(href);
|
||||
href = getRelativeHref(href);
|
||||
@@ -525,7 +524,7 @@ define([
|
||||
|
||||
var updateWeaker = [];
|
||||
var contains;
|
||||
var renamed = recent.map(function (pad) {
|
||||
recent.forEach(function (pad) {
|
||||
var p = parsePadUrl(pad.href);
|
||||
|
||||
if (p.type !== parsed.type) { return pad; }
|
||||
@@ -610,7 +609,7 @@ define([
|
||||
/*
|
||||
* Buttons
|
||||
*/
|
||||
var renamePad = common.renamePad = function (title, callback) {
|
||||
common.renamePad = function (title, callback) {
|
||||
if (title === null) { return; }
|
||||
|
||||
if (title.trim() === "") {
|
||||
@@ -618,7 +617,7 @@ define([
|
||||
title = getDefaultName(parsed);
|
||||
}
|
||||
|
||||
common.setPadTitle(title, function (err, data) {
|
||||
common.setPadTitle(title, function (err) {
|
||||
if (err) {
|
||||
console.log("unable to set pad title");
|
||||
console.log(err);
|
||||
@@ -668,7 +667,7 @@ define([
|
||||
return true;
|
||||
};
|
||||
|
||||
var arePinsSynced = common.arePinsSynced = function (cb) {
|
||||
common.arePinsSynced = function (cb) {
|
||||
if (!pinsReady()) { return void cb ('[RPC_NOT_READY]'); }
|
||||
|
||||
var list = getCanonicalChannelList();
|
||||
@@ -679,7 +678,7 @@ define([
|
||||
});
|
||||
};
|
||||
|
||||
var resetPins = common.resetPins = function (cb) {
|
||||
common.resetPins = function (cb) {
|
||||
if (!pinsReady()) { return void cb ('[RPC_NOT_READY]'); }
|
||||
|
||||
var list = getCanonicalChannelList();
|
||||
@@ -689,7 +688,7 @@ define([
|
||||
});
|
||||
};
|
||||
|
||||
var pinPads = common.pinPads = function (pads, cb) {
|
||||
common.pinPads = function (pads, cb) {
|
||||
if (!pinsReady()) { return void cb ('[RPC_NOT_READY]'); }
|
||||
|
||||
rpc.pin(pads, function (e, hash) {
|
||||
@@ -698,7 +697,7 @@ define([
|
||||
});
|
||||
};
|
||||
|
||||
var unpinPads = common.unpinPads = function (pads, cb) {
|
||||
common.unpinPads = function (pads, cb) {
|
||||
if (!pinsReady()) { return void cb ('[RPC_NOT_READY]'); }
|
||||
|
||||
rpc.unpin(pads, function (e, hash) {
|
||||
@@ -707,12 +706,12 @@ define([
|
||||
});
|
||||
};
|
||||
|
||||
var getPinnedUsage = common.getPinnedUsage = function (cb) {
|
||||
common.getPinnedUsage = function (cb) {
|
||||
if (!pinsReady()) { return void cb('[RPC_NOT_READY]'); }
|
||||
rpc.getFileListSize(cb);
|
||||
};
|
||||
|
||||
var getFileSize = common.getFileSize = function (href, cb) {
|
||||
common.getFileSize = function (href, cb) {
|
||||
var channelId = Hash.hrefToHexChannelId(href);
|
||||
rpc.getFileSize(channelId, function (e, bytes) {
|
||||
if (e) { return void cb(e); }
|
||||
@@ -720,11 +719,11 @@ define([
|
||||
});
|
||||
};
|
||||
|
||||
var getPinLimit = common.getPinLimit = function (cb) {
|
||||
common.getPinLimit = function (cb) {
|
||||
cb(void 0, typeof(AppConfig.pinLimit) === 'number'? AppConfig.pinLimit: 1000);
|
||||
};
|
||||
|
||||
var isOverPinLimit = common.isOverPinLimit = function (cb) {
|
||||
common.isOverPinLimit = function (cb) {
|
||||
if (!common.isLoggedIn() || !AppConfig.enablePinLimit) { return void cb(null, false); }
|
||||
var usage;
|
||||
var andThen = function (e, limit) {
|
||||
@@ -743,7 +742,7 @@ define([
|
||||
common.getPinnedUsage(todo);
|
||||
};
|
||||
|
||||
var createButton = common.createButton = function (type, rightside, data, callback) {
|
||||
common.createButton = function (type, rightside, data, callback) {
|
||||
var button;
|
||||
var size = "17px";
|
||||
switch (type) {
|
||||
@@ -832,7 +831,7 @@ define([
|
||||
var href = window.location.href;
|
||||
common.confirm(Messages.forgetPrompt, function (yes) {
|
||||
if (!yes) { return; }
|
||||
common.forgetPad(href, function (err, data) {
|
||||
common.forgetPad(href, function (err) {
|
||||
if (err) {
|
||||
console.log("unable to forget pad");
|
||||
console.error(err);
|
||||
@@ -1051,7 +1050,7 @@ define([
|
||||
|
||||
// Provide $container if you want to put the generated block in another element
|
||||
// Provide $initBlock if you already have the menu block and you want the content inserted in it
|
||||
var createLanguageSelector = common.createLanguageSelector = function ($container, $initBlock) {
|
||||
common.createLanguageSelector = function ($container, $initBlock) {
|
||||
var options = [];
|
||||
var languages = Messages._languages;
|
||||
var keys = Object.keys(languages).sort();
|
||||
@@ -1085,7 +1084,7 @@ define([
|
||||
return $block;
|
||||
};
|
||||
|
||||
var createUserAdminMenu = common.createUserAdminMenu = function (config) {
|
||||
common.createUserAdminMenu = function (config) {
|
||||
var $displayedName = $('<span>', {'class': config.displayNameCls || 'displayName'});
|
||||
var accountName = localStorage[common.userNameKey];
|
||||
var account = isLoggedIn();
|
||||
@@ -1172,24 +1171,24 @@ define([
|
||||
};
|
||||
var $userAdmin = createDropdown(dropdownConfigUser);
|
||||
|
||||
$userAdmin.find('a.logout').click(function (e) {
|
||||
$userAdmin.find('a.logout').click(function () {
|
||||
common.logout();
|
||||
window.location.href = '/';
|
||||
});
|
||||
$userAdmin.find('a.settings').click(function (e) {
|
||||
$userAdmin.find('a.settings').click(function () {
|
||||
if (parsed && parsed.type) {
|
||||
window.open('/settings/');
|
||||
} else {
|
||||
window.location.href = '/settings/';
|
||||
}
|
||||
});
|
||||
$userAdmin.find('a.login').click(function (e) {
|
||||
$userAdmin.find('a.login').click(function () {
|
||||
if (window.location.pathname !== "/") {
|
||||
sessionStorage.redirectTo = window.location.href;
|
||||
}
|
||||
window.location.href = '/login/';
|
||||
});
|
||||
$userAdmin.find('a.register').click(function (e) {
|
||||
$userAdmin.find('a.register').click(function () {
|
||||
if (window.location.pathname !== "/") {
|
||||
sessionStorage.redirectTo = window.location.href;
|
||||
}
|
||||
@@ -1281,7 +1280,8 @@ define([
|
||||
|
||||
common.arePinsSynced(function (err, yes) {
|
||||
if (!yes) {
|
||||
common.resetPins(function (err, hash) {
|
||||
common.resetPins(function (err) {
|
||||
if (err) { console.error(err); }
|
||||
console.log('RESET DONE');
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
define([
|
||||
'/common/treesome.js',
|
||||
'/bower_components/rangy/rangy-core.min.js'
|
||||
], function (Tree, Rangy, saveRestore) {
|
||||
var log = function (x) { console.log(x); };
|
||||
var error = function (x) { console.log(x); };
|
||||
], function (Tree, Rangy) {
|
||||
var verbose = function (x) { if (window.verboseMode) { console.log(x); } };
|
||||
|
||||
/* accepts the document used by the editor */
|
||||
@@ -45,7 +43,7 @@ define([
|
||||
});
|
||||
};
|
||||
|
||||
var exists = cursor.exists = function () {
|
||||
cursor.exists = function () {
|
||||
return (Range.start.el?1:0) | (Range.end.el?2:0);
|
||||
};
|
||||
|
||||
@@ -55,7 +53,7 @@ define([
|
||||
2 if end
|
||||
3 if start and end
|
||||
*/
|
||||
var inNode = cursor.inNode = function (el) {
|
||||
cursor.inNode = function (el) {
|
||||
var state = ['start', 'end'].map(function (pos, i) {
|
||||
return Tree.contains(el, Range[pos].el)? i +1: 0;
|
||||
});
|
||||
@@ -122,7 +120,7 @@ define([
|
||||
}
|
||||
};
|
||||
|
||||
var pushDelta = cursor.pushDelta = function (oldVal, newVal, offset) {
|
||||
cursor.pushDelta = function (oldVal, newVal) {
|
||||
if (oldVal === newVal) { return; }
|
||||
var commonStart = 0;
|
||||
while (oldVal.charAt(commonStart) === newVal.charAt(commonStart)) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
define([], function () {
|
||||
var exports = {};
|
||||
|
||||
var hexToUint8Array = exports.hexToUint8Array = function (s) {
|
||||
exports.hexToUint8Array = function (s) {
|
||||
// if not hex or odd number of characters
|
||||
if (!/[a-fA-F0-9]+/.test(s) || s.length % 2) { throw new Error("string is not hex"); }
|
||||
return s.split(/([0-9a-fA-F]{2})/)
|
||||
@@ -9,7 +9,7 @@ define([], function () {
|
||||
.map(function (x) { return Number('0x' + x); });
|
||||
};
|
||||
|
||||
var uint8ArrayToHex = exports.uint8ArrayToHex = function (a) {
|
||||
exports.uint8ArrayToHex = function (a) {
|
||||
return a.reduce(function(memo, i) {
|
||||
return memo + ((i < 16) ? '0' : '') + i.toString(16);
|
||||
}, '');
|
||||
|
||||
@@ -10,7 +10,7 @@ define([
|
||||
var TRASH = module.TRASH = "trash";
|
||||
var TEMPLATE = module.TEMPLATE = "template";
|
||||
|
||||
var init = module.init = function (files, config) {
|
||||
module.init = function (files, config) {
|
||||
var Cryptpad = config.Cryptpad;
|
||||
Messages = Cryptpad.Messages;
|
||||
|
||||
@@ -18,7 +18,7 @@ define([
|
||||
var NEW_FOLDER_NAME = Messages.fm_newFolder;
|
||||
var NEW_FILE_NAME = Messages.fm_newFile;
|
||||
|
||||
var DEBUG = config.DEBUG || false;
|
||||
//var DEBUG = config.DEBUG || false;
|
||||
var logging = function () {
|
||||
console.log.apply(console, arguments);
|
||||
};
|
||||
@@ -34,7 +34,7 @@ define([
|
||||
console.error.apply(console, arguments);
|
||||
};
|
||||
|
||||
var getStructure = exp.getStructure = function () {
|
||||
exp.getStructure = function () {
|
||||
var a = {};
|
||||
a[ROOT] = {};
|
||||
a[UNSORTED] = [];
|
||||
@@ -92,7 +92,7 @@ define([
|
||||
return path[0] === TRASH && path.length === 4;
|
||||
};
|
||||
|
||||
var isPathInFilesData = exp.isPathInFilesData = function (path) {
|
||||
exp.isPathInFilesData = function (path) {
|
||||
return path[0] && path[0] === FILES_DATA;
|
||||
};
|
||||
|
||||
@@ -100,7 +100,7 @@ define([
|
||||
return typeof(element) === "string";
|
||||
};
|
||||
|
||||
var isReadOnlyFile = exp.isReadOnlyFile = function (element) {
|
||||
exp.isReadOnlyFile = function (element) {
|
||||
if (!isFile(element)) { return false; }
|
||||
var parsed = Cryptpad.parsePadUrl(element);
|
||||
if (!parsed) { return false; }
|
||||
@@ -114,15 +114,15 @@ define([
|
||||
return typeof(element) !== "string";
|
||||
};
|
||||
|
||||
var isFolderEmpty = exp.isFolderEmpty = function (element) {
|
||||
exp.isFolderEmpty = function (element) {
|
||||
if (typeof(element) !== "object") { return false; }
|
||||
return Object.keys(element).length === 0;
|
||||
};
|
||||
|
||||
var hasSubfolder = exp.hasSubfolder = function (element, trashRoot) {
|
||||
exp.hasSubfolder = function (element, trashRoot) {
|
||||
if (typeof(element) !== "object") { return false; }
|
||||
var subfolder = 0;
|
||||
var addSubfolder = function (el, idx) {
|
||||
var addSubfolder = function (el) {
|
||||
subfolder += isFolder(el.element) ? 1 : 0;
|
||||
};
|
||||
for (var f in element) {
|
||||
@@ -137,10 +137,10 @@ define([
|
||||
return subfolder;
|
||||
};
|
||||
|
||||
var hasFile = exp.hasFile = function (element, trashRoot) {
|
||||
exp.hasFile = function (element, trashRoot) {
|
||||
if (typeof(element) !== "object") { return false; }
|
||||
var file = 0;
|
||||
var addFile = function (el, idx) {
|
||||
var addFile = function (el) {
|
||||
file += isFile(el.element) ? 1 : 0;
|
||||
};
|
||||
for (var f in element) {
|
||||
@@ -189,10 +189,10 @@ define([
|
||||
return inTree;
|
||||
};
|
||||
|
||||
var isFileInTrash = function (file) {
|
||||
/* var isFileInTrash = function (file) {
|
||||
var inTrash = false;
|
||||
var root = files[TRASH];
|
||||
var filter = function (trashEl, idx) {
|
||||
var filter = function (trashEl) {
|
||||
inTrash = isFileInTree(file, trashEl.element);
|
||||
return inTrash;
|
||||
};
|
||||
@@ -205,11 +205,7 @@ define([
|
||||
if (inTrash) { break; }
|
||||
}
|
||||
return inTrash;
|
||||
};
|
||||
|
||||
var isFileInUnsorted = function (file) {
|
||||
return files[UNSORTED].indexOf(file) !== -1;
|
||||
};
|
||||
};*/
|
||||
|
||||
var getUnsortedFiles = exp.getUnsortedFiles = function () {
|
||||
if (!files[UNSORTED]) {
|
||||
@@ -244,7 +240,7 @@ define([
|
||||
var getTrashFiles = exp.getTrashFiles = function () {
|
||||
var root = files[TRASH];
|
||||
var ret = [];
|
||||
var addFiles = function (el, idx) {
|
||||
var addFiles = function (el) {
|
||||
if (isFile(el.element)) {
|
||||
if(ret.indexOf(el.element) === -1) { ret.push(el.element); }
|
||||
} else {
|
||||
@@ -261,7 +257,7 @@ define([
|
||||
return ret;
|
||||
};
|
||||
|
||||
var getFilesDataFiles = exp.getFilesDataFiles = function () {
|
||||
exp.getFilesDataFiles = function () {
|
||||
var ret = [];
|
||||
files[FILES_DATA].forEach(function (el) {
|
||||
if (el.href && ret.indexOf(el.href) === -1) {
|
||||
@@ -351,7 +347,7 @@ define([
|
||||
return rootpaths.concat(unsortedpaths, templatepaths, trashpaths);
|
||||
};
|
||||
|
||||
var search = exp.search = function (value) {
|
||||
exp.search = function (value) {
|
||||
if (typeof(value) !== "string") { return []; }
|
||||
var res = [];
|
||||
// Search in ROOT
|
||||
@@ -402,7 +398,7 @@ define([
|
||||
|
||||
var ret = [];
|
||||
res.forEach(function (l) {
|
||||
var paths = findFile(l);
|
||||
//var paths = findFile(l);
|
||||
ret.push({
|
||||
paths: findFile(l),
|
||||
data: exp.getFileData(l)
|
||||
@@ -509,7 +505,7 @@ define([
|
||||
files[TRASH][obj.name].splice(idx, 1);
|
||||
});
|
||||
};
|
||||
var deleteMultiplePermanently = exp.deletePathsPermanently = function (paths) {
|
||||
exp.deletePathsPermanently = function (paths) {
|
||||
var hrefPaths = paths.filter(isPathInHrefArray);
|
||||
var rootPaths = paths.filter(isPathInRoot);
|
||||
var trashPaths = paths.filter(isPathInTrash);
|
||||
@@ -723,7 +719,7 @@ define([
|
||||
if (cb) { cb(); }
|
||||
};
|
||||
|
||||
var moveElements = exp.moveElements = function (paths, newParentPath, cb) {
|
||||
exp.moveElements = function (paths, newParentPath, cb) {
|
||||
var unsortedPaths = paths.filter(isPathInHrefArray);
|
||||
moveHrefArrayElements(unsortedPaths, newParentPath);
|
||||
// Copy the elements to their new location
|
||||
@@ -735,7 +731,7 @@ define([
|
||||
};
|
||||
|
||||
// Import elements in the file manager
|
||||
var importElements = exp.importElements = function (elements, path, cb) {
|
||||
exp.importElements = function (elements, path, cb) {
|
||||
if (!elements || elements.length === 0) { return; }
|
||||
var newParent = findElement(files, path);
|
||||
if (!newParent) { debug("Trying to import elements into a non-existing folder"); return; }
|
||||
@@ -748,7 +744,7 @@ define([
|
||||
if(cb) { cb(); }
|
||||
};
|
||||
|
||||
var createNewFolder = exp.createNewFolder = function (folderPath, name, cb) {
|
||||
exp.createNewFolder = function (folderPath, name, cb) {
|
||||
var parentEl = findElement(files, folderPath);
|
||||
var folderName = getAvailableName(parentEl, name || NEW_FOLDER_NAME);
|
||||
parentEl[folderName] = {};
|
||||
@@ -767,7 +763,7 @@ define([
|
||||
ctime: +new Date()
|
||||
});
|
||||
};
|
||||
var createNewFile = exp.createNewFile = function (filePath, name, type, cb) {
|
||||
exp.createNewFile = function (filePath, name, type, cb) {
|
||||
var parentEl = findElement(files, filePath);
|
||||
var fileName = getAvailableName(parentEl, name || NEW_FILE_NAME);
|
||||
var href = '/' + type + '/#' + Cryptpad.createRandomHash();
|
||||
@@ -799,7 +795,7 @@ define([
|
||||
};
|
||||
|
||||
// Restore an element (copy it elsewhere and remove from the trash root)
|
||||
var restoreTrash = exp.restoreTrash = function (path, cb) {
|
||||
exp.restoreTrash = function (path, cb) {
|
||||
if (!path || path.length !== 4 || path[0] !== TRASH) {
|
||||
debug("restoreTrash was called from an element not in the trash root: ", path);
|
||||
return;
|
||||
@@ -838,7 +834,7 @@ define([
|
||||
// Remove the last element from the path to get the parent path and the element name
|
||||
var parentPath = path.slice();
|
||||
var name;
|
||||
var element = findElement(files, path);
|
||||
//var element = findElement(files, path);
|
||||
if (path.length === 4) { // Trash root
|
||||
name = path[1];
|
||||
parentPath.pop();
|
||||
@@ -860,13 +856,13 @@ define([
|
||||
if(cb) { cb(); }
|
||||
};
|
||||
|
||||
var emptyTrash = exp.emptyTrash = function (cb) {
|
||||
exp.emptyTrash = function (cb) {
|
||||
files[TRASH] = {};
|
||||
checkDeletedFiles();
|
||||
if(cb) { cb(); }
|
||||
};
|
||||
|
||||
var deleteFileData = exp.deleteFileData = function (href, cb) {
|
||||
exp.deleteFileData = function (href, cb) {
|
||||
if (workgroup) { return; }
|
||||
|
||||
var toRemove = [];
|
||||
@@ -889,7 +885,7 @@ define([
|
||||
if(cb) { cb(); }
|
||||
};
|
||||
|
||||
var renameElement = exp.renameElement = function (path, newName, cb) {
|
||||
exp.renameElement = function (path, newName, cb) {
|
||||
if (path.length <= 1) {
|
||||
logError('Renaming `root` is forbidden');
|
||||
return;
|
||||
@@ -914,7 +910,7 @@ define([
|
||||
};
|
||||
|
||||
|
||||
var forgetPad = exp.forgetPad = function (href) {
|
||||
exp.forgetPad = function (href) {
|
||||
if (workgroup) { return; }
|
||||
if (!href || !isFile(href)) { return; }
|
||||
var path;
|
||||
@@ -985,7 +981,7 @@ define([
|
||||
};
|
||||
|
||||
// Replace a href by a stronger one everywhere in the drive (except FILES_DATA)
|
||||
var replaceHref = exp.replaceHref = function (o, n) {
|
||||
exp.replaceHref = function (o, n) {
|
||||
if (!isFile(o) || !isFile(n)) { return; }
|
||||
var paths = findFile(o);
|
||||
|
||||
@@ -1012,7 +1008,7 @@ define([
|
||||
|
||||
// addTemplate is called when we want to add a new pad, never visited, to the templates list
|
||||
// first, we must add it to FILES_DATA, so the input has to be an fileDAta object
|
||||
var addTemplate = exp.addTemplate = function (fileData) {
|
||||
exp.addTemplate = function (fileData) {
|
||||
if (workgroup) { return; }
|
||||
if (typeof fileData !== "object" || !fileData.href || !fileData.title) {
|
||||
console.error("filedata object expected to add a new template");
|
||||
@@ -1031,7 +1027,7 @@ define([
|
||||
}
|
||||
};
|
||||
|
||||
var listTemplates = exp.listTemplates = function (type) {
|
||||
exp.listTemplates = function () {
|
||||
if (workgroup) { return; }
|
||||
var templateFiles = getTemplateFiles();
|
||||
var res = [];
|
||||
@@ -1049,7 +1045,7 @@ define([
|
||||
});
|
||||
};
|
||||
|
||||
var fixFiles = exp.fixFiles = function () {
|
||||
exp.fixFiles = function () {
|
||||
// Explore the tree and check that everything is correct:
|
||||
// * 'root', 'trash', 'unsorted' and 'filesData' exist and are objects
|
||||
// * ROOT: Folders are objects, files are href
|
||||
@@ -1138,7 +1134,7 @@ define([
|
||||
var templateFiles = getTemplateFiles();
|
||||
var trashFiles = getTrashFiles();
|
||||
var toClean = [];
|
||||
fd.forEach(function (el, idx) {
|
||||
fd.forEach(function (el) {
|
||||
if (!el || typeof(el) !== "object") {
|
||||
debug("An element in filesData was not an object.", el);
|
||||
toClean.push(el);
|
||||
|
||||
@@ -127,9 +127,9 @@ define([
|
||||
return filesOp.replace(o, n);
|
||||
};
|
||||
|
||||
var changeHandlers = ret.changeHandlers = [];
|
||||
ret.changeHandlers = [];
|
||||
|
||||
ret.change = function (f) {};
|
||||
ret.change = function () {};
|
||||
|
||||
return ret;
|
||||
};
|
||||
@@ -166,7 +166,7 @@ define([
|
||||
return;
|
||||
}
|
||||
|
||||
proxy.on('change', [Cryptpad.displayNameKey], function (o, n, p) {
|
||||
proxy.on('change', [Cryptpad.displayNameKey], function (o, n) {
|
||||
if (typeof(n) !== "string") { return; }
|
||||
Cryptpad.changeDisplayName(n);
|
||||
});
|
||||
@@ -197,7 +197,6 @@ define([
|
||||
var exp = {};
|
||||
|
||||
window.addEventListener('storage', function (e) {
|
||||
var key = e.key;
|
||||
if (e.key !== Cryptpad.userHashKey) { return; }
|
||||
var o = e.oldValue;
|
||||
var n = e.newValue;
|
||||
|
||||
@@ -22,7 +22,7 @@ define([
|
||||
// 16 bytes for a deterministic channel key
|
||||
var channelSeed = dispense(16);
|
||||
// 32 bytes for a curve key
|
||||
var curveSeed = opt.curveSeed = dispense(32);
|
||||
opt.curveSeed = dispense(32);
|
||||
// 32 more for a signing key
|
||||
var edSeed = opt.edSeed = dispense(32);
|
||||
|
||||
@@ -43,9 +43,9 @@ define([
|
||||
// should never happen
|
||||
if (channelHex.length !== 32) { throw new Error('invalid channel id'); }
|
||||
|
||||
var channel64 = opt.channel64 = Cryptpad.hexToBase64(channelHex);
|
||||
opt.channel64 = Cryptpad.hexToBase64(channelHex);
|
||||
|
||||
var userHash = opt.userHash = '/1/edit/' + [opt.channel64, opt.keys.editKeyStr].join('/');
|
||||
opt.userHash = '/1/edit/' + [opt.channel64, opt.keys.editKeyStr].join('/');
|
||||
|
||||
return opt;
|
||||
};
|
||||
@@ -62,7 +62,7 @@ define([
|
||||
|
||||
var rt = opt.rt = Listmap.create(config);
|
||||
rt.proxy
|
||||
.on('ready', function (info) {
|
||||
.on('ready', function () {
|
||||
cb(void 0, rt);
|
||||
})
|
||||
.on('disconnect', function (info) {
|
||||
|
||||
@@ -46,7 +46,7 @@ define([
|
||||
var merge = function (obj1, obj2, keepOld) {
|
||||
if (typeof (obj1) !== "object" || typeof (obj2) !== "object") { return; }
|
||||
Object.keys(obj2).forEach(function (k) {
|
||||
var v = obj2[k];
|
||||
//var v = obj2[k];
|
||||
// If one of them is not an object or if we have a map and a array, don't override, create a new key
|
||||
if (!obj1[k] || typeof(obj1[k]) !== "object" || typeof(obj2[k]) !== "object" ||
|
||||
(getType(obj1[k]) !== getType(obj2[k]))) {
|
||||
@@ -80,7 +80,7 @@ define([
|
||||
path.pop();
|
||||
}
|
||||
|
||||
var p, next, nextRoot;
|
||||
var next, nextRoot;
|
||||
path.forEach(function (p, i) {
|
||||
if (!root) { return; }
|
||||
if (typeof(p) === "string") {
|
||||
@@ -128,7 +128,7 @@ define([
|
||||
});
|
||||
};
|
||||
|
||||
var mergeAnonDrive = exp.anonDriveIntoUser = function (proxy, cb) {
|
||||
exp.anonDriveIntoUser = function (proxy, cb) {
|
||||
// Make sure we have an FS_hash and we don't use it, otherwise just stop the migration and cb
|
||||
if (!localStorage.FS_hash || !Cryptpad.isLoggedIn()) {
|
||||
if (typeof(cb) === "function") { cb(); }
|
||||
|
||||
@@ -132,7 +132,7 @@ define(function () {
|
||||
};
|
||||
});
|
||||
|
||||
var extensionOf = Modes.extensionOf = function (mode) {
|
||||
Modes.extensionOf = function (mode) {
|
||||
var ext = '';
|
||||
list.some(function (o) {
|
||||
if (o.mode !== mode) { return; }
|
||||
|
||||
@@ -16,14 +16,14 @@
|
||||
});
|
||||
};
|
||||
|
||||
var create = Module.create = function (msg, title, icon) {
|
||||
var create = Module.create = function (msg, title) {
|
||||
return new Notification(title,{
|
||||
// icon: icon,
|
||||
body: msg,
|
||||
});
|
||||
};
|
||||
|
||||
var system = Module.system = function (msg, title, icon) {
|
||||
Module.system = function (msg, title, icon) {
|
||||
// Let's check if the browser supports notifications
|
||||
if (!isSupported()) { console.log("Notifications are not supported"); }
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
}
|
||||
};
|
||||
|
||||
var tab = Module.tab = function (frequency, count) {
|
||||
Module.tab = function (frequency, count) {
|
||||
var key = '_pendingTabNotification';
|
||||
|
||||
var favicon = document.getElementById('favicon');
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
define([
|
||||
'/bower_components/tweetnacl/nacl-fast.min.js',
|
||||
], function () {
|
||||
var MAX_LAG_BEFORE_TIMEOUT = 30000;
|
||||
var Nacl = window.nacl;
|
||||
|
||||
var uid = function () {
|
||||
@@ -130,22 +129,22 @@ types of messages:
|
||||
return sendMsg(ctx, data, cb);
|
||||
};
|
||||
|
||||
network.on('message', function (msg, sender) {
|
||||
network.on('message', function (msg) {
|
||||
onMsg(ctx, msg);
|
||||
});
|
||||
|
||||
network.on('disconnect', function (reason) {
|
||||
network.on('disconnect', function () {
|
||||
ctx.connected = false;
|
||||
});
|
||||
|
||||
network.on('reconnect', function (uid) {
|
||||
send('COOKIE', "", function (e, msg) {
|
||||
network.on('reconnect', function () {
|
||||
send('COOKIE', "", function (e) {
|
||||
if (e) { return void cb(e); }
|
||||
ctx.connected = true;
|
||||
});
|
||||
});
|
||||
|
||||
send('COOKIE', "", function (e, msg) {
|
||||
send('COOKIE', "", function (e) {
|
||||
if (e) { return void cb(e); }
|
||||
// callback to provide 'send' method to whatever needs it
|
||||
cb(void 0, { send: send, });
|
||||
|
||||
@@ -71,7 +71,7 @@ define([], function () {
|
||||
}
|
||||
};
|
||||
|
||||
var orderOfNodes = tree.orderOfNodes = function (a, b, root) {
|
||||
tree.orderOfNodes = function (a, b, root) {
|
||||
// b might not be supplied
|
||||
if (!b) { return; }
|
||||
// a and b might be the same element
|
||||
|
||||
@@ -9,7 +9,7 @@ define([
|
||||
var TRASH = module.TRASH = "trash";
|
||||
var TEMPLATE = module.TEMPLATE = "template";
|
||||
|
||||
var init = module.init = function (files, config) {
|
||||
module.init = function (files, config) {
|
||||
var exp = {};
|
||||
var Cryptpad = config.Cryptpad;
|
||||
var Messages = Cryptpad.Messages;
|
||||
@@ -19,7 +19,6 @@ define([
|
||||
var NEW_FILE_NAME = Messages.fm_newFile;
|
||||
|
||||
// Logging
|
||||
var DEBUG = config.DEBUG || false;
|
||||
var logging = function () {
|
||||
console.log.apply(console, arguments);
|
||||
};
|
||||
@@ -39,7 +38,7 @@ define([
|
||||
* UTILS
|
||||
*/
|
||||
|
||||
var getStructure = exp.getStructure = function () {
|
||||
exp.getStructure = function () {
|
||||
var a = {};
|
||||
a[ROOT] = {};
|
||||
a[TRASH] = {};
|
||||
@@ -58,7 +57,7 @@ define([
|
||||
return typeof(element) === "string";
|
||||
};
|
||||
|
||||
var isReadOnlyFile = exp.isReadOnlyFile = function (element) {
|
||||
exp.isReadOnlyFile = function (element) {
|
||||
if (!isFile(element)) { return false; }
|
||||
var parsed = Cryptpad.parsePadUrl(element);
|
||||
if (!parsed) { return false; }
|
||||
@@ -71,15 +70,15 @@ define([
|
||||
var isFolder = exp.isFolder = function (element) {
|
||||
return typeof(element) === "object";
|
||||
};
|
||||
var isFolderEmpty = exp.isFolderEmpty = function (element) {
|
||||
exp.isFolderEmpty = function (element) {
|
||||
if (typeof(element) !== "object") { return false; }
|
||||
return Object.keys(element).length === 0;
|
||||
};
|
||||
|
||||
var hasSubfolder = exp.hasSubfolder = function (element, trashRoot) {
|
||||
exp.hasSubfolder = function (element, trashRoot) {
|
||||
if (typeof(element) !== "object") { return false; }
|
||||
var subfolder = 0;
|
||||
var addSubfolder = function (el, idx) {
|
||||
var addSubfolder = function (el) {
|
||||
subfolder += isFolder(el.element) ? 1 : 0;
|
||||
};
|
||||
for (var f in element) {
|
||||
@@ -94,10 +93,10 @@ define([
|
||||
return subfolder;
|
||||
};
|
||||
|
||||
var hasFile = exp.hasFile = function (element, trashRoot) {
|
||||
exp.hasFile = function (element, trashRoot) {
|
||||
if (typeof(element) !== "object") { return false; }
|
||||
var file = 0;
|
||||
var addFile = function (el, idx) {
|
||||
var addFile = function (el) {
|
||||
file += isFile(el.element) ? 1 : 0;
|
||||
};
|
||||
for (var f in element) {
|
||||
@@ -232,7 +231,7 @@ define([
|
||||
_getFiles[TRASH] = function () {
|
||||
var root = files[TRASH];
|
||||
var ret = [];
|
||||
var addFiles = function (el, idx) {
|
||||
var addFiles = function (el) {
|
||||
if (isFile(el.element)) {
|
||||
if(ret.indexOf(el.element) === -1) { ret.push(el.element); }
|
||||
} else {
|
||||
@@ -297,7 +296,7 @@ define([
|
||||
|
||||
return paths;
|
||||
};
|
||||
var findFileInRoot = exp.findFileInRoot = function (href) {
|
||||
exp.findFileInRoot = function (href) {
|
||||
return _findFileInRoot([ROOT], href);
|
||||
};
|
||||
var _findFileInHrefArray = function (rootName, href) {
|
||||
@@ -352,7 +351,7 @@ define([
|
||||
var trashpaths = _findFileInTrash([TRASH], href);
|
||||
return rootpaths.concat(templatepaths, trashpaths);
|
||||
};
|
||||
var search = exp.search = function (value) {
|
||||
exp.search = function (value) {
|
||||
if (typeof(value) !== "string") { return []; }
|
||||
var res = [];
|
||||
// Search in ROOT
|
||||
@@ -403,7 +402,7 @@ define([
|
||||
|
||||
var ret = [];
|
||||
res.forEach(function (l) {
|
||||
var paths = findFile(l);
|
||||
//var paths = findFile(l);
|
||||
ret.push({
|
||||
paths: findFile(l),
|
||||
data: exp.getFileData(l)
|
||||
@@ -435,7 +434,7 @@ define([
|
||||
cb();
|
||||
};
|
||||
if (!Cryptpad.isLoggedIn() || !AppConfig.enablePinning) { return void todo(); }
|
||||
Cryptpad.pinPads([Cryptpad.hrefToHexChannelId(data.href)], function (e, hash) {
|
||||
Cryptpad.pinPads([Cryptpad.hrefToHexChannelId(data.href)], function (e) {
|
||||
if (e) { return void cb(e); }
|
||||
todo();
|
||||
});
|
||||
@@ -531,7 +530,7 @@ define([
|
||||
});
|
||||
exp.delete(toRemove, cb);
|
||||
};
|
||||
var restore = exp.restore = function (path, cb) {
|
||||
exp.restore = function (path, cb) {
|
||||
if (!isInTrashRoot(path)) { return; }
|
||||
var parentPath = path.slice();
|
||||
parentPath.pop();
|
||||
@@ -566,7 +565,7 @@ define([
|
||||
}
|
||||
}
|
||||
};
|
||||
var addFile = exp.addFile = function (filePath, name, type, cb) {
|
||||
exp.addFile = function (filePath, name, type, cb) {
|
||||
var parentEl = findElement(files, filePath);
|
||||
var fileName = getAvailableName(parentEl, name || NEW_FILE_NAME);
|
||||
var href = '/' + type + '/#' + Cryptpad.createRandomHash();
|
||||
@@ -586,7 +585,7 @@ define([
|
||||
});
|
||||
});
|
||||
};
|
||||
var addFolder = exp.addFolder = function (folderPath, name, cb) {
|
||||
exp.addFolder = function (folderPath, name, cb) {
|
||||
var parentEl = find(folderPath);
|
||||
var folderName = getAvailableName(parentEl, name || NEW_FOLDER_NAME);
|
||||
parentEl[folderName] = {};
|
||||
@@ -598,7 +597,7 @@ define([
|
||||
};
|
||||
|
||||
// FORGET (move with href not path)
|
||||
var forget = exp.forget = function (href) {
|
||||
exp.forget = function (href) {
|
||||
var paths = findFile(href);
|
||||
move(paths, [TRASH]);
|
||||
};
|
||||
@@ -700,18 +699,18 @@ define([
|
||||
// FILES_DATA (replaceHref)
|
||||
if (!nocheck) { checkDeletedFiles(); }
|
||||
};
|
||||
var deletePath = exp.delete = function (paths, cb, nocheck) {
|
||||
exp.delete = function (paths, cb, nocheck) {
|
||||
deleteMultiplePermanently(paths, nocheck);
|
||||
if (typeof cb === "function") { cb(); }
|
||||
};
|
||||
var emptyTrash = exp.emptyTrash = function (cb) {
|
||||
exp.emptyTrash = function (cb) {
|
||||
files[TRASH] = {};
|
||||
checkDeletedFiles();
|
||||
if(cb) { cb(); }
|
||||
};
|
||||
|
||||
// RENAME
|
||||
var rename = exp.rename = function (path, newName, cb) {
|
||||
exp.rename = function (path, newName, cb) {
|
||||
if (path.length <= 1) {
|
||||
logError('Renaming `root` is forbidden');
|
||||
return;
|
||||
@@ -753,7 +752,7 @@ define([
|
||||
}
|
||||
};
|
||||
// Replace a href by a stronger one everywhere in the drive (except FILES_DATA)
|
||||
var replaceHref = exp.replace = function (o, n) {
|
||||
exp.replace = function (o, n) {
|
||||
if (!isFile(o) || !isFile(n)) { return; }
|
||||
var paths = findFile(o);
|
||||
|
||||
@@ -782,7 +781,7 @@ define([
|
||||
* INTEGRITY CHECK
|
||||
*/
|
||||
|
||||
var fixFiles = exp.fixFiles = function () {
|
||||
exp.fixFiles = function () {
|
||||
// Explore the tree and check that everything is correct:
|
||||
// * 'root', 'trash', 'unsorted' and 'filesData' exist and are objects
|
||||
// * ROOT: Folders are objects, files are href
|
||||
@@ -841,9 +840,9 @@ define([
|
||||
return;
|
||||
}
|
||||
var rootFiles = getFiles([ROOT, TEMPLATE]).slice();
|
||||
var toClean = [];
|
||||
//var toClean = [];
|
||||
var root = find([ROOT]);
|
||||
us.forEach(function (el, idx) {
|
||||
us.forEach(function (el) {
|
||||
if (!isFile(el) || rootFiles.indexOf(el) !== -1) {
|
||||
return;
|
||||
//toClean.push(idx);
|
||||
@@ -878,7 +877,7 @@ define([
|
||||
var rootFiles = getFiles([ROOT, TRASH, 'hrefArray']);
|
||||
var root = find([ROOT]);
|
||||
var toClean = [];
|
||||
fd.forEach(function (el, idx) {
|
||||
fd.forEach(function (el) {
|
||||
if (!el || typeof(el) !== "object") {
|
||||
debug("An element in filesData was not an object.", el);
|
||||
toClean.push(el);
|
||||
|
||||
@@ -20,18 +20,18 @@
|
||||
visibilityChange: visibilityChange,
|
||||
};
|
||||
|
||||
var isSupported = Visible.isSupported = function () {
|
||||
Visible.isSupported = function () {
|
||||
return !(typeof(document.addEventListener) === "undefined" ||
|
||||
typeof document[hidden] === "undefined");
|
||||
};
|
||||
|
||||
var onChange = Visible.onChange = function (f) {
|
||||
Visible.onChange = function (f) {
|
||||
document.addEventListener(visibilityChange, function (ev) {
|
||||
f(!document[hidden], ev);
|
||||
}, false);
|
||||
};
|
||||
|
||||
var currently = Visible.currently = function () {
|
||||
Visible.currently = function () {
|
||||
return !document[hidden];
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user