diff --git a/www/common/notifications.js b/www/common/notifications.js index 771a84c3c..44cdb9dfd 100644 --- a/www/common/notifications.js +++ b/www/common/notifications.js @@ -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 {1}'; // 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 {1}'; // 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) }; -}); +}); \ No newline at end of file diff --git a/www/pad/comments.js b/www/pad/comments.js index b3ead0a82..ac7ef6353 100644 --- a/www/pad/comments.js +++ b/www/pad/comments.js @@ -154,11 +154,6 @@ 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 cb = Util.once(_cb); var userData = Env.metadataMgr.getUserData(); @@ -783,8 +778,6 @@ 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.comments_error); return; } diff --git a/www/pad/inner.js b/www/pad/inner.js index c77b99713..2919d3991 100644 --- a/www/pad/inner.js +++ b/www/pad/inner.js @@ -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 = '

'; }); - 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 ------- console.log('---- anchor test: make sure the exported anchor contains -----.'); 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=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(); -}); +}); \ No newline at end of file diff --git a/www/settings/inner.js b/www/settings/inner.js index 9353b2c64..255670c27 100644 --- a/www/settings/inner.js +++ b/www/settings/inner.js @@ -20,7 +20,7 @@ define([ 'css!/bower_components/bootstrap/dist/css/bootstrap.min.css', 'css!/bower_components/components-font-awesome/css/font-awesome.min.css', 'less!/settings/app-settings.less', -], function ( +], function( $, Toolbar, nThen, @@ -36,8 +36,7 @@ define([ ApiConfig, Backup, Feedback - ) -{ +) { var saveAs = window.saveAs; var APP = window.APP = {}; @@ -88,7 +87,7 @@ define([ 'cp-settings-code-spellcheck', ], 'subscription': { - onClick: function () { + onClick: function() { var urls = common.getMetadataMgr().getPrivateData().accounts; window.open(urls.upgradeURL); Feedback.send('SUBSCRIPTION_BUTTON'); @@ -111,34 +110,34 @@ define([ var create = {}; var SPECIAL_HINTS_HANDLER = { - safeLinks: function () { - return $('', {'class': 'cp-sidebarlayout-description'}) + safeLinks: function() { + return $('', { 'class': 'cp-sidebarlayout-description' }) .html(Messages._getKey('settings_safeLinksHint', [''])); }, }; - var DEFAULT_HINT_HANDLER = function (safeKey) { - return $('', {'class': 'cp-sidebarlayout-description'}) - .text(Messages['settings_'+safeKey+'Hint'] || 'Coming soon...'); + var DEFAULT_HINT_HANDLER = function(safeKey) { + return $('', { 'class': 'cp-sidebarlayout-description' }) + .text(Messages['settings_' + safeKey + 'Hint'] || 'Coming soon...'); }; - var makeBlock = function (key, getter, full) { - var safeKey = key.replace(/-([a-z])/g, function (g) { return g[1].toUpperCase(); }); + var makeBlock = function(key, getter, full) { + var safeKey = key.replace(/-([a-z])/g, function(g) { return g[1].toUpperCase(); }); - create[key] = function () { - var $div = $('
', {'class': 'cp-settings-' + key + ' cp-sidebarlayout-element'}); + create[key] = function() { + var $div = $('
', { 'class': 'cp-settings-' + key + ' cp-sidebarlayout-element' }); if (full) { - $('