Skip to content

Commit 57fd915

Browse files
authored
Merge pull request #8 from topcoder-platform/issues-355
Issues-355:cleanup code, Issues-354:Key events don't work properly on Android Chrome
2 parents ff80a22 + f02d50d commit 57fd915

File tree

1 file changed

+11
-78
lines changed

1 file changed

+11
-78
lines changed

js/topcodereditor.js

Lines changed: 11 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,12 @@
66
$('body').addClass('topcodereditor-active');
77

88
/**
9-
* Determine editor format to load, and asset path, default to Wysiwyg
9+
* Determine editor settings
1010
*/
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-
1911
var canUpload = (gdn.definition('canUpload', false)) ? 1 : 0;
2012
var maxUploadSize = gdn.definition('maxUploadSize');
2113
var allowedImageExtensions = gdn.definition('allowedImageExtensions');
22-
var allowedFileExtensions = gdn.definition('allowedFileExtensions');
23-
var allowedFileMimeTypes = gdn.definition('allowedFileMimeTypes');
2414
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-
}
4115

4216
/**
4317
* Convert the first char to Uppercase
@@ -62,7 +36,6 @@
6236
while (start && /\w/.test(line.charAt(start - 1))) --start
6337
while (end < line.length && /\w/.test(line.charAt(end))) ++end
6438
var word = line.slice(start, end).toLowerCase();
65-
//logMessage('word' + word + ', length:' + word.length);
6639
if(word.length > 1) {
6740
$.ajax({
6841
type: "GET",
@@ -139,7 +112,6 @@
139112
var position = {};
140113

141114
onSuccess = function onSuccess(jsonData) {
142-
updateMediaIDs(self, jsonData);
143115
afterFileUploaded(self, jsonData, position);
144116
resetFileInput(self);
145117
};
@@ -157,7 +129,6 @@
157129
self.updateStatusBar('upload-image', self.options.imageTexts.sbInit);
158130
// run custom error handler
159131
if (onError && typeof onError === 'function') {
160-
//onError(errorMessage);
161132
onError(errorMessage);
162133
}
163134
// run error handler from options
@@ -454,19 +425,7 @@
454425
// Set a cursor at the end of line
455426
cm.setSelection(startPoint, endPoint);
456427
}
457-
logMessage('position: file' + data.name +':' + JSON.stringify(startPoint) + ' , '+ JSON.stringify(endPoint));
458-
logMessage('line: getCursor:' + cm.getCursor().line);
459-
460428
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);
470429
}
471430

472431
function beforeUploadingImages(files) {
@@ -489,40 +448,6 @@
489448
*/
490449
var editorInit = function (textareaObj) {
491450
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-
526451
if ($currentEditableTextarea.length) {
527452
// instantiate new editor
528453
var editor = new EasyMDE({
@@ -582,10 +507,19 @@
582507

583508
// forceSync = true, need to clear form after async requests
584509
$currentEditableTextarea.closest('form').on('complete', function (frm, btn) {
585-
logMessage("form::complete");
586510
editor.codemirror.setValue('');
587511
});
588512

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+
589523
editor.codemirror.on('keydown', function (cm, event) {
590524
if (!cm.state.completionActive /*Enables keyboard navigation in autocomplete list*/) {
591525
if (event.key == '@') {
@@ -616,7 +550,6 @@
616550

617551
$(document).on('contentLoad', function(e) {
618552
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"]');
620553
return;
621554
}
622555
// Multiple editors are supported on a page

0 commit comments

Comments
 (0)