diff --git a/.jshintignore b/.jshintignore index aab1b485b..7b013e0da 100644 --- a/.jshintignore +++ b/.jshintignore @@ -11,6 +11,7 @@ www/common/hyperscript.js www/common/tippy.min.js www/pad/wysiwygarea-plugin.js -www/pad2/wysiwygarea-plugin.js +www/pad/mediatag-plugin.js +www/pad/mediatag-plugin-dialog.js www/common/media-tag-nacl.min.js diff --git a/bower.json b/bower.json index 24461eae7..af5560bf6 100644 --- a/bower.json +++ b/bower.json @@ -21,7 +21,7 @@ "jquery": "~2.1.3", "tweetnacl": "0.12.2", "components-font-awesome": "^4.6.3", - "ckeditor": "~4.7", + "ckeditor": "4.7.3", "codemirror": "^5.19.0", "requirejs": "2.3.5", "marked": "0.3.5", diff --git a/customize.dist/ckeditor-config.js b/customize.dist/ckeditor-config.js index aa551953e..3dc280116 100644 --- a/customize.dist/ckeditor-config.js +++ b/customize.dist/ckeditor-config.js @@ -10,7 +10,7 @@ CKEDITOR.editorConfig = function( config ) { // document itself and causes problems when it's sent across the wire and reflected back config.removePlugins= 'resize,elementspath'; config.resize_enabled= false; //bottom-bar - config.extraPlugins= 'autolink,colorbutton,colordialog,font,indentblock,justify'; + config.extraPlugins= 'autolink,colorbutton,colordialog,font,indentblock,justify,mediatag'; config.toolbarGroups= [ // {"name":"clipboard","groups":["clipboard","undo"]}, //{"name":"editing","groups":["find","selection"]}, diff --git a/customize.dist/messages.js b/customize.dist/messages.js index 2f31a516e..916afe135 100644 --- a/customize.dist/messages.js +++ b/customize.dist/messages.js @@ -15,6 +15,7 @@ var map = { var getStoredLanguage = function () { return localStorage.getItem(LS_LANG); }; var getBrowserLanguage = function () { return navigator.language || navigator.userLanguage; }; var getLanguage = function () { + if (window.cryptpadLanguage) { return window.cryptpadLanguage; } if (getStoredLanguage()) { return getStoredLanguage(); } var l = getBrowserLanguage() || ''; if (Object.keys(map).indexOf(l) !== -1) { diff --git a/customize.dist/pages.js b/customize.dist/pages.js index 6cebaec88..070788dc4 100644 --- a/customize.dist/pages.js +++ b/customize.dist/pages.js @@ -570,69 +570,66 @@ define([ }; var appToolbar = function () { - return h('div#toolbar.toolbar-container'); + return h('div#cp-toolbar.cp-toolbar-container'); }; Pages['/whiteboard/'] = Pages['/whiteboard/index.html'] = function () { return [ appToolbar(), - h('div#canvas-area', h('canvas#canvas', { + h('div#cp-app-whiteboard-canvas-area', h('canvas#cp-app-whiteboard-canvas', { width: 600, height: 600 })), - h('div#controls', { + h('div#cp-app-whiteboard-controls', { style: { display: 'block', } }, [ - h('button#clear.btn.btn-danger', Msg.canvas_clear), ' ', - h('button#toggleDraw.btn.btn-secondary', Msg.canvas_disable), - h('button#delete.btn.btn-secondary', { + h('button#cp-app-whiteboard-clear.btn.btn-danger', Msg.canvas_clear), ' ', + h('button#cp-app-whiteboard-toggledraw.btn.btn-secondary', Msg.canvas_disable), + h('button#cp-app-whiteboard-delete.btn.btn-secondary', { style: { display: 'none', } }, Msg.canvas_delete), - h('div.range-group', [ + h('div.cp-app-whiteboard-range-group', [ h('label', { - 'for': 'width' + 'for': 'cp-app-whiteboard-width' }, Msg.canvas_width), - h('input#width', { + h('input#cp-app-whiteboard-width', { type: 'range', - value: "5", min: "1", max: "100" }), - h('span#width-val', '5px') + h('span#cp-app-whiteboard-width-val', '5px') ]), - h('div.range-group', [ + h('div.cp-app-whiteboard-range-group', [ h('label', { - 'for': 'opacity', + 'for': 'cp-app-whiteboard-opacity', }, Msg.canvas_opacity), - h('input#opacity', { + h('input#cp-app-whiteboard-opacity', { type: 'range', - value: "1", min: "0.1", max: "1", step: "0.1" }), - h('span#opacity-val', '100%') + h('span#cp-app-whiteboard-opacity-val', '100%') ]), - h('span.selected', [ + h('span.cp-app-whiteboard-selected.cp-app-whiteboard-unselectable', [ h('img', { title: Msg.canvas_currentBrush }) ]) ]), - setHTML(h('div#colors'), ' '), - loadingScreen(), - h('div#cursors', { + setHTML(h('div#cp-app-whiteboard-colors'), ' '), + h('div#cp-app-whiteboard-cursors', { style: { display: 'none', background: 'white', 'text-align': 'center', } }), - h('div#pickers'), + h('div#cp-app-whiteboard-pickers'), ]; }; @@ -683,8 +680,7 @@ define([ ]) ]) ]) - ]), - loadingScreen() + ]) ]; }; diff --git a/customize.dist/src/less2/include/fileupload.less b/customize.dist/src/less2/include/fileupload.less index bd90ab5d3..a07d365bd 100644 --- a/customize.dist/src/less2/include/fileupload.less +++ b/customize.dist/src/less2/include/fileupload.less @@ -28,6 +28,11 @@ td { padding: @upload_pad_h @upload_pad_v; } + .cp-fileupload-table-link { + .fa { + margin-right: 5px; + } + } .cp-fileupload-table-progress { width: 200px; position: relative; diff --git a/customize.dist/src/less2/include/font.less b/customize.dist/src/less2/include/font.less index b1fdd0b19..33eb3dd3d 100644 --- a/customize.dist/src/less2/include/font.less +++ b/customize.dist/src/less2/include/font.less @@ -1,7 +1,7 @@ .font_neuropolitical () { @font-face { font-family: Neuropolitical; - src: url(./customize/fonts/neuropolitical.ttf) + src: url(/customize/fonts/neuropolitical.ttf) } } .font_open-sans () { diff --git a/customize.dist/src/less2/include/tokenfield.less b/customize.dist/src/less2/include/tokenfield.less index 2479e3330..da048b2fe 100644 --- a/customize.dist/src/less2/include/tokenfield.less +++ b/customize.dist/src/less2/include/tokenfield.less @@ -13,11 +13,12 @@ height: auto; min-height: 34px; padding-bottom: 0px; - &.focus { - border-color: #66afe9; - outline: 0; - box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 8px rgba(102, 175, 233, 0.6); - } + background-color: unset; + border: none; + display: flex; + flex-wrap: wrap; + align-items: center; + padding: 0 10px; .token { box-sizing: border-box; border-radius: 3px; @@ -25,8 +26,9 @@ border: 1px solid #d9d9d9; background-color: #ededed; white-space: nowrap; - margin: -1px 5px 5px 0; - vertical-align: center; + margin: 10px 5px; + height: 24px; + vertical-align: middle; cursor: default; color: #222; @@ -50,17 +52,17 @@ overflow: hidden; text-overflow: ellipsis; padding-left: 4px; - vertical-align: center; + vertical-align: middle; } .close { font-family: Arial; display: inline-block; - line-height: 100%; + line-height: 24px; font-size: 1.1em; margin-left: 5px; float: none; height: 100%; - vertical-align: center; + vertical-align: middle; padding-right: 4px; } &.active { @@ -73,11 +75,10 @@ } .token-input { background: none; - width: 0%; //60px; - min-width: 60px; + flex: 1; border: 0; padding: 0; - margin-bottom: 6px; + margin: 0 !important; // Override alertify box-shadow: none; max-width: 100%; &:focus { @@ -86,9 +87,5 @@ box-shadow: none; } } - &.disabled { - cursor: not-allowed; - background-color: #eeeeee; - } } } diff --git a/customize.dist/src/less2/include/toolbar-history.less b/customize.dist/src/less2/include/toolbar-history.less index 1a099bb76..0388f6401 100644 --- a/customize.dist/src/less2/include/toolbar-history.less +++ b/customize.dist/src/less2/include/toolbar-history.less @@ -1,7 +1,7 @@ @import (once) "./colortheme.less"; .history_main () { - body .cp-toolbar-history { + .cp-toolbar-history { display: none; text-align: center; * { diff --git a/customize.dist/src/less2/include/toolbar.less b/customize.dist/src/less2/include/toolbar.less index 366d24be4..d4b6fcebf 100644 --- a/customize.dist/src/less2/include/toolbar.less +++ b/customize.dist/src/less2/include/toolbar.less @@ -658,6 +658,14 @@ } } } + p.cp-toolbar-account { + &> span { + font-weight: bold; + span { + font-weight: normal; + } + } + } .cp-toolbar-backup { margin: 0; border-radius: 0; diff --git a/customize.dist/src/less2/main.less b/customize.dist/src/less2/main.less index 1fcd30815..b2f32baec 100644 --- a/customize.dist/src/less2/main.less +++ b/customize.dist/src/less2/main.less @@ -27,4 +27,6 @@ body.cp-app-code { @import "../../../code/app-code.less"; } body.cp-app-slide { @import "../../../slide/app-slide.less"; } body.cp-app-file { @import "../../../file/app-file.less"; } body.cp-app-filepicker { @import "../../../filepicker/app-filepicker.less"; } +//body.cp-app-poll { @import "../../../poll/app-poll.less"; } +body.cp-app-whiteboard { @import "../../../whiteboard/app-whiteboard.less"; } diff --git a/customize.dist/translations/messages.fr.js b/customize.dist/translations/messages.fr.js index db0ebbf9f..118eb6f7b 100644 --- a/customize.dist/translations/messages.fr.js +++ b/customize.dist/translations/messages.fr.js @@ -157,6 +157,10 @@ define(function () { out.filePicker_filter = "Filtrez les fichiers par leur nom"; out.or = 'ou'; + out.tags_title = "Mots-clés du pad"; + out.tags_add = "Modifier les mots-clés du pad"; + out.tags_duplicate = "Mot-clé déjà présent : {0}"; + out.slideOptionsText = "Options"; out.slideOptionsTitle = "Personnaliser la présentation"; out.slideOptionsButton = "Enregistrer (Entrée)"; @@ -204,8 +208,11 @@ define(function () { out.history_restoreDone = "Document restauré"; out.history_version = "Version :"; - // Ckeditor links + // Ckeditor out.openLinkInNewTab = "Ouvrir le lien dans un nouvel onglet"; + out.pad_mediatagTitle = "Options du Media-Tag"; + out.pad_mediatagWidth = "Largeur (px)"; + out.pad_mediatagHeight = "Hauteur (px)"; // Polls @@ -363,6 +370,8 @@ define(function () { out.fm_error_cantPin = "Erreur interne du serveur. Veuillez recharger la page et essayer de nouveau."; out.fm_viewListButton = "Liste"; out.fm_viewGridButton = "Grille"; + out.fm_renamedPad = "Vous avez renommé ce pad dans votre Drive. Son titre est:
{0}"; + out.fm_prop_tagsList = "Mots-clés"; // File - Context menu out.fc_newfolder = "Nouveau dossier"; out.fc_rename = "Renommer"; diff --git a/customize.dist/translations/messages.js b/customize.dist/translations/messages.js index 6a6becf5b..fc7c204d9 100644 --- a/customize.dist/translations/messages.js +++ b/customize.dist/translations/messages.js @@ -159,6 +159,10 @@ define(function () { out.filePicker_filter = "Filter files by name"; out.or = 'or'; + out.tags_title = "Tags"; + out.tags_add = "Update this pad's tags"; + out.tags_duplicate = "Duplicate tag: {0}"; + out.slideOptionsText = "Options"; out.slideOptionsTitle = "Customize your slides"; out.slideOptionsButton = "Save (enter)"; @@ -206,8 +210,11 @@ define(function () { out.history_restoreDone = "Document restored"; out.history_version = "Version:"; - // Ckeditor links + // Ckeditor out.openLinkInNewTab = "Open Link in New Tab"; + out.pad_mediatagTitle = "Media-Tag settings"; + out.pad_mediatagWidth = "Width (px)"; + out.pad_mediatagHeight = "Height (px)"; // Polls @@ -364,6 +371,8 @@ define(function () { out.fm_error_cantPin = "Internal server error. Please reload the page and try again."; out.fm_viewListButton = "List view"; out.fm_viewGridButton = "Grid view"; + out.fm_renamedPad = "You've set a custom name for this pad. Its shared title is:
{0}"; + out.fm_prop_tagsList = "Tags"; // File - Context menu out.fc_newfolder = "New folder"; out.fc_rename = "Rename"; diff --git a/www/code/app-code.less b/www/code/app-code.less index 8772a2653..d625da0da 100644 --- a/www/code/app-code.less +++ b/www/code/app-code.less @@ -3,10 +3,12 @@ @import (once) "../../customize/src/less2/include/markdown.less"; @import (once) '../../customize/src/less2/include/fileupload.less'; @import (once) '../../customize/src/less2/include/alertify.less'; +@import (once) '../../customize/src/less2/include/tokenfield.less'; .toolbar_main(); .fileupload_main(); .alertify_main(); +.tokenfield_main(); // body &.cp-app-code { diff --git a/www/code/inner.html b/www/code/inner.html index 485e06455..2ac5b56f8 100644 --- a/www/code/inner.html +++ b/www/code/inner.html @@ -2,7 +2,7 @@ - + diff --git a/www/media/assets/image.png-encrypted b/www/media/assets/image.png-encrypted deleted file mode 100644 index 634bb90f2..000000000 Binary files a/www/media/assets/image.png-encrypted and /dev/null differ diff --git a/www/media/index.html b/www/media/index.html deleted file mode 100644 index 1f8f2dcb1..000000000 --- a/www/media/index.html +++ /dev/null @@ -1,47 +0,0 @@ - - - - CryptPad - - - - - - - - - - -
-
- -
- -
-

-
-
- - diff --git a/www/media/inner.html b/www/media/inner.html deleted file mode 100644 index 7d04259bb..000000000 --- a/www/media/inner.html +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - -
- - - - diff --git a/www/media/main.js b/www/media/main.js deleted file mode 100644 index c864ad7e4..000000000 --- a/www/media/main.js +++ /dev/null @@ -1,139 +0,0 @@ -define([ - 'jquery', - '/bower_components/chainpad-crypto/crypto.js', - '/bower_components/chainpad-netflux/chainpad-netflux.js', - '/common/toolbar.js', - '/common/cryptpad-common.js', - //'/common/visible.js', - //'/common/notify.js', - //'pdfjs-dist/build/pdf', - //'pdfjs-dist/build/pdf.worker', - '/bower_components/tweetnacl/nacl-fast.min.js', - '/bower_components/file-saver/FileSaver.min.js', -], function ($, Crypto, realtimeInput, Toolbar, Cryptpad /*, Visible, Notify*/) { - //var Messages = Cryptpad.Messages; - //var saveAs = window.saveAs; - //window.Nacl = window.nacl; - $(function () { - - var ifrw = $('#pad-iframe')[0].contentWindow; - var $iframe = $('#pad-iframe').contents(); - - Cryptpad.addLoadingScreen(); - - var andThen = function () { - var $bar = $iframe.find('.toolbar-container'); - var secret = Cryptpad.getSecrets(); - - if (!secret.keys) { throw new Error("You need a hash"); } // TODO - - var cryptKey = secret.keys && secret.keys.fileKeyStr; - var fileId = secret.channel; - var hexFileName = Cryptpad.base64ToHex(fileId); - // var type = "image/png"; - - var parsed = Cryptpad.parsePadUrl(window.location.href); - var defaultName = Cryptpad.getDefaultName(parsed); - - var getTitle = function () { - var pad = Cryptpad.getRelativeHref(window.location.href); - var fo = Cryptpad.getStore().getProxy().fo; - var data = fo.getFileData(pad); - return data ? data.title : undefined; - }; - - var updateTitle = function (newTitle) { - var title = document.title = newTitle; - $bar.find('.' + Toolbar.constants.title).find('span.title').text(title); - $bar.find('.' + Toolbar.constants.title).find('input').val(title); - }; - - var suggestName = function () { - return document.title || getTitle() || ''; - }; - - var renameCb = function (err, title) { - document.title = title; - }; - - var $mt = $iframe.find('#encryptedFile'); - $mt.attr('src', '/blob/' + hexFileName.slice(0,2) + '/' + hexFileName); - $mt.attr('data-crypto-key', 'cryptpad:'+cryptKey); - // $mt.attr('data-type', type); - - $(window.document).on('decryption', function (e) { - var decrypted = e.originalEvent; - var metadata = decrypted.metadata; - - if (decrypted.callback) { decrypted.callback(); } - //console.log(metadata); - //console.log(defaultName); - if (!metadata || metadata.name !== defaultName) { return; } - var title = document.title = metadata.name; - updateTitle(title || defaultName); - }) - .on('decryptionError', function (e) { - var error = e.originalEvent; - Cryptpad.alert(error.message); - }) - .on('decryptionProgress', function (e) { - var progress = e.originalEvent; - console.log(progress.percent); - }); - - require(['/common/media-tag.js'], function (MediaTag) { - var configTb = { - displayed: ['useradmin', 'share', 'newpad'], - ifrw: ifrw, - common: Cryptpad, - title: { - onRename: renameCb, - defaultName: defaultName, - suggestName: suggestName - }, - share: { - secret: secret, - channel: hexFileName - } - }; - Toolbar.create($bar, null, null, null, null, configTb); - - updateTitle(Cryptpad.initialName || getTitle() || defaultName); - - /** - * Allowed mime types that have to be set for a rendering after a decryption. - * - * @type {Array} - */ - var allowedMediaTypes = [ - 'image/png', - 'image/jpeg', - 'image/jpg', - 'image/gif', - 'audio/mp3', - 'audio/ogg', - 'audio/wav', - 'audio/webm', - 'video/mp4', - 'video/ogg', - 'video/webm', - 'application/pdf', - 'application/dash+xml', - 'download' - ]; - - MediaTag.CryptoFilter.setAllowedMediaTypes(allowedMediaTypes); - - MediaTag($mt[0]); - - Cryptpad.removeLoadingScreen(); - }); - }; - - Cryptpad.ready(function () { - andThen(); - Cryptpad.reportAppUsage(); - }); - - }); -}); diff --git a/www/oldcode/code.less b/www/oldcode/code.less deleted file mode 100644 index 36883f377..000000000 --- a/www/oldcode/code.less +++ /dev/null @@ -1,102 +0,0 @@ -@import "/customize/src/less/variables.less"; -@import "/customize/src/less/mixins.less"; -@import "/common/markdown.less"; -@import "/common/file-dialog.less"; - -html, body{ - height: 100%; - width: 100%; - padding: 0px; - margin: 0px; - overflow: hidden; - box-sizing: border-box; - position: relative; -} -body { - display: flex; - flex-flow: column; - max-height: 100%; - min-height: auto; -} - -@slideTime: 500ms; -.CodeMirror { - display: inline-block; - height: 100%; - width: 50%; - &.transition { - transition: width @slideTime, min-width @slideTime, max-width @slideTime; - } - min-width: 20%; - max-width: 80%; - resize: horizontal; - font-size: initial; -} -.CodeMirror.fullPage { - //min-width: 100%; - max-width: 100%; - resize: none; - flex: 1; -} -.CodeMirror-focused .cm-matchhighlight { - background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAAFklEQVQI12NgYGBgkKzc8x9CMDAwAAAmhwSbidEoSQAAAABJRU5ErkJggg==); - background-position: bottom; - background-repeat: repeat-x; -} -#editorContainer { - flex: 1; - display: flex; - flex-flow: row; - height: 100%; - overflow: hidden; -} -#previewContainer { - flex: 1; - padding: 5px 20px; - overflow: auto; - display: inline-block; - height: 100%; - border-left: 1px solid black; - box-sizing: border-box; - font-family: Calibri,Ubuntu,sans-serif; - word-wrap: break-word; - position: relative; - media-tag { - * { - max-width:100%; - } - iframe[type="application/pdf"] { - max-height:50vh; - } - } -} - -#preview { - max-width: 40vw; - margin: 1em auto; - - .markdown_preformatted-code; - .markdown_gfm-table(black); -} - -.cp-splitter { - position: absolute; - height: 100%; - width: 8px; - top: 0; - left: 0; - - cursor: col-resize; -} - -@media (max-width: @media-medium-screen) { - .CodeMirror { - flex: 1; - max-width: 100%; - resize: none; - } - #previewContainer { - display: none !important; - } -} - diff --git a/www/oldcode/index.html b/www/oldcode/index.html deleted file mode 100644 index 0f8824bd4..000000000 --- a/www/oldcode/index.html +++ /dev/null @@ -1,41 +0,0 @@ - - - - CryptPad - - - - - - - -
- -
diff --git a/www/oldcode/inner.html b/www/oldcode/inner.html deleted file mode 100644 index 99bec8d08..000000000 --- a/www/oldcode/inner.html +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - -
-
- -
-
- - - diff --git a/www/oldcode/inner.js b/www/oldcode/inner.js deleted file mode 100644 index f6b83beee..000000000 --- a/www/oldcode/inner.js +++ /dev/null @@ -1,40 +0,0 @@ -define([ - 'jquery', - - 'cm/lib/codemirror', - - 'less!/bower_components/components-font-awesome/css/font-awesome.min.css', - 'css!/bower_components/bootstrap/dist/css/bootstrap.min.css', - 'less!/code/code.less', - 'less!/customize/src/less/toolbar.less', - 'less!/customize/src/less/cryptpad.less', - - 'css!cm/lib/codemirror.css', - 'css!cm/addon/dialog/dialog.css', - 'css!cm/addon/fold/foldgutter.css', - - 'cm/mode/markdown/markdown', - 'cm/addon/mode/loadmode', - 'cm/mode/meta', - 'cm/addon/mode/overlay', - 'cm/addon/mode/multiplex', - 'cm/addon/mode/simple', - 'cm/addon/edit/closebrackets', - 'cm/addon/edit/matchbrackets', - 'cm/addon/edit/trailingspace', - 'cm/addon/selection/active-line', - 'cm/addon/search/search', - 'cm/addon/search/match-highlighter', - 'cm/addon/search/searchcursor', - 'cm/addon/dialog/dialog', - 'cm/addon/fold/foldcode', - 'cm/addon/fold/foldgutter', - 'cm/addon/fold/brace-fold', - 'cm/addon/fold/xml-fold', - 'cm/addon/fold/markdown-fold', - 'cm/addon/fold/comment-fold', - 'cm/addon/display/placeholder', -], function ($, CMeditor) { - window.CodeMirror = CMeditor; - $('.loading-hidden').removeClass('loading-hidden'); -}); diff --git a/www/oldcode/main.js b/www/oldcode/main.js deleted file mode 100644 index 53ca1c5d8..000000000 --- a/www/oldcode/main.js +++ /dev/null @@ -1,559 +0,0 @@ -define([ - 'jquery', - '/bower_components/chainpad-crypto/crypto.js', - '/bower_components/chainpad-netflux/chainpad-netflux.js', - '/bower_components/textpatcher/TextPatcher.js', - '/common/toolbar2.js', - 'json.sortify', - '/bower_components/chainpad-json-validator/json-ot.js', - '/common/cryptpad-common.js', - '/common/cryptget.js', - '/common/diffMarked.js', - - 'less!/bower_components/components-font-awesome/css/font-awesome.min.css', - 'less!/customize/src/less/cryptpad.less' -], function ($, Crypto, Realtime, TextPatcher, Toolbar, JSONSortify, JsonOT, Cryptpad, - Cryptget, DiffMd) { - var Messages = Cryptpad.Messages; - - var APP = window.APP = { - Cryptpad: Cryptpad, - }; - - $(function () { - Cryptpad.addLoadingScreen(); - - var ifrw = APP.ifrw = $('#pad-iframe')[0].contentWindow; - var stringify = function (obj) { - return JSONSortify(obj); - }; - - var toolbar; - var editor; - - var secret = Cryptpad.getSecrets(); - var readOnly = secret.keys && !secret.keys.editKeyStr; - if (!secret.keys) { - secret.keys = secret.key; - } - - var onConnectError = function () { - Cryptpad.errorLoadingScreen(Messages.websocketError); - }; - - var andThen = function (CMeditor) { - var $iframe = $('#pad-iframe').contents(); - var $contentContainer = $iframe.find('#editorContainer'); - var $previewContainer = $iframe.find('#previewContainer'); - var $preview = $iframe.find('#preview'); - $preview.click(function (e) { - if (!e.target) { return; } - var $t = $(e.target); - if ($t.is('a') || $t.parents('a').length) { - e.preventDefault(); - var $a = $t.is('a') ? $t : $t.parents('a').first(); - var href = $a.attr('href'); - window.open(href); - } - }); - - var CodeMirror = Cryptpad.createCodemirror(ifrw, Cryptpad, null, CMeditor); - $iframe.find('.CodeMirror').addClass('fullPage'); - editor = CodeMirror.editor; - - var setIndentation = APP.setIndentation = function (units, useTabs) { - if (typeof(units) !== 'number') { return; } - editor.setOption('indentUnit', units); - editor.setOption('tabSize', units); - editor.setOption('indentWithTabs', useTabs); - }; - - var indentKey = 'indentUnit'; - var useTabsKey = 'indentWithTabs'; - - var proxy = Cryptpad.getProxy(); - - var updateIndentSettings = APP.updateIndentSettings = function () { - var indentUnit = proxy.settings[indentKey]; - var useTabs = proxy.settings[useTabsKey]; - setIndentation( - typeof(indentUnit) === 'number'? indentUnit: 2, - typeof(useTabs) === 'boolean'? useTabs: false); - }; - - proxy.on('change', ['settings', indentKey], updateIndentSettings); - proxy.on('change', ['settings', useTabsKey], updateIndentSettings); - - var $bar = $('#pad-iframe')[0].contentWindow.$('#cme_toolbox'); - - var isHistoryMode = false; - - var setEditable = APP.setEditable = function (bool) { - if (readOnly && bool) { return; } - editor.setOption('readOnly', !bool); - }; - - var Title; - var UserList; - var Metadata; - - var config = { - initialState: '{}', - websocketURL: Cryptpad.getWebsocketURL(), - channel: secret.channel, - // our public key - validateKey: secret.keys.validateKey || undefined, - readOnly: readOnly, - crypto: Crypto.createEncryptor(secret.keys), - network: Cryptpad.getNetwork(), - transformFunction: JsonOT.validate, - }; - - var canonicalize = function (t) { return t.replace(/\r\n/g, '\n'); }; - - var setHistory = function (bool, update) { - isHistoryMode = bool; - setEditable(!bool); - if (!bool && update) { - config.onRemote(); - } - }; - - var initializing = true; - - var stringifyInner = function (textValue) { - var obj = { - content: textValue, - metadata: { - users: UserList.userData, - defaultTitle: Title.defaultTitle - } - }; - if (!initializing) { - obj.metadata.title = Title.title; - } - // set mode too... - obj.highlightMode = CodeMirror.highlightMode; - - // stringify the json and send it into chainpad - return stringify(obj); - }; - - var forceDrawPreview = function () { - try { - DiffMd.apply(DiffMd.render(editor.getValue()), $preview); - } catch (e) { console.error(e); } - }; - - var drawPreview = Cryptpad.throttle(function () { - if (CodeMirror.highlightMode !== 'markdown') { return; } - if (!$previewContainer.is(':visible')) { return; } - forceDrawPreview(); - }, 150); - - var onLocal = config.onLocal = function () { - if (initializing) { return; } - if (isHistoryMode) { return; } - if (readOnly) { return; } - - editor.save(); - - drawPreview(); - - var textValue = canonicalize(CodeMirror.$textarea.val()); - var shjson = stringifyInner(textValue); - - APP.patchText(shjson); - - if (APP.realtime.getUserDoc() !== shjson) { - console.error("realtime.getUserDoc() !== shjson"); - } - }; - - var mediaTagModes = [ - 'markdown', - 'html', - 'htmlembedded', - 'htmlmixed', - 'index.html', - 'php', - 'velocity', - 'xml', - ]; - - var onModeChanged = function (mode) { - var $codeMirror = $iframe.find('.CodeMirror'); - window.clearTimeout(APP.previewTo); - $codeMirror.addClass('transition'); - APP.previewTo = window.setTimeout(function () { - $codeMirror.removeClass('transition'); - }, 500); - if (mediaTagModes.indexOf(mode) !== -1) { - APP.$mediaTagButton.show(); - } else { APP.$mediaTagButton.hide(); } - - if (mode === "markdown") { - APP.$previewButton.show(); - Cryptpad.getPadAttribute('previewMode', function (e, data) { - if (e) { return void console.error(e); } - if (data !== false) { - $previewContainer.show(); - APP.$previewButton.addClass('active'); - $codeMirror.removeClass('fullPage'); - } - }); - return; - } - APP.$previewButton.hide(); - $previewContainer.hide(); - APP.$previewButton.removeClass('active'); - $codeMirror.addClass('fullPage'); - if (typeof(APP.updateIndentSettings) === 'function') { - APP.updateIndentSettings(); - } - }; - - config.onInit = function (info) { - UserList = Cryptpad.createUserList(info, config.onLocal, Cryptget, Cryptpad); - - var titleCfg = { getHeadingText: CodeMirror.getHeadingText }; - Title = Cryptpad.createTitle(titleCfg, config.onLocal, Cryptpad); - - Metadata = Cryptpad.createMetadata(UserList, Title, null, Cryptpad); - - var configTb = { - displayed: ['title', 'useradmin', 'spinner', 'lag', 'state', 'share', 'userlist', 'newpad', 'limit', 'upgrade'], - userList: UserList.getToolbarConfig(), - share: { - secret: secret, - channel: info.channel - }, - title: Title.getTitleConfig(), - common: Cryptpad, - readOnly: readOnly, - ifrw: ifrw, - realtime: info.realtime, - network: info.network, - $container: $bar, - $contentContainer: $contentContainer - }; - toolbar = APP.toolbar = Toolbar.create(configTb); - - Title.setToolbar(toolbar); - CodeMirror.init(config.onLocal, Title, toolbar); - - var $rightside = toolbar.$rightside; - var $drawer = toolbar.$drawer; - - var editHash; - if (!readOnly) { - editHash = Cryptpad.getEditHashFromKeys(info.channel, secret.keys); - } - - /* add a history button */ - var histConfig = { - onLocal: config.onLocal, - onRemote: config.onRemote, - setHistory: setHistory, - applyVal: function (val) { - var remoteDoc = JSON.parse(val || '{}').content; - editor.setValue(remoteDoc || ''); - editor.save(); - }, - $toolbar: $bar - }; - var $hist = Cryptpad.createButton('history', true, {histConfig: histConfig}); - $drawer.append($hist); - - /* save as template */ - if (!Cryptpad.isTemplate(window.location.href)) { - var templateObj = { - rt: info.realtime, - Crypt: Cryptget, - getTitle: Title.getTitle - }; - var $templateButton = Cryptpad.createButton('template', true, templateObj); - $rightside.append($templateButton); - } - - /* add an export button */ - var $export = Cryptpad.createButton('export', true, {}, CodeMirror.exportText); - $drawer.append($export); - - if (!readOnly) { - /* add an import button */ - var $import = Cryptpad.createButton('import', true, {}, CodeMirror.importText); - $drawer.append($import); - } - - /* add a forget button */ - var forgetCb = function (err) { - if (err) { return; } - setEditable(false); - }; - var $forgetPad = Cryptpad.createButton('forget', true, {}, forgetCb); - $rightside.append($forgetPad); - - var fileDialogCfg = { - $body: $iframe.find('body'), - onSelect: function (href) { - var parsed = Cryptpad.parsePadUrl(href); - var hexFileName = Cryptpad.base64ToHex(parsed.hashData.channel); - var src = '/blob/' + hexFileName.slice(0,2) + '/' + hexFileName; - var mt = ''; - editor.replaceSelection(mt); - }, - data: APP - }; - APP.$mediaTagButton = $('