2017-01-19 05:40:08 +08:00
|
|
|
var TinyMCE = (function() {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
function initHighlightjs() {
|
2017-01-20 00:09:25 +08:00
|
|
|
$('[class*=language]').each(function(i, block) {
|
|
|
|
hljs.highlightBlock(block);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function initHighlightjsIframe(iframe) {
|
|
|
|
$('[class*=language]', iframe).each(function(i, block) {
|
|
|
|
hljs.highlightBlock(block);
|
2017-01-19 05:40:08 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-01-20 00:09:25 +08:00
|
|
|
// returns a public API for TinyMCE editor
|
2017-01-19 05:40:08 +08:00
|
|
|
return Object.freeze({
|
|
|
|
init : function() {
|
|
|
|
if (typeof tinyMCE != 'undefined') {
|
|
|
|
tinyMCE.init({
|
2018-09-13 20:50:00 +08:00
|
|
|
cache_suffix: '?v=4.7.13', // This suffix should be changed any time library is updated
|
2017-04-19 15:11:52 +08:00
|
|
|
selector: 'textarea.tinymce',
|
2017-04-21 22:09:04 +08:00
|
|
|
toolbar: ["undo redo | insert | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link | forecolor backcolor | customimageuploader | codesample"],
|
2018-06-11 16:18:35 +08:00
|
|
|
plugins: "autoresize,customimageuploader,link,advlist,codesample,autolink,lists,charmap,hr,anchor,searchreplace,wordcount,visualblocks,visualchars,insertdatetime,nonbreaking,save,contextmenu,directionality,paste,textcolor,colorpicker,textpattern",
|
2017-01-19 05:40:08 +08:00
|
|
|
codesample_languages: [{"text":"R","value":"r"},{"text":"MATLAB","value":"matlab"},{"text":"Python","value":"python"},{"text":"JSON","value":"javascript"},{"text":"HTML/XML","value":"markup"},{"text":"JavaScript","value":"javascript"},{"text":"CSS","value":"css"},{"text":"PHP","value":"php"},{"text":"Ruby","value":"ruby"},{"text":"Java","value":"java"},{"text":"C","value":"c"},{"text":"C#","value":"csharp"},{"text":"C++","value":"cpp"}],
|
2017-01-24 16:44:37 +08:00
|
|
|
removed_menuitems: 'newdocument',
|
2017-05-03 21:30:08 +08:00
|
|
|
object_resizing: false,
|
2017-01-24 16:44:37 +08:00
|
|
|
elementpath: false,
|
2017-05-03 21:30:08 +08:00
|
|
|
forced_root_block: false,
|
|
|
|
default_link_target: '_blank',
|
2017-01-24 20:10:01 +08:00
|
|
|
target_list: [
|
|
|
|
{title: 'New page', value: '_blank'},
|
|
|
|
{title: 'Same page', value: '_self'}
|
|
|
|
],
|
2017-01-24 16:44:37 +08:00
|
|
|
style_formats: [
|
|
|
|
{title: 'Headers', items: [
|
|
|
|
{title: 'Header 1', format: 'h1'},
|
|
|
|
{title: 'Header 2', format: 'h2'},
|
|
|
|
{title: 'Header 3', format: 'h3'},
|
|
|
|
{title: 'Header 4', format: 'h4'},
|
|
|
|
{title: 'Header 5', format: 'h5'},
|
|
|
|
{title: 'Header 6', format: 'h6'}
|
|
|
|
]},
|
|
|
|
{title: 'Inline', items: [
|
|
|
|
{title: 'Bold', icon: 'bold', format: 'bold'},
|
|
|
|
{title: 'Italic', icon: 'italic', format: 'italic'},
|
|
|
|
{title: 'Underline', icon: 'underline', format: 'underline'},
|
|
|
|
{title: 'Strikethrough', icon: 'strikethrough', format: 'strikethrough'},
|
|
|
|
{title: 'Superscript', icon: 'superscript', format: 'superscript'},
|
|
|
|
{title: 'Subscript', icon: 'subscript', format: 'subscript'},
|
|
|
|
{title: 'Code', icon: 'code', format: 'code'}
|
|
|
|
]},
|
|
|
|
{title: 'Blocks', items: [
|
|
|
|
{title: 'Paragraph', format: 'p'},
|
|
|
|
{title: 'Blockquote', format: 'blockquote'}
|
|
|
|
]},
|
|
|
|
{title: 'Alignment', items: [
|
|
|
|
{title: 'Left', icon: 'alignleft', format: 'alignleft'},
|
|
|
|
{title: 'Center', icon: 'aligncenter', format: 'aligncenter'},
|
|
|
|
{title: 'Right', icon: 'alignright', format: 'alignright'},
|
|
|
|
{title: 'Justify', icon: 'alignjustify', format: 'alignjustify'}
|
|
|
|
]}
|
|
|
|
],
|
2017-01-19 05:40:08 +08:00
|
|
|
init_instance_callback: function(editor) {
|
|
|
|
SmartAnnotation.init($(editor.contentDocument.activeElement));
|
2017-01-20 00:09:25 +08:00
|
|
|
initHighlightjsIframe($(this.iframeElement).contents());
|
2017-01-19 05:40:08 +08:00
|
|
|
},
|
|
|
|
setup: function(editor) {
|
2017-01-26 20:50:32 +08:00
|
|
|
editor.on('keydown', function(e) {
|
2017-01-20 00:09:25 +08:00
|
|
|
if(e.keyCode == 13 && $(editor.contentDocument.activeElement).atwho('isSelecting')) {
|
2017-01-19 05:40:08 +08:00
|
|
|
return false;
|
2017-01-20 00:09:25 +08:00
|
|
|
}
|
2017-01-19 05:40:08 +08:00
|
|
|
});
|
2017-01-20 00:09:25 +08:00
|
|
|
|
|
|
|
editor.on('NodeChange', function(e) {
|
|
|
|
var node = e.element;
|
|
|
|
var editor = this;
|
|
|
|
setTimeout(function() {
|
|
|
|
if($(node).is('pre') && !editor.isHidden()){
|
|
|
|
initHighlightjsIframe($(editor.iframeElement).contents());
|
|
|
|
}
|
|
|
|
}, 200);
|
|
|
|
|
|
|
|
});
|
|
|
|
},
|
2017-04-21 22:09:04 +08:00
|
|
|
codesample_content_css: '<%= asset_path('highlightjs-github-theme') %>'
|
2017-01-19 05:40:08 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
destroyAll: function() {
|
|
|
|
_.each(tinymce.editors, function(editor) {
|
2017-11-24 18:45:07 +08:00
|
|
|
if(editor) {
|
|
|
|
editor.destroy();
|
|
|
|
initHighlightjs();
|
|
|
|
}
|
2017-01-19 05:40:08 +08:00
|
|
|
});
|
|
|
|
},
|
|
|
|
refresh: function() {
|
|
|
|
this.destroyAll();
|
|
|
|
this.init();
|
|
|
|
},
|
2017-01-19 18:37:59 +08:00
|
|
|
getContent: function() {
|
|
|
|
return tinymce.editors[0].getContent();
|
|
|
|
},
|
2017-01-19 05:40:08 +08:00
|
|
|
highlight: initHighlightjs
|
|
|
|
});
|
|
|
|
|
|
|
|
})();
|