manual merge
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -5,8 +5,8 @@ define([
|
||||
var Cred = {};
|
||||
var Scrypt = window.scrypt;
|
||||
|
||||
Cred.MINIMUM_PASSWORD_LENGTH = typeof(AppConfig.minimum_password_length) === 'number'?
|
||||
AppConfig.minimum_password_length: 8;
|
||||
Cred.MINIMUM_PASSWORD_LENGTH = typeof(AppConfig.minimumPasswordLength) === 'number'?
|
||||
AppConfig.minimumPasswordLength: 8;
|
||||
|
||||
Cred.isLongEnoughPassword = function (passwd) {
|
||||
return passwd.length >= Cred.MINIMUM_PASSWORD_LENGTH;
|
||||
|
||||
@@ -499,11 +499,6 @@ define([
|
||||
if (cb) { cb(err, data); }
|
||||
});
|
||||
};
|
||||
/*common.setAttribute = function (attr, value, cb) {
|
||||
getStore().set(["cryptpad", attr].join('.'), value, function (err, data) {
|
||||
if (cb) { cb(err, data); }
|
||||
});
|
||||
};*/
|
||||
common.setLSAttribute = function (attr, value) {
|
||||
localStorage[attr] = value;
|
||||
};
|
||||
@@ -518,11 +513,6 @@ define([
|
||||
cb(err, data);
|
||||
});
|
||||
};
|
||||
/*common.getAttribute = function (attr, cb) {
|
||||
getStore().get(["cryptpad", attr].join('.'), function (err, data) {
|
||||
cb(err, data);
|
||||
});
|
||||
};*/
|
||||
|
||||
/* this returns a reference to your proxy. changing it will change your drive.
|
||||
*/
|
||||
@@ -1103,6 +1093,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 = $('<span>', {'class':'limit-container'});
|
||||
@@ -1738,7 +1729,7 @@ define([
|
||||
|
||||
var setActive = function ($el) {
|
||||
if ($el.length !== 1) { return; }
|
||||
$innerblock.find('.cp-dropdown-element-active').removeClass('cp-dropdown-element(active');
|
||||
$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()) {
|
||||
|
||||
@@ -88,7 +88,9 @@ define([
|
||||
// validate inputs
|
||||
if (!Cred.isValidUsername(uname)) { return void cb('INVAL_USER'); }
|
||||
if (!Cred.isValidPassword(passwd)) { return void cb('INVAL_PASS'); }
|
||||
if (!Cred.isLongEnoughPassword(passwd)) { return void cb('PASS_TOO_SHORT'); }
|
||||
if (isRegister && !Cred.isLongEnoughPassword(passwd)) {
|
||||
return void cb('PASS_TOO_SHORT');
|
||||
}
|
||||
|
||||
Cred.deriveFromPassphrase(uname, passwd, 128, function (bytes) {
|
||||
// results...
|
||||
|
||||
@@ -8,7 +8,7 @@ define([], function () {
|
||||
var version = userObject.version || 0;
|
||||
|
||||
// Migration 1: pad attributes moved to filesData
|
||||
var migrateAttributes = function () {
|
||||
var migratePadAttributesToData = function () {
|
||||
var files = userObject && userObject.drive;
|
||||
if (!files) { return; }
|
||||
|
||||
@@ -39,62 +39,43 @@ define([], function () {
|
||||
// Migration done
|
||||
};
|
||||
if (version < 1) {
|
||||
migrateAttributes();
|
||||
migratePadAttributesToData();
|
||||
Cryptpad.feedback('Migrate-1', true);
|
||||
userObject.version = version = 1;
|
||||
}
|
||||
|
||||
|
||||
// Migration 2: indentation settings for CodeMirror moved from root to 'settings'
|
||||
var migrateIndent = function () {
|
||||
var indentKey = 'cryptpad.indentUnit';
|
||||
var useTabsKey = 'cryptpad.indentWithTabs';
|
||||
userObject.settings = userObject.settings || {};
|
||||
if (userObject[indentKey]) {
|
||||
userObject.settings.indentUnit = userObject[indentKey];
|
||||
delete userObject[indentKey];
|
||||
}
|
||||
if (userObject[useTabsKey]) {
|
||||
userObject.settings.indentWithTabs = userObject[useTabsKey];
|
||||
delete userObject[useTabsKey];
|
||||
}
|
||||
};
|
||||
if (version < 2) {
|
||||
migrateIndent();
|
||||
Cryptpad.feedback('Migrate-2', true);
|
||||
userObject.version = version = 2;
|
||||
}
|
||||
|
||||
|
||||
// Migration 3: global attributes from root to 'settings' subobjects
|
||||
// Migration 2: global attributes from root to 'settings' subobjects
|
||||
var migrateAttributes = function () {
|
||||
var drawer = 'cryptpad.userlist-drawer';
|
||||
var polls = 'cryptpad.hide_poll_text';
|
||||
var indentKey = 'indentUnit';
|
||||
var useTabsKey = 'indentWithTabs';
|
||||
var indentKey = 'cryptpad.indentUnit';
|
||||
var useTabsKey = 'cryptpad.indentWithTabs';
|
||||
var settings = userObject.settings = userObject.settings || {};
|
||||
if (settings[indentKey] || settings[useTabsKey]) {
|
||||
if (typeof(userObject[indentKey]) !== "undefined") {
|
||||
settings.codemirror = settings.codemirror || {};
|
||||
settings.codemirror.indentUnit = settings[indentKey];
|
||||
settings.codemirror.indentWithTabs = settings[useTabsKey];
|
||||
delete settings[indentKey];
|
||||
delete settings[useTabsKey];
|
||||
settings.codemirror.indentUnit = userObject[indentKey];
|
||||
delete userObject[indentKey];
|
||||
}
|
||||
if (userObject[drawer]) {
|
||||
if (typeof(userObject[useTabsKey]) !== "undefined") {
|
||||
settings.codemirror = settings.codemirror || {};
|
||||
settings.codemirror.indentWithTabs = userObject[useTabsKey];
|
||||
delete userObject[useTabsKey];
|
||||
}
|
||||
if (typeof(userObject[drawer]) !== "undefined") {
|
||||
settings.toolbar = settings.toolbar || {};
|
||||
settings.toolbar['userlist-drawer'] = userObject[drawer];
|
||||
delete userObject[drawer];
|
||||
}
|
||||
if (userObject[polls]) {
|
||||
if (typeof(userObject[polls]) !== "undefined") {
|
||||
settings.poll = settings.poll || {};
|
||||
settings.poll['hide-text'] = userObject[polls];
|
||||
delete userObject[polls];
|
||||
}
|
||||
};
|
||||
if (version < 3) {
|
||||
if (version < 2) {
|
||||
migrateAttributes();
|
||||
Cryptpad.feedback('Migrate-3', true);
|
||||
userObject.version = version = 3;
|
||||
Cryptpad.feedback('Migrate-2', true);
|
||||
userObject.version = version = 2;
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
@@ -105,6 +105,21 @@ define([
|
||||
insideHandlers.push(content);
|
||||
}, true);
|
||||
|
||||
// Make sure both iframes are ready
|
||||
var readyHandlers = [];
|
||||
chan.onReady = function (h) {
|
||||
if (typeof(h) !== "function") { return; }
|
||||
readyHandlers.push(h);
|
||||
};
|
||||
chan.ready = function () {
|
||||
chan.whenReg('EV_RPC_READY', function () {
|
||||
chan.event('EV_RPC_READY');
|
||||
});
|
||||
chan.on('EV_RPC_READY', function () {
|
||||
readyHandlers.forEach(function (h) { h(); });
|
||||
});
|
||||
};
|
||||
|
||||
var txid;
|
||||
window.addEventListener('message', function (msg) {
|
||||
var data = JSON.parse(msg.data);
|
||||
|
||||
312
www/common/sframe-common-codemirror.js
Normal file
312
www/common/sframe-common-codemirror.js
Normal file
@@ -0,0 +1,312 @@
|
||||
define([
|
||||
'jquery',
|
||||
'/common/modes.js',
|
||||
'/common/themes.js',
|
||||
'/common/cryptpad-common.js',
|
||||
|
||||
'/bower_components/file-saver/FileSaver.min.js'
|
||||
], function ($, Modes, Themes, Cryptpad) {
|
||||
var saveAs = window.saveAs;
|
||||
var module = {};
|
||||
|
||||
module.create = function (Common, defaultMode, CMeditor) {
|
||||
var exp = {};
|
||||
var Messages = Cryptpad.Messages;
|
||||
|
||||
var CodeMirror = exp.CodeMirror = CMeditor;
|
||||
CodeMirror.modeURL = "cm/mode/%N/%N";
|
||||
|
||||
var $pad = $('#pad-iframe');
|
||||
var $textarea = exp.$textarea = $('#editor1');
|
||||
if (!$textarea.length) { $textarea = exp.$textarea = $pad.contents().find('#editor1'); }
|
||||
|
||||
var Title;
|
||||
var onLocal = function () {};
|
||||
var $rightside;
|
||||
var $drawer;
|
||||
exp.init = function (local, title, toolbar) {
|
||||
if (typeof local === "function") {
|
||||
onLocal = local;
|
||||
}
|
||||
Title = title;
|
||||
$rightside = toolbar.$rightside;
|
||||
$drawer = toolbar.$drawer;
|
||||
};
|
||||
|
||||
var editor = exp.editor = CMeditor.fromTextArea($textarea[0], {
|
||||
lineNumbers: true,
|
||||
lineWrapping: true,
|
||||
autoCloseBrackets: true,
|
||||
matchBrackets : true,
|
||||
showTrailingSpace : true,
|
||||
styleActiveLine : true,
|
||||
search: true,
|
||||
highlightSelectionMatches: {showToken: /\w+/},
|
||||
extraKeys: {"Shift-Ctrl-R": undefined},
|
||||
foldGutter: true,
|
||||
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
|
||||
mode: defaultMode || "javascript",
|
||||
readOnly: true
|
||||
});
|
||||
editor.setValue(Messages.codeInitialState);
|
||||
|
||||
var setMode = exp.setMode = function (mode, cb) {
|
||||
exp.highlightMode = mode;
|
||||
if (mode !== "text") {
|
||||
CMeditor.autoLoadMode(editor, mode);
|
||||
}
|
||||
editor.setOption('mode', mode);
|
||||
if (exp.$language) {
|
||||
var name = exp.$language.find('a[data-value="' + mode + '"]').text() || undefined;
|
||||
name = name ? Messages.languageButton + ' ('+name+')' : Messages.languageButton;
|
||||
exp.$language.setValue(mode, name);
|
||||
}
|
||||
if(cb) { cb(mode); }
|
||||
};
|
||||
|
||||
var setTheme = exp.setTheme = (function () {
|
||||
var path = '/common/theme/';
|
||||
|
||||
var $head = $(window.document.head);
|
||||
|
||||
var themeLoaded = exp.themeLoaded = function (theme) {
|
||||
return $head.find('link[href*="'+theme+'"]').length;
|
||||
};
|
||||
|
||||
var loadTheme = exp.loadTheme = function (theme) {
|
||||
$head.append($('<link />', {
|
||||
rel: 'stylesheet',
|
||||
href: path + theme + '.css',
|
||||
}));
|
||||
};
|
||||
|
||||
return function (theme, $select) {
|
||||
if (!theme) {
|
||||
editor.setOption('theme', 'default');
|
||||
} else {
|
||||
if (!themeLoaded(theme)) {
|
||||
loadTheme(theme);
|
||||
}
|
||||
editor.setOption('theme', theme);
|
||||
}
|
||||
if ($select) {
|
||||
var name = theme || undefined;
|
||||
name = name ? Messages.themeButton + ' ('+theme+')' : Messages.themeButton;
|
||||
$select.setValue(theme, name);
|
||||
}
|
||||
};
|
||||
}());
|
||||
|
||||
exp.getHeadingText = function () {
|
||||
var lines = editor.getValue().split(/\n/);
|
||||
|
||||
var text = '';
|
||||
lines.some(function (line) {
|
||||
// lines including a c-style comment are also valuable
|
||||
var clike = /^\s*(\/\*|\/\/)(.*)?(\*\/)*$/;
|
||||
if (clike.test(line)) {
|
||||
line.replace(clike, function (a, one, two) {
|
||||
if (!(two && two.replace)) { return; }
|
||||
text = two.replace(/\*\/\s*$/, '').trim();
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
// lisps?
|
||||
var lispy = /^\s*(;|#\|)+(.*?)$/;
|
||||
if (lispy.test(line)) {
|
||||
line.replace(lispy, function (a, one, two) {
|
||||
text = two;
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
// lines beginning with a hash are potentially valuable
|
||||
// works for markdown, python, bash, etc.
|
||||
var hash = /^#+(.*?)$/;
|
||||
if (hash.test(line)) {
|
||||
line.replace(hash, function (a, one) {
|
||||
text = one;
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO make one more pass for multiline comments
|
||||
});
|
||||
|
||||
return text.trim();
|
||||
};
|
||||
|
||||
exp.configureLanguage = function (cb, onModeChanged) {
|
||||
var options = [];
|
||||
Modes.list.forEach(function (l) {
|
||||
options.push({
|
||||
tag: 'a',
|
||||
attributes: {
|
||||
'data-value': l.mode,
|
||||
'href': '#',
|
||||
},
|
||||
content: l.language // Pretty name of the language value
|
||||
});
|
||||
});
|
||||
var dropdownConfig = {
|
||||
text: 'Mode', // Button initial text
|
||||
options: options, // Entries displayed in the menu
|
||||
left: true, // Open to the left of the button
|
||||
isSelect: true,
|
||||
feedback: 'CODE_LANGUAGE',
|
||||
};
|
||||
var $block = exp.$language = Cryptpad.createDropdown(dropdownConfig);
|
||||
$block.find('button').attr('title', Messages.languageButtonTitle);
|
||||
$block.find('a').click(function () {
|
||||
setMode($(this).attr('data-value'), onModeChanged);
|
||||
onLocal();
|
||||
});
|
||||
|
||||
if ($drawer) { $drawer.append($block); }
|
||||
if (cb) { cb(); }
|
||||
};
|
||||
|
||||
exp.configureTheme = function (cb) {
|
||||
/* Remember the user's last choice of theme using localStorage */
|
||||
var themeKey = ['codemirror', 'theme'];
|
||||
|
||||
var todo = function (err, lastTheme) {
|
||||
lastTheme = lastTheme || 'default';
|
||||
var options = [];
|
||||
Themes.forEach(function (l) {
|
||||
options.push({
|
||||
tag: 'a',
|
||||
attributes: {
|
||||
'data-value': l.name,
|
||||
'href': '#',
|
||||
},
|
||||
content: l.name // Pretty name of the language value
|
||||
});
|
||||
});
|
||||
var dropdownConfig = {
|
||||
text: 'Theme', // Button initial text
|
||||
options: options, // Entries displayed in the menu
|
||||
left: true, // Open to the left of the button
|
||||
isSelect: true,
|
||||
initialValue: lastTheme,
|
||||
feedback: 'CODE_THEME',
|
||||
};
|
||||
var $block = exp.$theme = Cryptpad.createDropdown(dropdownConfig);
|
||||
$block.find('button').attr('title', Messages.themeButtonTitle);
|
||||
|
||||
setTheme(lastTheme, $block);
|
||||
|
||||
$block.find('a').click(function () {
|
||||
var theme = $(this).attr('data-value');
|
||||
setTheme(theme, $block);
|
||||
Common.setAttribute(themeKey, theme);
|
||||
});
|
||||
|
||||
if ($drawer) { $drawer.append($block); }
|
||||
if (cb) { cb(); }
|
||||
};
|
||||
Common.getAttribute(themeKey, todo);
|
||||
};
|
||||
|
||||
exp.exportText = function () {
|
||||
var text = editor.getValue();
|
||||
|
||||
var ext = Modes.extensionOf(exp.highlightMode);
|
||||
|
||||
var title = Cryptpad.fixFileName(Title ? Title.suggestTitle('cryptpad') : "?") + (ext || '.txt');
|
||||
|
||||
Cryptpad.prompt(Messages.exportPrompt, title, function (filename) {
|
||||
if (filename === null) { return; }
|
||||
var blob = new Blob([text], {
|
||||
type: 'text/plain;charset=utf-8'
|
||||
});
|
||||
saveAs(blob, filename);
|
||||
});
|
||||
};
|
||||
exp.importText = function (content, file) {
|
||||
var $bar = $('#cme_toolbox');
|
||||
var mode;
|
||||
var mime = CodeMirror.findModeByMIME(file.type);
|
||||
|
||||
if (!mime) {
|
||||
var ext = /.+\.([^.]+)$/.exec(file.name);
|
||||
if (ext[1]) {
|
||||
mode = CMeditor.findModeByExtension(ext[1]);
|
||||
mode = mode && mode.mode || null;
|
||||
}
|
||||
} else {
|
||||
mode = mime && mime.mode || null;
|
||||
}
|
||||
|
||||
if (mode && Modes.list.some(function (o) { return o.mode === mode; })) {
|
||||
setMode(mode);
|
||||
$bar.find('#language-mode').val(mode);
|
||||
} else {
|
||||
console.log("Couldn't find a suitable highlighting mode: %s", mode);
|
||||
setMode('text');
|
||||
$bar.find('#language-mode').val('text');
|
||||
}
|
||||
|
||||
editor.setValue(content);
|
||||
onLocal();
|
||||
};
|
||||
|
||||
var cursorToPos = function(cursor, oldText) {
|
||||
var cLine = cursor.line;
|
||||
var cCh = cursor.ch;
|
||||
var pos = 0;
|
||||
var textLines = oldText.split("\n");
|
||||
for (var line = 0; line <= cLine; line++) {
|
||||
if(line < cLine) {
|
||||
pos += textLines[line].length+1;
|
||||
}
|
||||
else if(line === cLine) {
|
||||
pos += cCh;
|
||||
}
|
||||
}
|
||||
return pos;
|
||||
};
|
||||
|
||||
var posToCursor = function(position, newText) {
|
||||
var cursor = {
|
||||
line: 0,
|
||||
ch: 0
|
||||
};
|
||||
var textLines = newText.substr(0, position).split("\n");
|
||||
cursor.line = textLines.length - 1;
|
||||
cursor.ch = textLines[cursor.line].length;
|
||||
return cursor;
|
||||
};
|
||||
|
||||
exp.setValueAndCursor = function (oldDoc, remoteDoc, TextPatcher) {
|
||||
var scroll = editor.getScrollInfo();
|
||||
//get old cursor here
|
||||
var oldCursor = {};
|
||||
oldCursor.selectionStart = cursorToPos(editor.getCursor('from'), oldDoc);
|
||||
oldCursor.selectionEnd = cursorToPos(editor.getCursor('to'), oldDoc);
|
||||
|
||||
editor.setValue(remoteDoc);
|
||||
editor.save();
|
||||
|
||||
var op = TextPatcher.diff(oldDoc, remoteDoc);
|
||||
var selects = ['selectionStart', 'selectionEnd'].map(function (attr) {
|
||||
return TextPatcher.transformCursor(oldCursor[attr], op);
|
||||
});
|
||||
|
||||
if(selects[0] === selects[1]) {
|
||||
editor.setCursor(posToCursor(selects[0], remoteDoc));
|
||||
}
|
||||
else {
|
||||
editor.setSelection(posToCursor(selects[0], remoteDoc), posToCursor(selects[1], remoteDoc));
|
||||
}
|
||||
|
||||
editor.scrollTo(scroll.left, scroll.top);
|
||||
};
|
||||
|
||||
return exp;
|
||||
};
|
||||
|
||||
return module;
|
||||
});
|
||||
|
||||
@@ -26,6 +26,7 @@ define([
|
||||
var AppConfig = common.getAppConfig();
|
||||
var button;
|
||||
var size = "17px";
|
||||
var sframeChan = common.getSframeChannel();
|
||||
switch (type) {
|
||||
case 'export':
|
||||
button = $('<button>', {
|
||||
@@ -110,7 +111,7 @@ define([
|
||||
console.error("Parse error while setting the title", e);
|
||||
}
|
||||
}
|
||||
ctx.sframeChan.query('Q_SAVE_AS_TEMPLATE', {
|
||||
sframeChan.query('Q_SAVE_AS_TEMPLATE', {
|
||||
title: title,
|
||||
toSave: toSave
|
||||
}, function () {
|
||||
@@ -136,12 +137,12 @@ define([
|
||||
button
|
||||
.click(common.prepareFeedback(type))
|
||||
.click(function() {
|
||||
var msg = isLoggedIn() ? Messages.forgetPrompt : Messages.fm_removePermanentlyDialog;
|
||||
var msg = common.isLoggedIn() ? Messages.forgetPrompt : Messages.fm_removePermanentlyDialog;
|
||||
Cryptpad.confirm(msg, function (yes) {
|
||||
if (!yes) { return; }
|
||||
ctx.sframeChan.query('Q_MOVE_TO_TRASH', null, function (err) {
|
||||
sframeChan.query('Q_MOVE_TO_TRASH', null, function (err) {
|
||||
if (err) { return void callback(err); }
|
||||
var cMsg = isLoggedIn() ? Messages.movedToTrash : Messages.deleted;
|
||||
var cMsg = common.isLoggedIn() ? Messages.movedToTrash : Messages.deleted;
|
||||
Cryptpad.alert(cMsg, undefined, true);
|
||||
callback();
|
||||
return;
|
||||
@@ -151,6 +152,13 @@ define([
|
||||
});
|
||||
}
|
||||
break;
|
||||
case 'present':
|
||||
button = $('<button>', {
|
||||
title: Messages.presentButtonTitle,
|
||||
'class': "fa fa-play-circle cp-app-slide-present-button", // used in slide.js
|
||||
style: 'font:'+size+' FontAwesome'
|
||||
});
|
||||
break;
|
||||
case 'history':
|
||||
if (!AppConfig.enableHistory) {
|
||||
button = $('<span>');
|
||||
@@ -374,10 +382,19 @@ define([
|
||||
var $displayName = $userAdmin.find('.'+displayNameCls);
|
||||
|
||||
var $avatar = $userAdmin.find('.cp-dropdown-button-title');
|
||||
var loadingAvatar;
|
||||
var to;
|
||||
var oldUrl = '';
|
||||
var updateButton = function () {
|
||||
var myData = metadataMgr.getUserData();
|
||||
if (!myData) { return; }
|
||||
if (loadingAvatar) {
|
||||
// Try again in 200ms
|
||||
window.clearTimeout(to);
|
||||
to = window.setTimeout(updateButton, 200);
|
||||
return;
|
||||
}
|
||||
loadingAvatar = true;
|
||||
var newName = myData.name;
|
||||
var url = myData.avatar;
|
||||
$displayName.text(newName || Messages.anonymous);
|
||||
@@ -388,8 +405,11 @@ define([
|
||||
if ($img) {
|
||||
$userAdmin.find('button').addClass('cp-avatar');
|
||||
}
|
||||
loadingAvatar = false;
|
||||
});
|
||||
return;
|
||||
}
|
||||
loadingAvatar = false;
|
||||
};
|
||||
metadataMgr.onChange(updateButton);
|
||||
updateButton();
|
||||
@@ -442,27 +462,37 @@ define([
|
||||
UI.openTemplatePicker = function (common) {
|
||||
var metadataMgr = common.getMetadataMgr();
|
||||
var type = metadataMgr.getMetadataLazy().type;
|
||||
var first = true; // We can only pick a template once (for a new document)
|
||||
var fileDialogCfg = {
|
||||
onSelect: function (data) {
|
||||
if (data.type === type && first) {
|
||||
Cryptpad.addLoadingScreen({hideTips: true});
|
||||
var sframeChan = common.getSframeChannel();
|
||||
sframeChan.query('Q_TEMPLATE_USE', data.href, function () {
|
||||
first = false;
|
||||
Cryptpad.removeLoadingScreen();
|
||||
common.feedback('TEMPLATE_USED');
|
||||
});
|
||||
return;
|
||||
var sframeChan = common.getSframeChannel();
|
||||
|
||||
var onConfirm = function (yes) {
|
||||
if (!yes) { return; }
|
||||
var first = true; // We can only pick a template once (for a new document)
|
||||
var fileDialogCfg = {
|
||||
onSelect: function (data) {
|
||||
if (data.type === type && first) {
|
||||
Cryptpad.addLoadingScreen({hideTips: true});
|
||||
sframeChan.query('Q_TEMPLATE_USE', data.href, function () {
|
||||
first = false;
|
||||
Cryptpad.removeLoadingScreen();
|
||||
common.feedback('TEMPLATE_USED');
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
common.initFilePicker(fileDialogCfg);
|
||||
var pickerCfg = {
|
||||
types: [type],
|
||||
where: ['template']
|
||||
};
|
||||
common.openFilePicker(pickerCfg);
|
||||
};
|
||||
|
||||
sframeChan.query("Q_TEMPLATE_EXIST", type, function (err, data) {
|
||||
if (data) {
|
||||
Cryptpad.confirm(Messages.useTemplate, onConfirm);
|
||||
}
|
||||
};
|
||||
common.initFilePicker(common, fileDialogCfg);
|
||||
var pickerCfg = {
|
||||
types: [type],
|
||||
where: ['template']
|
||||
};
|
||||
common.openFilePicker(common, pickerCfg);
|
||||
});
|
||||
};
|
||||
|
||||
return UI;
|
||||
|
||||
@@ -107,12 +107,28 @@ define([
|
||||
});
|
||||
});
|
||||
|
||||
var currentTitle;
|
||||
var currentTabTitle;
|
||||
var setDocumentTitle = function () {
|
||||
if (!currentTabTitle) {
|
||||
document.title = currentTitle || 'CryptPad';
|
||||
return;
|
||||
}
|
||||
var title = currentTabTitle.replace(/\{title\}/g, currentTitle || 'CryptPad');
|
||||
document.title = title;
|
||||
};
|
||||
sframeChan.on('Q_SET_PAD_TITLE_IN_DRIVE', function (newTitle, cb) {
|
||||
document.title = newTitle;
|
||||
currentTitle = newTitle;
|
||||
setDocumentTitle();
|
||||
Cryptpad.renamePad(newTitle, undefined, function (err) {
|
||||
if (err) { cb('ERROR'); } else { cb(); }
|
||||
});
|
||||
});
|
||||
sframeChan.on('EV_SET_TAB_TITLE', function (newTabTitle) {
|
||||
currentTabTitle = newTabTitle;
|
||||
setDocumentTitle();
|
||||
});
|
||||
|
||||
|
||||
sframeChan.on('Q_SETTINGS_SET_DISPLAY_NAME', function (newName, cb) {
|
||||
Cryptpad.setDisplayName(newName, function (err) {
|
||||
@@ -234,7 +250,21 @@ define([
|
||||
});
|
||||
});
|
||||
|
||||
// Present mode URL
|
||||
sframeChan.on('Q_PRESENT_URL_GET_VALUE', function (data, cb) {
|
||||
var parsed = Cryptpad.parsePadUrl(window.location.href);
|
||||
cb(parsed.hashData && parsed.hashData.present);
|
||||
});
|
||||
sframeChan.on('EV_PRESENT_URL_SET_VALUE', function (data) {
|
||||
var parsed = Cryptpad.parsePadUrl(window.location.href);
|
||||
window.location.href = parsed.getUrl({
|
||||
embed: parsed.hashData.embed,
|
||||
present: data
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
// File upload
|
||||
var onFileUpload = function (sframeChan, data, cb) {
|
||||
var sendEvent = function (data) {
|
||||
sframeChan.event("EV_FILE_UPLOAD_STATE", data);
|
||||
@@ -270,6 +300,7 @@ define([
|
||||
onFileUpload(sframeChan, data, cb);
|
||||
});
|
||||
|
||||
// File picker
|
||||
var FP = {};
|
||||
var initFilePicker = function (types) {
|
||||
var config = {};
|
||||
@@ -297,6 +328,10 @@ define([
|
||||
sframeChan.on('Q_TEMPLATE_USE', function (href, cb) {
|
||||
Cryptpad.useTemplate(href, Cryptget, cb);
|
||||
});
|
||||
sframeChan.on('Q_TEMPLATE_EXIST', function (type, cb) {
|
||||
var hasTemplate = Cryptpad.listTemplates(type).length > 0;
|
||||
cb(hasTemplate);
|
||||
});
|
||||
|
||||
sframeChan.on('EV_GOTO_URL', function (url) {
|
||||
if (url) {
|
||||
@@ -306,6 +341,8 @@ define([
|
||||
}
|
||||
});
|
||||
|
||||
sframeChan.ready();
|
||||
|
||||
CpNfOuter.start({
|
||||
sframeChan: sframeChan,
|
||||
channel: secret.channel,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
define(['jquery'], function ($) {
|
||||
var module = {};
|
||||
|
||||
module.create = function (Common, cfg, onLocal) {
|
||||
module.create = function (Common, cfg) {
|
||||
var exp = {};
|
||||
var metadataMgr = Common.getMetadataMgr();
|
||||
var sframeChan = Common.getSframeChannel();
|
||||
@@ -32,7 +32,6 @@ define(['jquery'], function ($) {
|
||||
}
|
||||
};
|
||||
|
||||
// update title: href is optional; if not specified, we use window.location.href
|
||||
exp.updateTitle = function (newTitle, cb) {
|
||||
cb = cb || $.noop;
|
||||
if (newTitle === exp.title) { return; }
|
||||
|
||||
@@ -8,14 +8,30 @@ define([
|
||||
'/common/sframe-common-interface.js',
|
||||
'/common/sframe-common-history.js',
|
||||
'/common/sframe-common-file.js',
|
||||
'/common/sframe-common-codemirror.js',
|
||||
'/common/metadata-manager.js',
|
||||
|
||||
'/customize/application_config.js',
|
||||
'/common/cryptpad-common.js',
|
||||
'/common/common-realtime.js',
|
||||
'/common/common-util.js'
|
||||
], function ($, nThen, Messages, CpNfInner, SFrameChannel, Title, UI, History, File, MetadataMgr,
|
||||
AppConfig, Cryptpad, CommonRealtime, Util) {
|
||||
], function (
|
||||
$,
|
||||
nThen,
|
||||
Messages,
|
||||
CpNfInner,
|
||||
SFrameChannel,
|
||||
Title,
|
||||
UI,
|
||||
History,
|
||||
File,
|
||||
CodeMirror,
|
||||
MetadataMgr,
|
||||
AppConfig,
|
||||
Cryptpad,
|
||||
CommonRealtime,
|
||||
Util
|
||||
) {
|
||||
|
||||
// Chainpad Netflux Inner
|
||||
var funcs = {};
|
||||
@@ -40,7 +56,7 @@ define([
|
||||
funcs.getSframeChannel = function () { return ctx.sframeChan; };
|
||||
funcs.getAppConfig = function () { return AppConfig; };
|
||||
|
||||
var isLoggedIn = funcs.isLoggedIn = function () {
|
||||
funcs.isLoggedIn = function () {
|
||||
if (!ctx.cpNfInner) { throw new Error("cpNfInner is not ready!"); }
|
||||
return ctx.cpNfInner.metadataMgr.getPrivateData().accountName;
|
||||
};
|
||||
@@ -73,12 +89,8 @@ define([
|
||||
funcs.uploadFile = callWithCommon(File.uploadFile);
|
||||
funcs.createFileManager = callWithCommon(File.create);
|
||||
|
||||
// Misc
|
||||
|
||||
funcs.setDisplayName = function (name, cb) {
|
||||
cb = cb || $.noop;
|
||||
ctx.sframeChan.query('Q_SETTINGS_SET_DISPLAY_NAME', name, cb);
|
||||
};
|
||||
// CodeMirror
|
||||
funcs.initCodeMirrorApp = callWithCommon(CodeMirror.create);
|
||||
|
||||
// Window
|
||||
funcs.logout = function (cb) {
|
||||
@@ -89,12 +101,22 @@ define([
|
||||
funcs.notify = function () {
|
||||
ctx.sframeChan.event('EV_NOTIFY');
|
||||
};
|
||||
funcs.setTabTitle = function (newTitle) {
|
||||
ctx.sframeChan.event('EV_SET_TAB_TITLE', newTitle);
|
||||
};
|
||||
|
||||
funcs.setLoginRedirect = function (cb) {
|
||||
cb = cb || $.noop;
|
||||
ctx.sframeChan.query('Q_SET_LOGIN_REDIRECT', null, cb);
|
||||
};
|
||||
|
||||
funcs.isPresentUrl = function (cb) {
|
||||
ctx.sframeChan.query('Q_PRESENT_URL_GET_VALUE', null, cb);
|
||||
};
|
||||
funcs.setPresentUrl = function (value) {
|
||||
ctx.sframeChan.event('EV_PRESENT_URL_SET_VALUE', value);
|
||||
};
|
||||
|
||||
// Store
|
||||
funcs.sendAnonRpcMsg = function (msg, content, cb) {
|
||||
ctx.sframeChan.query('Q_ANON_RPC_MESSAGE', {
|
||||
@@ -152,6 +174,11 @@ define([
|
||||
return !data.readOnly || !data.availableHashes.editHash;
|
||||
};
|
||||
|
||||
funcs.setDisplayName = function (name, cb) {
|
||||
cb = cb || $.noop;
|
||||
ctx.sframeChan.query('Q_SETTINGS_SET_DISPLAY_NAME', name, cb);
|
||||
};
|
||||
|
||||
// Friends
|
||||
var pendingFriends = [];
|
||||
funcs.getPendingFriends = function () {
|
||||
@@ -226,6 +253,7 @@ define([
|
||||
Cryptpad.log(data.logText);
|
||||
});
|
||||
|
||||
ctx.sframeChan.ready();
|
||||
cb(funcs);
|
||||
});
|
||||
} };
|
||||
|
||||
@@ -17,6 +17,9 @@ define({
|
||||
// When either the outside or inside registers a query handler, this is sent.
|
||||
'EV_REGISTER_HANDLER': true,
|
||||
|
||||
// When an iframe is ready to receive messages
|
||||
'EV_RPC_READY': true,
|
||||
|
||||
// Realtime events called from the outside.
|
||||
// When someone joins the pad, argument is a string with their netflux id.
|
||||
'EV_RT_JOIN': true,
|
||||
@@ -40,7 +43,13 @@ define({
|
||||
// This changes the pad title in drive ONLY, the pad title needs to be changed inside of the
|
||||
// iframe and synchronized with the other users. This will not trigger a EV_METADATA_UPDATE
|
||||
// because the metadata contained in EV_METADATA_UPDATE does not contain the pad title.
|
||||
// It also sets the page (tab) title to the selected title, unles it is overridden by
|
||||
// the EV_SET_TAB_TITLE event.
|
||||
'Q_SET_PAD_TITLE_IN_DRIVE': true,
|
||||
// Set the page title (tab title) to the selected value which will override the pad title.
|
||||
// The new title value can contain {title}, which will be replaced by the pad title when it
|
||||
// is set or modified.
|
||||
'EV_SET_TAB_TITLE': true,
|
||||
|
||||
// Update the user's display-name which will be shown to contacts and people in the same pads.
|
||||
'Q_SETTINGS_SET_DISPLAY_NAME': true,
|
||||
@@ -104,12 +113,20 @@ define({
|
||||
|
||||
// Template picked, replace the content of the pad
|
||||
'Q_TEMPLATE_USE': true,
|
||||
// Check if we have template(s) for the selected pad type
|
||||
'Q_TEMPLATE_EXIST': true,
|
||||
|
||||
// File upload queries and events
|
||||
'Q_UPLOAD_FILE': true,
|
||||
'EV_FILE_UPLOAD_STATE': true,
|
||||
'Q_CANCEL_PENDING_FILE_UPLOAD': true,
|
||||
|
||||
<<<<<<< HEAD
|
||||
// Make the browser window navigate to a given URL, if no URL is passed then it will reload.
|
||||
'EV_GOTO_URL': true,
|
||||
=======
|
||||
// Present mode URL
|
||||
'Q_PRESENT_URL_GET_VALUE': true,
|
||||
'EV_PRESENT_URL_SET_VALUE': true,
|
||||
>>>>>>> 9271b0c1a860abaf765e9fe6e9948eff4487dc52
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user