remove // XXX related to translations

pull/1/head
David Benqué 5 years ago
parent 0eb89871cf
commit 09d1ddf825

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

@ -154,11 +154,6 @@ define([
selection.addRange(range); 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 cb = Util.once(_cb);
var userData = Env.metadataMgr.getUserData(); var userData = Env.metadataMgr.getUserData();
@ -783,8 +778,6 @@ define([
var applicable = Env.editor.plugins.comments.isApplicable(); var applicable = Env.editor.plugins.comments.isApplicable();
if (!applicable) { if (!applicable) {
// Abort if our selection contains a comment // Abort if our selection contains a comment
console.error("Can't add a comment here");
// XXX show error
UI.warn(Messages.comments_error); UI.warn(Messages.comments_error);
return; return;
} }

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

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