diff --git a/app/assets/javascripts/dragdrop.js b/app/assets/javascripts/dragdrop.js index 6ccc1910b9b..f25895e68aa 100644 --- a/app/assets/javascripts/dragdrop.js +++ b/app/assets/javascripts/dragdrop.js @@ -32,20 +32,10 @@ jQuery(function() { $('#side-dropzone').removeClass('hover'); }); $('.dropzone').on('drop',function(e) { - // this 'drop' listener is also reused for pages with just one form, ie. /wiki/new - const closestCommentFormWrapper = e.target.closest('div.comment-form-wrapper'); // this returns null if there is no match + const params = getEditorParams(e.target); // defined in editorHelper.js e.preventDefault(); - let params = {}; - // there are no .comment-form-wrappers on /wiki/edit or /wiki/new - // these pages just have a single text-input form. - if (closestCommentFormWrapper) { - $D.selected = $(closestCommentFormWrapper); - // assign the ID of the textarea within the closest comment-form-wrapper - params['textarea'] = closestCommentFormWrapper.querySelector('textarea').id; - } else { - // default to #text-input - // ideally there should only be one per page - params['textarea'] = 'text-input'; + if (params.hasOwnProperty('dSelected')) { + $D.selected = params['dSelected']; } $E.initialize(params); }); diff --git a/app/assets/javascripts/editor.js b/app/assets/javascripts/editor.js index be578dedc79..21f80d7a564 100644 --- a/app/assets/javascripts/editor.js +++ b/app/assets/javascripts/editor.js @@ -4,18 +4,10 @@ $(function() { // on pages with multiple comments, $D.selected needs to be accurate so that rich-text changes (bold, italic, etc.) go into the right comment form // however, the editor is also used on pages with JUST ONE form, and no other comments, eg. /wiki/new & /wiki/edit, so this code needs to be reusable for that context $('.rich-text-button').on('click', function(e) { - const closestCommentFormWrapper = e.target.closest('div.comment-form-wrapper'); // this returns null if there is no match - let params = {}; - // there are no .comment-form-wrappers on /wiki/edit or /wiki/new - // these pages just have a single text-input form. - if (closestCommentFormWrapper) { - $D.selected = $(closestCommentFormWrapper); - // assign the ID of the textarea within the closest comment-form-wrapper - params['textarea'] = closestCommentFormWrapper.querySelector('textarea').id; - } else { - // default to #text-input - // ideally there should only be one per page - params['textarea'] = 'text-input'; + const params = getEditorParams(e.target); // defined in editorHelper.js + // assign dSelected + if (params.hasOwnProperty('dSelected')) { + $D.selected = params['dSelected']; } $E.initialize(params); const action = e.currentTarget.dataset.action // 'bold', 'italic', etc.