diff --git a/.jshintignore b/.jshintignore index 93e467aef..919395546 100644 --- a/.jshintignore +++ b/.jshintignore @@ -11,3 +11,5 @@ NetFluxWebsocketServer.js WebRTCSrv.js www/common/media-tag.js www/scratch + +www/common/toolbar.js diff --git a/.jshintrc b/.jshintrc index c55ec0518..4928c524d 100644 --- a/.jshintrc +++ b/.jshintrc @@ -10,7 +10,7 @@ "notypeof": true, "shadow": false, "undef": true, - "unused": false, + "unused": true, "futurehostile":true, "browser": true, "predef": [ diff --git a/customize.dist/main.js b/customize.dist/main.js index a02433b05..cdaeedfdb 100644 --- a/customize.dist/main.js +++ b/customize.dist/main.js @@ -4,7 +4,7 @@ define([ '/common/cryptpad-common.js' ], function ($, Config, Cryptpad) { - var APP = window.APP = { + window.APP = { Cryptpad: Cryptpad, }; @@ -118,7 +118,7 @@ define([ $('button.login').click(); }); - $('button.login').click(function (e) { + $('button.login').click(function () { Cryptpad.addLoadingScreen(Messages.login_hashing); // We need a setTimeout(cb, 0) otherwise the loading screen is only displayed after hashing the password window.setTimeout(function () { @@ -171,15 +171,14 @@ define([ /* End Log in UI */ var addButtonHandlers = function () { - $('button.register').click(function (e) { + $('button.register').click(function () { var username = $('#name').val(); var passwd = $('#password').val(); - var remember = $('#rememberme').is(':checked'); sessionStorage.login_user = username; sessionStorage.login_pass = passwd; document.location.href = '/register/'; }); - $('button.gotodrive').click(function (e) { + $('button.gotodrive').click(function () { document.location.href = '/drive/'; }); }; diff --git a/customize.dist/messages.js b/customize.dist/messages.js index 18d329d6d..813978b52 100644 --- a/customize.dist/messages.js +++ b/customize.dist/messages.js @@ -112,9 +112,7 @@ define(req, function($, Default, Language) { if (!selector.length) { return; } - var $button = $(selector).find('button .buttonTitle'); // Select the current language in the list - var option = $(selector).find('[data-value="' + language + '"]'); selector.setValue(language || 'English'); // Listen for language change @@ -137,12 +135,12 @@ define(req, function($, Default, Language) { var key = $el.data('localization-append'); $el.append(messages[key]); }; - var translateTitle = function (i, e) { + var translateTitle = function () { var $el = $(this); var key = $el.data('localization-title'); $el.attr('title', messages[key]); }; - var translatePlaceholder = function (i, e) { + var translatePlaceholder = function () { var $el = $(this); var key = $el.data('localization-placeholder'); $el.attr('placeholder', messages[key]); diff --git a/customize.dist/share/frame.js b/customize.dist/share/frame.js index a07ff05ce..2698372fd 100644 --- a/customize.dist/share/frame.js +++ b/customize.dist/share/frame.js @@ -10,7 +10,7 @@ // create an invisible iframe with a given source // append it to a parent element // execute a callback when it has loaded - var create = Frame.create = function (parent, src, onload, timeout) { + Frame.create = function (parent, src, onload, timeout) { var iframe = document.createElement('iframe'); timeout = timeout || 10000; @@ -34,7 +34,7 @@ /* given an iframe with an rpc script loaded, create a frame object with an asynchronous 'send' method */ - var open = Frame.open = function (e, A, timeout) { + Frame.open = function (e, A, timeout) { var win = e.contentWindow; var frame = {}; @@ -44,7 +44,7 @@ timeout = timeout || 5000; - var accepts = frame.accepts = function (o) { + frame.accepts = function (o) { return A.some(function (e) { switch (typeof(e)) { case 'string': return e === o; @@ -55,7 +55,7 @@ var changeHandlers = frame.changeHandlers = []; - var change = frame.change = function (f) { + frame.change = function (f) { if (typeof(f) !== 'function') { throw new Error('[Frame.change] expected callback'); } @@ -94,7 +94,7 @@ }; window.addEventListener('message', _listener); - var close = frame.close = function () { + frame.close = function () { window.removeEventListener('message', _listener); }; @@ -130,31 +130,31 @@ win.postMessage(JSON.stringify(req), '*'); }; - var set = frame.set = function (key, val, cb) { + frame.set = function (key, val, cb) { send('set', key, val, cb); }; - var batchset = frame.setBatch = function (map, cb) { + frame.setBatch = function (map, cb) { send('batchset', void 0, map, cb); }; - var get = frame.get = function (key, cb) { + frame.get = function (key, cb) { send('get', key, void 0, cb); }; - var batchget = frame.getBatch = function (keys, cb) { + frame.getBatch = function (keys, cb) { send('batchget', void 0, keys, cb); }; - var remove = frame.remove = function (key, cb) { + frame.remove = function (key, cb) { send('remove', key, void 0, cb); }; - var batchremove = frame.removeBatch = function (keys, cb) { + frame.removeBatch = function (keys, cb) { send('batchremove', void 0, keys, cb); }; - var keys = frame.keys = function (cb) { + frame.keys = function (cb) { send('keys', void 0, void 0, cb); }; @@ -164,7 +164,7 @@ if (typeof(module) !== 'undefined' && module.exports) { module.exports = Frame; } else if (typeof(define) === 'function' && define.amd) { - define(['jquery'], function ($) { + define(['jquery'], function () { return Frame; }); } else { diff --git a/customize.dist/share/test.js b/customize.dist/share/test.js index efc9d81b4..a236dcfab 100644 --- a/customize.dist/share/test.js +++ b/customize.dist/share/test.js @@ -39,7 +39,7 @@ define([ return !keys.some(function (k) { return data[k] !== null; }); }; - Frame.create(document.body, domain + path, function (err, iframe, loadEvent) { + Frame.create(document.body, domain + path, function (err, iframe) { if (handleErr(err)) { return; } console.log("Created iframe"); @@ -50,7 +50,7 @@ define([ [function (i) { // test #1 var pew = randInt(); - frame.set('pew', pew, function (err, data) { + frame.set('pew', pew, function (err) { if (handleErr(err)) { return; } frame.get('pew', function (err, num) { if (handleErr(err)) { return; } @@ -76,9 +76,9 @@ define([ var keys = Object.keys(map); - frame.setBatch(map, function (err, data) { + frame.setBatch(map, function (err) { if (handleErr(err)) { return; } - frame.getBatch(keys, function (err, data) { + frame.getBatch(keys, function (err) { if (handleErr(err)) { return; } frame.removeBatch(Object.keys(map), function (err) { if (handleErr(err)) { return; } diff --git a/rpc.js b/rpc.js index 3f705fab0..3a7609b62 100644 --- a/rpc.js +++ b/rpc.js @@ -18,7 +18,7 @@ var isValidChannel = function (chan) { var 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'); @@ -127,7 +127,6 @@ var isValidCookie = function (Sessions, publicKey, cookie) { var idx = user.tokens.indexOf(parsed.seq); if (idx === -1) { return false; } - var next; if (idx > 0) { // make a new token addTokenForKey(Sessions, publicKey, makeToken()); @@ -325,9 +324,9 @@ var getHash = function (store, Sessions, publicKey, cb) { }); }; -var storeMessage = function (store, publicKey, msg, cb) { +/* var storeMessage = function (store, publicKey, msg, cb) { store.message(publicKey, JSON.stringify(msg), cb); -}; +}; */ var pinChannel = function (store, Sessions, publicKey, channels, cb) { if (!channels && channels.filter) { @@ -407,7 +406,7 @@ var resetUserPins = function (store, Sessions, publicKey, channelList, cb) { }; var getLimit = function (cb) { - + cb = cb; // TODO }; var safeMkdir = function (path, cb) { @@ -649,6 +648,7 @@ RPC.create = function (config /*:typeof(ConfigType)*/, cb /*:(?Error, ?Function) return void getFileSize(ctx.store, msg[1], Respond); case 'GET_LIMIT': // TODO implement this and cache it per-user return void getLimit(function (e, limit) { + limit = limit; Respond('NOT_IMPLEMENTED'); }); case 'GET_MULTIPLE_FILE_SIZE': diff --git a/storage/file.js b/storage/file.js index ab2bce617..857f147f4 100644 --- a/storage/file.js +++ b/storage/file.js @@ -28,7 +28,8 @@ var readMessages = function (path, msgHandler, cb) { }; var checkPath = function (path, callback) { - Fs.stat(path, function (err, stats) { + // TODO check if we actually need to use stat at all + Fs.stat(path, function (err) { if (!err) { callback(undefined, true); return; @@ -166,7 +167,7 @@ var getChannel = function (env, id, callback) { }); } }); - }).nThen(function (waitFor) { + }).nThen(function () { if (errorState) { return; } complete(); }); diff --git a/www/assert/main.js b/www/assert/main.js index 3306c3bab..392392db8 100644 --- a/www/assert/main.js +++ b/www/assert/main.js @@ -38,8 +38,6 @@ define([ }); }; - var $body = $('body'); - var HJSON_list = [ '["DIV",{"id":"target"},[["P",{"class":" alice bob charlie has.dot","id":"bang"},["pewpewpew"]]]]', diff --git a/www/code/main.js b/www/code/main.js index 50ff90aa1..8e709bc1b 100644 --- a/www/code/main.js +++ b/www/code/main.js @@ -37,7 +37,7 @@ define([ secret.keys = secret.key; } - var onConnectError = function (info) { + var onConnectError = function () { Cryptpad.errorLoadingScreen(Messages.websocketError); }; @@ -50,7 +50,6 @@ define([ var $bar = $('#pad-iframe')[0].contentWindow.$('#cme_toolbox'); var parsedHash = Cryptpad.parsePadUrl(window.location.href); var defaultName = Cryptpad.getDefaultName(parsedHash); - var initialState = Messages.codeInitialState; var isHistoryMode = false; @@ -172,10 +171,10 @@ define([ } }; - var isDefaultTitle = function () { +/* var isDefaultTitle = function () { var parsed = Cryptpad.parsePadUrl(window.location.href); return Cryptpad.isDefaultName(parsed, document.title); - }; + };*/ var initializing = true; @@ -226,7 +225,7 @@ define([ uid: Cryptpad.getUid(), }; addToUserData(myData); - Cryptpad.setAttribute('username', myUserName, function (err, data) { + Cryptpad.setAttribute('username', myUserName, function (err) { if (err) { console.log("Couldn't set username"); console.error(err); @@ -378,7 +377,7 @@ define([ } }; - var onInit = config.onInit = function (info) { + config.onInit = function (info) { userList = info.userList; var configTb = { @@ -407,12 +406,9 @@ define([ toolbar = module.toolbar = Toolbar.create(configTb); var $rightside = $bar.find('.' + Toolbar.constants.rightside); - var $userBlock = $bar.find('.' + Toolbar.constants.username); - var $usernameButton = module.$userNameButton = $($bar.find('.' + Toolbar.constants.changeUsername)); + module.$userNameButton = $($bar.find('.' + Toolbar.constants.changeUsername)); var editHash; - var viewHash = Cryptpad.getViewHashFromKeys(info.channel, secret.keys); - if (!readOnly) { editHash = Cryptpad.getEditHashFromKeys(info.channel, secret.keys); } @@ -475,7 +471,7 @@ define([ } /* add a forget button */ - var forgetCb = function (err, title) { + var forgetCb = function (err) { if (err) { return; } setEditable(false); }; @@ -502,9 +498,7 @@ define([ isSelect: true, }; var $block = module.$language = Cryptpad.createDropdown(dropdownConfig); - var $button = $block.find('.buttonTitle'); - - $block.find('a').click(function (e) { + $block.find('a').click(function () { setMode($(this).attr('data-value'), $block); onLocal(); }); @@ -537,11 +531,10 @@ define([ initialValue: lastTheme }; var $block = module.$theme = Cryptpad.createDropdown(dropdownConfig); - var $button = $block.find('.buttonTitle'); setTheme(lastTheme, $block); - $block.find('a').click(function (e) { + $block.find('a').click(function () { var theme = $(this).attr('data-value'); setTheme(theme, $block); localStorage.setItem(themeKey, theme); @@ -579,7 +572,7 @@ define([ } }; - var onReady = config.onReady = function (info) { + config.onReady = function (info) { module.users = info.userList.users; if (module.realtime !== info.realtime) { var realtime = module.realtime = info.realtime; @@ -693,7 +686,7 @@ define([ return cursor; }; - var onRemote = config.onRemote = function () { + config.onRemote = function () { if (initializing) { return; } if (isHistoryMode) { return; } var scroll = editor.getScrollInfo(); @@ -748,14 +741,14 @@ define([ } }; - var onAbort = config.onAbort = function (info) { + config.onAbort = function () { // inform of network disconnect setEditable(false); toolbar.failed(); Cryptpad.alert(Messages.common_connectionLost, undefined, true); }; - var onConnectionChange = config.onConnectionChange = function (info) { + config.onConnectionChange = function (info) { setEditable(info.state); toolbar.failed(); if (info.state) { @@ -767,9 +760,9 @@ define([ } }; - var onError = config.onError = onConnectError; + config.onError = onConnectError; - var realtime = module.realtime = Realtime.start(config); + module.realtime = Realtime.start(config); editor.on('change', onLocal); @@ -779,7 +772,7 @@ define([ var interval = 100; var second = function (CM) { - Cryptpad.ready(function (err, env) { + Cryptpad.ready(function () { andThen(CM); Cryptpad.reportAppUsage(); }); diff --git a/www/common/clipboard.js b/www/common/clipboard.js index 557c1a809..191895dfd 100644 --- a/www/common/clipboard.js +++ b/www/common/clipboard.js @@ -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 = $('', { type: 'text', }).val(text); diff --git a/www/common/common-hash.js b/www/common/common-hash.js index 1d731cec0..98e9152fb 100644 --- a/www/common/common-hash.js +++ b/www/common/common-hash.js @@ -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; }; diff --git a/www/common/common-history.js b/www/common/common-history.js index 702989508..1cd0e6555 100644 --- a/www/common/common-history.js +++ b/www/common/common-history.js @@ -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 = $('').text(Messages.history_version).appendTo($nav); + $('').text(Messages.history_version).appendTo($nav); var $cur = $('', { 'class' : 'gotoInput', 'type' : 'number', diff --git a/www/common/common-interface.js b/www/common/common-interface.js index 624bcfcf3..979ffcf67 100644 --- a/www/common/common-interface.js +++ b/www/common/common-interface.js @@ -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 = $('', {'id': 'loadingTip'}); - var $tip = $('', {'class': 'tips'}).text(getRandomTip()).appendTo($loadingTip); + $('', {'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 = $('').click(); $files.on('change', function (e) { diff --git a/www/common/common-util.js b/www/common/common-util.js index 5b54f5381..2542e0a22 100644 --- a/www/common/common-util.js +++ b/www/common/common-util.js @@ -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', {'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'); }); } diff --git a/www/common/cursor.js b/www/common/cursor.js index 6da99f1bd..04276a179 100644 --- a/www/common/cursor.js +++ b/www/common/cursor.js @@ -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)) { diff --git a/www/common/encode.js b/www/common/encode.js index 44b2071ba..df99bbf02 100644 --- a/www/common/encode.js +++ b/www/common/encode.js @@ -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); }, ''); diff --git a/www/common/fileObject.js b/www/common/fileObject.js index 6f947dbe3..f8988956b 100644 --- a/www/common/fileObject.js +++ b/www/common/fileObject.js @@ -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); diff --git a/www/common/fsStore.js b/www/common/fsStore.js index c5e30558c..a929e84b3 100644 --- a/www/common/fsStore.js +++ b/www/common/fsStore.js @@ -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; diff --git a/www/common/login.js b/www/common/login.js index dff4a3be3..004837ea1 100644 --- a/www/common/login.js +++ b/www/common/login.js @@ -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) { diff --git a/www/common/mergeDrive.js b/www/common/mergeDrive.js index dfd891291..4b41e1279 100644 --- a/www/common/mergeDrive.js +++ b/www/common/mergeDrive.js @@ -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(); } diff --git a/www/common/modes.js b/www/common/modes.js index aad83e44b..918a804a3 100644 --- a/www/common/modes.js +++ b/www/common/modes.js @@ -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; } diff --git a/www/common/notify.js b/www/common/notify.js index 2e1169b1b..7d723ac44 100644 --- a/www/common/notify.js +++ b/www/common/notify.js @@ -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'); diff --git a/www/common/rpc.js b/www/common/rpc.js index 2e1114729..45fe1eaec 100644 --- a/www/common/rpc.js +++ b/www/common/rpc.js @@ -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, }); diff --git a/www/common/toolbar2.js b/www/common/toolbar2.js index 2a1ceaeba..b91e16793 100644 --- a/www/common/toolbar2.js +++ b/www/common/toolbar2.js @@ -370,7 +370,7 @@ define([ return "Loading share button"; }; - var createFileShare = function (toolbar, config) { + var createFileShare = function () { if (!window.location.hash) { throw new Error("Unable to display the share button: hash required in the URL"); } @@ -467,7 +467,7 @@ define([ return $titleContainer; }; - var createLinkToMain = function (toolbar, config) { + var createLinkToMain = function (toolbar) { var $linkContainer = $('', { 'class': "cryptpad-link" }).appendTo(toolbar.$top); @@ -605,13 +605,12 @@ define([ return $spin; }; - var createState = function (toolbar, config) { + var createState = function (toolbar) { return toolbar.$userAdmin.find('.'+STATE_CLS).text(Messages.synchronizing).show(); }; - var createLimit = function (toolbar, config) { + var createLimit = function (toolbar) { if (!Config.enablePinning) { return; } - var usage; var $limitIcon = $('', {'class': 'fa fa-exclamation-triangle'}); var $limit = toolbar.$userAdmin.find('.'+LIMIT_CLS).attr({ 'title': Messages.pinLimitReached @@ -628,7 +627,7 @@ define([ return $limit; }; - var createNewPad = function (toolbar, config) { + var createNewPad = function (toolbar) { var $newPad = toolbar.$userAdmin.find('.'+NEWPAD_CLS).show(); var pads_options = []; @@ -676,7 +675,6 @@ define([ Cryptpad.createUserAdminMenu(userMenuCfg); var $userButton = $userAdmin.find('a.' + USERBUTTON_CLS); - var renameAlertOpened; $userButton.click(function (e) { e.preventDefault(); e.stopPropagation(); @@ -688,7 +686,7 @@ define([ }); }); }); - Cryptpad.onDisplayNameChanged(function (newName) { + Cryptpad.onDisplayNameChanged(function () { Cryptpad.findCancelButton().click(); }); @@ -697,7 +695,7 @@ define([ // Events var initClickEvents = function (toolbar, config) { - var removeDropdowns = function (e) { + var removeDropdowns = function () { toolbar.$toolbar.find('.cryptpad-dropdown').hide(); }; var cancelEditTitle = function (e) { @@ -720,7 +718,7 @@ define([ // Click in iframes try { if (w.$ && w.$('iframe').length) { - var innerIfrw = config.ifrw.$('iframe').each(function (i, el) { + config.ifrw.$('iframe').each(function (i, el) { $(el.contentWindow).on('click', removeDropdowns); $(el.contentWindow).on('click', cancelEditTitle); }); @@ -821,7 +819,7 @@ define([ // Main - var create = Bar.create = function (cfg) { + Bar.create = function (cfg) { var config = cfg || {}; Cryptpad = config.common; Messages = Cryptpad.Messages; diff --git a/www/common/treesome.js b/www/common/treesome.js index cf9dcff97..c3722e8a3 100644 --- a/www/common/treesome.js +++ b/www/common/treesome.js @@ -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 diff --git a/www/common/userObject.js b/www/common/userObject.js index 5d8232d3f..aa61c8573 100644 --- a/www/common/userObject.js +++ b/www/common/userObject.js @@ -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); diff --git a/www/common/visible.js b/www/common/visible.js index 4f84ecdf1..f73fa49bc 100644 --- a/www/common/visible.js +++ b/www/common/visible.js @@ -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]; }; diff --git a/www/drive/main.js b/www/drive/main.js index 88a67ca97..66d040d54 100644 --- a/www/drive/main.js +++ b/www/drive/main.js @@ -14,7 +14,7 @@ define([ var module = window.MODULE = {}; var Messages = Cryptpad.Messages; - var saveAs = window.saveAs; + //var saveAs = window.saveAs; // Use `$(function () {});` to make sure the html is loaded before doing anything else $(function () { @@ -22,7 +22,7 @@ define([ var ifrw = $('#pad-iframe')[0].contentWindow; Cryptpad.addLoadingScreen(); - var onConnectError = function (info) { + var onConnectError = function () { Cryptpad.errorLoadingScreen(Messages.websocketError); }; @@ -134,10 +134,9 @@ define([ return localStorage.searchCursor || 0; }; - - var now = function () { +/* var now = function () { return new Date().getTime(); - }; + }; */ var setEditable = function (state) { APP.editable = state; @@ -162,12 +161,12 @@ define([ var $slideIcon = $('', {"class": "fa fa-file-powerpoint-o file icon"}); var $pollIcon = $('', {"class": "fa fa-calendar file icon"}); var $whiteboardIcon = $('', {"class": "fa fa-paint-brush"}); - var $upIcon = $('', {"class": "fa fa-arrow-circle-up"}); + //var $upIcon = $('', {"class": "fa fa-arrow-circle-up"}); var $unsortedIcon = $('', {"class": "fa fa-files-o"}); var $templateIcon = $('', {"class": "fa fa-cubes"}); var $trashIcon = $('', {"class": "fa fa-trash"}); var $trashEmptyIcon = $('', {"class": "fa fa-trash-o"}); - var $collapseIcon = $('', {"class": "fa fa-minus-square-o expcol"}); + //var $collapseIcon = $('', {"class": "fa fa-minus-square-o expcol"}); var $expandIcon = $('', {"class": "fa fa-plus-square-o expcol"}); var $listIcon = $('', {"class": "fa fa-list"}); var $gridIcon = $('', {"class": "fa fa-th"}); @@ -228,8 +227,6 @@ define([ if (AppConfig.enableTemplates) { displayedCategories.push(TEMPLATE); } if (isWorkgroup()) { displayedCategories = [ROOT, TRASH, SEARCH]; } - var selectedElement; - if (!APP.readOnly) { setEditable(true); } @@ -557,7 +554,7 @@ define([ var hide = []; var hasFolder = false; - paths.forEach(function (p, i) { + paths.forEach(function (p) { var path = p.path; var $element = p.element; if (path.length === 1) { @@ -675,7 +672,7 @@ define([ var paths = getSelectedPaths($element); var $menu = $element.data('context'); if (!$menu) { return; } - var actions = []; + //var actions = []; var $actions = $menu.find('a'); var toHide = filterContextMenu($menu, paths); $actions = $actions.filter(function (i, el) { @@ -1173,6 +1170,7 @@ define([ }; // Display the full path in the title when displaying a directory from the trash + /* var getTrashTitle = function (path) { if (!path[0] || path[0] !== TRASH) { return; } var title = TRASH_NAME; @@ -1187,7 +1185,7 @@ define([ } } return title; - }; + }; */ var getPrettyName = function (name) { var pName; @@ -1218,7 +1216,7 @@ define([ if (idx < path.length - 1) { if (!noStyle) { $span.addClass('clickable'); - $span.click(function (e) { + $span.click(function () { var sliceEnd = idx + 1; if (isTrash && idx === 1) { sliceEnd = 4; } // Make sure we don't show the index or 'element' and 'path' module.displayDirectory(path.slice(0, sliceEnd)); @@ -1359,13 +1357,13 @@ define([ $block.find('a.newFolder').click(function () { filesOp.addFolder(currentPath, null, onCreated); }); - $block.find('a.newdoc').click(function (e) { + $block.find('a.newdoc').click(function () { var type = $(this).attr('data-type') || 'pad'; var name = Cryptpad.getDefaultName({type: type}); filesOp.addFile(currentPath, name, type, onCreated); }); } else { - $block.find('a.newdoc').click(function (e) { + $block.find('a.newdoc').click(function () { var type = $(this).attr('data-type') || 'pad'; sessionStorage[Cryptpad.newPadPathKey] = filesOp.isPathIn(currentPath, [TRASH]) ? '' : currentPath; window.open('/' + type + '/'); @@ -1390,7 +1388,7 @@ define([ return Cryptpad.getLSAttribute(SORT_FOLDER_DESC) === "true"; }; - var onSortByClick = function (e) { + var onSortByClick = function () { var $span = $(this); var value; if ($span.hasClass('foldername')) { @@ -1530,7 +1528,7 @@ define([ return keys; }; var sortTrashElements = function (folder, oldkeys, prop, asc) { - var root = files[TRASH]; + //var root = files[TRASH]; var test = folder ? filesOp.isFolder : filesOp.isFile; var keys = oldkeys.filter(function (e) { return test(e.element); @@ -1569,14 +1567,14 @@ define([ }; // Drive content toolbar - var createToolbar = function (path) { + var createToolbar = function () { var $toolbar = $driveToolbar; $toolbar.html(''); var $leftside = $('', {'class': 'leftside'}).appendTo($toolbar); if (!APP.mobile()) { $leftside.width($tree.width()); } - var $rightside = $('', {'class': 'rightside'}).appendTo($toolbar); + $('', {'class': 'rightside'}).appendTo($toolbar); return $toolbar; }; @@ -1702,7 +1700,7 @@ define([ var parsed = Cryptpad.parsePadUrl(href); var $table = $(''); var $icon = $('', {'rowspan': '3', 'class': 'icon'}).append(getFileIcon(href)); - var $title = $('', {'class': 'col1 title'}).text(r.data.title).click(function (e) { + var $title = $('', {'class': 'col1 title'}).text(r.data.title).click(function () { openFile(r.data.href); }); var $typeName = $('', {'class': 'label2'}).text(Messages.fm_type); @@ -1726,9 +1724,11 @@ define([ }); } var $openDir = $('', {'class': 'openDir'}).append($a); - var $row1 = $('').append($icon).append($title).append($typeName).append($type).appendTo($table); - var $row2 = $('').append($path).append($atimeName).append($atime).appendTo($table); - var $row3 = $('').append($openDir).append($ctimeName).append($ctime).appendTo($table); + + // rows 1-3 + $('').append($icon).append($title).append($typeName).append($type).appendTo($table); + $('').append($path).append($atimeName).append($atime).appendTo($table); + $('').append($openDir).append($ctimeName).append($ctime).appendTo($table); $('', {'class':'searchResult'}).append($table).appendTo($list); }); }); @@ -1793,11 +1793,11 @@ define([ if (mode) { $dirContent.addClass(getViewModeClass()); } - var $modeButton = createViewModeButton().appendTo($toolbar.find('.rightside')); + createViewModeButton().appendTo($toolbar.find('.rightside')); } var $list = $('').appendTo($dirContent); - var $title = createTitle(path).appendTo($toolbar.find('.rightside')); + createTitle(path).appendTo($toolbar.find('.rightside')); updatePathSize(); if (APP.mobile()) { @@ -1883,7 +1883,7 @@ define([ appStatus.ready(true); }; - var refreshFilesData = function () { +/* var refreshFilesData = function () { $content.find('.element-row').each(function (i, e) { var $el = $(e); if ($el.data('path')) { @@ -1898,7 +1898,8 @@ define([ $el.find('.ctime').attr('title', getDate(data.ctime)).text(getDate(data.ctime)); } }); - }; + }; */ + var createTreeElement = function (name, $icon, path, draggable, droppable, collapsable, active) { var $name = $('', { 'class': 'folder-element element' }).text(name); @@ -1961,7 +1962,7 @@ define([ var $rootElement = createTreeElement(ROOT_NAME, $rootIcon.clone(), [ROOT], false, true, false, isRootOpened); $rootElement.addClass('root'); $rootElement.find('>.element-row').contextmenu(openDirectoryContextMenu); - var $root = $('').append($rootElement).appendTo($container); + $('').append($rootElement).appendTo($container); $container = $rootElement; } else if (filesOp.isFolderEmpty(root)) { return; } @@ -2048,7 +2049,7 @@ define([ $container.append($div); }; - var resetTree = module.resetTree = function () { + module.resetTree = function () { $tree.html(''); if (displayedCategories.indexOf(SEARCH) !== -1) { createSearch($tree); } if (displayedCategories.indexOf(ROOT) !== -1) { createTree($tree, [ROOT]); } @@ -2057,7 +2058,7 @@ define([ if (displayedCategories.indexOf(TRASH) !== -1) { createTrash($tree, [TRASH]); } }; - var hideMenu = module.hideMenu = function () { + module.hideMenu = function () { $contextMenu.hide(); $trashTreeContextMenu.hide(); $trashContextMenu.hide(); @@ -2361,7 +2362,7 @@ define([ removeInput(); module.hideMenu(e); }); - $appContainer.on('mouseup drop', function (e) { + $appContainer.on('mouseup drop', function () { $iframe.find('.droppable').removeClass('droppable'); }); $appContainer.on('keydown', function (e) { @@ -2407,7 +2408,7 @@ define([ onRefresh.to = window.setTimeout(refresh, 500); } }; - proxy.on('change', [], function (o, n, p) { + proxy.on('change', [], function () { if (history.isHistoryMode) { return; } var path = arguments[2]; if (path[0] !== 'drive') { return false; } @@ -2422,7 +2423,7 @@ define([ } module.resetTree(); return false; - }).on('remove', [], function (o, p) { + }).on('remove', [], function () { if (history.isHistoryMode) { return; } var path = arguments[1]; if (path[0] !== 'drive') { return false; } @@ -2437,7 +2438,7 @@ define([ return false; }); - $iframe.find('#tree').mousedown(function (e) { + $iframe.find('#tree').mousedown(function () { if (APP.mobile()) { return; } if (APP.resizeTree) { return; } APP.resizeTree = window.setInterval(function () { @@ -2445,7 +2446,7 @@ define([ updatePathSize(); }, 100); }); - $appContainer.mouseup(function (e) { + $appContainer.mouseup(function () { window.clearInterval(APP.resizeTree); APP.resizeTree = undefined; }); @@ -2506,7 +2507,7 @@ define([ myUserNameTemp = myUserNameTemp.substr(0, 32); } var myUserName = myUserNameTemp; - Cryptpad.setAttribute('username', myUserName, function (err, data) { + Cryptpad.setAttribute('username', myUserName, function (err) { if (err) { logError("Couldn't set username", err); return; @@ -2587,7 +2588,7 @@ define([ common: Cryptpad, hideShare: true }; - var toolbar = APP.toolbar = info.realtime.toolbar = Toolbar.create(APP.$bar, info.myID, info.realtime, info.getLag, userList, config); + APP.toolbar = info.realtime.toolbar = Toolbar.create(APP.$bar, info.myID, info.realtime, info.getLag, userList, config); var $bar = APP.$bar; var $rightside = $bar.find('.' + Toolbar.constants.rightside); @@ -2621,10 +2622,10 @@ define([ var $usage = $('', {'class': 'usage'}).css('width', width+'px'); if (quota >= 0.8) { - var $upgrade = $('', { + $('', { 'class': 'upgrade buttonSuccess', title: Messages.upgradeTitle - }).text(Messages.upgrade).click(function (e) { + }).text(Messages.upgrade).click(function () { // TODO }).appendTo($leftside); } @@ -2659,7 +2660,7 @@ define([ // Close button clicked setHistory(false, true); }; - histConfig.onRevert = function (val) { + histConfig.onRevert = function () { // Revert button clicked setHistory(false, false); proxy.drive = history.currentObj.drive; @@ -2701,7 +2702,7 @@ define([ Cryptpad.removeLoadingScreen(); }); }; - var onDisconnect = function (info) { + var onDisconnect = function () { setEditable(false); if (APP.refresh) { APP.refresh(); } APP.toolbar.failed(); diff --git a/www/examples/board/board.js b/www/examples/board/board.js index 26d695173..eec92e681 100644 --- a/www/examples/board/board.js +++ b/www/examples/board/board.js @@ -169,6 +169,7 @@ define([ var $input = Input({ placeholder: 'card description', + id: id, }) .addClass('card-title'); @@ -206,7 +207,7 @@ define([ /* */ - Card.move = function (uid, A, B) { + Card.move = function (/*uid, A, B*/) { }; @@ -228,11 +229,10 @@ define([ } var card = proxy.cards[cid]; - - + card = card; // TODO actually draw }; - var Draw = Board.Draw = function ($lists) { + Board.Draw = function ($lists) { proxy.listOrder.forEach(function (luid) { List.draw($lists, luid); }); diff --git a/www/examples/board/main.js b/www/examples/board/main.js index c5c664c49..290f926b7 100644 --- a/www/examples/board/main.js +++ b/www/examples/board/main.js @@ -7,12 +7,12 @@ define([ '/bower_components/chainpad-listmap/chainpad-listmap.js', '/bower_components/chainpad-crypto/crypto.js', '/common/cryptpad-common.js', - '/common/visible.js', - '/common/notify.js', + //'/common/visible.js', + //'/common/notify.js', '/bower_components/file-saver/FileSaver.min.js' -], function ($, Config, Messages, Board, TextPatcher, Listmap, Crypto, Cryptpad, Visible, Notify) { +], function ($, Config, Messages, Board, TextPatcher, Listmap, Crypto, Cryptpad /*, Visible, Notify*/) { - var saveAs = window.saveAs; + // var saveAs = window.saveAs; Cryptpad.styleAlerts(); console.log("Initializing your realtime session..."); @@ -23,28 +23,28 @@ define([ Board: Board, }; +/* var unnotify = function () { if (!(module.tabNotification && typeof(module.tabNotification.cancel) === 'function')) { return; } module.tabNotification.cancel(); }; - var notify = function () { if (!(Visible.isSupported() && !Visible.currently())) { return; } unnotify(); module.tabNotification = Notify.tab(1000, 10); }; +*/ var setEditable = function (bool) { - + bool = bool; }; setEditable(false); - var $lists = $('#lists'); - var $addList = $('#create-list').click(function () { + $('#create-list').click(function () { Board.List.draw($lists); }); @@ -52,7 +52,7 @@ define([ Cryptpad.log("You are the first user to visit this board"); }; - var whenReady = function (opt) { + var whenReady = function () { var rt = module.rt; var proxy = rt.proxy; @@ -63,7 +63,6 @@ define([ Board.Draw($lists); if (first) { firstUser(); } - }; var config = { @@ -78,10 +77,10 @@ define([ var proxy = rt.proxy; proxy .on('create', function (info) { - var realtime = module.realtime = info.realtime; + module.realtime = info.realtime; window.location.hash = info.channel + secret.key; }) - .on('ready', function (info) { + .on('ready', function () { Cryptpad.log("Ready!"); whenReady({ diff --git a/www/examples/form/main.js b/www/examples/form/main.js index 04a65e2c4..7ffb1c0ec 100644 --- a/www/examples/form/main.js +++ b/www/examples/form/main.js @@ -128,7 +128,7 @@ define([ setEditable(false); - var onInit = config.onInit = function (info) { + config.onInit = function (info) { var realtime = module.realtime = info.realtime; window.location.hash = info.channel + secret.key; @@ -140,7 +140,7 @@ define([ }; var readValues = function () { - UI.each(function (ui, i, list) { + UI.each(function (ui) { Map[ui.id] = ui.value(); }); }; @@ -165,7 +165,7 @@ define([ if (UI.ids.indexOf(key) === -1) { Map[key] = parsed[key]; } }); - UI.each(function (ui, i, list) { + UI.each(function (ui) { var newval = parsed[ui.id]; var oldval = ui.value(); @@ -178,9 +178,7 @@ define([ if (ui.preserveCursor) { op = TextPatcher.diff(oldval, newval); selects = ['selectionStart', 'selectionEnd'].map(function (attr) { - var before = element[attr]; - var after = TextPatcher.transformCursor(element[attr], op); - return after; + return TextPatcher.transformCursor(element[attr], op); }); } @@ -195,13 +193,13 @@ define([ }); }; - var onRemote = config.onRemote = function (info) { + config.onRemote = function () { if (initializing) { return; } /* integrate remote changes */ updateValues(); }; - var onReady = config.onReady = function (info) { + config.onReady = function () { updateValues(); console.log("READY"); @@ -209,13 +207,13 @@ define([ initializing = false; }; - var onAbort = config.onAbort = function (info) { + config.onAbort = function () { window.alert("Network Connection Lost"); }; - var rt = Realtime.start(config); + Realtime.start(config); - UI.each(function (ui, i, list) { + UI.each(function (ui) { var type = ui.type; var events = eventsByType[type]; ui.$.on(events, onLocal); diff --git a/www/examples/form/ula.js b/www/examples/form/ula.js index 011783ff5..cc2d0763f 100644 --- a/www/examples/form/ula.js +++ b/www/examples/form/ula.js @@ -1,7 +1,7 @@ define([], function () { var ula = {}; - var uid = ula.uid = (function () { + ula.uid = (function () { var i = 0; var prefix = 'rt_'; return function () { return prefix + i++; }; diff --git a/www/examples/hack/index.html b/www/examples/hack/index.html deleted file mode 100644 index fb1dc3dcf..000000000 --- a/www/examples/hack/index.html +++ /dev/null @@ -1,77 +0,0 @@ - - - - - - - - - - - - - - - RUN - - - diff --git a/www/examples/hack/main.js b/www/examples/hack/main.js deleted file mode 100644 index c59460a60..000000000 --- a/www/examples/hack/main.js +++ /dev/null @@ -1,161 +0,0 @@ -define([ - 'jquery', - '/api/config', - '/bower_components/chainpad-netflux/chainpad-netflux.js', - '/bower_components/chainpad-crypto/crypto.js', - '/bower_components/textpatcher/TextPatcher.amd.js', - '/common/cryptpad-common.js' -], function ($, Config, Realtime, Crypto, TextPatcher, Cryptpad) { - - var secret = Cryptpad.getSecrets(); - - var $textarea = $('textarea'), - $run = $('#run'); - - var module = {}; - - var config = { - initialState: '', - websocketURL: Config.websocketURL, - channel: secret.channel, - crypto: Crypto.createEncryptor(secret.key), - }; - var initializing = true; - - var setEditable = function (bool) { $textarea.attr('disabled', !bool); }; - var canonicalize = function (text) { return text.replace(/\r\n/g, '\n'); }; - - setEditable(false); - - var onInit = config.onInit = function (info) { - window.location.hash = info.channel + secret.key; - $(window).on('hashchange', function() { window.location.reload(); }); - }; - - var onRemote = config.onRemote = function (info) { - if (initializing) { return; } - - var userDoc = info.realtime.getUserDoc(); - var current = canonicalize($textarea.val()); - - var op = TextPatcher.diff(current, userDoc); - - var elem = $textarea[0]; - - var selects = ['selectionStart', 'selectionEnd'].map(function (attr) { - return TextPatcher.transformCursor(elem[attr], op); - }); - - $textarea.val(userDoc); - elem.selectionStart = selects[0]; - elem.selectionEnd = selects[1]; - - // TODO do something on external messages - // http://webdesign.tutsplus.com/tutorials/how-to-display-update-notifications-in-the-browser-tab--cms-23458 - }; - - var onReady = config.onReady = function (info) { - module.patchText = TextPatcher.create({ - realtime: info.realtime - // logging: true - }); - initializing = false; - setEditable(true); - $textarea.val(info.realtime.getUserDoc()); - }; - - var onAbort = config.onAbort = function (info) { - setEditable(false); - window.alert("Server Connection Lost"); - }; - - var onLocal = config.onLocal = function () { - if (initializing) { return; } - module.patchText(canonicalize($textarea.val())); - }; - - var rt = window.rt = Realtime.start(config); - - var splice = function (str, index, chars) { - var count = chars.length; - return str.slice(0, index) + chars + str.slice((index -1) + count); - }; - - var setSelectionRange = function (input, start, end) { - if (input.setSelectionRange) { - input.focus(); - input.setSelectionRange(start, end); - } else if (input.createTextRange) { - var range = input.createTextRange(); - range.collapse(true); - range.moveEnd('character', end); - range.moveStart('character', start); - range.select(); - } - }; - - var setCursor = function (el, pos) { - setSelectionRange(el, pos, pos); - }; - - var state = {}; - - // TODO - $textarea.on('keydown', function (e) { - // track when control keys are pushed down - //switch (e.key) { } - }); - - // TODO - $textarea.on('keyup', function (e) { - // track when control keys are released - }); - - //$textarea.on('change', onLocal); - $textarea.on('keypress', function (e) { - onLocal(); - switch (e.key) { - case 'Tab': - // insert a tab wherever the cursor is... - var start = $textarea.prop('selectionStart'); - var end = $textarea.prop('selectionEnd'); - if (typeof start !== 'undefined') { - if (start === end) { - $textarea.val(function (i, val) { - return splice(val, start, "\t"); - }); - setCursor($textarea[0], start +1); - } else { - // indentation?? this ought to be fun. - - } - } - // simulate a keypress so the event goes through.. - // prevent default behaviour for tab - e.preventDefault(); - - onLocal(); - break; - default: - break; - } - }); - - ['cut', 'paste', 'change', 'keyup', 'keydown', 'select', 'textInput'] - .forEach(function (evt) { - $textarea.on(evt, onLocal); - }); - - $run.click(function (e) { - e.preventDefault(); - var content = $textarea.val(); - - try { - eval(content); // jshint ignore:line - } catch (err) { - // FIXME don't use alert, make an errorbox - window.alert(err.message); - console.error(err); - } - }); -}); diff --git a/www/examples/json/main.js b/www/examples/json/main.js index 90654afa6..434ac1a3e 100644 --- a/www/examples/json/main.js +++ b/www/examples/json/main.js @@ -26,15 +26,13 @@ define([ }); }; - var initializing = true; - setEditable(false); var rt = module.rt = RtListMap.create(config); rt.proxy.on('create', function (info) { console.log("initializing..."); window.location.hash = info.channel + secret.key; - }).on('ready', function (info) { + }).on('ready', function () { console.log("...your realtime object is ready"); rt.proxy @@ -42,7 +40,7 @@ define([ .on('change', [], function (o, n, p) { console.log("root change event firing for path [%s]: %s => %s", p.join(','), o, n); }) - .on('remove', [], function (o, p, root) { + .on('remove', [], function (o, p) { console.log("Removal of value [%s] at path [%s]", o, p.join(',')); }) .on('change', ['a', 'b', 'c'], function (o, n, p) { @@ -51,7 +49,7 @@ define([ return false; }) // on(event, cb) - .on('disconnect', function (info) { + .on('disconnect', function () { setEditable(false); window.alert("Network connection lost"); }); @@ -65,6 +63,7 @@ define([ console.log("evaluating `%s`", value); var x = rt.proxy; + x = x; // LOL jshint says this is unused otherwise <3 console.log('> ', eval(value)); // jshint ignore:line console.log(); diff --git a/www/examples/pin/main.js b/www/examples/pin/main.js index ad6905d7d..a54bc8ce1 100644 --- a/www/examples/pin/main.js +++ b/www/examples/pin/main.js @@ -3,7 +3,7 @@ define([ '/common/cryptpad-common.js', '/common/pinpad.js' ], function ($, Cryptpad, Pinpad) { - var APP = window.APP = { + window.APP = { Cryptpad: Cryptpad, }; @@ -37,7 +37,7 @@ define([ }; $(function () { - Cryptpad.ready(function (err, env) { + Cryptpad.ready(function () { var network = Cryptpad.getNetwork(); var proxy = Cryptpad.getStore().getProxy().proxy; diff --git a/www/examples/read/main.js b/www/examples/read/main.js index 5692f9b6b..32c301032 100644 --- a/www/examples/read/main.js +++ b/www/examples/read/main.js @@ -2,9 +2,7 @@ define([ 'jquery', '/common/cryptget.js' ], function ($, Crypt) { - var $target = $('#target'); - var $dest = $('#dest'); var useDoc = function (err, doc) { if (err) { return console.error(err); } diff --git a/www/examples/render/main.js b/www/examples/render/main.js index 8f504c30c..83cdaa36c 100644 --- a/www/examples/render/main.js +++ b/www/examples/render/main.js @@ -55,7 +55,7 @@ define([ var initializing = true; - var onInit = config.onInit = function (info) { + config.onInit = function (info) { window.location.hash = info.channel + secret.key; module.realtime = info.realtime; }; @@ -73,7 +73,7 @@ define([ }; // when your editor is ready - var onReady = config.onReady = function (info) { + config.onReady = function () { console.log("Realtime is ready!"); var userDoc = module.realtime.getUserDoc(); lazyDraw(getContent(userDoc)); @@ -81,13 +81,13 @@ define([ }; // when remote editors do things... - var onRemote = config.onRemote = function () { + config.onRemote = function () { if (initializing) { return; } var userDoc = module.realtime.getUserDoc(); lazyDraw(getContent(userDoc)); }; - var onLocal = config.onLocal = function () { + config.onLocal = function () { // we're not really expecting any local events for this editor... /* but we might add a second pane in the future so that you don't need a second window to edit your markdown */ @@ -96,9 +96,9 @@ define([ lazyDraw(userDoc); }; - var onAbort = config.onAbort = function () { + config.onAbort = function () { window.alert("Network Connection Lost"); }; - var rts = Realtime.start(config); + Realtime.start(config); }); diff --git a/www/examples/style/main.js b/www/examples/style/main.js index 5b8c0f987..12b2e4840 100644 --- a/www/examples/style/main.js +++ b/www/examples/style/main.js @@ -20,8 +20,6 @@ define([ crypto: Crypto.createEncryptor(secret.key), }; - var userName = module.userName = config.userName = Crypto.rand64(8); - var lazyDraw = (function () { var to, delay = 500; @@ -37,7 +35,7 @@ define([ var initializing = true; - var onInit = config.onInit = function (info) { + config.onInit = function (info) { window.location.hash = info.channel + secret.key; var realtime = module.realtime = info.realtime; module.patchText = TextPatcher.create({ @@ -50,28 +48,28 @@ define([ }); }; - var onReady = config.onReady = function (info) { + config.onReady = function () { var userDoc = module.realtime.getUserDoc(); draw(userDoc); console.log("Ready"); initializing = false; }; - var onRemote = config.onRemote = function () { + config.onRemote = function () { draw(module.realtime.getUserDoc()); }; - var onAbort = config.onAbort = function (info) { + config.onAbort = function () { // notify the user of the abort window.alert("Network Connection Lost"); }; - var onLocal = config.onLocal = function () { + config.onLocal = function () { // nope }; $edit.attr('href', '/examples/text/'+ window.location.hash); - var rt = Realtime.start(config); + Realtime.start(config); }); diff --git a/www/examples/text/main.js b/www/examples/text/main.js index 20bdbc6a6..eed9ff300 100644 --- a/www/examples/text/main.js +++ b/www/examples/text/main.js @@ -13,8 +13,6 @@ define([ TextPatcher: TextPatcher }; - var userName = module.userName = Crypto.rand64(8); - var initializing = true; var $textarea = $('textarea'); @@ -30,14 +28,14 @@ define([ setEditable(false); - var onInit = config.onInit = function (info) { + config.onInit = function (info) { window.location.hash = info.channel + secret.key; $(window).on('hashchange', function() { window.location.reload(); }); }; - var onRemote = config.onRemote = function (info) { + config.onRemote = function () { if (initializing) { return; } var userDoc = module.realtime.getUserDoc(); var content = canonicalize($textarea.val()); @@ -59,7 +57,7 @@ define([ module.patchText(canonicalize($textarea.val())); }; - var onReady = config.onReady = function (info) { + config.onReady = function (info) { var realtime = module.realtime = info.realtime; module.patchText = TextPatcher.create({ realtime: realtime @@ -71,12 +69,12 @@ define([ initializing = false; }; - var onAbort = config.onAbort = function (info) { + config.onAbort = function () { setEditable(false); window.alert("Server Connection Lost"); }; - var onConnectionChange = config.onConnectionChange = function (info) { + config.onConnectionChange = function (info) { if (info.state) { initializing = true; } else { @@ -85,7 +83,7 @@ define([ } }; - var rt = Realtime.start(config); + Realtime.start(config); ['cut', 'paste', 'change', 'keyup', 'keydown', 'select', 'textInput'] .forEach(function (evt) { diff --git a/www/file/file-crypto.js b/www/file/file-crypto.js index 4af79aa04..608b3bb6e 100644 --- a/www/file/file-crypto.js +++ b/www/file/file-crypto.js @@ -33,7 +33,9 @@ define([ // you don't need to worry about this running out. // you'd need a REAAAALLY big file - if (l === 0) { return true; } + if (l === 0) { + throw new Error('E_NONCE_TOO_LARGE'); + } } }; @@ -70,7 +72,6 @@ define([ // decrypt the chunk var plaintext = Nacl.secretbox.open(box, nonce, key); - // TODO handle nonce-too-large-error increment(nonce); return plaintext; }; diff --git a/www/file/main.js b/www/file/main.js index c0970c24f..1c25c5119 100644 --- a/www/file/main.js +++ b/www/file/main.js @@ -27,7 +27,7 @@ define([ var xhr = new XMLHttpRequest(); xhr.open("GET", src, true); xhr.responseType = "arraybuffer"; - xhr.onload = function (e) { + xhr.onload = function () { return void cb(void 0, new Uint8Array(xhr.response)); }; xhr.send(null); @@ -57,19 +57,19 @@ define([ var again = function (state, box) { switch (state) { case 0: - sendChunk(box, function (e, msg) { + sendChunk(box, function (e) { if (e) { return console.error(e); } next(again); }); break; case 1: - sendChunk(box, function (e, msg) { + sendChunk(box, function (e) { if (e) { return console.error(e); } next(again); }); break; case 2: - sendChunk(box, function (e, msg) { + sendChunk(box, function (e) { if (e) { return console.error(e); } Cryptpad.rpc.send('UPLOAD_COMPLETE', '', function (e, res) { if (e) { return void console.error(e); } @@ -171,7 +171,6 @@ define([ document.title = title; }; - var blob; var exportFile = function () { var suggestion = document.title; Cryptpad.prompt(Messages.exportPrompt, @@ -239,10 +238,10 @@ define([ display: 'block', }); - var $file = $form.find("#file").on('change', function (e) { + $form.find("#file").on('change', function (e) { var file = e.target.files[0]; var reader = new FileReader(); - reader.onloadend = function (e) { + reader.onloadend = function () { upload(this.result, { name: file.name, type: file.type, @@ -255,7 +254,7 @@ define([ Cryptpad.removeLoadingScreen(); }; - Cryptpad.ready(function (err, anv) { + Cryptpad.ready(function () { andThen(); Cryptpad.reportAppUsage(); }); diff --git a/www/login/main.js b/www/login/main.js index 6a85fb84c..973cd985f 100644 --- a/www/login/main.js +++ b/www/login/main.js @@ -3,11 +3,6 @@ define([ '/common/cryptpad-common.js', '/common/login.js' ], function ($, Cryptpad, Login) { - - var APP = window.APP = { - Cryptpad: Cryptpad, - }; - $(function () { var $main = $('#mainBlock'); var Messages = Cryptpad.Messages; @@ -61,7 +56,7 @@ define([ $('button.login').click(); }); - $('button.login').click(function (e) { + $('button.login').click(function () { Cryptpad.addLoadingScreen(Messages.login_hashing); // We need a setTimeout(cb, 0) otherwise the loading screen is only displayed after hashing the password window.setTimeout(function () { diff --git a/www/media/main.js b/www/media/main.js index b1d16377d..901b9d3e5 100644 --- a/www/media/main.js +++ b/www/media/main.js @@ -4,13 +4,13 @@ define([ '/bower_components/chainpad-netflux/chainpad-netflux.js', '/common/toolbar.js', '/common/cryptpad-common.js', - '/common/visible.js', - '/common/notify.js', + //'/common/visible.js', + //'/common/notify.js', '/bower_components/tweetnacl/nacl-fast.min.js', '/bower_components/file-saver/FileSaver.min.js', -], function ($, Crypto, realtimeInput, Toolbar, Cryptpad, Visible, Notify) { - var Messages = Cryptpad.Messages; - var saveAs = window.saveAs; +], function ($, Crypto, realtimeInput, Toolbar, Cryptpad /*, Visible, Notify*/) { + //var Messages = Cryptpad.Messages; + //var saveAs = window.saveAs; //window.Nacl = window.nacl; $(function () { @@ -85,17 +85,17 @@ define([ } }; Toolbar.create($bar, null, null, null, null, configTb); - var $rightside = $bar.find('.' + Toolbar.constants.rightside); + //var $rightside = $bar.find('.' + Toolbar.constants.rightside); updateTitle(Cryptpad.initialName || getTitle() || defaultName); - var mt = MediaTag($mt[0]); + MediaTag($mt[0]); Cryptpad.removeLoadingScreen(); }); }; - Cryptpad.ready(function (err, anv) { + Cryptpad.ready(function () { andThen(); Cryptpad.reportAppUsage(); }); diff --git a/www/pad/links.js b/www/pad/links.js index 25bca137e..0c064a762 100644 --- a/www/pad/links.js +++ b/www/pad/links.js @@ -42,7 +42,7 @@ define(function () { }); } if (editor.contextMenu) { - editor.contextMenu.addListener(function(startElement, selection, path) { + editor.contextMenu.addListener(function(startElement) { if (startElement) { var anchor = getActiveLink(editor); if (anchor && anchor.getAttribute('href')) { diff --git a/www/pad/main.js b/www/pad/main.js index e1b552a48..9ae4e4549 100644 --- a/www/pad/main.js +++ b/www/pad/main.js @@ -87,7 +87,7 @@ define([ return hj; }; - var onConnectError = function (info) { + var onConnectError = function () { Cryptpad.errorLoadingScreen(Messages.websocketError); }; @@ -103,7 +103,7 @@ define([ }); editor.on('instanceReady', Links.addSupportForOpeningLinksInNewTab(Ckeditor)); - editor.on('instanceReady', function (Ckeditor) { + editor.on('instanceReady', function () { var $bar = $('#pad-iframe')[0].contentWindow.$('#cke_1_toolbox'); var parsedHash = Cryptpad.parsePadUrl(window.location.href); var defaultName = Cryptpad.getDefaultName(parsedHash); @@ -167,7 +167,7 @@ define([ if (['addAttribute', 'modifyAttribute'].indexOf(info.diff.action) !== -1) { if (info.diff.name === 'href') { // console.log(info.diff); - var href = info.diff.newValue; + //var href = info.diff.newValue; // TODO normalize HTML entities if (/javascript *: */.test(info.diff.newValue)) { @@ -314,7 +314,7 @@ define([ uid: Cryptpad.getUid(), }; addToUserData(myData); - Cryptpad.setAttribute('username', newName, function (err, data) { + Cryptpad.setAttribute('username', newName, function (err) { if (err) { console.error("Couldn't set username"); return; @@ -323,11 +323,6 @@ define([ }); }; - var isDefaultTitle = function () { - var parsed = Cryptpad.parsePadUrl(window.location.href); - return Cryptpad.isDefaultName(parsed, document.title); - }; - var getHeadingText = function () { var text; if (['h1', 'h2', 'h3'].some(function (t) { @@ -483,7 +478,7 @@ define([ } }; - var onRemote = realtimeOptions.onRemote = function () { + realtimeOptions.onRemote = function () { if (initializing) { return; } if (isHistoryMode) { return; } @@ -544,7 +539,7 @@ define([ } }; - var getHTML = function (Dom) { + var getHTML = function () { return ('\n' + '\n' + inner.innerHTML); }; @@ -562,7 +557,7 @@ define([ saveAs(blob, filename); }); }; - var importFile = function (content, file) { + var importFile = function (content) { var shjson = stringify(Hyperjson.fromDOM(domFromHTML(content).body)); applyHjson(shjson); realtimeOptions.onLocal(); @@ -574,7 +569,7 @@ define([ editor.fire('change'); }; - var onInit = realtimeOptions.onInit = function (info) { + realtimeOptions.onInit = function (info) { userList = info.userList; var configTb = { @@ -596,11 +591,10 @@ define([ toolbar = info.realtime.toolbar = Toolbar.create($bar, info.myID, info.realtime, info.getLag, userList, configTb); var $rightside = $bar.find('.' + Toolbar.constants.rightside); - var $userBlock = $bar.find('.' + Toolbar.constants.username); - var $usernameButton = module.$userNameButton = $($bar.find('.' + Toolbar.constants.changeUsername)); + $bar.find('.' + Toolbar.constants.username); + module.$userNameButton = $($bar.find('.' + Toolbar.constants.changeUsername)); var editHash; - var viewHash = Cryptpad.getViewHashFromKeys(info.channel, secret.keys); if (!readOnly) { editHash = Cryptpad.getEditHashFromKeys(info.channel, secret.keys); @@ -680,7 +674,7 @@ define([ } /* add a forget button */ - var forgetCb = function (err, title) { + var forgetCb = function (err) { if (err) { return; } setEditable(false); }; @@ -694,7 +688,7 @@ define([ }; // this should only ever get called once, when the chain syncs - var onReady = realtimeOptions.onReady = function (info) { + realtimeOptions.onReady = function (info) { if (!module.isMaximized) { editor.execCommand('maximize'); module.isMaximized = true; @@ -780,7 +774,7 @@ define([ }); }; - var onAbort = realtimeOptions.onAbort = function (info) { + realtimeOptions.onAbort = function () { console.log("Aborting the session!"); // stop the user from continuing to edit setEditable(false); @@ -788,7 +782,7 @@ define([ Cryptpad.alert(Messages.common_connectionLost, undefined, true); }; - var onConnectionChange = realtimeOptions.onConnectionChange = function (info) { + realtimeOptions.onConnectionChange = function (info) { setEditable(info.state); toolbar.failed(); if (info.state) { @@ -800,7 +794,7 @@ define([ } }; - var onError = realtimeOptions.onError = onConnectError; + realtimeOptions.onError = onConnectError; var onLocal = realtimeOptions.onLocal = function () { if (initializing) { return; } @@ -816,7 +810,7 @@ define([ } }; - var rti = module.realtimeInput = realtimeInput.start(realtimeOptions); + module.realtimeInput = realtimeInput.start(realtimeOptions); Cryptpad.onLogout(function () { setEditable(false); }); @@ -834,7 +828,7 @@ define([ // export the typing tests to the window. // call like `test = easyTest()` // terminate the test like `test.cancel()` - var easyTest = window.easyTest = function () { + window.easyTest = function () { cursor.update(); var start = cursor.Range.start; var test = TypingTest.testInput(inner, start.el, start.offset, onLocal); @@ -846,7 +840,7 @@ define([ var interval = 100; var second = function (Ckeditor) { - Cryptpad.ready(function (err, env) { + Cryptpad.ready(function () { andThen(Ckeditor); Cryptpad.reportAppUsage(); }); diff --git a/www/poll/main.js b/www/poll/main.js index 1d6a151e5..0e6a22168 100644 --- a/www/poll/main.js +++ b/www/poll/main.js @@ -37,7 +37,7 @@ define([ var error = console.error; Cryptpad.addLoadingScreen(); - var onConnectError = function (info) { + var onConnectError = function () { Cryptpad.errorLoadingScreen(Messages.websocketError); }; @@ -97,15 +97,6 @@ define([ return newObj; }; - var setColumnDisabled = function (id, state) { - if (!state) { - $('input[data-rt-id^="' + id + '"]').removeAttr('disabled'); - return; - } - $('input[data-rt-id^="' + id + '"]').attr('disabled', 'disabled'); - }; - - var styleUncommittedColumn = function () { var id = APP.userid; @@ -286,7 +277,7 @@ define([ }; /* Called whenever an event is fired on an input element */ - var handleInput = function (input, isKeyup) { + var handleInput = function (input) { var type = input.type.toLowerCase(); var id = getRealtimeId(input); @@ -485,7 +476,7 @@ define([ uid: Cryptpad.getUid(), }; addToUserData(myData); - Cryptpad.setAttribute('username', newName, function (err, data) { + Cryptpad.setAttribute('username', newName, function (err) { if (err) { console.error("Couldn't set username"); return; @@ -558,7 +549,7 @@ define([ var colsOrder = sortColumns(displayedObj.table.colsOrder, userid); var $table = APP.$table = $(Render.asHTML(displayedObj, null, colsOrder, readOnly)); - var $createRow = APP.$createRow = $('#create-option').click(function () { + APP.$createRow = $('#create-option').click(function () { //console.error("BUTTON CLICKED! LOL"); Render.createRow(proxy, function (empty, id) { change(null, null, null, null, function() { @@ -567,7 +558,7 @@ define([ }); }); - var $createCol = APP.$createCol = $('#create-user').click(function () { + APP.$createCol = $('#create-user').click(function () { Render.createColumn(proxy, function (empty, id) { change(null, null, null, null, function() { $('.edit[data-rt-id="' + id + '"]').click(); @@ -576,7 +567,7 @@ define([ }); // Commit button - var $commit = APP.$commit = $('#commit').click(function () { + APP.$commit = $('#commit').click(function () { var uncommittedCopy = JSON.parse(JSON.stringify(APP.uncommitted)); APP.uncommitted = {}; prepareProxy(APP.uncommitted, copyObject(Render.Example)); @@ -586,13 +577,13 @@ define([ }); // #publish button is removed in readonly - var $publish = APP.$publish = $('#publish') + APP.$publish = $('#publish') .click(function () { publish(true); }); // #publish button is removed in readonly - var $admin = APP.$admin = $('#admin') + APP.$admin = $('#admin') .click(function () { publish(false); }); @@ -644,9 +635,7 @@ define([ var el = $description[0]; var selects = ['selectionStart', 'selectionEnd'].map(function (attr) { - var before = el[attr]; - var after = TextPatcher.transformCursor(el[attr], op); - return after; + return TextPatcher.transformCursor(el[attr], op); }); $description.val(n); if (op) { @@ -700,7 +689,7 @@ define([ }); }; - var disconnect = function (info) { + var disconnect = function () { //setEditable(false); // TODO APP.realtime.toolbar.failed(); Cryptpad.alert(Messages.common_connectionLost, undefined, true); @@ -713,11 +702,9 @@ define([ }; var create = function (info) { - var myID = APP.myID = info.myID; + APP.myID = info.myID; var editHash; - var viewHash = Cryptpad.getViewHashFromKeys(info.channel, secret.keys); - if (!readOnly) { editHash = Cryptpad.getEditHashFromKeys(info.channel, secret.keys); } @@ -748,17 +735,17 @@ define([ ifrw: window, common: Cryptpad, }; - var toolbar = info.realtime.toolbar = Toolbar.create(APP.$bar, info.myID, info.realtime, info.getLag, userList, config); + info.realtime.toolbar = Toolbar.create(APP.$bar, info.myID, info.realtime, info.getLag, userList, config); var $bar = APP.$bar; var $rightside = $bar.find('.' + Toolbar.constants.rightside); - var $userBlock = $bar.find('.' + Toolbar.constants.username); - var $editShare = $bar.find('.' + Toolbar.constants.editShare); - var $viewShare = $bar.find('.' + Toolbar.constants.viewShare); - var $usernameButton = APP.$userNameButton = $($bar.find('.' + Toolbar.constants.changeUsername)); + $bar.find('.' + Toolbar.constants.username); + $bar.find('.' + Toolbar.constants.editShare); + $bar.find('.' + Toolbar.constants.viewShare); + APP.$userNameButton = $($bar.find('.' + Toolbar.constants.changeUsername)); /* add a forget button */ - var forgetCb = function (err, title) { + var forgetCb = function (err) { if (err) { return; } disconnect(); }; @@ -814,6 +801,7 @@ define([ if (!userid) { userid = Render.coluid(); } APP.userid = userid; Cryptpad.setPadAttribute('userid', userid, function (e) { + if (e) { console.error(e); } ready(info, userid, readOnly); }); }); diff --git a/www/poll/render.js b/www/poll/render.js index dcf62079f..647b2fedd 100644 --- a/www/poll/render.js +++ b/www/poll/render.js @@ -57,7 +57,7 @@ var Renderer = function (Cryptpad) { return null; }; - var getCoordinates = Render.getCoordinates = function (id) { + Render.getCoordinates = function (id) { return id.split('_'); }; @@ -91,7 +91,7 @@ var Renderer = function (Cryptpad) { return null; }; - var createColumn = Render.createColumn = function (obj, cb, id, value) { + Render.createColumn = function (obj, cb, id, value) { var order = Cryptpad.find(obj, ['table', 'colsOrder']); if (!order) { throw new Error("Uninitialized realtime object!"); } id = id || coluid(); @@ -101,7 +101,7 @@ var Renderer = function (Cryptpad) { if (typeof(cb) === 'function') { cb(void 0, id); } }; - var removeColumn = Render.removeColumn = function (obj, id, cb) { + Render.removeColumn = function (obj, id, cb) { var order = Cryptpad.find(obj, ['table', 'colsOrder']); var parent = Cryptpad.find(obj, ['table', 'cols']); @@ -126,7 +126,7 @@ var Renderer = function (Cryptpad) { } }; - var createRow = Render.createRow = function (obj, cb, id, value) { + Render.createRow = function (obj, cb, id, value) { var order = Cryptpad.find(obj, ['table', 'rowsOrder']); if (!order) { throw new Error("Uninitialized realtime object!"); } id = id || rowuid(); @@ -136,7 +136,7 @@ var Renderer = function (Cryptpad) { if (typeof(cb) === 'function') { cb(void 0, id); } }; - var removeRow = Render.removeRow = function (obj, id, cb) { + Render.removeRow = function (obj, id, cb) { var order = Cryptpad.find(obj, ['table', 'rowsOrder']); var parent = Cryptpad.find(obj, ['table', 'rows']); @@ -153,7 +153,7 @@ var Renderer = function (Cryptpad) { if (typeof(cb) === 'function') { cb(); } }; - var setValue = Render.setValue = function (obj, id, value) { + Render.setValue = function (obj, id, value) { var type = typeofId(id); switch (type) { @@ -167,7 +167,7 @@ var Renderer = function (Cryptpad) { } }; - var getValue = Render.getValue = function (obj, id) { + Render.getValue = function (obj, id) { switch (typeofId(id)) { case 'row': return getRowValue(obj, id); case 'col': return getColumnValue(obj, id); @@ -219,7 +219,7 @@ var Renderer = function (Cryptpad) { })); } if (i === rows.length) { - return [null].concat(cols.map(function (col) { + return [null].concat(cols.map(function () { return { 'class': 'lastRow', }; @@ -359,7 +359,7 @@ var Renderer = function (Cryptpad) { return ['TABLE', {id:'table'}, [head, foot, body]]; }; - var asHTML = Render.asHTML = function (obj, rows, cols, readOnly) { + Render.asHTML = function (obj, rows, cols, readOnly) { return Hyperjson.toDOM(toHyperjson(cellMatrix(obj, rows, cols, readOnly), readOnly)); }; @@ -384,9 +384,7 @@ var Renderer = function (Cryptpad) { var op = TextPatcher.diff(o, n); info.selection = ['selectionStart', 'selectionEnd'].map(function (attr) { - var before = element[attr]; - var after = TextPatcher.transformCursor(element[attr], op); - return after; + return TextPatcher.transformCursor(element[attr], op); }); } }; @@ -432,7 +430,7 @@ var Renderer = function (Cryptpad) { } }; - var updateTable = Render.updateTable = function (table, obj, conf) { + Render.updateTable = function (table, obj, conf) { var DD = new DiffDOM(diffOptions); var rows = conf ? conf.rows : null; diff --git a/www/register/main.js b/www/register/main.js index b3892538d..6e97e2a93 100644 --- a/www/register/main.js +++ b/www/register/main.js @@ -2,14 +2,8 @@ define([ 'jquery', '/common/login.js', '/common/cryptpad-common.js', - '/common/cryptget.js', - '/common/credential.js' -], function ($, Login, Cryptpad, Crypt) { - - var APP = window.APP = { - Login: Login, - }; - + '/common/credential.js' // preloaded for login.js +], function ($, Login, Cryptpad) { var Messages = Cryptpad.Messages; $(function () { diff --git a/www/settings/main.js b/www/settings/main.js index 0d66b7886..2a2a7cd3d 100644 --- a/www/settings/main.js +++ b/www/settings/main.js @@ -16,10 +16,6 @@ define([ var Messages = Cryptpad.Messages; - var redirectToMain = function () { - window.location.href = '/'; - }; - // Manage changes in the realtime object made from another page var onRefresh = function (h) { if (typeof(h) !== "function") { return; } @@ -71,7 +67,7 @@ define([ var createDisplayNameInput = function (store) { var obj = store.proxy; var $div = $('', {'class': 'displayName'}); - var $label = $('', {'for' : 'displayName'}).text(Messages.user_displayName).appendTo($div); + $('', {'for' : 'displayName'}).text(Messages.user_displayName).appendTo($div); $('').appendTo($div); var $input = $('', { 'type': 'text', @@ -114,7 +110,7 @@ define([ }; var createResetTips = function () { var $div = $('', {'class': 'resetTips'}); - var $label = $('', {'for' : 'resetTips'}).text(Messages.settings_resetTips).appendTo($div); + $('', {'for' : 'resetTips'}).text(Messages.settings_resetTips).appendTo($div); $('').appendTo($div); var $button = $('', {'id': 'resetTips', 'class': 'btn btn-primary'}) .text(Messages.settings_resetTipsButton).appendTo($div); @@ -145,7 +141,7 @@ define([ saveAs(blob, filename); }); }; - var importFile = function (content, file) { + var importFile = function (content) { var $spinner = $('', {'class': 'fa fa-spinner fa-pulse'}).appendTo($div); Crypt.put(Cryptpad.getUserHash() || localStorage[Cryptpad.fileHashKey], content, function (e) { if (e) { console.error(e); } @@ -153,7 +149,7 @@ define([ }); }; - var $label = $('', {'for' : 'exportDrive'}).text(Messages.settings_backupTitle).appendTo($div); + $('', {'for' : 'exportDrive'}).text(Messages.settings_backupTitle).appendTo($div); $('').appendTo($div); /* add an export button */ var $export = Cryptpad.createButton('export', true, {}, exportFile); @@ -170,7 +166,7 @@ define([ var createResetDrive = function (obj) { var $div = $('', {'class': 'resetDrive'}); - var $label = $('', {'for' : 'resetDrive'}).text(Messages.settings_resetTitle).appendTo($div); + $('', {'for' : 'resetDrive'}).text(Messages.settings_resetTitle).appendTo($div); $('').appendTo($div); var $button = $('', {'id': 'resetDrive', 'class': 'btn btn-danger'}) .text(Messages.settings_reset).appendTo($div); @@ -259,7 +255,7 @@ define([ var createImportLocalPads = function (obj) { if (!Cryptpad.isLoggedIn()) { return; } var $div = $('', {'class': 'importLocalPads'}); - var $label = $('', {'for' : 'importLocalPads'}).text(Messages.settings_importTitle).appendTo($div); + $('', {'for' : 'importLocalPads'}).text(Messages.settings_importTitle).appendTo($div); $('').appendTo($div); var $button = $('', {'id': 'importLocalPads', 'class': 'btn btn-primary'}) .text(Messages.settings_import).appendTo($div); @@ -284,7 +280,7 @@ define([ var createLanguageSelector = function () { var $div = $('', {'class': 'importLocalPads'}); - var $label = $('').text(Messages.language).appendTo($div); + $('').text(Messages.language).appendTo($div); $('').appendTo($div); var $b = Cryptpad.createLanguageSelector().appendTo($div); $b.find('button').addClass('btn btn-secondary'); @@ -343,7 +339,6 @@ define([ }); window.addEventListener('storage', function (e) { - var key = e.key; if (e.key !== Cryptpad.userHashKey) { return; } var o = e.oldValue; var n = e.newValue; diff --git a/www/slide/main.js b/www/slide/main.js index d1972fae4..31b91d768 100644 --- a/www/slide/main.js +++ b/www/slide/main.js @@ -57,7 +57,7 @@ define([ var presentMode = Slide.isPresentURL(); - var onConnectError = function (info) { + var onConnectError = function () { Cryptpad.errorLoadingScreen(Messages.websocketError); }; @@ -222,11 +222,6 @@ define([ } }; - var isDefaultTitle = function () { - var parsed = Cryptpad.parsePadUrl(window.location.href); - return Cryptpad.isDefaultName(parsed, APP.title); - }; - var initializing = true; var stringifyInner = function (textValue) { @@ -281,7 +276,7 @@ define([ uid: Cryptpad.getUid(), }; addToUserData(myData); - Cryptpad.setAttribute('username', myUserName, function (err, data) { + Cryptpad.setAttribute('username', myUserName, function (err) { if (err) { console.log("Couldn't set username"); console.error(err); @@ -506,13 +501,13 @@ define([ h = Cryptpad.listenForKeys(todo, todoCancel); var $nav = $('').appendTo($div); - var $cancel = $('', {'class': 'cancel'}).text(Messages.cancelButton).appendTo($nav).click(todoCancel); - var $ok = $('', {'class': 'ok'}).text(Messages.settings_save).appendTo($nav).click(todo); + $('', {'class': 'cancel'}).text(Messages.cancelButton).appendTo($nav).click(todoCancel); + $('', {'class': 'ok'}).text(Messages.settings_save).appendTo($nav).click(todo); return $container; }; - var onInit = config.onInit = function (info) { + config.onInit = function (info) { userList = info.userList; var configTb = { @@ -534,11 +529,10 @@ define([ toolbar = module.toolbar = Toolbar.create($bar, info.myID, info.realtime, info.getLag, info.userList, configTb); var $rightside = $bar.find('.' + Toolbar.constants.rightside); - var $userBlock = $bar.find('.' + Toolbar.constants.username); - var $usernameButton = module.$userNameButton = $($bar.find('.' + Toolbar.constants.changeUsername)); + $bar.find('.' + Toolbar.constants.username); + module.$userNameButton = $($bar.find('.' + Toolbar.constants.changeUsername)); var editHash; - var viewHash = Cryptpad.getViewHashFromKeys(info.channel, secret.keys); if (!readOnly) { editHash = Cryptpad.getEditHashFromKeys(info.channel, secret.keys); @@ -595,14 +589,10 @@ define([ /* add an import button */ var $import = Cryptpad.createButton('import', true, {}, importText); $rightside.append($import); - - /* add a rename button */ - //var $setTitle = Cryptpad.createButton('rename', true, {suggestName: suggestName}, renameCb); - //$rightside.append($setTitle); } /* add a forget button */ - var forgetCb = function (err, title) { + var forgetCb = function (err) { if (err) { return; } setEditable(false); }; @@ -675,11 +665,10 @@ define([ initialValue: lastTheme }; var $block = module.$theme = Cryptpad.createDropdown(dropdownConfig); - var $button = $block.find('.buttonTitle'); setTheme(lastTheme, $block); - $block.find('a').click(function (e) { + $block.find('a').click(function () { var theme = $(this).attr('data-value'); setTheme(theme, $block); localStorage.setItem(themeKey, theme); @@ -762,7 +751,7 @@ define([ } }; - var onReady = config.onReady = function (info) { + config.onReady = function (info) { module.users = info.userList.users; if (module.realtime !== info.realtime) { @@ -883,7 +872,7 @@ define([ return cursor; }; - var onRemote = config.onRemote = function () { + config.onRemote = function () { if (initializing) { return; } if (isHistoryMode) { return; } var scroll = editor.getScrollInfo(); @@ -940,14 +929,14 @@ define([ } }; - var onAbort = config.onAbort = function (info) { + config.onAbort = function () { // inform of network disconnect setEditable(false); toolbar.failed(); Cryptpad.alert(Messages.common_connectionLost, undefined, true); }; - var onConnectionChange = config.onConnectionChange = function (info) { + config.onConnectionChange = function (info) { setEditable(info.state); toolbar.failed(); if (info.state) { @@ -959,9 +948,9 @@ define([ } }; - var onError = config.onError = onConnectError; + config.onError = onConnectError; - var realtime = module.realtime = Realtime.start(config); + module.realtime = Realtime.start(config); editor.on('change', onLocal); @@ -971,7 +960,7 @@ define([ var interval = 100; var second = function (CM) { - Cryptpad.ready(function (err, env) { + Cryptpad.ready(function () { andThen(CM); Cryptpad.reportAppUsage(); }); diff --git a/www/slide/slide.js b/www/slide/slide.js index 6c7b68fe8..c9e6f3dcd 100644 --- a/www/slide/slide.js +++ b/www/slide/slide.js @@ -9,7 +9,7 @@ define([ var checkedTaskItemPtn = /^\s*\[x\]\s*/; var uncheckedTaskItemPtn = /^\s*\[ \]\s*/; - renderer.listitem = function (text, level) { + renderer.listitem = function (text) { var isCheckedTaskItem = checkedTaskItemPtn.test(text); var isUncheckedTaskItem = uncheckedTaskItemPtn.test(text); if (isCheckedTaskItem) { @@ -28,8 +28,6 @@ define([ renderer: renderer }); - var truthy = function (x) { return x; }; - var Slide = { index: 0, lastIndex: 0, @@ -59,8 +57,7 @@ define([ var change = function (oldIndex, newIndex) { if (Slide.changeHandlers.length) { - Slide.changeHandlers.some(function (f, i) { - // HERE + Slide.changeHandlers.some(function (f) { f(oldIndex, newIndex, getNumberOfSlides()); }); } @@ -194,7 +191,7 @@ define([ change(Slide.lastIndex, Slide.index); }; - var updateOptions = Slide.updateOptions = function () { + Slide.updateOptions = function () { draw(Slide.index); }; @@ -233,7 +230,7 @@ define([ $modal.removeClass('shown'); }; - var update = Slide.update = function (content, init) { + Slide.update = function (content, init) { if (!Slide.shown && !init) { return; } if (!content) { content = ''; } var old = Slide.content; @@ -245,7 +242,7 @@ define([ change(Slide.lastIndex, Slide.index); }; - var left = Slide.left = function () { + Slide.left = function () { console.log('left'); Slide.lastIndex = Slide.index; @@ -253,7 +250,7 @@ define([ Slide.draw(i); }; - var right = Slide.right = function () { + Slide.right = function () { console.log('right'); Slide.lastIndex = Slide.index; @@ -261,7 +258,7 @@ define([ Slide.draw(i); }; - var first = Slide.first = function () { + Slide.first = function () { console.log('first'); Slide.lastIndex = Slide.index; @@ -269,7 +266,7 @@ define([ Slide.draw(i); }; - var last = Slide.last = function () { + Slide.last = function () { console.log('end'); Slide.lastIndex = Slide.index; @@ -279,7 +276,7 @@ define([ var addEvent = function () { var icon_to; - $modal.mousemove(function (e) { + $modal.mousemove(function () { var $buttons = $modal.find('.button'); $buttons.show(); if (icon_to) { window.clearTimeout(icon_to); } @@ -287,17 +284,17 @@ define([ $buttons.fadeOut(); }, 1000); }); - $modal.find('#button_exit').click(function (e) { + $modal.find('#button_exit').click(function () { var ev = $.Event("keyup"); ev.which = 27; $modal.trigger(ev); }); - $modal.find('#button_left').click(function (e) { + $modal.find('#button_left').click(function () { var ev = $.Event("keyup"); ev.which = 37; $modal.trigger(ev); }); - $modal.find('#button_right').click(function (e) { + $modal.find('#button_right').click(function () { var ev = $.Event("keyup"); ev.which = 39; $modal.trigger(ev); diff --git a/www/whiteboard/main.js b/www/whiteboard/main.js index b35ae705d..d78419b41 100644 --- a/www/whiteboard/main.js +++ b/www/whiteboard/main.js @@ -24,7 +24,7 @@ define([ $(function () { Cryptpad.addLoadingScreen(); - var onConnectError = function (info) { + var onConnectError = function () { Cryptpad.errorLoadingScreen(Messages.websocketError); }; var toolbar; @@ -330,8 +330,7 @@ window.canvas = canvas; return $color; }; - var editHash; - var onInit = config.onInit = function (info) { + config.onInit = function (info) { userList = info.userList; var config = { displayed: ['useradmin', 'spinner', 'lag', 'state', 'share', 'userlist', 'newpad', 'limit'], @@ -370,7 +369,7 @@ window.canvas = canvas; var $export = Cryptpad.createButton('export', true, {}, saveImage); $rightside.append($export); - var $forget = Cryptpad.createButton('forget', true, {}, function (err, title) { + var $forget = Cryptpad.createButton('forget', true, {}, function (err) { if (err) { return; } setEditable(false); toolbar.failed(); @@ -380,7 +379,6 @@ window.canvas = canvas; makeColorButton($rightside); var editHash; - var viewHash = Cryptpad.getViewHashFromKeys(info.channel, secret.keys); if (!readOnly) { editHash = Cryptpad.getEditHashFromKeys(info.channel, secret.keys); @@ -522,7 +520,7 @@ window.canvas = canvas; uid: Cryptpad.getUid(), }; addToUserData(myData); - Cryptpad.setAttribute('username', myUserName, function (err, data) { + Cryptpad.setAttribute('username', myUserName, function (err) { if (err) { console.log("Couldn't set username"); console.error(err); @@ -532,7 +530,7 @@ window.canvas = canvas; }); }; - var onReady = config.onReady = function (info) { + config.onReady = function (info) { var realtime = module.realtime = info.realtime; module.patchText = TextPatcher.create({ realtime: realtime @@ -578,14 +576,14 @@ window.canvas = canvas; }); }; - var onAbort = config.onAbort = function (info) { + config.onAbort = function () { setEditable(false); toolbar.failed(); Cryptpad.alert(Messages.common_connectionLost, undefined, true); }; // TODO onConnectionStateChange - var onConnectionChange = config.onConnectionChange = function (info) { + config.onConnectionChange = function (info) { setEditable(info.state); toolbar.failed(); if (info.state) { @@ -597,7 +595,7 @@ window.canvas = canvas; } }; - var rt = Realtime.start(config); + module.rt = Realtime.start(config); canvas.on('mouse:up', onLocal); @@ -611,7 +609,7 @@ window.canvas = canvas; }); }; - Cryptpad.ready(function (err, env) { + Cryptpad.ready(function () { andThen(); Cryptpad.reportAppUsage(); });