diff --git a/customize.dist/main.js b/customize.dist/main.js index 73c39ced5..ce74a4d32 100644 --- a/customize.dist/main.js +++ b/customize.dist/main.js @@ -88,7 +88,7 @@ define([ $('button.login').click(function () { // setTimeout 100ms to remove the keyboard on mobile devices before the loading screen pops up window.setTimeout(function () { - Cryptpad.addLoadingScreen({loadingText: Messages.login_hashing}); + UI.addLoadingScreen({loadingText: Messages.login_hashing}); // We need a setTimeout(cb, 0) otherwise the loading screen is only displayed after hashing the password window.setTimeout(function () { loginReady(function () { @@ -116,22 +116,22 @@ define([ } switch (err) { case 'NO_SUCH_USER': - Cryptpad.removeLoadingScreen(function () { + UI.removeLoadingScreen(function () { UI.alert(Messages.login_noSuchUser); }); break; case 'INVAL_USER': - Cryptpad.removeLoadingScreen(function () { + UI.removeLoadingScreen(function () { UI.alert(Messages.login_invalUser); }); break; case 'INVAL_PASS': - Cryptpad.removeLoadingScreen(function () { + UI.removeLoadingScreen(function () { UI.alert(Messages.login_invalPass); }); break; default: // UNHANDLED ERROR - Cryptpad.errorLoadingScreen(Messages.login_unhandledError); + UI.errorLoadingScreen(Messages.login_unhandledError); } }); }); diff --git a/www/common/common-interface.js b/www/common/common-interface.js index f03b4b481..76a603836 100644 --- a/www/common/common-interface.js +++ b/www/common/common-interface.js @@ -2,16 +2,17 @@ define([ 'jquery', '/customize/messages.js', '/common/common-util.js', + '/common/common-hash.js', + '/common/common-notifier.js', '/customize/application_config.js', '/bower_components/alertifyjs/dist/js/alertify.js', - '/common/notify.js', - '/common/visible.js', '/common/tippy.min.js', '/customize/pages.js', '/common/hyperscript.js', '/bower_components/bootstrap-tokenfield/dist/bootstrap-tokenfield.js', 'css!/common/tippy.css', -], function ($, Messages, Util, AppConfig, Alertify, Notify, Visible, Tippy, Pages, h) { +], function ($, Messages, Util, Hash, Notifier, AppConfig, + Alertify, Tippy, Pages, h) { var UI = {}; /* @@ -270,7 +271,7 @@ define([ document.body.appendChild(frame); setTimeout(function () { $ok.focus(); - UI.notify(); + Notifier.notify(); }); }; @@ -318,7 +319,7 @@ define([ document.body.appendChild(frame); setTimeout(function () { $(input).select().focus(); - UI.notify(); + Notifier.notify(); }); }; @@ -365,7 +366,7 @@ define([ document.body.appendChild(frame); setTimeout(function () { - UI.notify(); + Notifier.notify(); $(frame).find('.ok').focus(); if (typeof(opt.done) === 'function') { opt.done($ok.closest('.dialog')); @@ -468,44 +469,6 @@ define([ $('#' + LOADING).find('p').html(error || Messages.error); }; - // Notify - var notify = {}; - UI.unnotify = function () { - if (notify.tabNotification && - typeof(notify.tabNotification.cancel) === 'function') { - notify.tabNotification.cancel(); - } - }; - - UI.notify = function () { - if (Visible.isSupported() && !Visible.currently()) { - UI.unnotify(); - notify.tabNotification = Notify.tab(1000, 10); - } - }; - - if (Visible.isSupported()) { - Visible.onChange(function (yes) { - if (yes) { UI.unnotify(); } - }); - } - - UI.importContent = function (type, f, cfg) { - return function () { - var $files = $('', {type:"file"}); - if (cfg && cfg.accept) { - $files.attr('accept', cfg.accept); - } - $files.click(); - $files.on('change', function (e) { - var file = e.target.files[0]; - var reader = new FileReader(); - reader.onload = function (e) { f(e.target.result, file); }; - reader.readAsText(file, type); - }); - }; - }; - var $defaultIcon = $('', {"class": "fa fa-file-text-o"}); UI.getIcon = function (type) { var $icon = $defaultIcon.clone(); @@ -517,6 +480,17 @@ define([ return $icon; }; + UI.getFileIcon = function (data) { + var $icon = UI.getIcon(); + if (!data) { return $icon; } + var href = data.href; + if (!href) { return $icon; } + + var type = Hash.parsePadUrl(href).type; + $icon = UI.getIcon(type); + + return $icon; + }; // Tooltips @@ -524,11 +498,8 @@ define([ // If an element is removed from the UI while a tooltip is applied on that element, the tooltip will get hung // forever, this is a solution which just searches for tooltips which have no corrisponding element and removes // them. - var win; $('.tippy-popper').each(function (i, el) { - win = win || $('#pad-iframe').length? $('#pad-iframe')[0].contentWindow: undefined; - if (!win) { return; } - if (win.$('[aria-describedby=' + el.getAttribute('id') + ']').length === 0) { + if ($('[aria-describedby=' + el.getAttribute('id') + ']').length === 0) { el.remove(); } }); @@ -536,9 +507,9 @@ define([ UI.addTooltips = function () { var MutationObserver = window.MutationObserver; - var addTippy = function (el) { + var delay = typeof(AppConfig.tooltipDelay) === "number" ? AppConfig.tooltipDelay : 500; + var addTippy = function (i, el) { if (el.nodeName === 'IFRAME') { return; } - var delay = typeof(AppConfig.tooltipDelay) === "number" ? AppConfig.tooltipDelay : 500; Tippy(el, { position: 'bottom', distance: 0, @@ -547,26 +518,30 @@ define([ delay: [delay, 0] }); }; - var $body = $('body'); - var $padIframe = $('#pad-iframe').contents().find('body'); - $('[title]').each(function (i, el) { - addTippy(el); - }); - $('#pad-iframe').contents().find('[title]').each(function (i, el) { - addTippy(el); - }); + // This is the robust solution to remove dangling tooltips + // The mutation observer does not always find removed nodes. + setInterval(UI.clearTooltips, delay); + var checkRemoved = function (x) { + var out = false; + $(x).find('[aria-describedby]').each(function (i, el) { + var id = el.getAttribute('aria-describedby'); + if (id.indexOf('tippy-tooltip-') !== 0) { return; } + out = true; + }); + return out; + }; + $('[title]').each(addTippy); var observer = new MutationObserver(function(mutations) { + var removed = false; mutations.forEach(function(mutation) { - if (mutation.type === 'childList' && mutation.addedNodes.length) { - $body.find('[title]').each(function (i, el) { - addTippy(el); - }); - if (!$padIframe.length) { return; } - $padIframe.find('[title]').each(function (i, el) { - addTippy(el); - }); + for (var i = 0; i < mutation.addedNodes.length; i++) { + $(mutation.addedNodes[i]).find('[title]').each(addTippy); + } + for (var j = 0; j < mutation.removedNodes.length; j++) { + removed |= checkRemoved(mutation.removedNodes[j]); } }); + if (removed) { UI.clearTooltips(); } }); observer.observe($('body')[0], { attributes: false, @@ -574,14 +549,6 @@ define([ characterData: false, subtree: true }); - if ($('#pad-iframe').length) { - observer.observe($('#pad-iframe').contents().find('body')[0], { - attributes: false, - childList: true, - characterData: false, - subtree: true - }); - } }; return UI; diff --git a/www/common/common-notifier.js b/www/common/common-notifier.js new file mode 100644 index 000000000..7a658e193 --- /dev/null +++ b/www/common/common-notifier.js @@ -0,0 +1,29 @@ +define([ + '/common/visible.js', + '/common/notify.js' +], function (Visible, Notify) { + var Notifier = {}; + + var notify = {}; + Notifier.unnotify = function () { + if (notify.tabNotification && + typeof(notify.tabNotification.cancel) === 'function') { + notify.tabNotification.cancel(); + } + }; + + Notifier.notify = function () { + if (Visible.isSupported() && !Visible.currently()) { + Notifier.unnotify(); + notify.tabNotification = Notify.tab(1000, 10); + } + }; + + if (Visible.isSupported()) { + Visible.onChange(function (yes) { + if (yes) { Notifier.unnotify(); } + }); + } + + return Notifier; +}); diff --git a/www/common/common-ui-elements.js b/www/common/common-ui-elements.js index f955f8206..235cf693a 100644 --- a/www/common/common-ui-elements.js +++ b/www/common/common-ui-elements.js @@ -6,11 +6,9 @@ define([ '/common/common-language.js', '/common/common-interface.js', '/common/media-tag.js', - '/common/tippy.min.js', - '/customize/application_config.js', 'css!/common/tippy.css', -], function ($, Config, Cryptpad, Util, UI, Language, MediaTag, Tippy, AppConfig) { +], function ($, Config, Cryptpad, Util, Language, UI, MediaTag) { var UIElements = {}; var Messages = Cryptpad.Messages; @@ -36,7 +34,7 @@ define([ } return void console.error(err || res.error); } - Cryptpad.dialog.tagPrompt(res.data, function (tags) { + UI.dialog.tagPrompt(res.data, function (tags) { if (!Array.isArray(tags)) { return; } sframeChan.event('EV_TAGS_SET', { tags: tags, @@ -46,6 +44,22 @@ define([ }); }; + var importContent = function (type, f, cfg) { + return function () { + var $files = $('', {type:"file"}); + if (cfg && cfg.accept) { + $files.attr('accept', cfg.accept); + } + $files.click(); + $files.on('change', function (e) { + var file = e.target.files[0]; + var reader = new FileReader(); + reader.onload = function (e) { f(e.target.result, file); }; + reader.readAsText(file, type); + }); + }; + }; + UIElements.createButton = function (common, type, rightside, data, callback) { var AppConfig = common.getAppConfig(); var button; @@ -71,7 +85,7 @@ define([ if (callback) { button .click(common.prepareFeedback(type)) - .click(Cryptpad.importContent('text/plain', function (content, file) { + .click(importContent('text/plain', function (content, file) { callback(content, file); }, {accept: data ? data.accept : undefined})); } @@ -781,6 +795,37 @@ define([ return $block; }; + UIElements.createModal = function (cfg) { + var $body = cfg.$body || $('body'); + var $blockContainer = $body.find('#'+cfg.id); + if (!$blockContainer.length) { + $blockContainer = $('
', { + 'class': 'cp-modal-container', + 'id': cfg.id + }); + } + var hide = function () { + if (cfg.onClose) { return void cfg.onClose(); } + $blockContainer.hide(); + }; + $blockContainer.html('').appendTo($body); + var $block = $('
', {'class': 'cp-modal'}).appendTo($blockContainer); + $('', { + 'class': 'cp-modal-close fa fa-times', + 'title': Messages.filePicker_close + }).click(hide).appendTo($block); + $body.click(hide); + $block.click(function (e) { + e.stopPropagation(); + }); + $body.keydown(function (e) { + if (e.which === 27) { + hide(); + } + }); + return $blockContainer; + }; + UIElements.initFilePicker = function (common, cfg) { var onSelect = cfg.onSelect || $.noop; @@ -816,10 +861,10 @@ define([ var fileDialogCfg = { onSelect: function (data) { if (data.type === type && first) { - Cryptpad.addLoadingScreen({hideTips: true}); + UI.addLoadingScreen({hideTips: true}); sframeChan.query('Q_TEMPLATE_USE', data.href, function () { first = false; - Cryptpad.removeLoadingScreen(); + UI.removeLoadingScreen(); common.feedback('TEMPLATE_USED'); }); if (focus) { focus.focus(); } @@ -842,58 +887,5 @@ define([ }); }; - UIElements.addTooltips = function () { - var MutationObserver = window.MutationObserver; - var delay = typeof(AppConfig.tooltipDelay) === "number" ? AppConfig.tooltipDelay : 500; - var addTippy = function (i, el) { - if (el.nodeName === 'IFRAME') { return; } - Tippy(el, { - position: 'bottom', - distance: 0, - performance: true, - dynamicTitle: true, - delay: [delay, 0] - }); - }; - var clearTooltips = function () { - $('.tippy-popper').each(function (i, el) { - if ($('[aria-describedby=' + el.getAttribute('id') + ']').length === 0) { - el.remove(); - } - }); - }; - // This is the robust solution to remove dangling tooltips - // The mutation observer does not always find removed nodes. - setInterval(clearTooltips, delay); - var checkRemoved = function (x) { - var out = false; - $(x).find('[aria-describedby]').each(function (i, el) { - var id = el.getAttribute('aria-describedby'); - if (id.indexOf('tippy-tooltip-') !== 0) { return; } - out = true; - }); - return out; - }; - $('[title]').each(addTippy); - var observer = new MutationObserver(function(mutations) { - var removed = false; - mutations.forEach(function(mutation) { - for (var i = 0; i < mutation.addedNodes.length; i++) { - $(mutation.addedNodes[i]).find('[title]').each(addTippy); - } - for (var j = 0; j < mutation.removedNodes.length; j++) { - removed |= checkRemoved(mutation.removedNodes[j]); - } - }); - if (removed) { clearTooltips(); } - }); - observer.observe($('body')[0], { - attributes: false, - childList: true, - characterData: false, - subtree: true - }); - }; - return UIElements; }); diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 1f005aa71..e68d92b88 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -5,7 +5,6 @@ define([ '/common/fsStore.js', '/common/common-util.js', '/common/common-hash.js', - '/common/common-interface.js', '/common/common-messaging.js', '/file/file-crypto.js', '/common/common-realtime.js', @@ -17,7 +16,7 @@ define([ '/common/media-tag.js', '/bower_components/nthen/index.js', '/bower_components/localforage/dist/localforage.min.js', -], function ($, Config, Messages, Store, Util, Hash, UI, +], function ($, Config, Messages, Store, Util, Hash, Messaging, FileCrypto, Realtime, Language, Clipboard, Pinpad, AppConfig, MediaTag, Nthen, localForage) { @@ -58,29 +57,6 @@ define([ var rpc; var anon_rpc; - // import UI elements - //common.findCancelButton = UI.findCancelButton; REFACTOR - //common.findOKButton = UI.findOKButton; - //common.listenForKeys = UI.listenForKeys; - //common.stopListening = UI.stopListening; - //common.prompt = UI.prompt; - //common.confirm = UI.confirm; - //common.alert = UI.alert; - //common.log = UI.log; - common.warn = UI.warn; - common.spinner = UI.spinner; - common.addLoadingScreen = UI.addLoadingScreen; - common.removeLoadingScreen = UI.removeLoadingScreen; - common.errorLoadingScreen = UI.errorLoadingScreen; - common.notify = UI.notify; - common.unnotify = UI.unnotify; - common.getIcon = UI.getIcon; - common.addTooltips = UI.addTooltips; - common.clearTooltips = UI.clearTooltips; - common.importContent = UI.importContent; - common.tokenField = UI.tokenField; - common.dialog = UI.dialog; - // import common utilities for export common.find = Util.find; common.hexToBase64 = Util.hexToBase64; @@ -626,35 +602,7 @@ define([ return t.href === rhref; }); }; - common.selectTemplate = function (type, rt, Crypt) { - if (!AppConfig.enableTemplates) { return; } - var temps = listTemplates(type); - if (temps.length === 0) { return; } - var $content = $('
'); - $('').text(Messages.selectTemplate).appendTo($content); - $('

', {id:"selectTemplate"}).appendTo($content); - UI.alert($content.html(), null, true); - var $p = $('#selectTemplate'); - temps.forEach(function (t, i) { - $('', {href: t.href, title: t.title}).text(t.title).click(function (e) { - e.preventDefault(); - var parsed = parsePadUrl(t.href); - if(!parsed) { throw new Error("Cannot get template hash"); } - common.addLoadingScreen({hideTips: true}); - Crypt.get(parsed.hash, function (err, val) { - if (err) { throw new Error(err); } - var p = parsePadUrl(window.location.href); - Crypt.put(p.hash, val, function () { - UI.findOKButton().click(); - common.removeLoadingScreen(); - common.feedback('TEMPLATE_USED'); - }); - }); - }).appendTo($p); - if (i !== temps.length) { $('
').appendTo($p); } - }); - UI.findOKButton().text(Messages.cancelButton); - }; + // Secure iframes common.useTemplate = function (href, Crypt, cb) { var parsed = parsePadUrl(href); @@ -696,7 +644,6 @@ define([ _onDisplayNameChanged.forEach(function (h) { h(newName, isLocal); }); - common.clearTooltips(); }; // STORAGE @@ -781,9 +728,6 @@ define([ var data = makePad(href, name); getStore().pushData(data, function (e, id) { if (e) { - if (e === 'E_OVER_LIMIT') { - UI.alert(Messages.pinLimitNotPinned, null, true); - } return void cb(e); } getStore().addPad(id, common.initialPath); @@ -1299,105 +1243,6 @@ define([ 'image/gif', ]; - // This is duplicated in drive/main.js, it should be unified - var getFileIcon = common.getFileIcon = function (data) { - var $icon = common.getIcon(); - - if (!data) { return $icon; } - - var href = data.href; - if (!href) { return $icon; } - - var type = common.parsePadUrl(href).type; - $icon = common.getIcon(type); - - return $icon; - }; - - common.createModal = function (cfg) { - var $body = cfg.$body || $('body'); - var $blockContainer = $body.find('#'+cfg.id); - if (!$blockContainer.length) { - $blockContainer = $('

', { - 'class': 'cp-modal-container', - 'id': cfg.id - }); - } - var hide = function () { - if (cfg.onClose) { return void cfg.onClose(); } - $blockContainer.hide(); - }; - $blockContainer.html('').appendTo($body); - var $block = $('
', {'class': 'cp-modal'}).appendTo($blockContainer); - $('', { - 'class': 'cp-modal-close fa fa-times', - 'title': Messages.filePicker_close - }).click(hide).appendTo($block); - $body.click(hide); - $block.click(function (e) { - e.stopPropagation(); - }); - $body.keydown(function (e) { - if (e.which === 27) { - hide(); - } - }); - return $blockContainer; - }; - common.createFileDialog = function (cfg) { - var $blockContainer = common.createModal({ - id: 'fileDialog', - $body: cfg.$body - }); - var $block = $blockContainer.find('.cp-modal'); - var $description = $('

').text(Messages.filePicker_description); - $block.append($description); - var $filter = $('

', {'class': 'cp-modal-form'}).appendTo($block); - var $container = $('', {'class': 'fileContainer'}).appendTo($block); - var updateContainer = function () { - $container.html(''); - var filter = $filter.find('.filter').val().trim(); - var list = common.getUserFilesList(); - var fo = common.getFO(); - list.forEach(function (id) { - var data = fo.getFileData(id); - var name = fo.getTitle(id); - if (filter && name.toLowerCase().indexOf(filter.toLowerCase()) === -1) { - return; - } - var $span = $('', { - 'class': 'element', - 'title': name, - }).appendTo($container); - $span.append(getFileIcon(data)); - $span.append(name); - $span.click(function () { - if (typeof cfg.onSelect === "function") { cfg.onSelect(data.href); } - $blockContainer.hide(); - }); - }); - }; - var to; - $('', { - type: 'text', - 'class': 'filter', - 'placeholder': Messages.filePicker_filter - }).appendTo($filter).on('keypress', function () { - if (to) { window.clearTimeout(to); } - to = window.setTimeout(updateContainer, 300); - }); - //$filter.append(' '+Messages.or+' '); - var data = {FM: cfg.data.FM}; - $filter.append(common.createButton('upload', false, data, function () { - $blockContainer.hide(); - })); - updateContainer(); - $blockContainer.show(); - }; - - - - common.getShareHashes = function (secret, cb) { if (!window.location.hash) { var hashes = common.getHashes(secret.channel, secret); @@ -1443,7 +1288,6 @@ define([ (parseInt(verArr[0]) === parseInt(storedArr[0]) && parseInt(verArr[1]) > parseInt(storedArr[1])); if (!shouldUpdate) { return; } - //UI.alert(Messages._getKey('newVersion', [verArr.join('.')]), null, true); localStorage[CRYPTPAD_VERSION] = ver; }; @@ -1464,12 +1308,6 @@ define([ common.initialPath = sessionStorage[newPadPathKey]; delete sessionStorage[newPadPathKey]; } - common.onFriendRequest = function (confirmText, cb) { - UI.confirm(confirmText, cb, null, true); - }; - common.onFriendComplete = function (data) { - UI.log(data.logText); - }; var proxy; var network; @@ -1515,12 +1353,6 @@ define([ }).nThen(function (waitFor) { $(waitFor()); }).nThen(function (waitFor) { - // Race condition : if document.body is undefined when alertify.js is loaded, Alertify - // won't work. We have to reset it now to make sure it uses a correct "body" - UI.Alertify.reset(); - // clear any tooltips that might get hung - setInterval(function () { common.clearTooltips(); }, 5000); - // Load the new pad when the hash has changed var oldHref = document.location.href; window.onhashchange = function () { @@ -1644,7 +1476,6 @@ define([ } }).nThen(function () { updateLocalVersion(); - common.addTooltips(); f(void 0, env); if (typeof(window.onhashchange) === 'function') { window.onhashchange(); } }); diff --git a/www/common/fsStore.js b/www/common/fsStore.js index e554ca1de..df56e849a 100644 --- a/www/common/fsStore.js +++ b/www/common/fsStore.js @@ -312,12 +312,13 @@ define([ } else if (o && !n) { $(window).on('keyup', function (e) { if (e.keyCode === 27) { - Cryptpad.removeLoadingScreen(); + //UI.removeLoadingScreen(); } }); Cryptpad.logout(); - Cryptpad.addLoadingScreen({hideTips: true}); - Cryptpad.errorLoadingScreen(Cryptpad.Messages.onLogout, true); + UI.alert(Cryptpad.Messages.onLogout, null, true); + //UI.addLoadingScreen({hideTips: true}); + //UI.errorLoadingScreen(Cryptpad.Messages.onLogout, true); if (exp.info) { exp.info.network.disconnect(); } diff --git a/www/common/sframe-app-framework.js b/www/common/sframe-app-framework.js index 72a51d37e..3b68cf0ce 100644 --- a/www/common/sframe-app-framework.js +++ b/www/common/sframe-app-framework.js @@ -50,7 +50,7 @@ define([ AppConfig.badStateTimeout : 30000; var onConnectError = function () { - Cryptpad.errorLoadingScreen(Messages.websocketError); + UI.errorLoadingScreen(Messages.websocketError); }; var create = function (options, cb) { @@ -153,7 +153,7 @@ define([ evContentUpdate.fire(newContent); } catch (e) { console.log(e.stack); - Cryptpad.errorLoadingScreen(e.message); + UI.errorLoadingScreen(e.message); } }; @@ -266,7 +266,7 @@ define([ if (!readOnly) { onLocal(); } evOnReady.fire(newPad); - Cryptpad.removeLoadingScreen(emitResize); + UI.removeLoadingScreen(emitResize); var privateDat = cpNfInner.metadataMgr.getPrivateData(); if (options.thumbnail && privateDat.thumbnails) { @@ -375,7 +375,7 @@ define([ }; nThen(function (waitFor) { - Cryptpad.addLoadingScreen(); + UI.addLoadingScreen(); SFCommon.create(waitFor(function (c) { common = c; })); }).nThen(function (waitFor) { cpNfInner = common.startRealtime({ diff --git a/www/common/sframe-common-history.js b/www/common/sframe-common-history.js index 547e564d1..30d389816 100644 --- a/www/common/sframe-common-history.js +++ b/www/common/sframe-common-history.js @@ -85,7 +85,6 @@ define([ var onReady = function () { }; var Messages = common.Messages; - var Cryptpad = common.getCryptpadCommon(); var realtime; @@ -102,7 +101,7 @@ define([ $right.hide(); $cke.hide(); - Cryptpad.spinner($hist).get().show(); + UI.spinner($hist).get().show(); var onUpdate; diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index 494386c61..e5e344053 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -18,6 +18,7 @@ define([ var sframeChan; var FilePicker; var Messenger; + var Notifier; nThen(function (waitFor) { // Load #2, the loading screen is up so grab whatever you need... @@ -29,14 +30,16 @@ define([ '/common/sframe-channel.js', '/filepicker/main.js', '/common/common-messenger.js', + '/common/common-notifier.js', ], waitFor(function (_CpNfOuter, _Cryptpad, _Crypto, _Cryptget, SFrameChannel, - _FilePicker, _Messenger) { + _FilePicker, _Messenger, _Notifier) { CpNfOuter = _CpNfOuter; Cryptpad = _Cryptpad; Crypto = _Crypto; Cryptget = _Cryptget; FilePicker = _FilePicker; Messenger = _Messenger; + Notifier = _Notifier; if (localStorage.CRYPTPAD_URLARGS !== ApiConfig.requireConf.urlArgs) { console.log("New version, flushing cache"); @@ -176,7 +179,7 @@ define([ currentTitle = newTitle; setDocumentTitle(); Cryptpad.renamePad(newTitle, undefined, function (err) { - if (err) { cb('ERROR'); } else { cb(); } + cb(err); }); }); sframeChan.on('EV_SET_TAB_TITLE', function (newTabTitle) { @@ -203,7 +206,7 @@ define([ }); sframeChan.on('EV_NOTIFY', function () { - Cryptpad.notify(); + Notifier.notify(); }); sframeChan.on('Q_SET_LOGIN_REDIRECT', function (data, cb) { diff --git a/www/common/sframe-common-title.js b/www/common/sframe-common-title.js index b0f5a654e..317944993 100644 --- a/www/common/sframe-common-title.js +++ b/www/common/sframe-common-title.js @@ -1,7 +1,9 @@ define([ 'jquery', - '/common/common-util.js' -], function ($, Util) { + '/common/common-util.js', + '/common/common-interface.js', + '/customize/messages.js' +], function ($, Util, UI, Messages) { var module = {}; module.create = function (Common, cfg) { @@ -54,7 +56,9 @@ define([ }); metadataMgr.onTitleChange(function (title) { sframeChan.query('Q_SET_PAD_TITLE_IN_DRIVE', title, function (err) { - if (err) { return; } + if (err === 'E_OVER_LIMIT') { + return void UI.alert(Messages.pinLimitNotPinned, null, true); + } else if (err) { return; } evTitleChange.fire(title); if (titleUpdated) { titleUpdated(undefined, title); } }); diff --git a/www/common/sframe-common.js b/www/common/sframe-common.js index 2b2db6c4e..2d39d8ef4 100644 --- a/www/common/sframe-common.js +++ b/www/common/sframe-common.js @@ -359,7 +359,7 @@ define([ }; }); - UIElements.addTooltips(); + UI.addTooltips(); ctx.sframeChan.on('EV_RT_CONNECT', function () { CommonRealtime.setConnectionState(true); }); ctx.sframeChan.on('EV_RT_DISCONNECT', function () { CommonRealtime.setConnectionState(false); }); diff --git a/www/common/toolbar3.js b/www/common/toolbar3.js index d7455be81..fb3bd72e2 100644 --- a/www/common/toolbar3.js +++ b/www/common/toolbar3.js @@ -529,10 +529,10 @@ define([ $('

').text(Messages.fileEmbedTitle).appendTo($content); var $script = $('

').text(Messages.fileEmbedScript).appendTo($content); $('
').appendTo($script); - $script.append(Cryptpad.dialog.selectable(Common.getMediatagScript())); + $script.append(UI.dialog.selectable(Common.getMediatagScript())); var $tag = $('

').text(Messages.fileEmbedTag).appendTo($content); $('
').appendTo($tag); - $tag.append(Cryptpad.dialog.selectable(Common.getMediatagFromHref(url))); + $tag.append(UI.dialog.selectable(Common.getMediatagFromHref(url))); UI.alert($content[0], null, true); }); @@ -787,7 +787,7 @@ define([ 'target': '_blank', 'href': origin + '/' + p + '/', }, - content: $('

').append(Cryptpad.getIcon(p)).html() + Messages.type[p] + content: $('
').append(UI.getIcon(p)).html() + Messages.type[p] }); }); var dropdownConfig = { diff --git a/www/contacts/inner.js b/www/contacts/inner.js index 68558909f..ae12ad665 100644 --- a/www/contacts/inner.js +++ b/www/contacts/inner.js @@ -29,13 +29,13 @@ define([ var Messages = Cryptpad.Messages; var APP = {}; var onConnectError = function () { - Cryptpad.errorLoadingScreen(Messages.websocketError); + UI.errorLoadingScreen(Messages.websocketError); }; var common; var sFrameChan; nThen(function (waitFor) { - $(waitFor(Cryptpad.addLoadingScreen)); + $(waitFor(UI.addLoadingScreen)); SFCommon.create(waitFor(function (c) { APP.common = common = c; })); }).nThen(function (waitFor) { sFrameChan = common.getSframeChannel(); @@ -87,13 +87,13 @@ define([ UI.create(messenger, $(friendList), $(messaging), common); - Cryptpad.removeLoadingScreen(); + UI.removeLoadingScreen(); /* sFrameChan.query('Q_HEY_BUDDY', null, function (err, data) { if (!data) { return; } if (data.error) { - Cryptpad.warn(data.error); + UI.warn(data.error); } else { UI.log(data.response); } diff --git a/www/contacts/messenger-ui.js b/www/contacts/messenger-ui.js index cb65644ec..3f8c8d09c 100644 --- a/www/contacts/messenger-ui.js +++ b/www/contacts/messenger-ui.js @@ -4,13 +4,14 @@ define([ '/customize/messages.js', '/common/common-util.js', '/common/common-interface.js', + '/common/common-notifier.js', '/common/hyperscript.js', '/bower_components/marked/marked.min.js', '/common/media-tag.js', -], function ($, Cryptpad, Messages, Util, UI, h, Marked, MediaTag) { +], function ($, Cryptpad, Messages, Util, UI, Notifier, h, Marked, MediaTag) { 'use strict'; - var UI = {}; + var MessengerUI = {}; var m = function (md) { var d = h('div.cp-app-contacts-content'); @@ -42,7 +43,7 @@ define([ }; }; - UI.create = function (messenger, $userlist, $messages, common) { + MessengerUI.create = function (messenger, $userlist, $messages, common) { var origin = common.getMetadataMgr().getPrivateData().origin; var state = window.state = { @@ -391,7 +392,7 @@ define([ var initializing = true; messenger.on('message', function (message) { - if (!initializing) { Cryptpad.notify(); } + if (!initializing) { Notifier.notify(); } var curvePublic = message.curve; var name = displayNames[curvePublic]; @@ -516,7 +517,7 @@ define([ count--; if (count === 0) { initializing = false; - Cryptpad.removeLoadingScreen(); + UI.removeLoadingScreen(); } }; ready(); @@ -526,5 +527,5 @@ define([ }); }; - return UI; + return MessengerUI; }); diff --git a/www/drive/inner.js b/www/drive/inner.js index 40b622b03..9c756cb18 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -48,7 +48,7 @@ define([ }; var onConnectError = function () { - Cryptpad.errorLoadingScreen(Messages.websocketError); + UI.errorLoadingScreen(Messages.websocketError); }; var E_OVER_LIMIT = 'E_OVER_LIMIT'; @@ -1215,9 +1215,9 @@ define([ // This is duplicated in cryptpad-common, it should be unified var getFileIcon = function (id) { var data = filesOp.getFileData(id); - return Cryptpad.getFileIcon(data); + return UI.getFileIcon(data); }; - var getIcon = Cryptpad.getIcon; + var getIcon = UI.getIcon; // Create the "li" element corresponding to the file/folder located in "path" var createElement = function (path, elPath, root, isFolder) { @@ -1803,7 +1803,7 @@ define([ .text(Messages.fm_newFile)); $element.attr('title', Messages.fm_newFile); $element.click(function () { - var $modal = Cryptpad.createModal({ + var $modal = UIElements.createModal({ id: 'cp-app-drive-new-ghost-dialog', $body: $('body') }); @@ -2481,7 +2481,7 @@ define([ $('
').appendTo($d); if (!ro) { $('
').append(Pages['/poll/']()); $('body').append($div.html()); })); diff --git a/www/profile/inner.js b/www/profile/inner.js index a012e24e4..5f7ca4c76 100644 --- a/www/profile/inner.js +++ b/www/profile/inner.js @@ -38,7 +38,7 @@ define([ _onRefresh: [] }; var onConnectError = function () { - Cryptpad.errorLoadingScreen(Messages.websocketError); + UI.errorLoadingScreen(Messages.websocketError); }; // Decryption event for avatar mediatag (TODO not needed anymore?) @@ -412,7 +412,7 @@ define([ createLeftside(); } - Cryptpad.removeLoadingScreen(); + UI.removeLoadingScreen(); }; var createToolbar = function () { @@ -430,7 +430,7 @@ define([ }; nThen(function (waitFor) { - $(waitFor(Cryptpad.addLoadingScreen)); + $(waitFor(UI.addLoadingScreen)); SFCommon.create(waitFor(function (c) { APP.common = common = c; })); }).nThen(function (waitFor) { APP.$container = $('#cp-sidebarlayout-container'); @@ -455,7 +455,7 @@ define([ // If not logged in, you can only view other users's profile if (!privateData.readOnly && !common.isLoggedIn()) { - Cryptpad.removeLoadingScreen(); + UI.removeLoadingScreen(); var $p = $('

', {id: CREATE_ID}).append(Messages.profile_register); var $a = $('', { diff --git a/www/register/main.js b/www/register/main.js index f5169c940..412ae0b36 100644 --- a/www/register/main.js +++ b/www/register/main.js @@ -122,7 +122,7 @@ define([ registering = true; // setTimeout 100ms to remove the keyboard on mobile devices before the loading screen pops up window.setTimeout(function () { - Cryptpad.addLoadingScreen({ + UI.addLoadingScreen({ loadingText: Messages.login_hashing, hideTips: true, }); @@ -135,28 +135,28 @@ define([ if (err) { switch (err) { case 'NO_SUCH_USER': - Cryptpad.removeLoadingScreen(function () { + UI.removeLoadingScreen(function () { UI.alert(Messages.login_noSuchUser, function () { registering = false; }); }); break; case 'INVAL_USER': - Cryptpad.removeLoadingScreen(function () { + UI.removeLoadingScreen(function () { UI.alert(Messages.login_invalUser, function () { registering = false; }); }); break; case 'INVAL_PASS': - Cryptpad.removeLoadingScreen(function () { + UI.removeLoadingScreen(function () { UI.alert(Messages.login_invalPass, function () { registering = false; }); }); break; case 'PASS_TOO_SHORT': - Cryptpad.removeLoadingScreen(function () { + UI.removeLoadingScreen(function () { var warning = Messages._getKey('register_passwordTooShort', [ Cred.MINIMUM_PASSWORD_LENGTH ]); @@ -167,7 +167,7 @@ define([ break; case 'ALREADY_REGISTERED': // logMeIn should reset registering = false - Cryptpad.removeLoadingScreen(function () { + UI.removeLoadingScreen(function () { UI.confirm(Messages.register_alreadyRegistered, function (yes) { if (!yes) { return; } proxy.login_name = uname; @@ -182,7 +182,7 @@ define([ break; default: // UNHANDLED ERROR registering = false; - Cryptpad.errorLoadingScreen(Messages.login_unhandledError); + UI.errorLoadingScreen(Messages.login_unhandledError); } return; } diff --git a/www/settings/inner.js b/www/settings/inner.js index 2df079406..e0e21f355 100644 --- a/www/settings/inner.js +++ b/www/settings/inner.js @@ -25,7 +25,7 @@ define([ Cryptpad: Cryptpad, }; var onConnectError = function () { - Cryptpad.errorLoadingScreen(Messages.websocketError); + UI.errorLoadingScreen(Messages.websocketError); }; var common; @@ -73,7 +73,7 @@ define([ var userHref = Cryptpad.getUserHrefFromKeys(accountName, publicKey); var $pubLabel = $('', {'class': 'label'}) .text(Messages.settings_publicSigningKey); - $key.append($pubLabel).append(Cryptpad.dialog.selectable(userHref)); + $key.append($pubLabel).append(UI.dialog.selectable(userHref)); } return $div; @@ -490,7 +490,7 @@ define([ nThen(function (waitFor) { - $(waitFor(Cryptpad.addLoadingScreen)); + $(waitFor(UI.addLoadingScreen)); SFCommon.create(waitFor(function (c) { APP.common = common = c; })); }).nThen(function (waitFor) { APP.$container = $('#cp-sidebarlayout-container'); @@ -548,6 +548,6 @@ define([ createLeftside(); createUsageButton(); - Cryptpad.removeLoadingScreen(); + UI.removeLoadingScreen(); }); }); diff --git a/www/todo/inner.js b/www/todo/inner.js index 20470a235..cf89af08c 100644 --- a/www/todo/inner.js +++ b/www/todo/inner.js @@ -6,6 +6,7 @@ define([ '/common/cryptpad-common.js', '/bower_components/nthen/index.js', '/common/sframe-common.js', + '/common/common-interface.js', '/todo/todo.js', 'css!/bower_components/bootstrap/dist/css/bootstrap.min.css', @@ -19,19 +20,20 @@ define([ Cryptpad, nThen, SFCommon, + UI, Todo ) { var Messages = Cryptpad.Messages; var APP = window.APP = {}; var onConnectError = function () { - Cryptpad.errorLoadingScreen(Messages.websocketError); + UI.errorLoadingScreen(Messages.websocketError); }; var common; var sFrameChan; nThen(function (waitFor) { - $(waitFor(Cryptpad.addLoadingScreen)); + $(waitFor(UI.addLoadingScreen)); SFCommon.create(waitFor(function (c) { APP.common = common = c; })); }).nThen(function (waitFor) { sFrameChan = common.getSframeChannel(); @@ -47,7 +49,7 @@ define([ var $list = $('#cp-app-todo-taskslist'); var removeTips = function () { - Cryptpad.clearTooltips(); + UI.clearTooltips(); }; var onReady = function () { @@ -188,11 +190,11 @@ define([ editTask = editTask; display(); - Cryptpad.removeLoadingScreen(); + UI.removeLoadingScreen(); }; var onInit = function () { - Cryptpad.addLoadingScreen(); + UI.addLoadingScreen(); $body.on('dragover', function (e) { e.preventDefault(); }); $body.on('drop', function (e) { e.preventDefault(); }); diff --git a/www/whiteboard/inner.js b/www/whiteboard/inner.js index e390ea19c..af02b4ec3 100644 --- a/www/whiteboard/inner.js +++ b/www/whiteboard/inner.js @@ -61,7 +61,7 @@ define([ var toolbar; var onConnectError = function () { - Cryptpad.errorLoadingScreen(Messages.websocketError); + UI.errorLoadingScreen(Messages.websocketError); }; var andThen = function (common) { @@ -537,7 +537,7 @@ define([ (hjson.metadata && typeof(hjson.metadata.type) !== 'undefined' && hjson.metadata.type !== 'whiteboard')) { var errorText = Messages.typeError; - Cryptpad.errorLoadingScreen(errorText); + UI.errorLoadingScreen(errorText); throw new Error(errorText); } newDoc = hjson.content; @@ -556,7 +556,7 @@ define([ setEditable(!readOnly); initializing = false; config.onLocal(); - Cryptpad.removeLoadingScreen(); + UI.removeLoadingScreen(); initThumbnails(); @@ -637,7 +637,7 @@ define([ nThen(function (waitFor) { $(waitFor(function () { - Cryptpad.addLoadingScreen(); + UI.addLoadingScreen(); var $div = $('