diff --git a/www/common/common-interface.js b/www/common/common-interface.js index 609317ea3..654c140e8 100644 --- a/www/common/common-interface.js +++ b/www/common/common-interface.js @@ -58,35 +58,52 @@ define([ var dialog = UI.dialog = {}; - dialog.selectable = function (value) { - var input = h('input', { + var merge = function (a, b) { + var c = {}; + if (a) { + Object.keys(a).forEach(function (k) { + c[k] = a[k]; + }); + } + if (b) { + Object.keys(b).forEach(function (k) { + c[k] = b[k]; + }); + } + return c; + }; + + dialog.selectable = function (value, opt) { + var attrs = merge({ type: 'text', readonly: 'readonly', - }); + }, opt); + + var input = h('input', attrs); $(input).val(value).click(function () { input.select(); }); return input; }; - dialog.okButton = function () { - return h('button.ok', { tabindex: '2', }, Messages.okButton); + dialog.okButton = function (content) { + return h('button.ok', { tabindex: '2', }, content || Messages.okButton); }; - dialog.cancelButton = function () { - return h('button.cancel', { tabindex: '1'}, Messages.cancelButton); + dialog.cancelButton = function (content) { + return h('button.cancel', { tabindex: '1'}, content || Messages.cancelButton); }; dialog.message = function (text) { - return h('p.message', text); + return h('p.msg', text); }; dialog.textInput = function (opt) { - return h('input', opt || { - placeholder: '', + var attrs = merge({ type: 'text', 'class': 'cp-text-input', - }); + }, opt); + return h('input', attrs); }; dialog.nav = function (content) { @@ -191,12 +208,20 @@ define([ UI.alert = function (msg, cb, force) { cb = cb || function () {}; - if (typeof(msg) === 'string' && force !== true) { - msg = Util.fixHTML(msg); + + var message; + if (typeof(msg) === 'string') { + // sanitize + if (!force) { msg = Util.fixHTML(msg); } + message = dialog.message(); + message.innerHTML = msg; + } else { + message = dialog.message(msg); } + var ok = dialog.okButton(); var frame = dialog.frame([ - dialog.message(msg), + message, dialog.nav(ok), ]); @@ -211,92 +236,102 @@ define([ document.body.appendChild(frame); setTimeout(function () { $ok.focus(); - if (typeof(UI.notify) === 'function') { - UI.notify(); - } + UI.notify(); }); }; UI.prompt = function (msg, def, cb, opt, force) { - opt = opt || {}; cb = cb || function () {}; - if (force !== true) { msg = Util.fixHTML(msg); } + opt = opt || {}; - var keyHandler = listenForKeys(function () { // yes - findOKButton().click(); - }, function () { // no - findCancelButton().click(); + var input = dialog.textInput(); + input.value = typeof(def) === 'string'? def: ''; + + var message; + if (typeof(msg) === 'string') { + if (!force) { msg = Util.fixHTML(msg); } + message = dialog.message(); + message.innerHTML = msg; + } else { + message = dialog.message(msg); + } + + var ok = dialog.okButton(opt.ok); + var cancel = dialog.cancelButton(opt.cancel); + var frame = dialog.frame([ + message, + input, + dialog.nav([ cancel, ok, ]), + ]); + + var listener; + var close = Util.once(function () { + $(frame).fadeOut(150, function () { $(this).remove(); }); + stopListening(listener); }); - // Make sure we don't call both the "yes" and "no" handlers if we use "findOKButton().click()" - // in the callback - var isClicked = false; + var $ok = $(ok).click(function (ev) { cb(input.value, ev); }); + var $cancel = $(cancel).click(function (ev) { cb(null, ev); }); + listener = listenForKeys(function () { // yes + close(); $ok.click(); + }, function () { // no + close(); $cancel.click(); + }); - Alertify - .defaultValue(def || '') - .okBtn(opt.ok || Messages.okButton || 'OK') - .cancelBtn(opt.cancel || Messages.cancelButton || 'Cancel') - .prompt(msg, function (val, ev) { - if (isClicked) { return; } - isClicked = true; - cb(val, ev); - stopListening(keyHandler); - }, function (ev) { - if (isClicked) { return; } - isClicked = true; - cb(null, ev); - stopListening(keyHandler); - }); - if (typeof(UI.notify) === 'function') { + document.body.appendChild(frame); + setTimeout(function () { + input.select().focus(); UI.notify(); - } + }); }; UI.confirm = function (msg, cb, opt, force, styleCB) { - opt = opt || {}; cb = cb || function () {}; - if (force !== true) { msg = Util.fixHTML(msg); } + opt = opt || {}; - var keyHandler = listenForKeys(function () { - findOKButton().click(); - }, function () { - findCancelButton().click(); + var message; + if (typeof(msg) === 'string') { + if (!force) { msg = Util.fixHTML(msg); } + message = dialog.message(); + message.innerHTML = msg; + } else { + message = dialog.message(msg); + } + + var ok = dialog.okButton(opt.ok); + var cancel = dialog.cancelButton(opt.cancel); + + var frame = dialog.frame([ + message, + dialog.nav(opt.reverseOrder? + [ok, cancel]: [cancel, ok]), + ]); + + var listener; + var close = Util.once(function () { + $(frame).fadeOut(150, function () { $(this).remove(); }); + stopListening(listener); }); - // Make sure we don't call both the "yes" and "no" handlers if we use "findOKButton().click()" - // in the callback - var isClicked = false; + var $ok = $(ok).click(function (ev) { close(); cb(true, ev); }); + var $cancel = $(cancel).click(function (ev) { close(); cb(false, ev); }); - Alertify - .okBtn(opt.ok || Messages.okButton || 'OK') - .cancelBtn(opt.cancel || Messages.cancelButton || 'Cancel') - .confirm(msg, function () { - if (isClicked) { return; } - isClicked = true; - cb(true); - stopListening(keyHandler); - }, function () { - if (isClicked) { return; } - isClicked = true; - cb(false); - stopListening(keyHandler); - }); + if (opt.cancelClass) { $cancel.addClass(opt.cancelClass); } + if (opt.okClass) { $ok.addClass(opt.okClass); } - window.setTimeout(function () { - var $ok = findOKButton(); - var $cancel = findCancelButton(); - if (opt.okClass) { $ok.addClass(opt.okClass); } - if (opt.cancelClass) { $cancel.addClass(opt.cancelClass); } - if (opt.reverseOrder) { - $ok.insertBefore($ok.prev()); - } + listener = listenForKeys(function () { + $ok.click(); + }, function () { + $cancel.click(); + }); + + document.body.appendChild(frame); + setTimeout(function () { + UI.notify(); if (typeof(styleCB) === 'function') { styleCB($ok.closest('.dialog')); } - }, 0); - if (typeof(UI.notify) === 'function') { - UI.notify(); - } + }); }; UI.log = function (msg) { diff --git a/www/common/common-messenger.js b/www/common/common-messenger.js index 32b4ac5be..f40b85ae8 100644 --- a/www/common/common-messenger.js +++ b/www/common/common-messenger.js @@ -3,8 +3,7 @@ define([ '/bower_components/chainpad-crypto/crypto.js', '/common/curve.js', '/common/common-hash.js', - '/common/common-realtime.js' -], function ($, Crypto, Curve, Hash, Realtime) { +], function ($, Crypto, Curve, Hash) { 'use strict'; var Msg = { inputs: [], @@ -242,7 +241,7 @@ define([ if (!proxy.friends) { return; } var friends = proxy.friends; delete friends[curvePublic]; - Realtime.whenRealtimeSyncs(common, realtime, cb); + common.whenRealtimeSyncs(realtime, cb); }; var pushMsg = function (channel, cryptMsg) { @@ -472,7 +471,7 @@ define([ channel.wc.bcast(cryptMsg).then(function () { delete friends[curvePublic]; delete channels[curvePublic]; - Realtime.whenRealtimeSyncs(common, realtime, function () { + common.whenRealtimeSyncs(realtime, function () { cb(); }); }, function (err) { diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 6f34a0325..1cb14144b 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -1089,6 +1089,7 @@ define([ */ var LIMIT_REFRESH_RATE = 30000; // milliseconds common.createUsageBar = function (cb) { + if (!isLoggedIn()) { return cb("NOT_LOGGED_IN"); } // getPinnedUsage updates common.account.usage, and other values // so we can just use those and only check for errors var $container = $('', {'class':'limit-container'}); diff --git a/www/drive/main.js b/www/drive/main.js index 0282cdfc8..7730996b4 100644 --- a/www/drive/main.js +++ b/www/drive/main.js @@ -2340,9 +2340,9 @@ define([ $('
').appendTo($d); if (!ro) { $('