|
6 | 6 | $('body').addClass('topcodereditor-active');
|
7 | 7 |
|
8 | 8 | /**
|
9 |
| - * Determine editor format to load, and asset path, default to Wysiwyg |
| 9 | + * Determine editor settings |
10 | 10 | */
|
11 |
| - var editor, |
12 |
| - editorCacheBreakValue = Math.random(), |
13 |
| - editorVersion = gdn.definition('editorVersion', editorCacheBreakValue), |
14 |
| - defaultInputFormat = gdn.definition('defaultInputFormat', 'Markdown'), |
15 |
| - defaultMobileInputFormat = gdn.definition('defaultMobileInputFormat', 'Markdown'), |
16 |
| - editorInputFormat = gdn.definition('editorInputFormat', 'Markdown'), |
17 |
| - topcoderEditorToolbar = gdn.definition('topcoderEditorToolbar'); |
18 |
| - |
19 | 11 | var canUpload = (gdn.definition('canUpload', false)) ? 1 : 0;
|
20 | 12 | var maxUploadSize = gdn.definition('maxUploadSize');
|
21 | 13 | var allowedImageExtensions = gdn.definition('allowedImageExtensions');
|
22 |
| - var allowedFileExtensions = gdn.definition('allowedFileExtensions'); |
23 |
| - var allowedFileMimeTypes = gdn.definition('allowedFileMimeTypes'); |
24 | 14 | var allowedFileMimeTypeWithExts = gdn.definition('allowedFileMimeTypeWithExts');
|
25 |
| - var maxFileUploads = gdn.definition('maxFileUploads'); |
26 |
| - var debug = false; |
27 |
| - |
28 |
| - logMessage('topcoderEditorData:' + JSON.stringify(topcoderEditorToolbar)); |
29 |
| - logMessage('maxUploadSize:' + maxUploadSize); |
30 |
| - logMessage('allowedImageExtensions:' + allowedImageExtensions); |
31 |
| - logMessage('allowedFileExtensions:' + allowedFileExtensions); |
32 |
| - logMessage('allowedFileMimeTypes:' + allowedFileMimeTypes); |
33 |
| - logMessage('allowedFileMimeTypeWithExts:' + allowedFileMimeTypeWithExts); |
34 |
| - logMessage('maxFileUploads:' + maxFileUploads); |
35 |
| - |
36 |
| - function logMessage(message) { |
37 |
| - if (debug) { |
38 |
| - console.log('TopcoderEditorPlugin::'+ message); |
39 |
| - } |
40 |
| - } |
41 | 15 |
|
42 | 16 | /**
|
43 | 17 | * Convert the first char to Uppercase
|
|
62 | 36 | while (start && /\w/.test(line.charAt(start - 1))) --start
|
63 | 37 | while (end < line.length && /\w/.test(line.charAt(end))) ++end
|
64 | 38 | var word = line.slice(start, end).toLowerCase();
|
65 |
| - //logMessage('word' + word + ', length:' + word.length); |
66 | 39 | if(word.length > 1) {
|
67 | 40 | $.ajax({
|
68 | 41 | type: "GET",
|
|
139 | 112 | var position = {};
|
140 | 113 |
|
141 | 114 | onSuccess = function onSuccess(jsonData) {
|
142 |
| - updateMediaIDs(self, jsonData); |
143 | 115 | afterFileUploaded(self, jsonData, position);
|
144 | 116 | resetFileInput(self);
|
145 | 117 | };
|
|
157 | 129 | self.updateStatusBar('upload-image', self.options.imageTexts.sbInit);
|
158 | 130 | // run custom error handler
|
159 | 131 | if (onError && typeof onError === 'function') {
|
160 |
| - //onError(errorMessage); |
161 | 132 | onError(errorMessage);
|
162 | 133 | }
|
163 | 134 | // run error handler from options
|
|
454 | 425 | // Set a cursor at the end of line
|
455 | 426 | cm.setSelection(startPoint, endPoint);
|
456 | 427 | }
|
457 |
| - logMessage('position: file' + data.name +':' + JSON.stringify(startPoint) + ' , '+ JSON.stringify(endPoint)); |
458 |
| - logMessage('line: getCursor:' + cm.getCursor().line); |
459 |
| - |
460 | 428 | cm.focus();
|
461 |
| - logMessage('after focus: getCursor:' + cm.getCursor().line); |
462 |
| - } |
463 |
| - |
464 |
| - function updateMediaIDs(editor, jsonData) { |
465 |
| - var $element = editor.element; |
466 |
| - var postForm = $($element.closest('form')); |
467 |
| - $(postForm).append('<input type="hidden" id="Form_MediaIDs" name="MediaIDs[]" value="'+jsonData.mediaID+'"/>'); |
468 |
| - var mediaIDs = $(postForm).find('input[name="MediaIDs[]"]'); |
469 |
| - logMessage('MediaIDs='+mediaIDs); |
470 | 429 | }
|
471 | 430 |
|
472 | 431 | function beforeUploadingImages(files) {
|
|
489 | 448 | */
|
490 | 449 | var editorInit = function (textareaObj) {
|
491 | 450 | var $currentEditableTextarea = $(textareaObj);
|
492 |
| - var $postForm = $(textareaObj).closest('form'); |
493 |
| - var currentFormFormat = $postForm.find('input[name="Format"]'); |
494 |
| - var currentTextBoxWrapper; // div wrapper |
495 |
| - |
496 |
| - if (currentFormFormat.length) { |
497 |
| - currentFormFormat = currentFormFormat[0].value.toLowerCase(); |
498 |
| - } |
499 |
| - |
500 |
| - logMessage('The default format is '+ editorInputFormat); |
501 |
| - logMessage('The form format is '+ JSON.stringify(currentFormFormat)); |
502 |
| - |
503 |
| - currentTextBoxWrapper = $currentEditableTextarea.parent('.TextBoxWrapper'); |
504 |
| - // If singleInstance is false, then odds are the editor is being |
505 |
| - // loaded inline and there are other instances on page. |
506 |
| - var singleInstance = true; |
507 |
| - |
508 |
| - // Determine if editing a comment, or not. When editing a comment, |
509 |
| - // it has a comment id, while adding a new comment has an empty |
510 |
| - // comment id. The value is a hidden input. |
511 |
| - var commentId = $postForm.find('#Form_CommentID').val(); |
512 |
| - var discussionId = $postForm.find('#Form_DiscussionID').val(); |
513 |
| - var formConversationId = $postForm.find('#Form_ConversationID').val(); |
514 |
| - var draftId = $postForm.find('#Form_DraftID').val(); |
515 |
| - |
516 |
| - logMessage('DiscussionID=' + discussionId); |
517 |
| - logMessage('CommentID=' + commentId); |
518 |
| - logMessage('DraftID=' + draftId); |
519 |
| - |
520 |
| - if (typeof commentId != 'undefined' && commentId != '') { |
521 |
| - singleInstance = false; |
522 |
| - } |
523 |
| - |
524 |
| - logMessage('isSingleInstance='+singleInstance); |
525 |
| - |
526 | 451 | if ($currentEditableTextarea.length) {
|
527 | 452 | // instantiate new editor
|
528 | 453 | var editor = new EasyMDE({
|
|
582 | 507 |
|
583 | 508 | // forceSync = true, need to clear form after async requests
|
584 | 509 | $currentEditableTextarea.closest('form').on('complete', function (frm, btn) {
|
585 |
| - logMessage("form::complete"); |
586 | 510 | editor.codemirror.setValue('');
|
587 | 511 | });
|
588 | 512 |
|
| 513 | + editor.codemirror.on('change', function (cm, event) { |
| 514 | + // Key events don't work properly on Android Chrome |
| 515 | + if (!cm.state.completionActive /*Enables keyboard navigation in autocomplete list*/) { |
| 516 | + if (event.origin == '+input' && event.text && event.text.length > 0 && event.text[0] === '@') { |
| 517 | + cm.showHint({ completeSingle: false, alignWithWord: true }); |
| 518 | + return; |
| 519 | + } |
| 520 | + } |
| 521 | + }); |
| 522 | + |
589 | 523 | editor.codemirror.on('keydown', function (cm, event) {
|
590 | 524 | if (!cm.state.completionActive /*Enables keyboard navigation in autocomplete list*/) {
|
591 | 525 | if (event.key == '@') {
|
|
616 | 550 |
|
617 | 551 | $(document).on('contentLoad', function(e) {
|
618 | 552 | if ($('.BodyBox[format="Markdown"], .BodyBox[format="wysiwyg"],.js-bodybox[format="Markdown"], .js-bodybox[format="wysiwyg"]', e.target).length === 0) {
|
619 |
| - console.log('Supported only [format="Markdown"][format="wysiwyg"]'); |
620 | 553 | return;
|
621 | 554 | }
|
622 | 555 | // Multiple editors are supported on a page
|
|
0 commit comments