Merge branch 'staging' into framework

This commit is contained in:
Caleb James DeLisle
2017-10-12 17:07:10 +03:00
21 changed files with 391 additions and 260 deletions

View File

@@ -76,6 +76,7 @@ define([
common.renamePad(title || "", href, function (err) {
if (err) { return void console.error(err); }
onComplete(href);
common.setPadAttribute('fileType', metadata.type, null, href);
});
});
};

View File

@@ -179,9 +179,11 @@ define([
var tagger = dialog.frame([
dialog.message([
Messages.tags_add,
h('p', Messages.tags_searchHint)
h('br'),
Messages.tags_searchHint,
]),
input,
h('center', h('small', Messages.tags_notShared)),
dialog.nav(),
]);

View File

@@ -489,8 +489,8 @@ define([
};
// STORAGE
common.setPadAttribute = function (attr, value, cb) {
var href = getRelativeHref(window.location.href);
common.setPadAttribute = function (attr, value, cb, href) {
href = getRelativeHref(href || window.location.href);
getStore().setPadAttribute(href, attr, value, cb);
};
common.setDisplayName = function (value, cb) {
@@ -1204,8 +1204,8 @@ define([
};
// Forget button
var moveToTrash = common.moveToTrash = function (cb) {
var href = window.location.href;
var moveToTrash = common.moveToTrash = function (cb, href) {
href = href || window.location.href;
common.forgetPad(href, function (err) {
if (err) {
console.log("unable to forget pad");

View File

@@ -62,6 +62,46 @@ define([
editor.scrollTo(scroll.left, scroll.top);
};
module.getHeadingText = function (editor) {
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();
};
module.create = function (Common, defaultMode, CMeditor) {
var exp = {};
var Messages = Cryptpad.Messages;
@@ -152,43 +192,7 @@ define([
}());
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();
return module.getHeadingText(editor);
};
exp.configureLanguage = function (cb, onModeChanged) {

View File

@@ -1,8 +1,9 @@
define([
'jquery',
'/file/file-crypto.js',
'/common/common-thumbnail.js',
'/bower_components/tweetnacl/nacl-fast.min.js',
], function ($, FileCrypto) {
], function ($, FileCrypto, Thumb) {
var Nacl = window.nacl;
var module = {};
@@ -220,30 +221,46 @@ define([
var handleFile = File.handleFile = function (file, e, thumbnail) {
var thumb;
var finish = function (arrayBuffer) {
var file_arraybuffer;
var finish = function () {
var metadata = {
name: file.name,
type: file.type,
};
if (thumb) { metadata.thumbnail = thumb; }
queue.push({
blob: arrayBuffer,
blob: file_arraybuffer,
metadata: metadata,
dropEvent: e
});
};
var processFile = function () {
blobToArrayBuffer(file, function (e, buffer) {
finish(buffer);
});
};
if (!thumbnail) { return void processFile(); }
blobToArrayBuffer(thumbnail, function (e, buffer) {
blobToArrayBuffer(file, function (e, buffer) {
if (e) { console.error(e); }
thumb = arrayBufferToString(buffer);
processFile();
file_arraybuffer = buffer;
if (thumbnail) { // there is already a thumbnail
return blobToArrayBuffer(thumbnail, function (e, buffer) {
if (e) { console.error(e); }
thumb = arrayBufferToString(buffer);
finish();
});
}
if (!Thumb.isSupportedType(file.type)) { return finish(); }
// make a resized thumbnail from the image..
Thumb.fromImageBlob(file, function (e, thumb_blob) {
if (e) { console.error(e); }
if (!thumb_blob) { return finish(); }
blobToArrayBuffer(thumb_blob, function (e, buffer) {
if (e) {
console.error(e);
return finish();
}
thumb = arrayBufferToString(buffer);
finish();
});
});
});
};

View File

@@ -150,9 +150,6 @@ define([
'class': "fa fa-trash cryptpad-forget",
style: 'font:'+size+' FontAwesome'
});
if (!common.isStrongestStored()) {
button.addClass('cp-toolbar-hidden');
}
if (callback) {
button
.click(common.prepareFeedback(type))
@@ -216,7 +213,7 @@ define([
title: Messages.tags_title,
})
.click(common.prepareFeedback(type))
.click(function () { UI.updateTags(null); });
.click(function () { UI.updateTags(common, null); });
break;
default:
button = $('<button>', {

View File

@@ -216,6 +216,12 @@ define([
});
sframeChan.on('Q_MOVE_TO_TRASH', function (data, cb) {
cb = cb || $.noop;
if (readOnly && hashes.editHash) {
var appPath = window.location.pathname;
Cryptpad.moveToTrash(cb, appPath + '#' + hashes.editHash);
return;
}
Cryptpad.moveToTrash(cb);
});
@@ -262,7 +268,7 @@ define([
msg = parsed[1][4];
if (msg) {
msg = msg.replace(/^cp\|/, '');
var decryptedMsg = crypto.decrypt(msg, secret.keys.validateKey);
var decryptedMsg = crypto.decrypt(msg, true);
msgs.push(decryptedMsg);
}
};

View File

@@ -657,9 +657,10 @@ define([
// We need to override the "a" tag action here because it is inside the iframe!
var inDrive = /^\/drive/;
var origin = config.metadataMgr.getPrivateData().origin;
var href = inDrive.test(origin) ? origin+'/index.html' : origin+'/drive/';
var privateData = config.metadataMgr.getPrivateData();
var origin = privateData.origin;
var pathname = privateData.pathname;
var href = inDrive.test(pathname) ? origin+'/index.html' : origin+'/drive/';
var buttonTitle = inDrive ? Messages.header_homeTitle : Messages.header_logoTitle;
var $aTag = $('<a>', {

View File

@@ -6,6 +6,7 @@
<style>
.loading-hidden { display: none; }
#editor1 { display: none; }
.cp-app-drive-context { display: none; }
</style>
</head>
<body class="cp-app-drive">

View File

@@ -77,7 +77,7 @@ define([
sfCommon: common,
};
if (uploadMode) {
displayed.push('pageTitle'); //TODO in toolbar
displayed.push('pageTitle');
configTb.pageTitle = Messages.upload_title;
}
var toolbar = APP.toolbar = Toolbar.create(configTb);

View File

@@ -28,7 +28,7 @@
@poll-uncommitted-bg: #ddd; //lighten(@poll-th-bg, 50%);
@poll-uncommitted-text: black;
@poll-placeholder: #666;
@poll-placeholder: #fff;
@poll-border-color: #555;
@poll-cover-color: #000;
@poll-fg: #000;
@@ -63,10 +63,6 @@ overflow-x: hidden;
}
}
.cp-app-poll-table-text-cell input[type="text"] {
width: 400px;
}
input[type="text"], textarea {
background-color: white;
color: black;
@@ -81,12 +77,13 @@ input[type="text"][disabled], textarea[disabled] {
// The placeholder color only seems to effect Safari when not set
input[type="text"][disabled]::placeholder {
//color: @poll-placeholder;
color: @poll-placeholder;
opacity: 1;
}
table#cp-app-poll-table {
margin: 0px;
overflow: hidden;
}
#cp-app-poll-table-container {
position: relative;
@@ -106,6 +103,7 @@ table#cp-app-poll-table {
overflow: hidden;
}
#cp-app-poll-create-option {
order: 3;
display: inline-flex;
width: 50px;
height: 24px;
@@ -125,6 +123,7 @@ table#cp-app-poll-table {
min-width: 80%;
width: 80%;
min-height: 200px;
height: 200px;
border: 1px solid black;
.CodeMirror-placeholder {
color: #777;
@@ -149,17 +148,25 @@ table#cp-app-poll-table {
max-height: 20em;
}
}
.cp-app-poll-published {
#cp-app-poll-description {
display: none;
&~ .CodeMirror {
div.cp-app-poll-published {
div.cp-app-poll-realtime {
#cp-app-poll-description {
display: none;
&~ .CodeMirror {
display: none;
}
}
#cp-app-poll-description-published {
display: block;
&:empty {
display: none;
}
}
#cp-app-poll-nocomments {
display: none;
}
}
#cp-app-poll-description-published {
display: block;
&:empty {
display: none;
#cp-app-poll-comments {
display: block;
}
}
}
@@ -218,6 +225,15 @@ div.cp-app-poll-realtime {
padding: 0px;
margin: 0px;
.cp-app-poll-table-scrolled {
tr td:last-child {
right: 0;
}
tr td:nth-last-child(2) {
right: 100px;
}
}
table {
border-collapse: collapse;
width: ~"calc(100% - 1px)";
@@ -231,10 +247,6 @@ div.cp-app-poll-realtime {
div.cp-app-poll-table-text-cell {
background-color: @poll-uncommitted-bg !important;
color: @poll-uncommitted-text !important;
input {
width: ~"calc(100% - 80px)" !important;
vertical-align: middle;
}
}
text-align: center;
background-color: @poll-uncommitted-bg !important;
@@ -272,14 +284,22 @@ div.cp-app-poll-realtime {
margin: 0px;
div.cp-app-poll-table-text-cell {
height: 28px;
padding: 0px;
margin: 0px;
height: 100%;
display: flex;
align-items: center;
.cp-app-poll-table-remove {
order: 1;
}
.cp-app-poll-table-edit {
order: 3;
}
input {
width: 80%;
width: 90%;
height: 100%;
min-width: 0;
order: 2;
flex: 1;
height: 24px;
border: 0px;
margin: 2px;
&[disabled] {
@@ -375,6 +395,9 @@ div.cp-app-poll-realtime {
}
thead {
height: 52px;
tr {
height: 52px;
}
td {
padding: 0px 5px;
background: @poll-th-bg;
@@ -382,6 +405,11 @@ div.cp-app-poll-realtime {
&:not(:last-child) {
border-right: 1px solid rgba(255,255,255,0.2);
}
&:last-child {
height: 52px;
line-height: 52px;
text-align: center;
}
&:nth-last-child(2) {
border-right: 1px solid @poll-border-color;
}
@@ -490,11 +518,18 @@ div.cp-app-poll-realtime {
display: none;
}
}
#cp-app-poll-nocomments {
color: #999;
text-align: center;
margin: 20px;
font: @colortheme_app-font;
}
#cp-app-poll-comments {
width: 50%;
margin: 20px auto;
min-width: 400px;
padding-bottom: 5px;
display: none;
button {
border-radius: 0;
}

View File

@@ -46,9 +46,7 @@ define([
var Messages = Cryptpad.Messages;
var saveAs = window.saveAs;
var Render = Renderer(Cryptpad);
var APP = window.APP = {
Render: Render,
unlocked: {
row: [],
col: []
@@ -57,6 +55,7 @@ define([
Cryptpad: Cryptpad,
mobile: function () { return $('body').width() <= 600; } // Menu and content area are not inline-block anymore for mobiles
};
var Render = Renderer(Cryptpad, APP);
var debug = $.noop; //console.log;
@@ -221,11 +220,12 @@ define([
return newObj;
};
var enableColumn = function (id) {
var $input = $('input[disabled="disabled"][data-rt-id^="' + id + '"]')
var enableColumn = APP.enableColumn = function (id, table) {
table = table || $('body');
var $input = $(table).find('input[disabled="disabled"][data-rt-id^="' + id + '"]')
.removeAttr('disabled');
$input.closest('td').addClass('cp-app-poll-table-editing');
$('.cp-app-poll-table-lock[data-rt-id="' + id + '"]').addClass('fa-unlock')
$(table).find('.cp-app-poll-table-lock[data-rt-id="' + id + '"]').addClass('fa-unlock')
.removeClass('fa-lock').attr('title', Messages.poll_unlocked);
};
var disableColumn = function (id) {
@@ -235,10 +235,13 @@ define([
$('.cp-app-poll-table-lock[data-rt-id="' + id + '"]').addClass('fa-lock')
.removeClass('fa-unlock').attr('title', Messages.poll_locked);
};
var enableRow = function (id) {
var $input = $('input[type="text"][disabled="disabled"][data-rt-id="' + id + '"]').removeAttr('disabled');
var enableRow = APP.enableRow = function (id, table) {
table = table || $('body');
var $input = $(table).find('input[disabled="disabled"][data-rt-id="' + id + '"]')
.removeAttr('disabled');
$input.closest('td').addClass('cp-app-poll-table-editing');
$('span.cp-app-poll-table-edit[data-rt-id="' + id + '"]').css('visibility', 'hidden');
$(table).find('span.cp-app-poll-table-edit[data-rt-id="' + id + '"]')
.css('visibility', 'hidden');
};
var disableRow = function (id) {
var $input = $('input[type="text"][data-rt-id="' + id + '"]')
@@ -247,77 +250,11 @@ define([
$('span.cp-app-poll-table-edit[data-rt-id="' + id + '"]').css('visibility', 'visible');
};
var styleUserColumn = function () {
var userid = APP.userid;
if (!userid) { return; }
// Enable input for the userid column
enableColumn(userid);
$('input[disabled="disabled"][data-rt-id^="' + userid + '"]')
.attr('placeholder', Messages.poll_userPlaceholder);
$('.cp-app-poll-table-lock[data-rt-id="' + userid + '"]').remove();
$('[data-rt-id^="' + userid + '"]').closest('td')
.addClass("cp-app-poll-table-own");
$('.cp-app-poll-table-bookmark[data-rt-id="' + userid + '"]').css('visibility', '')
.addClass('cp-app-poll-table-bookmark-full')
.attr('title', Messages.poll_bookmarked_col);
};
var styleUncommittedColumn = function () {
var $scroll = $('#cp-app-poll-table-scroll');
var hasScroll = $scroll.width() < $scroll[0].scrollWidth;
APP.uncommitted.content.colsOrder.forEach(function(id) {
// Enable the checkboxes for the uncommitted column
enableColumn(id);
$('.cp-app-poll-table-lock[data-rt-id="' + id + '"]').remove();
$('.cp-app-poll-table-remove[data-rt-id="' + id + '"]').remove();
$('.cp-app-poll-table-bookmark[data-rt-id="' + id + '"]').remove();
$('td.cp-app-poll-table-uncommitted .cover').addClass("cp-app-poll-table-uncommitted");
var $uncommittedCol = $('[data-rt-id^="' + id + '"]').closest('td');
$uncommittedCol.addClass("cp-app-poll-table-uncommitted");
if (hasScroll) {
$uncommittedCol.css('right', '100px');
}
});
APP.uncommitted.content.rowsOrder.forEach(function(id) {
// Enable the checkboxes for the uncommitted column
enableRow(id);
$('.cp-app-poll-table-edit[data-rt-id="' + id + '"]').remove();
$('.cp-app-poll-table-remove[data-rt-id="' + id + '"]').remove();
$('[data-rt-id="' + id + '"]').closest('tr').addClass("cp-app-poll-table-uncommitted");
});
};
var unlockElements = function () {
APP.unlocked.row.forEach(enableRow);
APP.unlocked.col.forEach(enableColumn);
};
var updateTableButtons = function () {
var uncomColId = APP.uncommitted.content.colsOrder[0];
var uncomRowId = APP.uncommitted.content.rowsOrder[0];
var $createOption = APP.$table.find('tbody input[data-rt-id="' + uncomRowId+'"]')
.closest('td').find('> div');
$createOption.append(APP.$createRow);
var $createUser = APP.$table.find('thead input[data-rt-id="' + uncomColId + '"]')
.closest('td');
$createUser.prepend(APP.$createCol);
if (APP.proxy.content.colsOrder.indexOf(APP.userid) === -1) {
APP.$table.find('.cp-app-poll-table-bookmark').css('visibility', '');
}
//$('#cp-app-poll-create-user, #cp-app-poll-create-option').css('display', 'inline-flex');
if (!APP.proxy ||
!APP.proxy.content.rowsOrder ||
APP.proxy.content.rowsOrder.length === 0) {
//$('#create-user').hide();
}
var width = $('#cp-app-poll-table').outerWidth();
if (width) {
//$('#create-user').css('left', width + 30 + 'px');
}
};
var setTablePublished = function (bool) {
if (bool) {
if (APP.$publish) { APP.$publish.hide(); }
@@ -329,59 +266,32 @@ define([
$('#cp-app-poll-form').removeClass('cp-app-poll-published');
}
};
var addCount = function () {
var addScrollClass = function () {
var $scroll = $('#cp-app-poll-table-scroll');
var hasScroll = $scroll.width() < $scroll[0].scrollWidth;
var $countCol = $('tr td:last-child');
var hasScroll = $scroll.width() < $scroll[0].scrollWidth && $scroll.width() > 100;
if (hasScroll) {
$countCol.css('right', '0');
$scroll.addClass('cp-app-poll-table-scrolled');
return;
}
var $thead = APP.$table.find('thead');
var $tr = APP.$table.find('tbody tr').first();
$thead.find('tr td').last()
.css({
'height': $thead.height()+'px',
'text-align': 'center',
'line-height': $thead.height()+'px'
})
.text(Messages.poll_total);
var winner = {
v: 0,
ids: []
};
APP.count = {};
APP.proxy.content.rowsOrder.forEach(function (rId) {
var count = Object.keys(APP.proxy.content.cells)
.filter(function (k) {
return k.indexOf(rId) !== -1 && APP.proxy.content.cells[k] === 1;
}).length;
if (count > winner.v) {
winner.v = count;
winner.ids = [rId];
} else if (count && count === winner.v) {
winner.ids.push(rId);
}
APP.count[rId] = count;
APP.$table.find('[data-rt-count-id="' + rId + '"]')
.text(count)
.css({
'height': $tr.height()+'px',
'line-height': $tr.height()+'px'
});
});
winner.ids.forEach(function (rId) {
$('[data-rt-id="' + rId + '"]').closest('td').addClass('cp-app-poll-table-winner');
$('[data-rt-count-id="' + rId + '"]').addClass('cp-app-poll-table-winner');
});
$scroll.removeClass('cp-app-poll-table-scrolled');
};
var updateTableButtons = function () {
var uncomColId = APP.uncommitted.content.colsOrder[0];
var uncomRowId = APP.uncommitted.content.rowsOrder[0];
var $createOption = $('tbody input[data-rt-id="' + uncomRowId+'"]')
.closest('td').find('> div');
$createOption.find('#cp-app-poll-create-option').remove();
$createOption.append(APP.$createRow);
var $createUser = $('thead input[data-rt-id="' + uncomColId + '"]')
.closest('td');
$createUser.find('#cp-app-poll-create-user').remove();
$createUser.prepend(APP.$createCol);
};
var updateDisplayedTable = function () {
styleUserColumn();
styleUncommittedColumn();
unlockElements();
updateTableButtons();
setTablePublished(APP.proxy.published);
addCount();
addScrollClass();
updateTableButtons();
};
var unlockColumn = function (id, cb) {
@@ -464,11 +374,13 @@ define([
Render.updateTable(table, displayedObj, conf);
// Fix autocomplete bug:
displayedObj.content.rowsOrder.forEach(function (rowId) {
if (f.id === rowId) { return; }
$('input[data-rt-id="' + rowId +'"]').val(displayedObj.content.rows[rowId] || '');
});
displayedObj.content.colsOrder.forEach(function (rowId) {
$('input[data-rt-id="' + rowId +'"]')
.val(displayedObj.content.cols[rowId] || '');
displayedObj.content.colsOrder.forEach(function (colId) {
if (f.id === colId) { return; }
$('input[data-rt-id="' + colId +'"]')
.val(displayedObj.content.cols[colId] || '');
});
updateDisplayedTable();
setFocus(f);
@@ -512,7 +424,7 @@ define([
case 'text':
debug("text[rt-id='%s'] [%s]", id, input.value);
Render.setValue(object, id, input.value);
change(null, null, null, 250);
change(null, null, null, 1000);
break;
case 'number':
debug("checkbox[tr-id='%s'] %s", id, input.value);
@@ -630,6 +542,7 @@ define([
switch (nodeName) {
case 'INPUT':
if ($(target).is('[type="text"]') && !isKeyup) { return; }
if (isKeyup && (e.keyCode === 13 || e.keyCode === 27)) {
var id = target.getAttribute('data-rt-id');
if ($(target).parents('.cp-app-poll-table-uncommitted').length
@@ -783,6 +696,7 @@ define([
return comments[a].time > comments[b].time;
}).forEach(function (k) {
var c = comments[k];
var name = c.name || Messages.anonymous;
var $c = $('<div>', {
'class': 'cp-app-poll-comments-list-el'
}).prependTo($comments);
@@ -794,7 +708,7 @@ define([
if (c.avatar && avatars[c.avatar]) {
$avatar.append(avatars[c.avatar]);
} else {
common.displayAvatar($avatar, c.avatar, c.name, function ($img) {
common.displayAvatar($avatar, c.avatar, name, function ($img) {
if (c.avatar && $img.length) { avatars[c.avatar] = $img[0].outerHTML; }
});
}
@@ -803,11 +717,11 @@ define([
'href': APP.origin + '/profile/#' + c.profile,
'target': '_blank',
'class': 'cp-app-poll-comments-list-data-name'
}).appendTo($data).text(c.name);
}).appendTo($data).text(name);
} else {
$('<span>', {
'class': 'cp-app-poll-comments-list-data-name'
}).appendTo($data).text(c.name);
}).appendTo($data).text(name);
}
$('<span>', {
'class': 'cp-app-poll-comments-list-data-time'
@@ -845,10 +759,12 @@ define([
};
var addComment = function () {
if (!APP.proxy.comments) { APP.proxy.comments = {}; }
var name = APP.$addComment.find('.cp-app-poll-comments-add-name').val();
var msg = APP.$addComment.find('.cp-app-poll-comments-add-msg').val();
var name = APP.$addComment.find('.cp-app-poll-comments-add-name').val().trim();
var msg = APP.$addComment.find('.cp-app-poll-comments-add-msg').val().trim();
var time = +new Date();
if (!msg) { return; }
var profile, avatar;
if (common.isLoggedIn()) {
profile = metadataMgr.getUserData().profile;
@@ -938,12 +854,6 @@ define([
unlockRow(rowuid);
}
var displayedObj = mergeUncommitted(proxy, uncommitted, false);
var colsOrder = sortColumns(displayedObj.content.colsOrder, userid);
var $table = APP.$table = $(Render.asHTML(displayedObj, null, colsOrder, APP.readOnly));
/*
Extract uncommitted data (row or column) and create a new uncommitted row or column
*/
@@ -1004,6 +914,15 @@ define([
});
});
var displayedObj = mergeUncommitted(proxy, uncommitted, false);
var colsOrder = sortColumns(displayedObj.content.colsOrder, userid);
Render.updateTable($('#cp-app-poll-table-scroll').find('table')[0], displayedObj, {
cols: colsOrder,
readOnly: APP.readOnly
});
// Description
APP.editor.on('change', function () {
var val = APP.editor.getValue();
@@ -1012,7 +931,7 @@ define([
APP.$addComment.find('.cp-app-poll-comments-add-submit').click(addComment);
APP.$addComment.find('.cp-app-poll-comments-add-cancel').click(resetComment);
$('#cp-app-poll-table-scroll').html('').prepend($table);
var $table = APP.$table = $('#cp-app-poll-table-scroll').find('table');
updateDisplayedTable();
updateDescription(null, APP.proxy.description || '');
@@ -1079,6 +998,11 @@ define([
Cryptpad.findOKButton().click();
};
var getHeadingText = function () {
if (!APP.editor) { return; }
return SframeCM.getHeadingText(APP.editor);
};
var onCreate = function (info) {
APP.myID = info.myID;
@@ -1092,7 +1016,8 @@ define([
metadataMgr = common.getMetadataMgr();
Title = common.createTitle();
var titleCfg = { getHeadingText: getHeadingText };
Title = common.createTitle(titleCfg);
var configTb = {
displayed: ['title', 'useradmin', 'spinner', 'share', 'userlist', 'newpad', 'limit'],

View File

@@ -1,9 +1,10 @@
define([
//'/common/cryptpad-common.js',
'jquery',
'/bower_components/hyperjson/hyperjson.js',
'/bower_components/textpatcher/TextPatcher.js',
'/bower_components/diff-dom/diffDOM.js',
], function (Hyperjson, TextPatcher) {
], function ($, Hyperjson, TextPatcher) {
var DiffDOM = window.diffDOM;
var Example = {
@@ -30,7 +31,7 @@ by maintaining indexes in rowsOrder and colsOrder
}
};
var Renderer = function (Cryptpad) {
var Renderer = function (Cryptpad, APP) {
var Render = {
Example: Example
@@ -222,7 +223,9 @@ var Renderer = function (Cryptpad) {
disabled: 'disabled'
};
return result;
})).concat([null]);
})).concat([{
content: Cryptpad.Messages.poll_total
}]);
}
if (i === rows.length) {
return [null].concat(cols.map(function () {
@@ -307,7 +310,7 @@ var Renderer = function (Cryptpad) {
}
return ['TD', {}, elements];
}
return ['TD', cell, []];
return ['TD', cell, [cell.content]];
};
var clone = function (o) {
@@ -444,6 +447,107 @@ var Renderer = function (Cryptpad) {
}
};
var styleUserColumn = function (table) {
var userid = APP.userid;
if (!userid) { return; }
// Enable input for the userid column
APP.enableColumn(userid, table);
$(table).find('input[disabled="disabled"][data-rt-id^="' + userid + '"]')
.attr('placeholder', Cryptpad.Messages.poll_userPlaceholder);
$(table).find('.cp-app-poll-table-lock[data-rt-id="' + userid + '"]').remove();
$(table).find('[data-rt-id^="' + userid + '"]').closest('td')
.addClass("cp-app-poll-table-own");
$(table).find('.cp-app-poll-table-bookmark[data-rt-id="' + userid + '"]')
.css('visibility', '')
.addClass('cp-app-poll-table-bookmark-full')
.attr('title', Cryptpad.Messages.poll_bookmarked_col);
};
var styleUncommittedColumn = function (table) {
APP.uncommitted.content.colsOrder.forEach(function(id) {
// Enable the checkboxes for the uncommitted column
APP.enableColumn(id, table);
$(table).find('.cp-app-poll-table-lock[data-rt-id="' + id + '"]').remove();
$(table).find('.cp-app-poll-table-remove[data-rt-id="' + id + '"]').remove();
$(table).find('.cp-app-poll-table-bookmark[data-rt-id="' + id + '"]').remove();
$(table).find('td.cp-app-poll-table-uncommitted .cover')
.addClass("cp-app-poll-table-uncommitted");
var $uncommittedCol = $(table).find('[data-rt-id^="' + id + '"]').closest('td');
$uncommittedCol.addClass("cp-app-poll-table-uncommitted");
});
APP.uncommitted.content.rowsOrder.forEach(function(id) {
// Enable the checkboxes for the uncommitted column
APP.enableRow(id, table);
$(table).find('.cp-app-poll-table-edit[data-rt-id="' + id + '"]').remove();
$(table).find('.cp-app-poll-table-remove[data-rt-id="' + id + '"]').remove();
$(table).find('[data-rt-id="' + id + '"]').closest('tr')
.addClass("cp-app-poll-table-uncommitted");
});
};
var unlockElements = function (table) {
APP.unlocked.row.forEach(function (id) { APP.enableRow(id, table); });
APP.unlocked.col.forEach(function (id) { APP.enableColumn(id, table); });
};
var updateTableButtons = function (table) {
var uncomColId = APP.uncommitted.content.colsOrder[0];
var uncomRowId = APP.uncommitted.content.rowsOrder[0];
var $createOption = $(table).find('tbody input[data-rt-id="' + uncomRowId+'"]')
.closest('td').find('> div');
$createOption.append(APP.$createRow);
var $createUser = $(table).find('thead input[data-rt-id="' + uncomColId + '"]')
.closest('td');
$createUser.prepend(APP.$createCol);
if (APP.proxy.content.colsOrder.indexOf(APP.userid) === -1) {
$(table).find('.cp-app-poll-table-bookmark').css('visibility', '');
}
};
var addCount = function (table) {
var $tr = $(table).find('tbody tr').first();
var winner = {
v: 0,
ids: []
};
APP.count = {};
APP.proxy.content.rowsOrder.forEach(function (rId) {
var count = Object.keys(APP.proxy.content.cells)
.filter(function (k) {
return k.indexOf(rId) !== -1 && APP.proxy.content.cells[k] === 1;
}).length;
if (count > winner.v) {
winner.v = count;
winner.ids = [rId];
} else if (count && count === winner.v) {
winner.ids.push(rId);
}
APP.count[rId] = count;
var h = $tr.height() || 28;
$(table).find('[data-rt-count-id="' + rId + '"]')
.text(count)
.css({
'height': h+'px',
'line-height': h+'px'
});
});
winner.ids.forEach(function (rId) {
$(table).find('[data-rt-id="' + rId + '"]').closest('td')
.addClass('cp-app-poll-table-winner');
$(table).find('[data-rt-count-id="' + rId + '"]')
.addClass('cp-app-poll-table-winner');
});
};
var styleTable = function (table) {
styleUserColumn(table);
styleUncommittedColumn(table);
unlockElements(table);
updateTableButtons(table);
addCount(table);
};
Render.updateTable = function (table, obj, conf) {
var DD = new DiffDOM(diffOptions);
@@ -457,6 +561,9 @@ var Renderer = function (Cryptpad) {
if (!hj) { throw new Error("Expected Hyperjson!"); }
var table2 = Hyperjson.toDOM(hj);
styleTable(table2);
var patch = DD.diff(table, table2);
DD.apply(table, patch);
};

View File

@@ -77,7 +77,7 @@ define([
var c = Slide.content;
var m = '<span class="cp-app-slide-container"><span class="'+slideClass+'">'+DiffMd.render(c).replace(separatorReg, '</span></span><span class="cp-app-slide-container"><span class="'+slideClass+'">')+'</span></span>';
DiffMd.apply(m, $content);
try { DiffMd.apply(m, $content); } catch (e) { return console.error(e); }
var length = getNumberOfSlides();
$modal.find('style.cp-app-slide-style').remove();

View File

@@ -46,6 +46,7 @@
// contains user tools
#cp-app-whiteboard-controls {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: center;