2017-06-27 20:25:02 +08:00
|
|
|
|
define([
|
2017-06-29 16:49:35 +08:00
|
|
|
|
'jquery',
|
2017-09-05 17:35:15 +08:00
|
|
|
|
'/common/diffMarked.js',
|
|
|
|
|
'/bower_components/nthen/index.js',
|
|
|
|
|
'/common/sframe-common.js',
|
2017-09-27 22:53:16 +08:00
|
|
|
|
'/common/sframe-app-framework.js',
|
2018-01-16 18:26:16 +08:00
|
|
|
|
'/common/sframe-common-codemirror.js',
|
2017-09-27 22:53:16 +08:00
|
|
|
|
'/common/common-util.js',
|
2017-11-13 23:32:40 +08:00
|
|
|
|
'/common/common-hash.js',
|
2017-09-27 22:53:16 +08:00
|
|
|
|
'/common/modes.js',
|
2018-10-06 00:05:39 +08:00
|
|
|
|
'/common/visible.js',
|
2018-11-22 21:45:12 +08:00
|
|
|
|
'/common/TypingTests.js',
|
2017-11-14 01:09:19 +08:00
|
|
|
|
'/customize/messages.js',
|
2017-07-04 18:37:24 +08:00
|
|
|
|
'cm/lib/codemirror',
|
2020-04-09 22:06:04 +08:00
|
|
|
|
'/bower_components/chainpad/chainpad.dist.js',
|
|
|
|
|
|
2017-07-04 18:37:24 +08:00
|
|
|
|
|
2017-07-03 16:55:25 +08:00
|
|
|
|
'css!cm/lib/codemirror.css',
|
|
|
|
|
'css!cm/addon/dialog/dialog.css',
|
|
|
|
|
'css!cm/addon/fold/foldgutter.css',
|
|
|
|
|
|
2018-01-18 22:04:06 +08:00
|
|
|
|
'cm/mode/gfm/gfm',
|
2017-07-04 18:37:24 +08:00
|
|
|
|
'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',
|
2017-09-05 17:35:15 +08:00
|
|
|
|
|
2018-07-14 21:15:23 +08:00
|
|
|
|
'less!/code/app-code.less'
|
|
|
|
|
|
2017-09-05 17:35:15 +08:00
|
|
|
|
], function (
|
|
|
|
|
$,
|
|
|
|
|
DiffMd,
|
|
|
|
|
nThen,
|
|
|
|
|
SFCommon,
|
2017-09-27 22:53:16 +08:00
|
|
|
|
Framework,
|
2018-01-16 18:26:16 +08:00
|
|
|
|
SFCodeMirror,
|
2017-09-27 22:53:16 +08:00
|
|
|
|
Util,
|
2017-11-13 23:32:40 +08:00
|
|
|
|
Hash,
|
2017-09-27 22:53:16 +08:00
|
|
|
|
Modes,
|
2018-10-06 00:05:39 +08:00
|
|
|
|
Visible,
|
2018-11-22 21:45:12 +08:00
|
|
|
|
TypingTest,
|
2017-11-14 01:09:19 +08:00
|
|
|
|
Messages,
|
2020-04-09 22:06:04 +08:00
|
|
|
|
CMeditor,
|
|
|
|
|
ChainPad)
|
2017-09-05 17:35:15 +08:00
|
|
|
|
{
|
2017-07-04 18:37:24 +08:00
|
|
|
|
window.CodeMirror = CMeditor;
|
2017-09-05 17:35:15 +08:00
|
|
|
|
|
2017-09-27 22:53:16 +08:00
|
|
|
|
var MEDIA_TAG_MODES = Object.freeze([
|
|
|
|
|
'markdown',
|
2018-03-01 18:23:16 +08:00
|
|
|
|
'gfm',
|
2017-09-27 22:53:16 +08:00
|
|
|
|
'html',
|
|
|
|
|
'htmlembedded',
|
|
|
|
|
'htmlmixed',
|
|
|
|
|
'index.html',
|
|
|
|
|
'php',
|
|
|
|
|
'velocity',
|
|
|
|
|
'xml',
|
|
|
|
|
]);
|
2017-09-08 00:56:58 +08:00
|
|
|
|
|
2018-12-06 23:43:48 +08:00
|
|
|
|
var mkPrintButton = function (framework, $content, $print) {
|
|
|
|
|
var $printButton = framework._.sfCommon.createButton('print', true);
|
|
|
|
|
$printButton.click(function () {
|
|
|
|
|
$print.html($content.html());
|
|
|
|
|
window.focus();
|
|
|
|
|
window.print();
|
|
|
|
|
framework.feedback('PRINT_CODE');
|
|
|
|
|
});
|
|
|
|
|
framework._.toolbar.$drawer.append($printButton);
|
|
|
|
|
};
|
2018-02-28 00:38:29 +08:00
|
|
|
|
var mkMarkdownTb = function (editor, framework) {
|
|
|
|
|
var $codeMirrorContainer = $('#cp-app-code-container');
|
|
|
|
|
var markdownTb = framework._.sfCommon.createMarkdownToolbar(editor);
|
|
|
|
|
$codeMirrorContainer.prepend(markdownTb.toolbar);
|
|
|
|
|
|
|
|
|
|
framework._.toolbar.$rightside.append(markdownTb.button);
|
|
|
|
|
|
|
|
|
|
var modeChange = function (mode) {
|
|
|
|
|
if (['markdown', 'gfm'].indexOf(mode) !== -1) { return void markdownTb.setState(true); }
|
|
|
|
|
markdownTb.setState(false);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
modeChange: modeChange
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
var mkHelpMenu = function (framework) {
|
|
|
|
|
var $codeMirrorContainer = $('#cp-app-code-container');
|
2020-01-10 00:30:15 +08:00
|
|
|
|
$codeMirrorContainer.prepend(framework._.sfCommon.getBurnAfterReadingWarning());
|
2018-03-08 22:39:46 +08:00
|
|
|
|
var helpMenu = framework._.sfCommon.createHelpMenu(['text', 'code']);
|
2018-02-28 00:38:29 +08:00
|
|
|
|
$codeMirrorContainer.prepend(helpMenu.menu);
|
|
|
|
|
|
2018-03-01 00:59:27 +08:00
|
|
|
|
framework._.toolbar.$drawer.append(helpMenu.button);
|
2018-02-28 00:38:29 +08:00
|
|
|
|
};
|
2017-10-19 20:39:38 +08:00
|
|
|
|
var mkPreviewPane = function (editor, CodeMirror, framework, isPresentMode) {
|
2017-09-05 17:35:15 +08:00
|
|
|
|
var $previewContainer = $('#cp-app-code-preview');
|
|
|
|
|
var $preview = $('#cp-app-code-preview-content');
|
2017-10-19 20:39:38 +08:00
|
|
|
|
var $editorContainer = $('#cp-app-code-editor');
|
2017-11-27 19:17:35 +08:00
|
|
|
|
var $codeMirrorContainer = $('#cp-app-code-container');
|
2017-09-27 22:53:16 +08:00
|
|
|
|
var $codeMirror = $('.CodeMirror');
|
2017-10-19 20:39:38 +08:00
|
|
|
|
|
2018-02-28 00:38:29 +08:00
|
|
|
|
$('<img>', {
|
|
|
|
|
src: '/customize/main-favicon.png',
|
|
|
|
|
alt: '',
|
|
|
|
|
class: 'cp-app-code-preview-empty'
|
|
|
|
|
}).appendTo($previewContainer);
|
2017-10-19 20:39:38 +08:00
|
|
|
|
|
2018-03-01 21:32:14 +08:00
|
|
|
|
var $previewButton = framework._.sfCommon.createButton('preview', true);
|
2017-09-05 17:35:15 +08:00
|
|
|
|
var forceDrawPreview = function () {
|
|
|
|
|
try {
|
2018-02-28 00:38:29 +08:00
|
|
|
|
if (editor.getValue() === '') {
|
|
|
|
|
$previewContainer.addClass('cp-app-code-preview-isempty');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$previewContainer.removeClass('cp-app-code-preview-isempty');
|
2018-08-31 21:41:08 +08:00
|
|
|
|
DiffMd.apply(DiffMd.render(editor.getValue()), $preview, framework._.sfCommon);
|
2017-09-05 17:35:15 +08:00
|
|
|
|
} catch (e) { console.error(e); }
|
|
|
|
|
};
|
2017-09-27 22:53:16 +08:00
|
|
|
|
var drawPreview = Util.throttle(function () {
|
2018-01-18 22:04:06 +08:00
|
|
|
|
if (['markdown', 'gfm'].indexOf(CodeMirror.highlightMode) === -1) { return; }
|
2017-10-19 20:39:38 +08:00
|
|
|
|
if (!$previewButton.is('.cp-toolbar-button-active')) { return; }
|
2017-09-05 17:35:15 +08:00
|
|
|
|
forceDrawPreview();
|
2019-12-06 06:42:13 +08:00
|
|
|
|
}, 400);
|
2017-09-05 17:35:15 +08:00
|
|
|
|
|
2017-09-27 22:53:16 +08:00
|
|
|
|
var previewTo;
|
|
|
|
|
$previewButton.click(function () {
|
|
|
|
|
clearTimeout(previewTo);
|
2017-09-05 17:35:15 +08:00
|
|
|
|
$codeMirror.addClass('transition');
|
2017-09-27 22:53:16 +08:00
|
|
|
|
previewTo = setTimeout(function () {
|
2017-09-05 17:35:15 +08:00
|
|
|
|
$codeMirror.removeClass('transition');
|
|
|
|
|
}, 500);
|
2018-01-18 22:04:06 +08:00
|
|
|
|
if (['markdown', 'gfm'].indexOf(CodeMirror.highlightMode) === -1) {
|
2017-09-27 22:53:16 +08:00
|
|
|
|
$previewContainer.show();
|
|
|
|
|
}
|
|
|
|
|
$previewContainer.toggle();
|
|
|
|
|
if ($previewContainer.is(':visible')) {
|
|
|
|
|
forceDrawPreview();
|
2017-11-27 19:17:35 +08:00
|
|
|
|
$codeMirrorContainer.removeClass('cp-app-code-fullpage');
|
2017-09-27 22:53:16 +08:00
|
|
|
|
$previewButton.addClass('cp-toolbar-button-active');
|
|
|
|
|
framework._.sfCommon.setPadAttribute('previewMode', true, function (e) {
|
|
|
|
|
if (e) { return console.log(e); }
|
|
|
|
|
});
|
|
|
|
|
} else {
|
2017-11-27 19:17:35 +08:00
|
|
|
|
$codeMirrorContainer.addClass('cp-app-code-fullpage');
|
2017-09-27 22:53:16 +08:00
|
|
|
|
$previewButton.removeClass('cp-toolbar-button-active');
|
|
|
|
|
framework._.sfCommon.setPadAttribute('previewMode', false, function (e) {
|
|
|
|
|
if (e) { return console.log(e); }
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
2017-11-27 19:17:35 +08:00
|
|
|
|
|
2018-02-28 00:38:29 +08:00
|
|
|
|
framework._.toolbar.$rightside.append($previewButton);
|
2017-09-05 17:35:15 +08:00
|
|
|
|
|
2017-09-27 22:53:16 +08:00
|
|
|
|
$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');
|
2020-02-12 01:19:16 +08:00
|
|
|
|
if (/^\/[^\/]/.test(href)) {
|
2020-02-12 01:20:45 +08:00
|
|
|
|
var privateData = framework._.cpNfInner.metadataMgr.getPrivateData();
|
2020-02-12 01:19:16 +08:00
|
|
|
|
href = privateData.origin + href;
|
|
|
|
|
} else if (/^#/.test(href)) {
|
2020-02-12 01:24:12 +08:00
|
|
|
|
var target = document.getElementById('cp-md-0-'+href.slice(1));
|
|
|
|
|
if (target) { target.scrollIntoView(); }
|
2020-02-12 01:19:16 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
2017-11-27 21:44:44 +08:00
|
|
|
|
framework._.sfCommon.openUnsafeURL(href);
|
2017-09-27 22:53:16 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var modeChange = function (mode) {
|
2018-01-18 22:04:06 +08:00
|
|
|
|
if (['markdown', 'gfm'].indexOf(mode) !== -1) {
|
2017-09-27 22:53:16 +08:00
|
|
|
|
$previewButton.show();
|
|
|
|
|
framework._.sfCommon.getPadAttribute('previewMode', function (e, data) {
|
2017-09-05 17:35:15 +08:00
|
|
|
|
if (e) { return void console.error(e); }
|
|
|
|
|
if (data !== false) {
|
|
|
|
|
$previewContainer.show();
|
2017-10-19 20:39:38 +08:00
|
|
|
|
$previewButton.addClass('cp-toolbar-button-active');
|
2017-11-27 19:17:35 +08:00
|
|
|
|
$codeMirrorContainer.removeClass('cp-app-code-fullpage');
|
2017-10-19 20:39:38 +08:00
|
|
|
|
if (isPresentMode) {
|
|
|
|
|
$editorContainer.addClass('cp-app-code-present');
|
|
|
|
|
}
|
2017-09-05 17:35:15 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
2017-11-28 00:55:20 +08:00
|
|
|
|
return;
|
2017-09-05 17:35:15 +08:00
|
|
|
|
}
|
2017-10-19 20:39:38 +08:00
|
|
|
|
$editorContainer.removeClass('cp-app-code-present');
|
2017-09-27 22:53:16 +08:00
|
|
|
|
$previewButton.hide();
|
2017-09-05 17:35:15 +08:00
|
|
|
|
$previewContainer.hide();
|
2017-09-27 22:53:16 +08:00
|
|
|
|
$previewButton.removeClass('active');
|
2017-11-27 19:17:35 +08:00
|
|
|
|
$codeMirrorContainer.addClass('cp-app-code-fullpage');
|
2017-09-05 17:35:15 +08:00
|
|
|
|
};
|
|
|
|
|
|
2017-10-25 00:49:58 +08:00
|
|
|
|
var isVisible = function () {
|
|
|
|
|
return $previewContainer.is(':visible');
|
|
|
|
|
};
|
|
|
|
|
|
2017-09-27 22:53:16 +08:00
|
|
|
|
framework.onReady(function () {
|
|
|
|
|
// add the splitter
|
|
|
|
|
var splitter = $('<div>', {
|
|
|
|
|
'class': 'cp-splitter'
|
|
|
|
|
}).appendTo($previewContainer);
|
2017-09-05 17:35:15 +08:00
|
|
|
|
|
2017-09-27 22:53:16 +08:00
|
|
|
|
$preview.on('scroll', function() {
|
|
|
|
|
splitter.css('top', $preview.scrollTop() + 'px');
|
2017-09-05 17:35:15 +08:00
|
|
|
|
});
|
|
|
|
|
|
2017-11-27 19:17:35 +08:00
|
|
|
|
var $target = $codeMirrorContainer;
|
2017-09-05 17:35:15 +08:00
|
|
|
|
|
2017-09-27 22:53:16 +08:00
|
|
|
|
splitter.on('mousedown', function (e) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
var x = e.pageX;
|
|
|
|
|
var w = $target.width();
|
2017-10-05 21:12:24 +08:00
|
|
|
|
var handler = function (evt) {
|
2017-09-27 22:53:16 +08:00
|
|
|
|
if (evt.type === 'mouseup') {
|
|
|
|
|
$(window).off('mouseup mousemove', handler);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$target.css('width', (w - x + evt.pageX) + 'px');
|
|
|
|
|
editor.refresh();
|
2017-10-05 21:12:24 +08:00
|
|
|
|
};
|
|
|
|
|
$(window).off('mouseup mousemove', handler);
|
|
|
|
|
$(window).on('mouseup mousemove', handler);
|
2017-09-27 22:53:16 +08:00
|
|
|
|
});
|
2019-09-26 17:56:53 +08:00
|
|
|
|
|
|
|
|
|
var previewInt;
|
|
|
|
|
var clear = function () { clearInterval(previewInt); };
|
|
|
|
|
|
|
|
|
|
// keep trying to draw until you're confident it has been drawn
|
|
|
|
|
previewInt = setInterval(function () {
|
|
|
|
|
// give up if it's not a valid preview mode
|
|
|
|
|
if (['markdown', 'gfm'].indexOf(CodeMirror.highlightMode) === -1) { return void clear(); }
|
|
|
|
|
// give up if content has been drawn
|
|
|
|
|
if ($preview.text()) { return void clear(); }
|
|
|
|
|
// only draw if there is actually content to display
|
|
|
|
|
if (editor && !editor.getValue().trim()) { return void clear(); }
|
|
|
|
|
forceDrawPreview();
|
|
|
|
|
}, 1000);
|
2017-09-27 22:53:16 +08:00
|
|
|
|
});
|
2017-09-05 17:35:15 +08:00
|
|
|
|
|
2017-09-27 22:53:16 +08:00
|
|
|
|
framework._.sfCommon.getPadAttribute('previewMode', function (e, data) {
|
|
|
|
|
if (e) { return void console.error(e); }
|
|
|
|
|
if (data === false && $previewButton) {
|
|
|
|
|
$previewButton.click();
|
|
|
|
|
}
|
|
|
|
|
});
|
2017-09-05 17:35:15 +08:00
|
|
|
|
|
2018-10-06 00:05:39 +08:00
|
|
|
|
Visible.onChange(function (visible) {
|
|
|
|
|
if (visible) {
|
|
|
|
|
drawPreview();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2017-09-27 22:53:16 +08:00
|
|
|
|
return {
|
|
|
|
|
forceDraw: forceDrawPreview,
|
|
|
|
|
draw: drawPreview,
|
2017-10-25 00:49:58 +08:00
|
|
|
|
modeChange: modeChange,
|
|
|
|
|
isVisible: isVisible
|
2017-09-27 22:53:16 +08:00
|
|
|
|
};
|
|
|
|
|
};
|
2017-09-05 17:35:15 +08:00
|
|
|
|
|
2017-10-03 22:57:57 +08:00
|
|
|
|
var mkFilePicker = function (framework, editor, evModeChange) {
|
|
|
|
|
evModeChange.reg(function (mode) {
|
|
|
|
|
if (MEDIA_TAG_MODES.indexOf(mode) !== -1) {
|
|
|
|
|
// Embedding is endabled
|
|
|
|
|
framework.setMediaTagEmbedder(function (mt) {
|
|
|
|
|
editor.replaceSelection($(mt)[0].outerHTML);
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
// Embedding is disabled
|
|
|
|
|
framework.setMediaTagEmbedder();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2017-09-27 22:53:16 +08:00
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-09-05 17:35:15 +08:00
|
|
|
|
|
2020-04-09 22:06:04 +08:00
|
|
|
|
var authorUid = function (existing) {
|
|
|
|
|
if (!Array.isArray(existing)) { existing = []; }
|
|
|
|
|
var n;
|
|
|
|
|
var i = 0;
|
|
|
|
|
while (!n || existing.indexOf(n) !== -1 && i++ < 1000) {
|
|
|
|
|
n = Math.floor(Math.random() * 1000000);
|
|
|
|
|
}
|
|
|
|
|
// If we can't find a valid number in 1000 iterations, use 0...
|
|
|
|
|
if (existing.indexOf(n) !== -1) { n = 0; }
|
|
|
|
|
return n;
|
|
|
|
|
};
|
|
|
|
|
|
2017-10-19 20:39:38 +08:00
|
|
|
|
var andThen2 = function (editor, CodeMirror, framework, isPresentMode) {
|
2017-09-05 17:35:15 +08:00
|
|
|
|
|
2017-09-27 22:53:16 +08:00
|
|
|
|
var common = framework._.sfCommon;
|
2019-08-27 21:31:22 +08:00
|
|
|
|
var privateData = common.getMetadataMgr().getPrivateData();
|
2017-09-05 17:35:15 +08:00
|
|
|
|
|
2017-10-19 20:39:38 +08:00
|
|
|
|
var previewPane = mkPreviewPane(editor, CodeMirror, framework, isPresentMode);
|
2018-02-28 00:38:29 +08:00
|
|
|
|
var markdownTb = mkMarkdownTb(editor, framework);
|
2018-12-06 23:43:48 +08:00
|
|
|
|
|
2020-04-09 22:06:04 +08:00
|
|
|
|
var $removeAuthorColorsButton = framework._.sfCommon.createButton('removeauthorcolors', true, {icon: 'fa-paint-brush', title: 'Autorenfarben entfernen'}); // XXX
|
2020-04-07 22:52:38 +08:00
|
|
|
|
framework._.toolbar.$rightside.append($removeAuthorColorsButton);
|
|
|
|
|
$removeAuthorColorsButton.click(function() {
|
2020-04-08 02:30:55 +08:00
|
|
|
|
var selfrom = editor.getCursor("from");
|
|
|
|
|
var selto = editor.getCursor("to");
|
|
|
|
|
if (!editor.somethingSelected() || selfrom === selto) {
|
|
|
|
|
editor.getAllMarks().forEach(function (marker) {
|
|
|
|
|
marker.clear();
|
|
|
|
|
});
|
2020-04-09 22:06:04 +08:00
|
|
|
|
authormarks.authors = {};
|
|
|
|
|
authormarks.marks = [];
|
2020-04-07 22:52:38 +08:00
|
|
|
|
} else {
|
2020-04-08 02:30:55 +08:00
|
|
|
|
editor.findMarks(selfrom, selto).forEach(function (marker) {
|
|
|
|
|
marker.clear();
|
|
|
|
|
});
|
2020-04-07 22:52:38 +08:00
|
|
|
|
}
|
|
|
|
|
framework.localChange();
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-09 22:06:04 +08:00
|
|
|
|
var authormarks = {
|
|
|
|
|
marks: [],
|
|
|
|
|
authors: {}
|
|
|
|
|
};
|
2020-04-07 22:52:38 +08:00
|
|
|
|
var authormarksLocal = [];
|
2020-04-09 22:06:04 +08:00
|
|
|
|
var myAuthorId = 0;
|
|
|
|
|
|
|
|
|
|
var MARK_OPACITY = 90;
|
|
|
|
|
|
|
|
|
|
var addMark = function (from, to, uid) {
|
|
|
|
|
var author = authormarks.authors[uid] || {};
|
|
|
|
|
editor.markText(from, to, {
|
|
|
|
|
inclusiveLeft: uid === myAuthorId,
|
|
|
|
|
inclusiveRight: uid === myAuthorId,
|
|
|
|
|
css: "background-color: " + author.color + MARK_OPACITY,
|
|
|
|
|
attributes: {
|
|
|
|
|
'data-type': 'authormark',
|
|
|
|
|
'data-uid': uid
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
var sortMarks = function (a, b) {
|
|
|
|
|
if (!Array.isArray(b)) { return -1; }
|
|
|
|
|
if (!Array.isArray(a)) { return 1; }
|
|
|
|
|
// Check line
|
|
|
|
|
if (a[1] < b[1]) { return -1; }
|
|
|
|
|
if (a[1] > b[1]) { return 1; }
|
|
|
|
|
// Same line: check start offset
|
|
|
|
|
if (a[2] < b[2]) { return -1; }
|
|
|
|
|
if (a[2] > b[2]) { return 1; }
|
|
|
|
|
return 0;
|
|
|
|
|
};
|
|
|
|
|
|
2020-04-07 22:08:28 +08:00
|
|
|
|
|
2018-12-06 23:43:48 +08:00
|
|
|
|
var $print = $('#cp-app-code-print');
|
|
|
|
|
var $content = $('#cp-app-code-preview-content');
|
|
|
|
|
mkPrintButton(framework, $content, $print);
|
|
|
|
|
|
2018-02-28 00:38:29 +08:00
|
|
|
|
mkHelpMenu(framework);
|
|
|
|
|
|
2017-09-27 22:53:16 +08:00
|
|
|
|
var evModeChange = Util.mkEvent();
|
|
|
|
|
evModeChange.reg(previewPane.modeChange);
|
2018-02-28 00:38:29 +08:00
|
|
|
|
evModeChange.reg(markdownTb.modeChange);
|
2017-09-05 17:35:15 +08:00
|
|
|
|
|
2018-11-06 00:30:07 +08:00
|
|
|
|
CodeMirror.mkIndentSettings(framework._.cpNfInner.metadataMgr);
|
2017-09-27 22:53:16 +08:00
|
|
|
|
CodeMirror.init(framework.localChange, framework._.title, framework._.toolbar);
|
2017-10-03 22:57:57 +08:00
|
|
|
|
mkFilePicker(framework, editor, evModeChange);
|
2017-09-05 17:35:15 +08:00
|
|
|
|
|
2017-09-27 22:53:16 +08:00
|
|
|
|
if (!framework.isReadOnly()) {
|
2018-01-16 18:26:16 +08:00
|
|
|
|
CodeMirror.configureTheme(common, function () {
|
|
|
|
|
CodeMirror.configureLanguage(common, null, evModeChange.fire);
|
2017-09-27 22:53:16 +08:00
|
|
|
|
});
|
|
|
|
|
} else {
|
2018-01-16 18:26:16 +08:00
|
|
|
|
CodeMirror.configureTheme(common);
|
2017-09-27 22:53:16 +08:00
|
|
|
|
}
|
2017-09-05 17:35:15 +08:00
|
|
|
|
|
2020-04-09 22:06:04 +08:00
|
|
|
|
var checkAuthors = function (userDoc) {
|
|
|
|
|
var chainpad = framework._.cpNfInner.chainpad;
|
|
|
|
|
var authDoc = JSON.parse(chainpad.getAuthDoc() || '{}');
|
|
|
|
|
if (!authDoc.content || !userDoc.content) { return; }
|
|
|
|
|
if (!authormarks || !Array.isArray(authormarks.marks)) { return; }
|
|
|
|
|
var oldDoc = CodeMirror.canonicalize(editor.getValue());
|
|
|
|
|
var theirOps = ChainPad.Diff.diff(oldDoc, userDoc.content);
|
|
|
|
|
var myOps = ChainPad.Diff.diff(authDoc.content, userDoc.content);
|
|
|
|
|
// If I have uncommited content when receiving a remote patch, and they have
|
|
|
|
|
// pushed content to the same line as me, I need to update all the authormarks
|
|
|
|
|
// after their changes to push them by the length of the text I added
|
|
|
|
|
var changed = false;
|
|
|
|
|
console.log(JSON.stringify(authDoc.authormarks));
|
|
|
|
|
console.log(JSON.stringify(authormarks));
|
|
|
|
|
console.warn(myOps);
|
|
|
|
|
console.warn(theirOps);
|
|
|
|
|
myOps.forEach(function (op) {
|
|
|
|
|
var pos = SFCodeMirror.posToCursor(op.offset, authDoc.content);
|
|
|
|
|
var size = (op.toInsert.length - op.toRemove);
|
|
|
|
|
|
|
|
|
|
// If the remote change includes an operation on the same line,
|
|
|
|
|
// fix the offsets and continue to my next operation
|
|
|
|
|
// NOTE: we need to fix all the marks that are **after** the change with
|
|
|
|
|
// the bigger offset
|
|
|
|
|
theirOps.some(function (_op) {
|
|
|
|
|
var _pos = SFCodeMirror.posToCursor(_op.offset, oldDoc);
|
|
|
|
|
if (_pos.line !== pos.line) { return; }
|
|
|
|
|
|
|
|
|
|
var ch = Math.max(_pos.ch, pos.ch);
|
|
|
|
|
// Get the marks from this line and check offsets after the change
|
|
|
|
|
authormarks.marks.forEach(function (array) {
|
|
|
|
|
if (array[1] !== pos.line) { return; }
|
|
|
|
|
// Move the end position if it's on the same line and after the change
|
|
|
|
|
if (!array[4] && array[3] >= ch) {
|
|
|
|
|
array[3] += size;
|
|
|
|
|
changed = true;
|
|
|
|
|
}
|
|
|
|
|
// Move the start position if it's after the change
|
|
|
|
|
if (array[2] >= ch) {
|
|
|
|
|
array[2] += size;
|
|
|
|
|
changed = true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
framework.localChange();
|
|
|
|
|
};
|
2017-09-18 18:09:18 +08:00
|
|
|
|
|
2017-09-27 22:53:16 +08:00
|
|
|
|
framework.onContentUpdate(function (newContent) {
|
|
|
|
|
var highlightMode = newContent.highlightMode;
|
|
|
|
|
if (highlightMode && highlightMode !== CodeMirror.highlightMode) {
|
|
|
|
|
CodeMirror.setMode(highlightMode, evModeChange.fire);
|
2017-09-05 17:35:15 +08:00
|
|
|
|
}
|
2020-04-07 22:08:28 +08:00
|
|
|
|
|
2020-04-09 22:06:04 +08:00
|
|
|
|
if (newContent.authormarks) {
|
|
|
|
|
authormarks = newContent.authormarks;
|
|
|
|
|
if (!authormarks.marks) { authormarks.marks = []; }
|
|
|
|
|
if (!authormarks.authors) { authormarks.authors = {}; }
|
|
|
|
|
}
|
2020-04-07 22:08:28 +08:00
|
|
|
|
|
2020-04-09 22:06:04 +08:00
|
|
|
|
var chainpad = framework._.cpNfInner.chainpad;
|
|
|
|
|
var ops = ChainPad.Diff.diff(chainpad.getAuthDoc(), chainpad.getUserDoc());
|
|
|
|
|
if (ops.length) {
|
|
|
|
|
console.error(ops);
|
|
|
|
|
}
|
|
|
|
|
checkAuthors(newContent);
|
|
|
|
|
|
|
|
|
|
CodeMirror.contentUpdate(newContent); //, authormarks.marks, authormarksLocal);
|
2017-09-27 22:53:16 +08:00
|
|
|
|
previewPane.draw();
|
|
|
|
|
});
|
2017-09-18 18:09:18 +08:00
|
|
|
|
|
2017-09-27 22:53:16 +08:00
|
|
|
|
framework.setContentGetter(function () {
|
2018-12-17 18:44:08 +08:00
|
|
|
|
CodeMirror.removeCursors();
|
2017-10-02 22:34:37 +08:00
|
|
|
|
var content = CodeMirror.getContent();
|
|
|
|
|
content.highlightMode = CodeMirror.highlightMode;
|
2017-09-27 22:53:16 +08:00
|
|
|
|
previewPane.draw();
|
2020-04-07 22:08:28 +08:00
|
|
|
|
|
2020-04-09 22:06:04 +08:00
|
|
|
|
var colorlist = content.colorlist || {};
|
|
|
|
|
|
2020-04-07 22:08:28 +08:00
|
|
|
|
// get author marks
|
2020-04-09 22:06:04 +08:00
|
|
|
|
var authors = authormarks.authors || {};
|
|
|
|
|
var _marks = [];
|
|
|
|
|
var previous;
|
2020-04-07 22:08:28 +08:00
|
|
|
|
editor.getAllMarks().forEach(function (mark) {
|
2020-04-08 02:30:55 +08:00
|
|
|
|
var pos = mark.find();
|
2020-04-09 22:06:04 +08:00
|
|
|
|
var attributes = mark.attributes || {};
|
|
|
|
|
if (!pos || attributes['data-type'] !== 'authormark') { return; }
|
|
|
|
|
|
|
|
|
|
var uid = attributes['data-uid'] || 0;
|
|
|
|
|
var author = authors[uid] || {};
|
|
|
|
|
|
|
|
|
|
// Check if we need to merge
|
|
|
|
|
if (previous && previous.data && previous.data[0] === uid) {
|
|
|
|
|
if (previous.pos.to.line === pos.from.line
|
|
|
|
|
&& previous.pos.to.ch === pos.from.ch) {
|
|
|
|
|
// Merge the marks
|
|
|
|
|
previous.mark.clear();
|
|
|
|
|
mark.clear();
|
|
|
|
|
addMark(previous.pos.from, pos.to, uid);
|
|
|
|
|
// Remove the data for the previous one
|
|
|
|
|
_marks.pop();
|
|
|
|
|
// Update the position to create the new data
|
|
|
|
|
pos.from = previous.pos.from;
|
2020-04-08 02:30:55 +08:00
|
|
|
|
}
|
2020-04-07 22:08:28 +08:00
|
|
|
|
}
|
2020-04-09 22:06:04 +08:00
|
|
|
|
|
|
|
|
|
var array = [uid, pos.from.line, pos.from.ch];
|
|
|
|
|
if (pos.from.line === pos.to.line && pos.to.ch > (pos.from.ch+1)) {
|
|
|
|
|
// If there is more than 1 character, add the "to" character
|
|
|
|
|
array.push(pos.to.ch);
|
|
|
|
|
} else if (pos.from.line !== pos.to.line) {
|
|
|
|
|
// If the mark is on more than one line, add the "to" line data
|
|
|
|
|
Array.prototype.push.apply(array, [pos.to.line, pos.to.ch]);
|
|
|
|
|
}
|
|
|
|
|
_marks.push(array);
|
|
|
|
|
previous = {
|
|
|
|
|
pos: pos,
|
|
|
|
|
mark: mark,
|
|
|
|
|
data: array
|
|
|
|
|
};
|
2020-04-07 22:08:28 +08:00
|
|
|
|
});
|
2020-04-09 22:06:04 +08:00
|
|
|
|
_marks.sort(sortMarks);
|
|
|
|
|
content.authormarks = {marks: _marks, authors: authormarks.authors};
|
|
|
|
|
//authormarksLocal = _marks.slice();
|
2020-04-07 22:08:28 +08:00
|
|
|
|
|
2017-10-02 22:34:37 +08:00
|
|
|
|
return content;
|
2017-09-27 22:53:16 +08:00
|
|
|
|
});
|
2017-09-05 17:35:15 +08:00
|
|
|
|
|
2018-12-17 18:44:08 +08:00
|
|
|
|
var cursorTo;
|
|
|
|
|
var updateCursor = function () {
|
|
|
|
|
if (cursorTo) { clearTimeout(cursorTo); }
|
|
|
|
|
if (editor._noCursorUpdate) { return; }
|
|
|
|
|
cursorTo = setTimeout(function () {
|
|
|
|
|
framework.updateCursor();
|
|
|
|
|
}, 500); // 500ms to make sure it is sent after chainpad sync
|
|
|
|
|
};
|
2018-12-05 00:18:42 +08:00
|
|
|
|
framework.onCursorUpdate(CodeMirror.setRemoteCursor);
|
|
|
|
|
framework.setCursorGetter(CodeMirror.getCursor);
|
2018-12-17 18:44:08 +08:00
|
|
|
|
editor.on('cursorActivity', updateCursor);
|
2018-12-05 00:18:42 +08:00
|
|
|
|
|
2017-09-27 22:53:16 +08:00
|
|
|
|
framework.onEditableChange(function () {
|
|
|
|
|
editor.setOption('readOnly', framework.isLocked() || framework.isReadOnly());
|
|
|
|
|
});
|
2017-09-05 17:35:15 +08:00
|
|
|
|
|
2017-09-27 22:53:16 +08:00
|
|
|
|
framework.setTitleRecommender(CodeMirror.getHeadingText);
|
2017-09-05 17:35:15 +08:00
|
|
|
|
|
2020-04-09 22:06:04 +08:00
|
|
|
|
var getMyAuthorId = function () {
|
|
|
|
|
var existing = Object.keys(authormarks.authors || {});
|
|
|
|
|
if (!common.isLoggedIn()) { return authorUid(existing); }
|
|
|
|
|
|
|
|
|
|
var userData = common.getMetadataMgr().getUserData();
|
|
|
|
|
var uid;
|
|
|
|
|
existing.some(function (id) {
|
|
|
|
|
var author = authormarks.authors[id] || {};
|
|
|
|
|
if (author.curvePublic !== userData.curvePublic) { return; }
|
|
|
|
|
uid = Number(id);
|
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
// XXX update my color?
|
|
|
|
|
return uid || authorUid(existing);
|
|
|
|
|
};
|
|
|
|
|
|
2017-09-27 22:53:16 +08:00
|
|
|
|
framework.onReady(function (newPad) {
|
2018-02-28 20:16:30 +08:00
|
|
|
|
editor.focus();
|
|
|
|
|
|
2017-09-27 22:53:16 +08:00
|
|
|
|
if (newPad && !CodeMirror.highlightMode) {
|
2018-01-18 22:04:06 +08:00
|
|
|
|
CodeMirror.setMode('gfm', evModeChange.fire);
|
2017-09-27 22:53:16 +08:00
|
|
|
|
//console.log("%s => %s", CodeMirror.highlightMode, CodeMirror.$language.val());
|
2017-09-05 17:35:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-09 22:06:04 +08:00
|
|
|
|
myAuthorId = getMyAuthorId();
|
|
|
|
|
console.warn(myAuthorId);
|
|
|
|
|
|
2017-09-05 17:35:15 +08:00
|
|
|
|
var fmConfig = {
|
|
|
|
|
dropArea: $('.CodeMirror'),
|
|
|
|
|
body: $('body'),
|
|
|
|
|
onUploaded: function (ev, data) {
|
2017-11-13 23:32:40 +08:00
|
|
|
|
var parsed = Hash.parsePadUrl(data.url);
|
2018-05-26 00:00:10 +08:00
|
|
|
|
var secret = Hash.getSecrets('file', parsed.hash, data.password);
|
2019-08-27 21:31:22 +08:00
|
|
|
|
var fileHost = privateData.fileHost || privateData.origin;
|
|
|
|
|
var src = fileHost + Hash.getBlobPathFromHex(secret.channel);
|
2018-05-26 00:00:10 +08:00
|
|
|
|
var key = Hash.encodeBase64(secret.keys.cryptKey);
|
|
|
|
|
var mt = '<media-tag src="' + src + '" data-crypto-key="cryptpad:' + key + '"></media-tag>';
|
2017-09-05 17:35:15 +08:00
|
|
|
|
editor.replaceSelection(mt);
|
|
|
|
|
}
|
|
|
|
|
};
|
2017-09-27 22:53:16 +08:00
|
|
|
|
common.createFileManager(fmConfig);
|
|
|
|
|
});
|
2017-09-05 17:35:15 +08:00
|
|
|
|
|
2017-09-27 22:53:16 +08:00
|
|
|
|
framework.onDefaultContentNeeded(function () {
|
2018-02-28 00:38:29 +08:00
|
|
|
|
editor.setValue(''); //Messages.codeInitialState);
|
2017-09-27 22:53:16 +08:00
|
|
|
|
});
|
2017-09-05 17:35:15 +08:00
|
|
|
|
|
2017-10-03 22:57:57 +08:00
|
|
|
|
framework.setFileExporter(CodeMirror.getContentExtension, CodeMirror.fileExporter);
|
2019-07-13 16:25:22 +08:00
|
|
|
|
framework.setFileImporter({}, function () {
|
|
|
|
|
/* setFileImporter currently takes a function with the following signature:
|
|
|
|
|
(content, file) => {}
|
|
|
|
|
I used 'apply' with 'arguments' to avoid breaking things if this API ever changes.
|
|
|
|
|
*/
|
|
|
|
|
var ret = CodeMirror.fileImporter.apply(null, Array.prototype.slice.call(arguments));
|
|
|
|
|
previewPane.modeChange(ret.mode);
|
|
|
|
|
return ret;
|
|
|
|
|
});
|
2017-09-05 17:35:15 +08:00
|
|
|
|
|
2017-09-27 22:53:16 +08:00
|
|
|
|
framework.setNormalizer(function (c) {
|
|
|
|
|
return {
|
|
|
|
|
content: c.content,
|
2020-04-07 22:08:28 +08:00
|
|
|
|
highlightMode: c.highlightMode,
|
|
|
|
|
authormarks: c.authormarks
|
2017-09-27 22:53:16 +08:00
|
|
|
|
};
|
2017-09-11 23:52:34 +08:00
|
|
|
|
});
|
|
|
|
|
|
2020-04-07 22:08:28 +08:00
|
|
|
|
editor.on('change', function( cm, change ) {
|
2020-04-09 22:06:04 +08:00
|
|
|
|
if (change.text !== undefined && (change.origin === "+input" || change.origin === "paste")) {
|
2020-04-07 22:08:28 +08:00
|
|
|
|
// add new author mark if text is added. marks from removed text are removed automatically
|
2020-04-09 22:06:04 +08:00
|
|
|
|
|
|
|
|
|
// If my text is inside an existing mark:
|
|
|
|
|
// * if it's my mark, do nothing
|
|
|
|
|
// * if it's someone else's mark, break it
|
|
|
|
|
// We can only have one author mark at a given position, but there may be
|
|
|
|
|
// another mark (cursor selection...) at this position so we use ".some"
|
|
|
|
|
var toSplit, abort;
|
|
|
|
|
editor.findMarksAt(change.from).some(function (mark) {
|
|
|
|
|
if (!mark.attributes) { return; }
|
|
|
|
|
if (mark.attributes['data-type'] !== 'authormark') { return; }
|
|
|
|
|
if (mark.attributes['data-uid'] !== myAuthorId) {
|
|
|
|
|
toSplit = {
|
|
|
|
|
mark: mark,
|
|
|
|
|
uid: mark.attributes['data-uid']
|
|
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
// This is our mark: abort to avoid making a new one
|
|
|
|
|
abort = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
if (abort) { return void framework.localChange(); }
|
|
|
|
|
|
|
|
|
|
// Add my data to the doc if it's missing
|
|
|
|
|
if (!authormarks.authors[myAuthorId]) {
|
|
|
|
|
var userData = common.getMetadataMgr().getUserData();
|
|
|
|
|
authormarks.authors[myAuthorId] = {
|
|
|
|
|
name: userData.name,
|
|
|
|
|
curvePublic: userData.curvePublic,
|
|
|
|
|
color: userData.color
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var to_add = {
|
|
|
|
|
line: change.from.line + change.text.length-1,
|
|
|
|
|
};
|
2020-04-08 01:07:12 +08:00
|
|
|
|
if (change.text.length > 1) {
|
2020-04-09 22:06:04 +08:00
|
|
|
|
// Multiple lines => take the length of the text added to the last line
|
|
|
|
|
to_add.ch = change.text[change.text.length-1].length;
|
2020-04-08 01:07:12 +08:00
|
|
|
|
} else {
|
2020-04-09 22:06:04 +08:00
|
|
|
|
// Single line => use the "from" position and add the length of the text
|
|
|
|
|
to_add.ch = change.from.ch + change.text[change.text.length-1].length;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (toSplit && toSplit.mark && typeof(toSplit.uid) !== "undefined") {
|
|
|
|
|
// Break the other user's mark if needed
|
|
|
|
|
var _pos = toSplit.mark.find();
|
|
|
|
|
toSplit.mark.clear();
|
|
|
|
|
addMark(_pos.from, change.from, toSplit.uid); // their mark, 1st part
|
|
|
|
|
addMark(change.from, to_add, myAuthorId); // my mark
|
|
|
|
|
addMark(to_add, _pos.to, toSplit.uid); // their mark, 2nd part
|
|
|
|
|
} else {
|
|
|
|
|
// Add my mark
|
|
|
|
|
addMark(change.from, to_add, myAuthorId);
|
2020-04-08 01:07:12 +08:00
|
|
|
|
}
|
2020-04-08 02:30:55 +08:00
|
|
|
|
} else if (change.origin === "setValue") {
|
2020-04-07 22:08:28 +08:00
|
|
|
|
// on remote update: remove all marks, add new marks
|
2020-04-08 02:30:55 +08:00
|
|
|
|
editor.getAllMarks().forEach(function (marker) {
|
2020-04-09 22:06:04 +08:00
|
|
|
|
if (marker.attributes && marker.attributes['data-type'] === 'authormark') {
|
|
|
|
|
marker.clear();
|
|
|
|
|
}
|
2020-04-08 02:30:55 +08:00
|
|
|
|
});
|
2020-04-09 22:06:04 +08:00
|
|
|
|
authormarks.marks.forEach(function (mark) {
|
2020-04-08 02:30:55 +08:00
|
|
|
|
var from_line;
|
|
|
|
|
var to_line;
|
|
|
|
|
var from_ch;
|
|
|
|
|
var to_ch;
|
2020-04-09 22:06:04 +08:00
|
|
|
|
var uid = mark[0];
|
|
|
|
|
if (!authormarks.authors || !authormarks.authors[uid]) { return; }
|
|
|
|
|
var data = authormarks.authors[uid];
|
2020-04-08 02:30:55 +08:00
|
|
|
|
if (mark.length === 3) {
|
2020-04-08 02:49:36 +08:00
|
|
|
|
from_line = mark[1];
|
|
|
|
|
to_line = mark[1];
|
|
|
|
|
from_ch = mark[2];
|
|
|
|
|
to_ch = mark[2]+1;
|
2020-04-08 02:30:55 +08:00
|
|
|
|
} else if (mark.length === 4) {
|
2020-04-08 02:49:36 +08:00
|
|
|
|
from_line = mark[1];
|
|
|
|
|
to_line = mark[1];
|
|
|
|
|
from_ch = mark[2];
|
2020-04-08 02:30:55 +08:00
|
|
|
|
to_ch = mark[3];
|
2020-04-08 02:49:36 +08:00
|
|
|
|
} else if (mark.length === 5) {
|
|
|
|
|
from_line = mark[1];
|
|
|
|
|
to_line = mark[3];
|
|
|
|
|
from_ch = mark[2];
|
|
|
|
|
to_ch = mark[4];
|
2020-04-08 02:30:55 +08:00
|
|
|
|
}
|
2020-04-09 22:06:04 +08:00
|
|
|
|
addMark({
|
|
|
|
|
line: from_line, ch: from_ch
|
|
|
|
|
}, {
|
|
|
|
|
line: to_line, ch: to_ch
|
|
|
|
|
}, uid);
|
2020-04-07 22:08:28 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
framework.localChange();
|
|
|
|
|
});
|
2017-09-05 17:35:15 +08:00
|
|
|
|
|
2017-09-27 22:53:16 +08:00
|
|
|
|
framework.start();
|
2018-11-22 21:45:12 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
window.easyTest = function () {
|
|
|
|
|
var test = TypingTest.testCode(editor);
|
|
|
|
|
return test;
|
|
|
|
|
};
|
2017-09-05 17:35:15 +08:00
|
|
|
|
};
|
|
|
|
|
|
2017-10-25 00:49:58 +08:00
|
|
|
|
var getThumbnailContainer = function () {
|
|
|
|
|
var $preview = $('#cp-app-code-preview-content');
|
|
|
|
|
if ($preview.length && $preview.is(':visible')) {
|
|
|
|
|
return $preview[0];
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2017-09-05 17:35:15 +08:00
|
|
|
|
var main = function () {
|
|
|
|
|
var CodeMirror;
|
|
|
|
|
var editor;
|
2017-09-27 22:53:16 +08:00
|
|
|
|
var framework;
|
2017-09-05 17:35:15 +08:00
|
|
|
|
|
|
|
|
|
nThen(function (waitFor) {
|
2017-09-27 22:53:16 +08:00
|
|
|
|
|
|
|
|
|
Framework.create({
|
|
|
|
|
toolbarContainer: '#cme_toolbox',
|
2017-10-25 00:49:58 +08:00
|
|
|
|
contentContainer: '#cp-app-code-editor',
|
2017-10-26 18:31:16 +08:00
|
|
|
|
thumbnail: {
|
|
|
|
|
getContainer: getThumbnailContainer,
|
|
|
|
|
filter: function (el, before) {
|
|
|
|
|
if (before) {
|
2018-01-09 22:25:11 +08:00
|
|
|
|
//$(el).parents().css('overflow', 'visible');
|
2017-10-26 18:31:16 +08:00
|
|
|
|
$(el).css('max-height', Math.max(600, $(el).width()) + 'px');
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-11-06 20:36:54 +08:00
|
|
|
|
$(el).parents().css('overflow', '');
|
2017-10-26 18:31:16 +08:00
|
|
|
|
$(el).css('max-height', '');
|
2017-11-20 21:17:29 +08:00
|
|
|
|
editor.refresh();
|
2017-10-26 18:31:16 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-27 22:53:16 +08:00
|
|
|
|
}, waitFor(function (fw) { framework = fw; }));
|
|
|
|
|
|
|
|
|
|
nThen(function (waitFor) {
|
|
|
|
|
$(waitFor());
|
|
|
|
|
}).nThen(function () {
|
2018-01-16 18:26:16 +08:00
|
|
|
|
CodeMirror = SFCodeMirror.create(null, CMeditor);
|
2017-11-27 19:17:35 +08:00
|
|
|
|
$('#cp-app-code-container').addClass('cp-app-code-fullpage');
|
2017-09-27 22:53:16 +08:00
|
|
|
|
editor = CodeMirror.editor;
|
|
|
|
|
}).nThen(waitFor());
|
|
|
|
|
|
2017-09-05 17:35:15 +08:00
|
|
|
|
}).nThen(function (/*waitFor*/) {
|
2018-01-16 18:26:16 +08:00
|
|
|
|
framework._.sfCommon.isPresentUrl(function (err, val) {
|
2017-10-19 20:39:38 +08:00
|
|
|
|
andThen2(editor, CodeMirror, framework, val);
|
|
|
|
|
});
|
2017-09-05 17:35:15 +08:00
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
main();
|
2017-06-29 16:49:35 +08:00
|
|
|
|
});
|