Merge branch 'staging' of github.com:xwiki-labs/cryptpad into staging

pull/1/head
ansuz 5 years ago
commit f68a1a3b1b

@ -8,17 +8,17 @@ define([
'/common/common-constants.js',
'/customize/messages.js',
'/bower_components/nthen/index.js'
], function ($, h, Hash, UI, UIElements, Util, Constants, Messages, nThen) {
], function($, h, Hash, UI, UIElements, Util, Constants, Messages, nThen) {
var handlers = {};
var defaultDismiss = function (common, data) {
return function (e) {
var defaultDismiss = function(common, data) {
return function(e) {
if (e) {
e.preventDefault();
e.stopPropagation();
}
common.mailbox.dismiss(data, function (err) {
common.mailbox.dismiss(data, function(err) {
if (err) { return void console.error(err); }
});
};
@ -26,7 +26,7 @@ define([
// Friend request
handlers['FRIEND_REQUEST'] = function (common, data) {
handlers['FRIEND_REQUEST'] = function(common, data) {
var content = data.content;
var msg = content.msg;
var userData = msg.content.user || msg.content;
@ -34,7 +34,7 @@ define([
msg.content = { user: userData };
// Display the notification
content.getFormatText = function () {
content.getFormatText = function() {
return Messages._getKey('friendRequest_notification', [name]);
};
@ -43,14 +43,14 @@ define([
// if not archived, add handlers
if (!content.archived) {
content.handler = function () {
content.handler = function() {
UIElements.displayFriendRequestModal(common, data);
};
common.addFriendRequest(data);
}
};
handlers['FRIEND_REQUEST_ACCEPTED'] = function (common, data) {
handlers['FRIEND_REQUEST_ACCEPTED'] = function(common, data) {
var content = data.content;
var msg = content.msg;
var userData = typeof(msg.content.user) === "object" ? msg.content.user : {
@ -58,7 +58,7 @@ define([
curvePublic: msg.content.user
};
var name = Util.fixHTML(userData.displayName) || Messages.anonymous;
content.getFormatText = function () {
content.getFormatText = function() {
return Messages._getKey('friendRequest_accepted', [name]);
};
if (!content.archived) {
@ -66,7 +66,7 @@ define([
}
};
handlers['FRIEND_REQUEST_DECLINED'] = function (common, data) {
handlers['FRIEND_REQUEST_DECLINED'] = function(common, data) {
var content = data.content;
var msg = content.msg;
var userData = typeof(msg.content.user) === "object" ? msg.content.user : {
@ -74,7 +74,7 @@ define([
curvePublic: msg.content.user
};
var name = Util.fixHTML(userData.displayName) || Messages.anonymous;
content.getFormatText = function () {
content.getFormatText = function() {
return Messages._getKey('friendRequest_declined', [name]);
};
if (!content.archived) {
@ -84,29 +84,29 @@ define([
// Share pad
handlers['SHARE_PAD'] = function (common, data) {
handlers['SHARE_PAD'] = function(common, data) {
var content = data.content;
var msg = content.msg;
var type = Hash.parsePadUrl(msg.content.href).type;
var key = type === 'drive' ? 'notification_folderShared' :
(type === 'file' ? 'notification_fileShared' :
'notification_padShared');
(type === 'file' ? 'notification_fileShared' :
'notification_padShared');
var name = Util.fixHTML(msg.content.name) || Messages.anonymous;
var title = Util.fixHTML(msg.content.title);
content.getFormatText = function () {
content.getFormatText = function() {
return Messages._getKey(key, [name, title]);
};
content.handler = function () {
var todo = function () {
content.handler = function() {
var todo = function() {
common.openURL(msg.content.href);
defaultDismiss(common, data)();
};
nThen(function (waitFor) {
nThen(function(waitFor) {
if (msg.content.isTemplate) {
common.sessionStorage.put(Constants.newPadPathKey, ['template'], waitFor());
}
common.sessionStorage.put('newPadPassword', msg.content.password || '', waitFor());
}).nThen(function () {
}).nThen(function() {
todo();
});
};
@ -116,12 +116,12 @@ define([
};
// New support message from the admins
handlers['SUPPORT_MESSAGE'] = function (common, data) {
handlers['SUPPORT_MESSAGE'] = function(common, data) {
var content = data.content;
content.getFormatText = function () {
content.getFormatText = function() {
return Messages.support_notification;
};
content.handler = function () {
content.handler = function() {
common.openURL('/support/');
defaultDismiss(common, data)();
};
@ -130,7 +130,7 @@ define([
}
};
handlers['REQUEST_PAD_ACCESS'] = function (common, data) {
handlers['REQUEST_PAD_ACCESS'] = function(common, data) {
var content = data.content;
var msg = content.msg;
@ -140,13 +140,13 @@ define([
// Display the notification
var name = Util.fixHTML(msg.content.user.displayName) || Messages.anonymous;
var title = Util.fixHTML(msg.content.title);
content.getFormatText = function () {
content.getFormatText = function() {
return Messages._getKey('requestEdit_request', [title, name]);
};
// if not archived, add handlers
if (!content.archived) {
content.handler = function () {
content.handler = function() {
var link = h('a', {
href: '#'
}, Messages.requestEdit_viewPad);
@ -160,12 +160,12 @@ define([
verified,
link
]);
$(link).click(function (e) {
$(link).click(function(e) {
e.preventDefault();
e.stopPropagation();
common.openURL(msg.content.href);
});
UI.confirm(div, function (yes) {
UI.confirm(div, function(yes) {
if (!yes) { return; }
common.getSframeChannel().event('EV_GIVE_ACCESS', {
channel: msg.content.channel,
@ -182,7 +182,7 @@ define([
}
};
handlers['GIVE_PAD_ACCESS'] = function (common, data) {
handlers['GIVE_PAD_ACCESS'] = function(common, data) {
var content = data.content;
var msg = content.msg;
@ -195,26 +195,26 @@ define([
var title = Util.fixHTML(msg.content.title);
// Display the notification
content.getFormatText = function () {
content.getFormatText = function() {
return Messages._getKey('requestEdit_accepted', [title, name]);
};
// if not archived, add handlers
content.handler = function () {
content.handler = function() {
common.openURL(msg.content.href);
defaultDismiss(common, data)();
};
};
handlers['ADD_OWNER'] = function (common, data) {
handlers['ADD_OWNER'] = function(common, data) {
var content = data.content;
var msg = content.msg;
// Display the notification
var name = Util.fixHTML(msg.content.user.displayName) || Messages.anonymous;
var title = Util.fixHTML(msg.content.title);
content.getFormatText = function () {
content.getFormatText = function() {
return Messages._getKey('owner_request', [name, title]);
};
@ -223,7 +223,7 @@ define([
// if not archived, add handlers
if (!content.archived) {
content.handler = function () {
content.handler = function() {
if (msg.content.teamChannel) {
return void UIElements.displayAddTeamOwnerModal(common, data);
}
@ -232,7 +232,7 @@ define([
}
};
handlers['ADD_OWNER_ANSWER'] = function (common, data) {
handlers['ADD_OWNER_ANSWER'] = function(common, data) {
var content = data.content;
var msg = content.msg;
@ -240,7 +240,7 @@ define([
var name = Util.fixHTML(msg.content.user.displayName) || Messages.anonymous;
var title = Util.fixHTML(msg.content.title);
var key = 'owner_request_' + (msg.content.answer ? 'accepted' : 'declined');
content.getFormatText = function () {
content.getFormatText = function() {
return Messages._getKey(key, [name, title]);
};
if (!content.archived) {
@ -248,7 +248,7 @@ define([
}
};
handlers['RM_OWNER'] = function (common, data) {
handlers['RM_OWNER'] = function(common, data) {
var content = data.content;
var msg = content.msg;
@ -256,7 +256,7 @@ define([
var name = Util.fixHTML(msg.content.user.displayName) || Messages.anonymous;
var title = Util.fixHTML(msg.content.title);
var key = 'owner_removed' + (msg.content.pending ? 'Pending' : '');
content.getFormatText = function () {
content.getFormatText = function() {
return Messages._getKey(key, [name, title]);
};
if (!content.archived) {
@ -264,32 +264,32 @@ define([
}
};
handlers['INVITE_TO_TEAM'] = function (common, data) {
handlers['INVITE_TO_TEAM'] = function(common, data) {
var content = data.content;
var msg = content.msg;
// Display the notification
var name = Util.fixHTML(msg.content.user.displayName) || Messages.anonymous;
var teamName = Util.fixHTML(Util.find(msg, ['content', 'team', 'metadata', 'name']) || '');
content.getFormatText = function () {
var teamName = Util.fixHTML(Util.find(msg, ['content', 'team', 'metadata', 'name'])  || '');
content.getFormatText = function() {
var text = Messages._getKey('team_invitedToTeam', [name, teamName]);
return text;
};
if (!content.archived) {
content.handler = function () {
content.handler = function() {
UIElements.displayInviteTeamModal(common, data);
};
}
};
handlers['KICKED_FROM_TEAM'] = function (common, data) {
handlers['KICKED_FROM_TEAM'] = function(common, data) {
var content = data.content;
var msg = content.msg;
// Display the notification
var name = Util.fixHTML(msg.content.user.displayName) || Messages.anonymous;
var teamName = Util.fixHTML(Util.find(msg, ['content', 'teamName']) || '');
content.getFormatText = function () {
var teamName = Util.fixHTML(Util.find(msg, ['content', 'teamName'])  || '');
content.getFormatText = function() {
var text = Messages._getKey('team_kickedFromTeam', [name, teamName]);
return text;
};
@ -298,16 +298,16 @@ define([
}
};
handlers['INVITE_TO_TEAM_ANSWER'] = function (common, data) {
handlers['INVITE_TO_TEAM_ANSWER'] = function(common, data) {
var content = data.content;
var msg = content.msg;
// Display the notification
var name = Util.fixHTML(msg.content.user.displayName) || Messages.anonymous;
var teamName = Util.fixHTML(Util.find(msg, ['content', 'team', 'metadata', 'name']) || '') ||
Util.fixHTML(Util.find(msg, ['content', 'teamName']));
var teamName = Util.fixHTML(Util.find(msg, ['content', 'team', 'metadata', 'name'])  || '') ||
Util.fixHTML(Util.find(msg, ['content', 'teamName']));
var key = 'team_' + (msg.content.answer ? 'accept' : 'decline') + 'Invitation';
content.getFormatText = function () {
content.getFormatText = function() {
return Messages._getKey(key, [name, teamName]);
};
if (!content.archived) {
@ -315,26 +315,24 @@ define([
}
};
Messages.comments_notification = 'Replies to your comment "{0}" in <b>{1}</b>'; // XXX
Messages.unknownPad = "Unknown pad"; // XXX
handlers['COMMENT_REPLY'] = function (common, data) {
handlers['COMMENT_REPLY'] = function(common, data) {
var content = data.content;
var msg = content.msg;
// Display the notification
//var name = Util.fixHTML(msg.content.user.displayName) || Messages.anonymous;
var comment = Util.fixHTML(msg.content.comment).slice(0,20).trim();
var comment = Util.fixHTML(msg.content.comment).slice(0, 20).trim();
if (msg.content.comment.length > 20) {
comment += '...';
}
var title = Util.fixHTML(msg.content.title || Messages.unknownPad);
var href = msg.content.href;
content.getFormatText = function () {
content.getFormatText = function() {
return Messages._getKey('comments_notification', [comment, title]);
};
if (href) {
content.handler = function () {
content.handler = function() {
common.openURL(href);
defaultDismiss(common, data)();
};
@ -344,8 +342,7 @@ define([
}
};
Messages.mentions_notification = '{0} has mentionned you in <b>{1}</b>'; // XXX
handlers['MENTION'] = function (common, data) {
handlers['MENTION'] = function(common, data) {
var content = data.content;
var msg = content.msg;
@ -354,11 +351,11 @@ define([
var title = Util.fixHTML(msg.content.title || Messages.unknownPad);
var href = msg.content.href;
content.getFormatText = function () {
content.getFormatText = function() {
return Messages._getKey('mentions_notification', [name, title]);
};
if (href) {
content.handler = function () {
content.handler = function() {
common.openURL(href);
defaultDismiss(common, data)();
};
@ -372,7 +369,7 @@ define([
// NOTE: don't forget to fixHTML everything returned by "getFormatText"
return {
add: function (common, data) {
add: function(common, data) {
var type = data.content.msg.type;
if (handlers[type]) {
@ -385,9 +382,9 @@ define([
data.content.isDismissible = typeof data.content.dismissHandler === "function";
}
},
remove: function (common, data) {
remove: function(common, data) {
common.removeFriendRequest(data.hash);
},
allowed: Object.keys(handlers)
};
});
});

@ -1353,5 +1353,17 @@
"oo_login": "Bitte logge dich ein oder erstelle ein Account, um die Performance von Tabellen zu verbessern.",
"pad_usePageWidth": "Seitenansicht",
"pad_useFullWidth": "Volle Breite",
"cba_title": "Autorenfarben"
"cba_title": "Autorenfarben",
"comments_resolve": "Abschließen",
"comments_submit": "Absenden",
"comments_notification": "Antworten auf deinen Kommentar \"{0}\" in <b>{1}</b>",
"comments_deleted": "Kommentar vom Autor gelöscht",
"comments_comment": "Kommentieren",
"comments_reply": "Antworten",
"mentions_notification": "{0} hat dich in <b>{1}</b> erwähnt",
"settings_padNotifHint": "Benachrichtigungen über Antworten auf deine Kommentare ignorieren",
"settings_padNotifTitle": "Kommentar-Benachrichtigungen",
"settings_padNotifCheckbox": "Kommentar-Benachrichtigungen deaktivieren",
"comments_edited": "Bearbeitet",
"unknownPad": "Unbekanntes Pad"
}

@ -1365,5 +1365,6 @@
"comments_deleted": "Commentaire effacé par son auteur",
"mentions_notification": "{0} vous a mentionné dans <b>{1}</b>",
"unknownPad": "Pad inconnu",
"comments_notification": "Réponses à votre commentaire \"{0}\" sur <b>{1}</b>"
"comments_notification": "Réponses à votre commentaire \"{0}\" sur <b>{1}</b>",
"comments_error": "Impossible d'ajouter un commentaire ici"
}

@ -1365,5 +1365,6 @@
"comments_comment": "Comment",
"settings_padNotifTitle": "Comment notifications",
"settings_padNotifHint": "Ignore notifications when someone replies to one of your comments",
"settings_padNotifCheckbox": "Disable comment notifications"
"settings_padNotifCheckbox": "Disable comment notifications",
"comments_error": "Can't add a comment here"
}

@ -6,44 +6,44 @@ define([
'/common/hyperscript.js',
'/common/common-interface.js',
'/customize/messages.js'
], function ($, Sortify, Util, Hash, h, UI, Messages) {
], function($, Sortify, Util, Hash, h, UI, Messages) {
var Comments = {};
/*
{
authors: {
"id": {
name: "",
curvePublic: "",
avatar: "",
profile: ""
}
},
data: {
"uid": {
m: [{
u: id,
m: "str", // comment
t: +new Date,
v: "str", // value of the commented content
e: undefined/1, // edited
d: undefined/1, // deleted
}],
d: undefined/1,
/*
{
authors: {
"id": {
name: "",
curvePublic: "",
avatar: "",
profile: ""
}
},
data: {
"uid": {
m: [{
u: id,
m: "str", // comment
t: +new Date,
v: "str", // value of the commented content
e: undefined/1, // edited
d: undefined/1, // deleted
}],
d: undefined/1,
}
}
}
}
*/
*/
var COMMENTS = {
authors: {},
data: {}
};
var canonicalize = function (t) { return t.replace(/\r\n/g, '\n'); };
var canonicalize = function(t) { return t.replace(/\r\n/g, '\n'); };
// XXX function duplicated from www/code/markers.js
var authorUid = function (existing) {
var authorUid = function(existing) {
if (!Array.isArray(existing)) { existing = []; }
var n;
var i = 0;
@ -54,12 +54,12 @@ define([
if (existing.indexOf(n) !== -1) { n = 0; }
return n;
};
var getAuthorId = function (Env, curve) {
var getAuthorId = function(Env, curve) {
var existing = Object.keys(Env.comments.authors || {}).map(Number);
if (!Env.common.isLoggedIn()) { return authorUid(existing); }
var uid;
existing.some(function (id) {
existing.some(function(id) {
var author = Env.comments.authors[id] || {};
if (author.curvePublic !== curve) { return; }
uid = Number(id);
@ -70,7 +70,7 @@ define([
// Return the author ID and add/update the data for registered users
// Return the username for unregistered users
var updateAuthorData = function (Env, onChange) {
var updateAuthorData = function(Env, onChange) {
var userData = Env.metadataMgr.getUserData();
if (!Env.common.isLoggedIn()) {
return userData.name;
@ -89,13 +89,13 @@ define([
return myAuthorId;
};
var updateMetadata = function (Env) {
var updateMetadata = function(Env) {
var md = Util.clone(Env.metadataMgr.getMetadata());
md.comments = Util.clone(Env.comments);
Env.metadataMgr.updateMetadata(md);
};
var sendReplyNotification = function (Env, uid) {
var sendReplyNotification = function(Env, uid) {
if (!Env.comments || !Env.comments.data || !Env.comments.authors) { return; }
if (!Env.common.isLoggedIn()) { return; }
var thread = Env.comments.data[uid];
@ -104,7 +104,7 @@ define([
var privateData = Env.metadataMgr.getPrivateData();
var others = {};
// Get all the other registered users with a mailbox
thread.m.forEach(function (obj) {
thread.m.forEach(function(obj) {
var u = obj.u;
if (typeof(u) !== "number") { return; }
var author = Env.comments.authors[u];
@ -118,11 +118,11 @@ define([
};
});
// Send the notification
Object.keys(others).forEach(function (id) {
Object.keys(others).forEach(function(id) {
var data = others[id];
Env.common.mailbox.sendTo("COMMENT_REPLY", {
channel: privateData.channel,
comment: data.comment,
comment: data.comment.replace(/<[^>]*>/g, ''),
content: data.content
}, {
channel: data.notifications,
@ -132,12 +132,12 @@ define([
};
var cleanMentions = function ($el) {
var cleanMentions = function($el) {
$el.html('');
var el = $el[0];
var allowed = ['data-profile', 'data-name', 'data-avatar', 'class'];
// Remove unnecessary/unsafe attributes
for (var i=el.attributes.length-1; i>0; i--) {
for (var i = el.attributes.length - 1; i > 0; i--) {
var name = el.attributes[i] && el.attributes[i].name;
if (allowed.indexOf(name) === -1) {
$el.removeAttr(name);
@ -146,7 +146,7 @@ define([
};
// Seletc all text of a contenteditable element
var selectAll = function (element) {
var selectAll = function(element) {
var selection = window.getSelection();
var range = document.createRange();
range.selectNodeContents(element);
@ -154,12 +154,7 @@ define([
selection.addRange(range);
};
Messages.comments_deleted = "Comment deleted by its author"; // XXX
Messages.comments_edited = "Edited"; // XXX
Messages.comments_submit = "Submit"; // XXX
Messages.comments_reply = "Reply"; // XXX
Messages.comments_resolve = "Resolve"; // XXX
var getCommentForm = function (Env, reply, _cb, editContent) {
var getCommentForm = function(Env, reply, _cb, editContent) {
var cb = Util.once(_cb);
var userData = Env.metadataMgr.getUserData();
var name = Util.fixHTML(userData.name || Messages.anonymous);
@ -188,12 +183,12 @@ define([
]);
// List of allowed attributes in mentions
$(submit).click(function (e) {
$(submit).click(function(e) {
e.stopPropagation();
var clone = textarea.cloneNode(true);
var notify = {};
var $clone = $(clone);
$clone.find('span.cp-mentions').each(function (i, el) {
$clone.find('span.cp-mentions').each(function(i, el) {
var $el = $(el);
var curve = $el.attr('data-curve');
var notif = $el.attr('data-notifications');
@ -209,7 +204,7 @@ define([
// Send notification
var privateData = Env.metadataMgr.getPrivateData();
var userData = Env.metadataMgr.getUserData();
Object.keys(notify).forEach(function (curve) {
Object.keys(notify).forEach(function(curve) {
if (curve === userData.curvePublic) { return; }
Env.common.mailbox.sendTo("MENTION", {
channel: privateData.channel,
@ -222,12 +217,12 @@ define([
// Push the content
cb(content);
});
$(cancel).click(function (e) {
$(cancel).click(function(e) {
e.stopPropagation();
cb();
});
var $text = $(textarea).keydown(function (e) {
var $text = $(textarea).keydown(function(e) {
e.stopPropagation();
if (e.which === 27) {
$(cancel).click();
@ -243,14 +238,14 @@ define([
e.stopImmediatePropagation();
e.preventDefault();
}
}).click(function (e) {
}).click(function(e) {
e.stopPropagation();
});
if (Env.common.isLoggedIn()) {
var authors = {};
Object.keys((Env.comments && Env.comments.authors) || {}).forEach(function (id) {
Object.keys((Env.comments && Env.comments.authors) ||  {}).forEach(function(id) {
var obj = Util.clone(Env.comments.authors[id]);
authors[obj.curvePublic] = obj;
});
@ -273,14 +268,14 @@ define([
h('i.fa.fa-times'),
Messages.kanban_delete
]);
$(deleteButton).click(function (e) {
$(deleteButton).click(function(e) {
e.stopPropagation();
cb(false);
});
}
setTimeout(function () {
setTimeout(function() {
$(textarea).focus();
selectAll(textarea);
});
@ -300,13 +295,13 @@ define([
]);
};
var isVisible = function (el, $container) {
var isVisible = function(el, $container) {
var size = $container.outerHeight();
var pos = el.getBoundingClientRect();
return (pos.bottom < size) && (pos.y > 0);
};
var redrawComments = function (Env) {
var redrawComments = function(Env) {
// Don't redraw if there were no change
var str = Sortify(Env.comments || {});
if (str === Env.oldComments) { return; }
@ -347,15 +342,15 @@ define([
var userData = Env.metadataMgr.getUserData();
// Get all the comment threads in their order in the pad
var threads = Env.$inner.find('comment').map(function (i, el) {
var threads = Env.$inner.find('comment').map(function(i, el) {
return el.getAttribute('data-uid');
}).toArray();
// Draw all comment threads
Util.deduplicateString(threads).forEach(function (key) {
Util.deduplicateString(threads).forEach(function(key) {
// Get thread data
var obj = Env.comments.data[key];
if (!obj || obj.d || !Array.isArray(obj.m) || !obj.m.length) {
if (!obj || obj.d ||  !Array.isArray(obj.m) ||  !obj.m.length) {
return;
}
@ -367,23 +362,22 @@ define([
var $actions;
// Draw all messages for this thread
(obj.m || []).forEach(function (msg, i) {
(obj.m || []).forEach(function(msg, i) {
var replyCls = i === 0 ? '' : '.cp-comment-reply';
if (msg.d) {
content.push(h('div.cp-comment.cp-comment-deleted'+replyCls,
Messages.comments_deleted));
content.push(h('div.cp-comment.cp-comment-deleted' + replyCls,
Messages.comments_deleted));
return;
}
var author = typeof(msg.u) === "number" ?
((Env.comments.authors || {})[msg.u] || {}) :
{ name: msg.u };
((Env.comments.authors || {})[msg.u] || {}) : { name: msg.u };
var name = Util.fixHTML(author.name || Messages.anonymous);
var date = new Date(msg.t);
var avatar = h('span.cp-avatar');
Env.common.displayAvatar($(avatar), author.avatar, name);
if (author.profile) {
$(avatar).click(function (e) {
$(avatar).click(function(e) {
Env.common.openURL(Hash.hashToHref(author.profile, 'profile'));
e.stopPropagation();
});
@ -394,7 +388,7 @@ define([
m.innerHTML = msg.m;
var $m = $(m);
$m.find('> *:not(span.cp-mentions)').remove();
$m.find('span.cp-mentions').each(function (i, el) {
$m.find('span.cp-mentions').each(function(i, el) {
var $el = $(el);
var name = $el.attr('data-name');
var avatarUrl = $el.attr('data-avatar');
@ -412,11 +406,11 @@ define([
]);
if (profile) {
$el.attr('tabindex', 1);
$el.addClass('cp-mentions-clickable').click(function (e) {
$el.addClass('cp-mentions-clickable').click(function(e) {
e.preventDefault();
e.stopPropagation();
Env.common.openURL(Hash.hashToHref(profile, 'profile'));
}).focus(function (e) {
}).focus(function(e) {
e.stopPropagation();
});
}
@ -432,18 +426,18 @@ define([
// Add edit button when applicable (last message of the thread, written by ourselves)
var edit;
if (i === (obj.m.length -1) && author.curvePublic === userData.curvePublic) {
if (i === (obj.m.length - 1) && author.curvePublic === userData.curvePublic) {
edit = h('span.cp-comment-edit', {
tabindex:1,
tabindex: 1,
title: Messages.clickToEdit
}, h('i.fa.fa-pencil'));
$(edit).click(function (e) {
$(edit).click(function(e) {
Env.$container.find('.cp-comment-active').removeClass('cp-comment-active');
$div.addClass('cp-comment-active');
e.stopPropagation();
Env.$container.find('.cp-comment-form').remove();
if ($actions) { $actions.hide(); }
var form = getCommentForm(Env, key, function (val) {
var form = getCommentForm(Env, key, function(val) {
// Show the "reply" and "resolve" buttons again
$(form).closest('.cp-comment-container')
.find('.cp-comment-actions').css('display', '');
@ -460,7 +454,7 @@ define([
msg.d = 1;
if (container) {
$(container).addClass('cp-comment-deleted')
.html(Messages.comments_deleted);
.html(Messages.comments_deleted);
}
if (obj.m.length === 1) {
delete Env.comments.data[key];
@ -481,7 +475,7 @@ define([
}
// Add the comment
content.push(container = h('div.cp-comment'+replyCls, [
content.push(container = h('div.cp-comment' + replyCls, [
h('div.cp-comment-header', [
avatar,
h('span.cp-comment-metadata', [
@ -523,10 +517,10 @@ define([
}, content));
$div = $(div);
$(reply).click(function (e) {
$(reply).click(function(e) {
e.stopPropagation();
$actions.hide();
var form = getCommentForm(Env, key, function (val) {
var form = getCommentForm(Env, key, function(val) {
// Show the "reply" and "resolve" buttons again
$(form).closest('.cp-comment-container')
.find('.cp-comment-actions').css('display', '');
@ -537,8 +531,8 @@ define([
if (!obj || !Array.isArray(obj.m)) { return; }
// Get the value of the commented text
var res = Env.$inner.find('comment[data-uid="'+key+'"]').toArray();
var value = res.map(function (el) {
var res = Env.$inner.find('comment[data-uid="' + key + '"]').toArray();
var value = res.map(function(el) {
return el.innerText;
}).join('\n');
@ -562,7 +556,7 @@ define([
$div.append(form);
// Make sure the submit button is visible: scroll by the height of the form
setTimeout(function () {
setTimeout(function() {
var yContainer = Env.$container[0].getBoundingClientRect().bottom;
var yActions = form.getBoundingClientRect().bottom;
if (yActions > yContainer) {
@ -573,7 +567,7 @@ define([
UI.confirmButton(resolve, {
classes: 'btn-danger'
}, function () {
}, function() {
// Delete the comment
delete Env.comments.data[key];
@ -582,11 +576,11 @@ define([
Env.framework.localChange();
});
var focusContent = function () {
var focusContent = function() {
// Add class "active"
Env.$inner.find('comment.active').removeClass('active');
Env.$inner.find('comment[data-uid="'+key+'"]').addClass('active');
var $last = Env.$inner.find('comment[data-uid="'+key+'"]').last();
Env.$inner.find('comment[data-uid="' + key + '"]').addClass('active');
var $last = Env.$inner.find('comment[data-uid="' + key + '"]').last();
// Scroll into view
if (!$last.length) { return; }
@ -594,7 +588,7 @@ define([
if (!visible) { $last[0].scrollIntoView(); }
};
$div.on('click focus', function (e) {
$div.on('click focus', function(e) {
// Prevent the click event to propagate if we're already selected
// The propagation to #cp-app-pad-inner would trigger the "unselect" handler
e.stopPropagation();
@ -621,7 +615,7 @@ define([
// Restore selection
if (oldRangeObj) {
setTimeout(function () {
setTimeout(function() {
if (!oldRangeObj) { return; }
var range = document.createRange();
range.setStart(oldRangeObj.start, oldRangeObj.startO);
@ -639,7 +633,7 @@ define([
}
};
var onChange = function (Env) {
var onChange = function(Env) {
var md = Util.clone(Env.metadataMgr.getMetadata());
Env.comments = md.comments;
var changed = false;
@ -649,7 +643,7 @@ define([
}
if (Env.ready === 0) {
Env.ready = true;
updateAuthorData(Env, function () {
updateAuthorData(Env, function() {
changed = true;
});
// On ready, if our user data have changed or if we've added the initial structure
@ -661,7 +655,7 @@ define([
} else if (Env.ready) {
// Everytime there is a metadata change, check if our user data have changed
// and push the updates if necessary
updateAuthorData(Env, function () {
updateAuthorData(Env, function() {
updateMetadata(Env);
Env.framework.localChange();
});
@ -670,7 +664,7 @@ define([
};
// Check if comments have been deleted from the document but not from metadata
var checkDeleted = function (Env) {
var checkDeleted = function(Env) {
if (!Env.comments || !Env.comments.data) { return; }
// Don't recheck if there were no change
@ -679,7 +673,7 @@ define([
Env.oldCheck = str;
// If there is no comment stored in the metadata, abort
var comments = Object.keys(Env.comments.data || {}).filter(function (id) {
var comments = Object.keys(Env.comments.data || {}).filter(function(id) {
return !Env.comments.data[id].d;
});
@ -687,7 +681,7 @@ define([
// Get the comments from the document
var toUncomment = {};
var uids = Env.$inner.find('comment').map(function (i, el) {
var uids = Env.$inner.find('comment').map(function(i, el) {
var id = el.getAttribute('data-uid');
// Empty comment: remove from dom
if (!el.innerHTML && el.parentElement) {
@ -713,13 +707,13 @@ define([
}).toArray();
if (Object.keys(toUncomment).length) {
Object.keys(toUncomment).forEach(function (id) {
Object.keys(toUncomment).forEach(function(id) {
Env.editor.plugins.comments.uncomment(id, toUncomment[id]);
});
}
// Check if a comment has been deleted
comments.forEach(function (uid) {
comments.forEach(function(uid) {
if (uids.indexOf(uid) !== -1) { return; }
// comment has been deleted
var data = Env.comments.data[uid];
@ -734,19 +728,19 @@ define([
}
};
var removeCommentBubble = function (Env) {
var removeCommentBubble = function(Env) {
Env.bubble = undefined;
Env.$contentContainer.find('.cp-comment-bubble').remove();
};
var updateBubble = function (Env) {
var updateBubble = function(Env) {
if (!Env.bubble) { return; }
var pos = Env.bubble.node.getBoundingClientRect();
if (pos.y < 0 || pos.y > Env.$inner.outerHeight()) {
//removeCommentBubble(Env);
}
Env.bubble.button.setAttribute('style', 'top:'+pos.y+'px');
Env.bubble.button.setAttribute('style', 'top:' + pos.y + 'px');
};
var addCommentBubble = function (Env) {
var addCommentBubble = function(Env) {
var ranges = Env.editor.getSelectedRanges();
if (!ranges.length) { return; }
var el = ranges[0].endContainer || ranges[0].startContainer;
@ -760,14 +754,14 @@ define([
var y = pos.y;
if (y < 0 || y > Env.$inner.outerHeight()) { return; }
var button = h('button.btn.btn-secondary', {
style: 'top:'+y+'px;',
style: 'top:' + y + 'px;',
title: Messages.comments_comment
},h('i.fa.fa-comment'));
}, h('i.fa.fa-comment'));
Env.bubble = {
node: node,
button: button
};
$(button).click(function (e) {
$(button).click(function(e)  {
e.stopPropagation();
Env.editor.execCommand('comment');
Env.bubble = undefined;
@ -775,8 +769,8 @@ define([
Env.$contentContainer.append(h('div.cp-comment-bubble', button));
};
var addAddCommentHandler = function (Env) {
Env.editor.plugins.comments.addComment = function (uid, addMark) {
var addAddCommentHandler = function(Env) {
Env.editor.plugins.comments.addComment = function(uid, addMark) {
if (!Env.ready) { return; }
if (!Env.comments) { Env.comments = Util.clone(COMMENTS); }
@ -784,16 +778,14 @@ define([
var applicable = Env.editor.plugins.comments.isApplicable();
if (!applicable) {
// Abort if our selection contains a comment
console.error("Can't add a comment here");
// XXX show error
UI.warn(Messages.error);
UI.warn(Messages.comments_error);
return;
}
// Remove active class on other comments
Env.$container.find('.cp-comment-active').removeClass('cp-comment-active');
Env.$container.find('.cp-comment-form').remove();
var form = getCommentForm(Env, false, function (val) {
var form = getCommentForm(Env, false, function(val) {
$(form).remove();
Env.$inner.focus();
@ -833,10 +825,10 @@ define([
};
Env.$iframe.on('scroll', function () {
Env.$iframe.on('scroll', function() {
updateBubble(Env);
});
$(Env.ifrWindow.document).on('selectionchange', function () {
$(Env.ifrWindow.document).on('selectionchange', function() {
removeCommentBubble(Env);
var applicable = Env.editor.plugins.comments.isApplicable();
if (!applicable) { return; }
@ -844,14 +836,14 @@ define([
});
};
var onContentUpdate = function (Env) {
var onContentUpdate = function(Env) {
if (!Env.ready) { return; }
// Check deleted
onChange(Env);
checkDeleted(Env);
};
var ready = function (Env) {
var ready = function(Env) {
Env.ready = 0;
// If you're the only edit user online, clear "deleted" comments
@ -862,7 +854,7 @@ define([
// Clear data
var data = (Env.comments && Env.comments.data) || {};
Object.keys(data).forEach(function (uid) {
Object.keys(data).forEach(function(uid) {
if (data[uid].d) { delete data[uid]; }
});
@ -871,12 +863,12 @@ define([
Env.framework.localChange();
};
Comments.create = function (cfg) {
Comments.create = function(cfg) {
var Env = cfg;
Env.comments = Util.clone(COMMENTS);
var ro = cfg.framework.isReadOnly();
var onEditableChange = function (unlocked) {
var onEditableChange = function(unlocked) {
Env.$container.removeClass('cp-comments-readonly');
if (ro || !unlocked) {
Env.$container.addClass('cp-comments-readonly');
@ -888,7 +880,7 @@ define([
addAddCommentHandler(Env);
// Unselect comment when clicking outside
$(window).click(function (e) {
$(window).click(function(e) {
var $target = $(e.target);
if (!$target.length) { return; }
if ($target.is('.cp-comment-container')) { return; }
@ -903,21 +895,21 @@ define([
Env.$container.find('.cp-comment-form').remove();
});
// Unselect comment when clicking on another part of the doc
Env.$inner.on('click', function (e) {
Env.$inner.on('click', function(e) {
if ($(e.target).closest('comment').length) { return; }
Env.$container.find('.cp-comment-active').removeClass('cp-comment-active');
Env.$inner.find('comment.active').removeClass('active');
Env.$container.find('.cp-comment-form').remove();
});
Env.$inner.on('click', 'comment', function (e) {
Env.$inner.on('click', 'comment', function(e) {
var $comment = $(e.target);
var uid = $comment.attr('data-uid');
if (!uid) { return; }
Env.$container.find('.cp-comment-container[data-uid="'+uid+'"]').click();
Env.$container.find('.cp-comment-container[data-uid="' + uid + '"]').click();
});
var call = function (f) {
return function () {
var call = function(f) {
return function() {
try {
[].unshift.call(arguments, Env);
return f.apply(null, arguments);

@ -1,7 +1,7 @@
require(['/api/config'], function (ApiConfig) {
require(['/api/config'], function(ApiConfig) {
// see ckeditor_base.js getUrl()
window.CKEDITOR_GETURL = function (resource) {
if (resource.indexOf( '/' ) === 0) {
window.CKEDITOR_GETURL = function(resource) {
if (resource.indexOf('/') === 0) {
resource = window.CKEDITOR.basePath.replace(/\/bower_components\/.*/, '') + resource;
} else if (resource.indexOf(':/') === -1) {
resource = window.CKEDITOR.basePath + resource;
@ -44,7 +44,7 @@ define([
'css!/bower_components/bootstrap/dist/css/bootstrap.min.css',
'css!/bower_components/components-font-awesome/css/font-awesome.min.css',
'less!/pad/app-pad.less'
], function (
], function(
$,
Hyperjson,
Framework,
@ -65,16 +65,15 @@ define([
ChainPad,
AppConfig,
Test
)
{
) {
var DiffDom = window.diffDOM;
var slice = function (coll) {
var slice = function(coll) {
return Array.prototype.slice.call(coll);
};
var removeListeners = function (root) {
slice(root.attributes).map(function (attr) {
var removeListeners = function(root) {
slice(root.attributes).map(function(attr) {
if (/^on/.test(attr.name)) {
root.attributes.removeNamedItem(attr.name);
}
@ -82,7 +81,7 @@ define([
slice(root.children).forEach(removeListeners);
};
var hjsonToDom = function (H) {
var hjsonToDom = function(H) {
var dom = Hyperjson.toDOM(H);
removeListeners(dom);
return dom;
@ -97,17 +96,17 @@ define([
// MEDIATAG: Filter elements to serialize
// * Remove the drag&drop and resizers from the hyperjson
var isWidget = function (el) {
return typeof (el.getAttribute) === "function" &&
(el.getAttribute('data-cke-hidden-sel') ||
(el.getAttribute('class') &&
(/cke_widget_drag/.test(el.getAttribute('class')) ||
/cke_image_resizer/.test(el.getAttribute('class')))
)
);
var isWidget = function(el) {
return typeof(el.getAttribute) === "function" &&
(el.getAttribute('data-cke-hidden-sel') ||
(el.getAttribute('class') &&
(/cke_widget_drag/.test(el.getAttribute('class')) ||
/cke_image_resizer/.test(el.getAttribute('class')))
)
);
};
var isNotMagicLine = function (el) {
var isNotMagicLine = function(el) {
return !(el && typeof(el.getAttribute) === 'function' &&
el.getAttribute('class') &&
el.getAttribute('class').split(' ').indexOf('non-realtime') !== -1);
@ -115,12 +114,12 @@ define([
var isCursor = Cursors.isCursor;
var shouldSerialize = function (el) {
var shouldSerialize = function(el) {
return isNotMagicLine(el) && !isWidget(el) && !isCursor(el);
};
// MEDIATAG: Filter attributes in the serialized elements
var widgetFilter = function (hj) {
var widgetFilter = function(hj) {
// Send a widget ID == 0 to avoid a fight between browsers and
// prevent the container from having the "selected" class (blue border)
if (hj[1].class) {
@ -137,7 +136,7 @@ define([
//hj[1]['data-cke-widget-id'] = "0";
}
// Remove the title attribute of the drag&drop icons (translation conflicts)
if (split.indexOf('cke_widget_drag_handler') !== -1 ||
if (split.indexOf('cke_widget_drag_handler') !== -1 ||
split.indexOf('cke_image_resizer') !== -1) {
hj[1].title = undefined;
}
@ -145,18 +144,18 @@ define([
return hj;
};
var hjsonFilters = function (hj) {
var hjsonFilters = function(hj) {
/* catch `type="_moz"` before it goes over the wire */
var brFilter = function (hj) {
var brFilter = function(hj) {
if (hj[1].type === '_moz') { hj[1].type = undefined; }
return hj;
};
var mediatagContentFilter = function (hj) {
var mediatagContentFilter = function(hj) {
if (hj[0] === 'MEDIA-TAG') { hj[2] = []; }
return hj;
};
var commentActiveFilter = function (hj) {
if (hj[0] === 'COMMENT') { delete (hj[1] || {}).class; }
var commentActiveFilter = function(hj) {
if (hj[0] === 'COMMENT') { delete(hj[1] || {}).class; }
return hj;
};
brFilter(hj);
@ -166,7 +165,7 @@ define([
return hj;
};
var domFromHTML = function (html) {
var domFromHTML = function(html) {
return new DOMParser().parseFromString(html, 'text/html');
};
@ -180,22 +179,22 @@ define([
];
var CKEDITOR_CHECK_INTERVAL = 100;
var ckEditorAvailable = function (cb) {
var ckEditorAvailable = function(cb) {
var intr;
var check = function () {
var check = function() {
if (window.CKEDITOR) {
clearTimeout(intr);
cb(window.CKEDITOR);
}
};
intr = setInterval(function () {
intr = setInterval(function() {
console.log("Ckeditor was not defined. Trying again in %sms", CKEDITOR_CHECK_INTERVAL);
check();
}, CKEDITOR_CHECK_INTERVAL);
check();
};
var mkHelpMenu = function (framework) {
var mkHelpMenu = function(framework) {
var $toolbarContainer = $('.cke_toolbox_main');
$toolbarContainer.before(framework._.sfCommon.getBurnAfterReadingWarning());
var helpMenu = framework._.sfCommon.createHelpMenu(['text', 'pad']);
@ -204,9 +203,9 @@ define([
framework._.toolbar.$drawer.append(helpMenu.button);
};
var mkDiffOptions = function (cursor, readOnly) {
var mkDiffOptions = function(cursor, readOnly) {
return {
preDiffApply: function (info) {
preDiffApply: function(info) {
/*
Don't accept attributes that begin with 'on'
these are probably listeners, and we don't want to
@ -257,15 +256,15 @@ define([
}
// CkEditor drag&drop icon container
if (info.node && info.node.tagName === 'SPAN' &&
info.node.getAttribute('class') &&
info.node.getAttribute('class').split(' ').indexOf('cke_widget_drag_handler_container') !== -1) {
info.node.getAttribute('class') &&
info.node.getAttribute('class').split(' ').indexOf('cke_widget_drag_handler_container') !== -1) {
return true;
}
// CkEditor drag&drop title (language fight)
if (info.node && info.node.getAttribute &&
info.node.getAttribute('class') &&
(info.node.getAttribute('class').split(' ').indexOf('cke_widget_drag_handler') !== -1 ||
info.node.getAttribute('class').split(' ').indexOf('cke_image_resizer') !== -1 ) ) {
info.node.getAttribute('class') &&
(info.node.getAttribute('class').split(' ').indexOf('cke_widget_drag_handler') !== -1 ||
info.node.getAttribute('class').split(' ').indexOf('cke_image_resizer') !== -1)) {
return true;
}
@ -287,15 +286,13 @@ define([
// Don't remote the "active" class of our comments
if (info.node && info.node.tagName === 'COMMENT') {
if (info.diff.action === 'removeAttribute' &&
['class'].indexOf(info.diff.name) !== -1) {
if (info.diff.action === 'removeAttribute' && ['class'].indexOf(info.diff.name) !== -1) {
return true;
}
}
if (info.node && info.node.tagName === 'BODY') {
if (info.diff.action === 'removeAttribute' &&
['class', 'spellcheck'].indexOf(info.diff.name) !== -1) {
if (info.diff.action === 'removeAttribute' && ['class', 'spellcheck'].indexOf(info.diff.name) !== -1) {
return true;
}
}
@ -343,50 +340,50 @@ define([
return true;
}
/*
cursor.update();
/*
cursor.update();
// no use trying to recover the cursor if it doesn't exist
if (!cursor.exists()) { return; }
// no use trying to recover the cursor if it doesn't exist
if (!cursor.exists()) { return; }
/* frame is either 0, 1, 2, or 3, depending on which
cursor frames were affected: none, first, last, or both
*/
/*
var frame = info.frame = cursor.inNode(info.node);
/* frame is either 0, 1, 2, or 3, depending on which
cursor frames were affected: none, first, last, or both
*/
/*
var frame = info.frame = cursor.inNode(info.node);
if (!frame) { return; }
if (!frame) { return; }
if (frame && typeof info.diff.oldValue === 'string' && typeof info.diff.newValue === 'string') {
//var pushes = cursor.pushDelta(info.diff.oldValue, info.diff.newValue);
var ops = ChainPad.Diff.diff(info.diff.oldValue, info.diff.newValue);
if (frame && typeof info.diff.oldValue === 'string' && typeof info.diff.newValue === 'string') {
//var pushes = cursor.pushDelta(info.diff.oldValue, info.diff.newValue);
var ops = ChainPad.Diff.diff(info.diff.oldValue, info.diff.newValue);
if (frame & 1) {
// push cursor start if necessary
cursor.transformRange(cursor.Range.start, ops);
}
if (frame & 2) {
// push cursor end if necessary
cursor.transformRange(cursor.Range.end, ops);
}
}
*/
if (frame & 1) {
// push cursor start if necessary
cursor.transformRange(cursor.Range.start, ops);
}
if (frame & 2) {
// push cursor end if necessary
cursor.transformRange(cursor.Range.end, ops);
}
}
*/
},
/*
postDiffApply: function (info) {
if (info.frame) {
if (info.node) {
if (info.frame & 1) { cursor.fixStart(info.node); }
if (info.frame & 2) { cursor.fixEnd(info.node); }
} else { console.error("info.node did not exist"); }
var sel = cursor.makeSelection();
var range = cursor.makeRange();
cursor.fixSelection(sel, range);
}
}
*/
/*
postDiffApply: function (info) {
if (info.frame) {
if (info.node) {
if (info.frame & 1) { cursor.fixStart(info.node); }
if (info.frame & 2) { cursor.fixEnd(info.node); }
} else { console.error("info.node did not exist"); }
var sel = cursor.makeSelection();
var range = cursor.makeRange();
cursor.fixSelection(sel, range);
}
}
*/
};
};
@ -394,30 +391,29 @@ define([
////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////
var addToolbarHideBtn = function (framework, $bar) {
var addToolbarHideBtn = function(framework, $bar) {
// Expand / collapse the toolbar
var cfg = {
element: $bar
};
var onClick = function (visible) {
var onClick = function(visible) {
framework._.sfCommon.setAttribute(['pad', 'showToolbar'], visible);
};
framework._.sfCommon.getAttribute(['pad', 'showToolbar'], function (err, data) {
if (($(window).height() >= 800 || $(window).width() >= 800) &&
(typeof(data) === "undefined" || data)) { $('.cke_toolbox_main').show(); }
else { $('.cke_toolbox_main').hide(); }
framework._.sfCommon.getAttribute(['pad', 'showToolbar'], function(err, data) {
if (($(window).height() >= 800 || $(window).width() >= 800) &&
(typeof(data) === "undefined" || data)) { $('.cke_toolbox_main').show(); } else { $('.cke_toolbox_main').hide(); }
var $collapse = framework._.sfCommon.createButton('toggle', true, cfg, onClick);
framework._.toolbar.$rightside.append($collapse);
});
};
var displayMediaTags = function (framework, dom, mediaTagMap) {
setTimeout(function () { // Just in case
var displayMediaTags = function(framework, dom, mediaTagMap) {
setTimeout(function() { // Just in case
var tags = dom.querySelectorAll('media-tag:empty');
Array.prototype.slice.call(tags).forEach(function (el) {
Array.prototype.slice.call(tags).forEach(function(el) {
MediaTag(el);
$(el).on('keydown', function (e) {
if ([8,46].indexOf(e.which) !== -1) {
$(el).on('keydown', function(e) {
if ([8, 46].indexOf(e.which) !== -1) {
$(el).remove();
framework.localChange();
}
@ -439,19 +435,19 @@ define([
});
};
var restoreMediaTags = function (tempDom, mediaTagMap) {
var restoreMediaTags = function(tempDom, mediaTagMap) {
var tags = tempDom.querySelectorAll('media-tag:empty');
Array.prototype.slice.call(tags).forEach(function (tag) {
Array.prototype.slice.call(tags).forEach(function(tag) {
var src = tag.getAttribute('src');
if (mediaTagMap[src]) {
mediaTagMap[src].forEach(function (n) {
mediaTagMap[src].forEach(function(n) {
tag.appendChild(n.cloneNode());
});
}
});
};
var andThen2 = function (editor, Ckeditor, framework) {
var andThen2 = function(editor, Ckeditor, framework) {
var mediaTagMap = {};
var $contentContainer = $('#cke_1_contents');
var $html = $('html');
@ -461,7 +457,7 @@ define([
}
var ml = editor._.magiclineBackdoor.that.line.$;
[ml, ml.parentElement].forEach(function (el) {
[ml, ml.parentElement].forEach(function(el) {
el.setAttribute('class', 'non-realtime');
});
@ -479,14 +475,14 @@ define([
var inner = window.inner = documentBody;
var $inner = $(inner);
var observer = new MutationObserver(function (muts) {
muts.forEach(function (mut) {
var observer = new MutationObserver(function(muts) {
muts.forEach(function(mut) {
if (mut.type === 'childList') {
var $a;
for (var i = 0; i < mut.addedNodes.length; i++) {
$a = $(mut.addedNodes[i]);
if ($a.is('p') && $a.find('> span:empty').length
&& $a.find('> br').length && $a.children().length === 2) {
if ($a.is('p') && $a.find('> span:empty').length &&
$a.find('> br').length && $a.children().length === 2) {
$a.find('> span').append($a.find('> br'));
}
}
@ -519,7 +515,7 @@ define([
// Display other users cursor
var cursors = Cursors.create(inner, hjsonToDom, cursor);
var openLink = function (e) {
var openLink = function(e) {
var el = e.currentTarget;
if (!el || el.nodeName !== 'A') { return; }
var href = el.getAttribute('href');
@ -530,7 +526,7 @@ define([
mkHelpMenu(framework);
framework._.sfCommon.getAttribute(['pad', 'width'], function (err, data) {
framework._.sfCommon.getAttribute(['pad', 'width'], function(err, data) {
var active = data || typeof(data) === "undefined";
if (active) {
$contentContainer.addClass('cke_body_width');
@ -539,50 +535,50 @@ define([
}
});
framework.onEditableChange(function (unlocked) {
framework.onEditableChange(function(unlocked) {
if (!framework.isReadOnly()) {
$inner.attr('contenteditable', '' + Boolean(unlocked));
}
$inner.css({ background: unlocked ? '#fff' : '#eee' });
});
framework.setMediaTagEmbedder(function ($mt) {
framework.setMediaTagEmbedder(function($mt) {
$mt.attr('contenteditable', 'false');
//$mt.attr('tabindex', '1');
//MEDIATAG
var element = new window.CKEDITOR.dom.element($mt[0]);
editor.insertElement(element);
editor.widgets.initOn( element, 'mediatag' );
editor.widgets.initOn(element, 'mediatag');
});
framework.setTitleRecommender(function () {
framework.setTitleRecommender(function() {
var text;
if (['h1', 'h2', 'h3'].some(function (t) {
var $header = $inner.find(t + ':first-of-type');
if ($header.length && $header.text()) {
text = $header.text();
return true;
}
})) { return text; }
if (['h1', 'h2', 'h3'].some(function(t) {
var $header = $inner.find(t + ':first-of-type');
if ($header.length && $header.text()) {
text = $header.text();
return true;
}
})) { return text; }
});
var DD = new DiffDom(mkDiffOptions(cursor, framework.isReadOnly()));
var cursorStopped = false;
var cursorTo;
var updateCursor = function () {
var updateCursor = function() {
if (cursorTo) { clearTimeout(cursorTo); }
// If we're receiving content
if (cursorStopped) { return void setTimeout(updateCursor, 100); }
cursorTo = setTimeout(function () {
cursorTo = setTimeout(function() {
framework.updateCursor();
}, 500); // 500ms to make sure it is sent after chainpad sync
};
// apply patches, and try not to lose the cursor in the process!
framework.onContentUpdate(function (hjson) {
framework.onContentUpdate(function(hjson) {
if (!Array.isArray(hjson)) { throw new Error(Messages.typeError); }
var userDocStateDom = hjsonToDom(hjson);
cursorStopped = true;
@ -598,7 +594,7 @@ define([
userDocStateDom.normalize();
inner.normalize();
$(userDocStateDom).find('span[data-cke-display-name="media-tag"]:empty').each(function (i, el) {
$(userDocStateDom).find('span[data-cke-display-name="media-tag"]:empty').each(function(i, el) {
$(el).remove();
});
@ -617,15 +613,15 @@ define([
var ops = ChainPad.Diff.diff(oldText, newText);
cursor.restoreOffset(ops);
setTimeout(function () {
setTimeout(function() {
cursorStopped = false;
updateCursor();
}, 200);
// MEDIATAG: Migrate old mediatags to the widget system
$inner.find('media-tag:not(.cke_widget_element)').each(function (i, el) {
$inner.find('media-tag:not(.cke_widget_element)').each(function(i, el) {
var element = new window.CKEDITOR.dom.element(el);
editor.widgets.initOn( element, 'mediatag' );
editor.widgets.initOn(element, 'mediatag');
});
displayMediaTags(framework, inner, mediaTagMap);
@ -642,19 +638,19 @@ define([
comments.onContentUpdate();
});
framework.setTextContentGetter(function () {
framework.setTextContentGetter(function() {
var innerCopy = inner.cloneNode(true);
displayMediaTags(framework, innerCopy, mediaTagMap);
innerCopy.normalize();
$(innerCopy).find('*').each(function (i, el) {
$(innerCopy).find('*').each(function(i, el) {
$(el).append(' ');
});
var str = $(innerCopy).text();
str = str.replace(/\s\s+/g, ' ');
return str;
});
framework.setContentGetter(function () {
$inner.find('span[data-cke-display-name="media-tag"]:empty').each(function (i, el) {
framework.setContentGetter(function() {
$inner.find('span[data-cke-display-name="media-tag"]:empty').each(function(i, el) {
$(el).remove();
});
@ -677,7 +673,7 @@ define([
$('.cke_toolbox_main').hide();
}
framework.onReady(function (newPad) {
framework.onReady(function(newPad) {
editor.focus();
if (!module.isMaximized) {
@ -700,7 +696,7 @@ define([
var fmConfig = {
ckeditor: editor,
body: $('body'),
onUploaded: function (ev, data) {
onUploaded: function(ev, data) {
var parsed = Hash.parsePadUrl(data.url);
var secret = Hash.getSecrets('file', parsed.hash, data.password);
var fileHost = privateData.fileHost || privateData.origin;
@ -714,39 +710,39 @@ define([
} else {
editor.insertElement(element);
}
editor.widgets.initOn( element, 'mediatag' );
editor.widgets.initOn(element, 'mediatag');
}
};
window.APP.FM = framework._.sfCommon.createFileManager(fmConfig);
framework._.sfCommon.getAttribute(['pad', 'spellcheck'], function (err, data) {
framework._.sfCommon.getAttribute(['pad', 'spellcheck'], function(err, data) {
if (framework.isReadOnly()) { return; }
if (data) {
$iframe.find('body').attr('spellcheck', true);
}
});
framework._.sfCommon.isPadStored(function (err, val) {
framework._.sfCommon.isPadStored(function(err, val) {
if (!val) { return; }
var b64images = $inner.find('img[src^="data:image"]:not(.cke_reset)');
if (b64images.length && framework._.sfCommon.isLoggedIn()) {
var no = h('button.cp-corner-cancel', Messages.cancel);
var yes = h('button.cp-corner-primary', Messages.ok);
var actions = h('div', [no, yes]);
var modal = UI.cornerPopup(Messages.pad_base64, actions, '', {big: true});
$(no).click(function () {
var modal = UI.cornerPopup(Messages.pad_base64, actions, '', { big: true });
$(no).click(function() {
modal.delete();
});
$(yes).click(function () {
$(yes).click(function() {
modal.delete();
b64images.each(function (i, el) {
b64images.each(function(i, el) {
var src = $(el).attr('src');
var blob = Util.dataURIToBlob(src);
var ext = '.' + (blob.type.split('/')[1] || 'png');
var name = (framework._.title.getTitle() || 'Pad')+'_image';
var name = (framework._.title.getTitle() || 'Pad') + '_image';
blob.name = name + ext;
var ev = {
insertElement: function (newEl) {
insertElement: function(newEl) {
var element = new window.CKEDITOR.dom.element(el);
newEl.replace(element);
setTimeout(framework.localChange);
@ -769,34 +765,34 @@ define([
});*/
});
framework.onDefaultContentNeeded(function () {
framework.onDefaultContentNeeded(function() {
inner.innerHTML = '<p></p>';
});
var importMediaTags = function (dom, cb) {
var importMediaTags = function(dom, cb) {
var $dom = $(dom);
$dom.find('media-tag').each(function (i, el) {
$dom.find('media-tag').each(function(i, el) {
$(el).empty();
});
cb($dom[0]);
};
framework.setFileImporter({ accept: 'text/html' }, function (content, f, cb) {
importMediaTags(domFromHTML(content).body, function (dom) {
framework.setFileImporter({ accept: 'text/html' }, function(content, f, cb) {
importMediaTags(domFromHTML(content).body, function(dom) {
cb(Hyperjson.fromDOM(dom));
});
}, true);
framework.setFileExporter(Exporter.ext, function (cb) {
framework.setFileExporter(Exporter.ext, function(cb) {
Exporter.main(inner, cb);
}, true);
framework.setNormalizer(function (hjson) {
framework.setNormalizer(function(hjson) {
return [
'BODY',
{
"class": "cke_editable cke_editable_themed cke_contents_ltr cke_show_borders",
"contenteditable": "true",
"spellcheck":"false"
"spellcheck": "false"
},
hjson[2]
];
@ -829,7 +825,7 @@ define([
The solution is the "input" event, triggered by the browser as soon as the
character is inserted.
*/
inner.addEventListener('input', function () {
inner.addEventListener('input', function() {
framework.localChange();
updateCursor();
editor.fire('cp-wc'); // Update word count
@ -838,8 +834,8 @@ define([
var wordCount = h('span.cp-app-pad-wordCount');
$('.cke_toolbox_main').append(wordCount);
editor.on('cp-wc-update', function () {
if (!editor.wordCount || typeof (editor.wordCount.wordCount) === "undefined") {
editor.on('cp-wc-update', function() {
if (!editor.wordCount || typeof(editor.wordCount.wordCount) === "undefined") {
wordCount.innerText = '';
return;
}
@ -849,7 +845,7 @@ define([
// export the typing tests to the window.
// call like `test = easyTest()`
// terminate the test like `test.cancel()`
window.easyTest = function () {
window.easyTest = function() {
cursor.update();
//var start = cursor.Range.start;
//var test = TypingTest.testInput(inner, start.el, start.offset, framework.localChange);
@ -861,18 +857,18 @@ define([
// Fix the scrollbar if it's reset when clicking on a button (firefox only?)
var buttonScrollTop;
$('.cke_toolbox_main').find('.cke_button, .cke_combo_button').mousedown(function () {
$('.cke_toolbox_main').find('.cke_button, .cke_combo_button').mousedown(function() {
buttonScrollTop = $('iframe').contents().scrollTop();
setTimeout(function () {
setTimeout(function() {
$('iframe').contents().scrollTop(buttonScrollTop);
});
});
$('.cke_toolbox_main').find('.cke_button').click(function () {
$('.cke_toolbox_main').find('.cke_button').click(function() {
var e = this;
var classString = e.getAttribute('class');
var classes = classString.split(' ').filter(function (c) {
var classes = classString.split(' ').filter(function(c) {
return /cke_button__/.test(c);
});
@ -885,12 +881,12 @@ define([
framework.start();
};
var main = function () {
var main = function() {
var Ckeditor;
var editor;
var framework;
nThen(function (waitFor) {
nThen(function(waitFor) {
Framework.create({
toolbarContainer: '#cp-app-pad-toolbar',
contentContainer: '#cp-app-pad-editor',
@ -917,15 +913,15 @@ define([
module.cursor.fixSelection(sel, range);
}
}*/
}, waitFor(function (fw) { window.APP.framework = framework = fw; }));
}, waitFor(function(fw) { window.APP.framework = framework = fw; }));
nThen(function (waitFor) {
ckEditorAvailable(waitFor(function (ck) {
nThen(function(waitFor) {
ckEditorAvailable(waitFor(function(ck) {
Ckeditor = ck;
require(['/pad/wysiwygarea-plugin.js'], waitFor());
}));
$(waitFor());
}).nThen(function (waitFor) {
}).nThen(function(waitFor) {
Ckeditor.config.toolbarCanCollapse = true;
if (screen.height < 800) {
Ckeditor.config.toolbarStartupExpanded = false;
@ -947,20 +943,19 @@ define([
'import': Messages.pad_mediatagImport,
options: Messages.pad_mediatagOptions
};
Messages.comments_comment = "COMMENT"; // XXX
Ckeditor._commentsTranslations = {
comment: Messages.comments_comment,
};
Ckeditor.plugins.addExternal('mediatag','/pad/', 'mediatag-plugin.js');
Ckeditor.plugins.addExternal('blockbase64','/pad/', 'disable-base64.js');
Ckeditor.plugins.addExternal('comments','/pad/', 'comment.js');
Ckeditor.plugins.addExternal('wordcount','/pad/wordcount/', 'plugin.js');
Ckeditor.plugins.addExternal('mediatag', '/pad/', 'mediatag-plugin.js');
Ckeditor.plugins.addExternal('blockbase64', '/pad/', 'disable-base64.js');
Ckeditor.plugins.addExternal('comments', '/pad/', 'comment.js');
Ckeditor.plugins.addExternal('wordcount', '/pad/wordcount/', 'plugin.js');
module.ckeditor = editor = Ckeditor.replace('editor1', {
customConfig: '/customize/ckeditor-config.js',
});
editor.addCommand('pagemode', {
exec: function () {
exec: function() {
if (!framework) { return; }
var $contentContainer = $('#cke_1_contents');
var $button = $('.cke_button__pagemode');
@ -983,12 +978,12 @@ define([
});
editor.on('instanceReady', waitFor());
}).nThen(function () {
editor.plugins.mediatag.import = function ($mt) {
}).nThen(function() {
editor.plugins.mediatag.import = function($mt) {
framework._.sfCommon.importMediaTag($mt);
};
Links.init(Ckeditor, editor);
}).nThen(function () {
}).nThen(function() {
// Move ckeditor parts to have a structure like the other apps
var $contentContainer = $('#cke_1_contents');
var $mainContainer = $('#cke_editor1 > .cke_inner');
@ -998,19 +993,19 @@ define([
$ckeToolbar.find('.cke_button__image_icon').parent().hide();
}).nThen(waitFor());
}).nThen(function (/*waitFor*/) {
}).nThen(function( /*waitFor*/ ) {
function launchAnchorTest(test) {
// -------- anchor test: make sure the exported anchor contains <a name="..."> -------
console.log('---- anchor test: make sure the exported anchor contains <a name="..."> -----.');
function tryAndTestExport() {
console.log("Starting tryAndTestExport.");
editor.on( 'dialogShow', function( evt ) {
editor.on('dialogShow', function(evt) {
console.log("Anchor dialog detected.");
var dialog = evt.data;
$(dialog.parts.contents.$).find("input").val('xx-' + Math.round(Math.random()*1000));
$(dialog.parts.contents.$).find("input").val('xx-' + Math.round(Math.random() * 1000));
dialog.click(window.CKEDITOR.dialog.okButton(editor).id);
} );
});
var existingText = editor.getData();
editor.insertText("A bit of text");
console.log("Launching anchor command.");
@ -1020,46 +1015,45 @@ define([
var waitH = window.setInterval(function() {
console.log("Waited 2s for the dialog to appear");
var anchors = window.CKEDITOR.plugins["link"].getEditorAnchors(editor);
if(!anchors || anchors.length===0) {
if (!anchors || anchors.length === 0) {
test.fail("No anchors found. Please adjust document");
} else {
console.log(anchors.length + " anchors found.");
var exported = Exporter.getHTML(window.inner);
console.log("Obtained exported: " + exported);
var allFound = true;
for(var i=0; i<anchors.length; i++) {
for (var i = 0; i < anchors.length; i++) {
var anchor = anchors[i];
console.log("Anchor " + anchor.name);
var expected = "<a id=\"" + anchor.id + "\" name=\"" + anchor.name + "\" ";
var found = exported.indexOf(expected)>=0;
var found = exported.indexOf(expected) >= 0;
console.log("Found " + expected + " " + found + ".");
allFound = allFound && found;
}
console.log("Cleaning up.");
if(allFound) {
if (allFound) {
// clean-up
editor.execCommand('undo');
editor.execCommand('undo');
var nint = window.setInterval(function(){
var nint = window.setInterval(function() {
console.log("Waiting for undo to yield same result.");
if(existingText === editor.getData()) {
if (existingText === editor.getData()) {
window.clearInterval(nint);
test.pass();
}
}, 500);
} else
{
} else {
test.fail("Not all expected a elements found for document at " + window.top.location + ".");
}
}
window.clearInterval(waitH);
},2000);
}, 2000);
}
var intervalHandle = window.setInterval(function() {
if(editor.status==="ready") {
if (editor.status === "ready") {
window.clearInterval(intervalHandle);
console.log("Editor is ready.");
tryAndTestExport();
@ -1076,4 +1070,4 @@ define([
});
};
main();
});
});

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save