app/assets/javascripts/codemirror/editor.js in kit_cms-2.3.20 vs app/assets/javascripts/codemirror/editor.js in kit_cms-2.3.22
- old
+ new
@@ -5,31 +5,68 @@
*= require "./htmlmixed"
*= require "./sass"
*= require "./css"
*= require "./markdown"
*= require "./xml"
+ *= require "./ruby"
*= require "./javascript"
*= require "./dialog"
*= require "./match-highlighter"
*= require "./matchbrackets"
*= require "./searchcursor"
*= require "./search"
*= require "./collapserange"
*
*/
-var html_editors = new Array();
+var _editors = {};
+function deregister_editor_by_name(name) {
+ var editor_record = get_editor_record_by_name(name);
+ delete _editors[editor_record.id];
+}
+
+function get_editor_record_by_name(name) {
+ for (var id in _editors) {
+ if (_editors[id].name === name) {
+ return _editors[id];
+ }
+ }
+ return null;
+}
+
+function register_editor(editor, id, name) {
+ var the_editor = { editor: editor, id: id, name: name };
+ _editors[id] = the_editor;
+}
+
+function get_editor_by_id(id) {
+ return _editors[id].editor;
+}
+
+function get_editor_by_name(name) {
+ var editor_record = get_editor_record_by_name(name);
+ if (editor_record) return editor_record.editor;
+ return null;
+}
+
function do_bold(editor) {
insert_formatting(editor, "*", "*", "Bold");
}
function do_underline(editor) {
insert_formatting(editor, "_", "_", "Underlined");
}
-function do_cmd(editor, cmd) {
+function do_cmd(id, cmd) {
+ var editor = get_editor_by_id(id);
+ if (cmd=='wink') {
+ do_smile(editor, 'wink');
+ }
+ if (cmd=='smile') {
+ do_smile(editor, 'smile');
+ }
if (cmd=='list') {
do_list(editor, '-');
}
if (cmd=='numbered_list') {
do_list(editor, '1.');
@@ -60,16 +97,15 @@
}
if (cmd=='redo') {
do_redo(editor);
}
if (cmd=='preview') {
- do_preview(editor);
+ do_preview(editor,id);
}
}
function do_prefix(editor, prefix) {
- var editor = html_editors[editor];
var start_pos = editor.getCursor('start');
var end_pos = editor.getCursor('end');
if (editor.somethingSelected()) {
for (var i = start_pos.line; i <= end_pos.line; i++) {
@@ -93,50 +129,53 @@
insert_formatting(editor, '[', '](' + url + ')', 'Link');
}
function do_video(editor) {
- var editor = html_editors[editor];
var start_pos = editor.getCursor('start');
var url = prompt("Enter Youtube 'share' URL or Vimeo URL");
editor.replaceSelection(url);
start_pos.ch = start_pos.ch + url.length;
editor.setCursor(start_pos);
editor.focus();
}
+function do_smile(editor, smile) {
+ var start_pos = editor.getCursor('start');
+ editor.replaceSelection(" :" + smile + ": ");
+ start_pos.ch = start_pos.ch + smile.length + 4;
+ editor.setCursor(start_pos);
+ editor.focus();
+}
+
function do_undo(editor) {
- var editor = html_editors[editor];
editor.undo();
}
function do_redo(editor) {
- var editor = html_editors[editor];
editor.redo();
}
function do_image(editor) {
- var editor = html_editors[editor];
var url = prompt("Enter the full URL of the image", "http://");
var start_pos = editor.getCursor('start');
editor.replaceSelection("![](" + url + ")");
start_pos.ch = start_pos.ch + url.length + 5;
editor.setCursor(start_pos);
editor.focus();
}
-function do_list(editor_name,list) {
- var editor = html_editors[editor_name];
+function do_list(editor,list) {
var start_pos = editor.getCursor('start');
var end_pos = editor.getCursor('end');
var to_insert = '';
if (editor.somethingSelected()) {
if (start_pos.line != end_pos.line) {
- do_prefix(editor_name, list);
+ do_prefix(editor, list);
return;
}
else {
var selection = editor.getSelection();
editor.replaceSelection(((start_pos.ch==0) ? '' : '\r') + list + ' ' + selection + '\r' + list + ' ');
@@ -164,11 +203,10 @@
}
editor.focus();
}
function insert_formatting(editor,start,end,placeholder) {
- var editor = html_editors[editor];
var current = editor.getSelection();
var placeholder_mode = false;
var start_pos = editor.getCursor("start");
var end_pos = editor.getCursor("end");
@@ -189,14 +227,14 @@
}
editor.focus();
}
-function do_preview(field) {
- var editor = html_editors[field];
- $('#preview_' + field).dialog({ autoOpen: true,
- width: 800, height: 500, modal: true, resizable: true, show: {effect:"drop"}, title: "Preview", closeOnEscape: true, dialogClass: "modal_markdown_preview" });
+function do_preview(editor,id) {
+
+ $('#preview_' + id).dialog({ autoOpen: true,
+ width: 820, height: 500, modal: true, resizable: false, class: "preview_modal", show: {effect:"drop"}, title: "Preview", closeOnEscape: true, dialogClass: "modal_markdown_preview" });
$.post('/utility/markdown_preview', {body: editor.getValue()}, function(data) {
- $('#preview_' + field).html(data);
+ $('#preview_' + id).html(data);
});
}