', {
- 'class': 'fa fa-caret-down',
- }).appendTo($button);*/
-
- // Menu
- var $innerblock = $('', {'class': 'cp-dropdown-content'});
- if (config.left) { $innerblock.addClass('cp-dropdown-left'); }
-
- config.options.forEach(function (o) {
- if (!isValidOption(o)) { return; }
- $('<' + o.tag + '>', o.attributes || {}).html(o.content || '').appendTo($innerblock);
- });
-
- $container.append($button).append($innerblock);
-
- var value = config.initialValue || '';
-
- var setActive = function ($el) {
- if ($el.length !== 1) { return; }
- $innerblock.find('.cp-dropdown-element-active').removeClass('cp-dropdown-element-active');
- $el.addClass('cp-dropdown-element-active');
- var scroll = $el.position().top + $innerblock.scrollTop();
- if (scroll < $innerblock.scrollTop()) {
- $innerblock.scrollTop(scroll);
- } else if (scroll > ($innerblock.scrollTop() + 280)) {
- $innerblock.scrollTop(scroll-270);
- }
- };
-
- var hide = function () {
- window.setTimeout(function () { $innerblock.hide(); }, 0);
- };
-
- var show = function () {
- $innerblock.show();
- $innerblock.find('.cp-dropdown-element-active').removeClass('cp-dropdown-element-active');
- if (config.isSelect && value) {
- var $val = $innerblock.find('[data-value="'+value+'"]');
- setActive($val);
- $innerblock.scrollTop($val.position().top + $innerblock.scrollTop());
- }
- if (config.feedback && store) { common.feedback(config.feedback); }
- };
-
- $container.click(function (e) {
- e.stopPropagation();
- var state = $innerblock.is(':visible');
- $('.cp-dropdown-content').hide();
- try {
- $('iframe').each(function (idx, ifrw) {
- $(ifrw).contents().find('.cp-dropdown-content').hide();
- });
- } catch (er) {
- // empty try catch in case this iframe is problematic (cross-origin)
- }
- if (state) {
- hide();
- return;
- }
- show();
- });
-
- if (config.isSelect) {
- var pressed = '';
- var to;
- $container.keydown(function (e) {
- var $value = $innerblock.find('[data-value].cp-dropdown-element-active');
- if (e.which === 38) { // Up
- if ($value.length) {
- var $prev = $value.prev();
- setActive($prev);
- }
- }
- if (e.which === 40) { // Down
- if ($value.length) {
- var $next = $value.next();
- setActive($next);
- }
- }
- if (e.which === 13) { //Enter
- if ($value.length) {
- $value.click();
- hide();
- }
- }
- if (e.which === 27) { // Esc
- hide();
- }
- });
- $container.keypress(function (e) {
- window.clearTimeout(to);
- var c = String.fromCharCode(e.which);
- pressed += c;
- var $value = $innerblock.find('[data-value^="'+pressed+'"]:first');
- if ($value.length) {
- setActive($value);
- $innerblock.scrollTop($value.position().top + $innerblock.scrollTop());
- }
- to = window.setTimeout(function () {
- pressed = '';
- }, 1000);
- });
-
- $container.setValue = function (val, name) {
- value = val;
- var $val = $innerblock.find('[data-value="'+val+'"]');
- var textValue = name || $val.html() || val;
- $button.find('.cp-dropdown-button-title').html(textValue);
- };
- $container.getValue = function () {
- return value || '';
- };
- }
-
- return $container;
- };
-
common.getShareHashes = function (secret, cb) {
if (!window.location.hash) {
var hashes = common.getHashes(secret.channel, secret);
@@ -1623,7 +1443,7 @@ define([
(parseInt(verArr[0]) === parseInt(storedArr[0]) &&
parseInt(verArr[1]) > parseInt(storedArr[1]));
if (!shouldUpdate) { return; }
- //common.alert(Messages._getKey('newVersion', [verArr.join('.')]), null, true);
+ //UI.alert(Messages._getKey('newVersion', [verArr.join('.')]), null, true);
localStorage[CRYPTPAD_VERSION] = ver;
};
@@ -1645,10 +1465,10 @@ define([
delete sessionStorage[newPadPathKey];
}
common.onFriendRequest = function (confirmText, cb) {
- common.confirm(confirmText, cb, null, true);
+ UI.confirm(confirmText, cb, null, true);
};
common.onFriendComplete = function (data) {
- common.log(data.logText);
+ UI.log(data.logText);
};
var proxy;
diff --git a/www/common/fsStore.js b/www/common/fsStore.js
index 56764dc6b..e554ca1de 100644
--- a/www/common/fsStore.js
+++ b/www/common/fsStore.js
@@ -4,8 +4,9 @@ define([
'/bower_components/chainpad-crypto/crypto.js?v=0.1.5',
'/bower_components/textpatcher/TextPatcher.amd.js',
'/common/userObject.js',
+ '/common/common-interface.js',
'/common/migrate-user-object.js',
-], function ($, Listmap, Crypto, TextPatcher, FO, Migrate) {
+], function ($, Listmap, Crypto, TextPatcher, FO, UI, Migrate) {
/*
This module uses localStorage, which is synchronous, but exposes an
asyncronous API. This is so that we can substitute other storage
@@ -361,7 +362,7 @@ define([
if (path[0] === 'drive' && path[1] === "migrate" && value === 1) {
rt.network.disconnect();
rt.realtime.abort();
- Cryptpad.alert(Cryptpad.Messages.fs_migration, null, true);
+ UI.alert(Cryptpad.Messages.fs_migration, null, true);
}
});
};
diff --git a/www/common/sframe-app-framework.js b/www/common/sframe-app-framework.js
index 342108678..72a51d37e 100644
--- a/www/common/sframe-app-framework.js
+++ b/www/common/sframe-app-framework.js
@@ -10,6 +10,7 @@ define([
'/common/sframe-common.js',
'/customize/messages.js',
'/common/common-util.js',
+ '/common/common-interface.js',
'/common/common-thumbnail.js',
'/customize/application_config.js',
@@ -28,6 +29,7 @@ define([
SFCommon,
Messages,
Util,
+ UI,
Thumb,
AppConfig)
{
@@ -287,9 +289,9 @@ define([
var onConnectionChange = function (info) {
stateChange(info.state ? STATE.INITIALIZING : STATE.DISCONNECTED);
if (info.state) {
- Cryptpad.findOKButton().click();
+ UI.findOKButton().click();
} else {
- Cryptpad.alert(Messages.common_connectionLost, undefined, true);
+ UI.alert(Messages.common_connectionLost, undefined, true);
}
};
@@ -297,7 +299,7 @@ define([
var $export = common.createButton('export', true, {}, function () {
var ext = (typeof(extension) === 'function') ? extension() : extension;
var suggestion = title.suggestTitle('cryptpad-document');
- Cryptpad.prompt(Messages.exportPrompt,
+ UI.prompt(Messages.exportPrompt,
Cryptpad.fixFileName(suggestion) + '.' + ext, function (filename)
{
if (!(typeof(filename) === 'string' && filename)) { return; }
@@ -426,13 +428,13 @@ define([
if (infiniteSpinnerModal) { return; }
infiniteSpinnerModal = true;
stateChange(STATE.INFINITE_SPINNER);
- Cryptpad.confirm(Messages.realtime_unrecoverableError, function (yes) {
+ UI.confirm(Messages.realtime_unrecoverableError, function (yes) {
if (!yes) { return; }
common.gotoURL();
});
cpNfInner.chainpad.onSettle(function () {
infiniteSpinnerModal = false;
- Cryptpad.findCancelButton().click();
+ UI.findCancelButton().click();
stateChange(STATE.READY);
onRemote();
});
diff --git a/www/common/sframe-common-codemirror.js b/www/common/sframe-common-codemirror.js
index b7037164f..3b8d3d3ad 100644
--- a/www/common/sframe-common-codemirror.js
+++ b/www/common/sframe-common-codemirror.js
@@ -2,9 +2,12 @@ define([
'jquery',
'/common/modes.js',
'/common/themes.js',
- '/common/cryptpad-common.js',
+ '/customize/messages.js',
+ '/common/common-ui-elements.js',
+ '/common/common-hash.js',
+ '/common/common-util.js',
'/bower_components/textpatcher/TextPatcher.js',
-], function ($, Modes, Themes, Cryptpad, TextPatcher) {
+], function ($, Modes, Themes, Messages, UIElements, Hash, Util, TextPatcher) {
var module = {};
var cursorToPos = function(cursor, oldText) {
@@ -101,7 +104,6 @@ define([
module.create = function (Common, defaultMode, CMeditor) {
var exp = {};
- var Messages = Cryptpad.Messages;
var CodeMirror = exp.CodeMirror = CMeditor;
CodeMirror.modeURL = "cm/mode/%N/%N";
@@ -211,7 +213,7 @@ define([
isSelect: true,
feedback: 'CODE_LANGUAGE',
};
- var $block = exp.$language = Cryptpad.createDropdown(dropdownConfig);
+ var $block = exp.$language = UIElements.createDropdown(dropdownConfig);
$block.find('button').attr('title', Messages.languageButtonTitle);
$block.find('a').click(function () {
setMode($(this).attr('data-value'), onModeChanged);
@@ -248,7 +250,7 @@ define([
initialValue: lastTheme,
feedback: 'CODE_THEME',
};
- var $block = exp.$theme = Cryptpad.createDropdown(dropdownConfig);
+ var $block = exp.$theme = UIElements.createDropdown(dropdownConfig);
$block.find('button').attr('title', Messages.themeButtonTitle);
setTheme(lastTheme, $block);
@@ -324,8 +326,8 @@ define([
//var cursor = editor.getCursor();
//var cleanName = data.name.replace(/[\[\]]/g, '');
//var text = '!['+cleanName+']('+data.url+')';
- var parsed = Cryptpad.parsePadUrl(data.url);
- var hexFileName = Cryptpad.base64ToHex(parsed.hashData.channel);
+ var parsed = Hash.parsePadUrl(data.url);
+ var hexFileName = Util.base64ToHex(parsed.hashData.channel);
var src = '/blob/' + hexFileName.slice(0,2) + '/' + hexFileName;
var mt = '';
diff --git a/www/common/sframe-common-file.js b/www/common/sframe-common-file.js
index c8b1b7d7c..7033edff7 100644
--- a/www/common/sframe-common-file.js
+++ b/www/common/sframe-common-file.js
@@ -2,8 +2,10 @@ define([
'jquery',
'/file/file-crypto.js',
'/common/common-thumbnail.js',
+ '/common/common-interface.js',
+
'/bower_components/tweetnacl/nacl-fast.min.js',
-], function ($, FileCrypto, Thumb) {
+], function ($, FileCrypto, Thumb, UI) {
var Nacl = window.nacl;
var module = {};
@@ -123,7 +125,7 @@ define([
window.open(origin + $link.attr('href'), '_blank');
});
var title = metadata.name;
- Cryptpad.log(Messages._getKey('upload_success', [title]));
+ UI.log(Messages._getKey('upload_success', [title]));
common.prepareFeedback('upload')();
if (config.onUploaded) {
@@ -140,18 +142,18 @@ define([
queue.next();
if (e === 'TOO_LARGE') {
// TODO update table to say too big?
- return void Cryptpad.alert(Messages.upload_tooLarge);
+ return void UI.alert(Messages.upload_tooLarge);
}
if (e === 'NOT_ENOUGH_SPACE') {
// TODO update table to say not enough space?
- return void Cryptpad.alert(Messages.upload_notEnoughSpace);
+ return void UI.alert(Messages.upload_notEnoughSpace);
}
console.error(e);
- return void Cryptpad.alert(Messages.upload_serverError);
+ return void UI.alert(Messages.upload_serverError);
};
onPending = function (cb) {
- Cryptpad.confirm(Messages.upload_uploadPending, cb);
+ UI.confirm(Messages.upload_uploadPending, cb);
};
file.noStore = config.noStore;
@@ -161,7 +163,7 @@ define([
console.log('Upload started...');
});
} catch (e) {
- Cryptpad.alert(Messages.upload_serverError);
+ UI.alert(Messages.upload_serverError);
}
};
@@ -260,7 +262,7 @@ define([
var onFileDrop = File.onFileDrop = function (file, e) {
if (!common.isLoggedIn()) {
- return Cryptpad.alert(common.Messages.upload_mustLogin);
+ return UI.alert(common.Messages.upload_mustLogin);
}
Array.prototype.slice.call(file).forEach(function (d) {
diff --git a/www/common/sframe-common-history.js b/www/common/sframe-common-history.js
index 9167afc5f..547e564d1 100644
--- a/www/common/sframe-common-history.js
+++ b/www/common/sframe-common-history.js
@@ -1,8 +1,10 @@
define([
'jquery',
+ '/common/common-interface.js',
'/bower_components/chainpad-json-validator/json-ot.js',
+
'/bower_components/chainpad/chainpad.dist.js',
-], function ($, JsonOT) {
+], function ($, UI, JsonOT) {
var ChainPad = window.ChainPad;
var History = {};
@@ -203,11 +205,11 @@ define([
onClose();
});
$rev.click(function () {
- Cryptpad.confirm(Messages.history_restorePrompt, function (yes) {
+ UI.confirm(Messages.history_restorePrompt, function (yes) {
if (!yes) { return; }
close();
onRevert();
- Cryptpad.log(Messages.history_restoreDone);
+ UI.log(Messages.history_restoreDone);
});
});
diff --git a/www/common/sframe-common.js b/www/common/sframe-common.js
index b3d61d504..2b2db6c4e 100644
--- a/www/common/sframe-common.js
+++ b/www/common/sframe-common.js
@@ -16,6 +16,7 @@ define([
'/common/common-realtime.js',
'/common/common-util.js',
'/common/common-thumbnail.js',
+ '/common/common-interface.js',
'/bower_components/localforage/dist/localforage.min.js'
], function (
$,
@@ -24,7 +25,7 @@ define([
CpNfInner,
SFrameChannel,
Title,
- UI,
+ UIElements,
History,
File,
CodeMirror,
@@ -34,6 +35,7 @@ define([
CommonRealtime,
Util,
Thumb,
+ UI,
localForage
) {
// Chainpad Netflux Inner
@@ -74,16 +76,16 @@ define([
};
// UI
- funcs.createUserAdminMenu = callWithCommon(UI.createUserAdminMenu);
- funcs.initFilePicker = callWithCommon(UI.initFilePicker);
- funcs.openFilePicker = callWithCommon(UI.openFilePicker);
- funcs.openTemplatePicker = callWithCommon(UI.openTemplatePicker);
- funcs.displayMediatagImage = callWithCommon(UI.displayMediatagImage);
- funcs.displayAvatar = callWithCommon(UI.displayAvatar);
- funcs.createButton = callWithCommon(UI.createButton);
- funcs.createUsageBar = callWithCommon(UI.createUsageBar);
- funcs.updateTags = callWithCommon(UI.updateTags);
- funcs.createLanguageSelector = callWithCommon(UI.createLanguageSelector);
+ funcs.createUserAdminMenu = callWithCommon(UIElements.createUserAdminMenu);
+ funcs.initFilePicker = callWithCommon(UIElements.initFilePicker);
+ funcs.openFilePicker = callWithCommon(UIElements.openFilePicker);
+ funcs.openTemplatePicker = callWithCommon(UIElements.openTemplatePicker);
+ funcs.displayMediatagImage = callWithCommon(UIElements.displayMediatagImage);
+ funcs.displayAvatar = callWithCommon(UIElements.displayAvatar);
+ funcs.createButton = callWithCommon(UIElements.createButton);
+ funcs.createUsageBar = callWithCommon(UIElements.createUsageBar);
+ funcs.updateTags = callWithCommon(UIElements.updateTags);
+ funcs.createLanguageSelector = callWithCommon(UIElements.createLanguageSelector);
// Thumb
funcs.displayThumbnail = callWithCommon(Thumb.displayThumbnail);
@@ -357,19 +359,19 @@ define([
};
});
- UI.addTooltips();
+ UIElements.addTooltips();
ctx.sframeChan.on('EV_RT_CONNECT', function () { CommonRealtime.setConnectionState(true); });
ctx.sframeChan.on('EV_RT_DISCONNECT', function () { CommonRealtime.setConnectionState(false); });
ctx.sframeChan.on('Q_INCOMING_FRIEND_REQUEST', function (confirmMsg, cb) {
- Cryptpad.confirm(confirmMsg, cb, null, true);
+ UI.confirm(confirmMsg, cb, null, true);
});
ctx.sframeChan.on('EV_FRIEND_REQUEST', function (data) {
var i = pendingFriends.indexOf(data.netfluxId);
if (i !== -1) { pendingFriends.splice(i, 1); }
- Cryptpad.log(data.logText);
+ UI.log(data.logText);
});
ctx.sframeChan.ready();
diff --git a/www/common/toolbar.js b/www/common/toolbar.js
deleted file mode 100644
index 0735260a1..000000000
--- a/www/common/toolbar.js
+++ /dev/null
@@ -1,865 +0,0 @@
-define([
- 'jquery',
- '/customize/application_config.js',
- '/api/config'
-], function ($, Config, ApiConfig) {
-
- var urlArgs = ApiConfig.requireConf.urlArgs;
-
- var Messages = {};
-
- var Bar = {
- constants: {},
- };
-
- /** Id of the div containing the user list. */
- var USER_LIST_CLS = Bar.constants.userlist = 'cryptpad-user-list';
-
- /** Id of the div containing the lag info. */
- var LAG_ELEM_CLS = Bar.constants.lag = 'cryptpad-lag';
-
- var LIMIT_ELEM_CLS = Bar.constants.lag = 'cryptpad-limit';
-
- /** The toolbar class which contains the user list, debug link and lag. */
- var TOOLBAR_CLS = Bar.constants.toolbar = 'cryptpad-toolbar';
-
- var TOP_CLS = Bar.constants.top = 'cryptpad-toolbar-top';
- var LEFTSIDE_CLS = Bar.constants.leftside = 'cryptpad-toolbar-leftside';
- var RIGHTSIDE_CLS = Bar.constants.rightside = 'cryptpad-toolbar-rightside';
- var HISTORY_CLS = Bar.constants.history = 'cryptpad-toolbar-history';
-
- var SPINNER_CLS = Bar.constants.spinner = 'cryptpad-spinner';
-
- var STATE_CLS = Bar.constants.state = 'cryptpad-state';
-
- var USERNAME_CLS = Bar.constants.username = 'cryptpad-toolbar-username';
-
- var READONLY_CLS = Bar.constants.readonly = 'cryptpad-readonly';
-
- var USERBUTTONS_CONTAINER_CLS = Bar.constants.userButtonsContainer = "cryptpad-userbuttons-container";
- var USERLIST_CLS = Bar.constants.userlist = "cryptpad-dropdown-users";
- var EDITSHARE_CLS = Bar.constants.editShare = "cryptpad-dropdown-editShare";
- var VIEWSHARE_CLS = Bar.constants.viewShare = "cryptpad-dropdown-viewShare";
- var SHARE_CLS = Bar.constants.viewShare = "cryptpad-dropdown-share";
- var DROPDOWN_CONTAINER_CLS = Bar.constants.dropdownContainer = "cryptpad-dropdown-container";
- var DROPDOWN_CLS = Bar.constants.dropdown = "cryptpad-dropdown";
- var TITLE_CLS = Bar.constants.title = "cryptpad-title";
- var USER_CLS = Bar.constants.userAdmin = "cryptpad-user";
- var USERBUTTON_CLS = Bar.constants.changeUsername = "cryptpad-change-username";
-
- var SPINNER_DISAPPEAR_TIME = 3000;
-
- var uid = function () {
- return 'cryptpad-uid-' + String(Math.random()).substring(2);
- };
-
- var $style;
-
- var connected = false;
- var firstConnection = true;
- var lagErrors = 0;
-
- var styleToolbar = function ($container, href, version) {
- href = href || '/customize/toolbar.css' + (version?('?' + version): '');
-
- $.ajax({
- url: href,
- dataType: 'text',
- success: function (data) {
- $container.append($('