Commit 355cfa0c authored by Tim Zallmann's avatar Tim Zallmann Committed by Mike Greiling

Made loading for GFM Inputs conditional

Double check if already initialised
parent 63124283
import $ from 'jquery';
import './autosize'; import './autosize';
import './bind_in_out'; import './bind_in_out';
import './markdown/render_gfm'; import './markdown/render_gfm';
import initGFMInput from './markdown/gfm_auto_complete';
import initCopyAsGFM from './markdown/copy_as_gfm'; import initCopyAsGFM from './markdown/copy_as_gfm';
import initCopyToClipboard from './copy_to_clipboard'; import initCopyToClipboard from './copy_to_clipboard';
import './details_behavior'; import './details_behavior';
...@@ -15,9 +15,27 @@ import initCollapseSidebarOnWindowResize from './collapse_sidebar_on_window_resi ...@@ -15,9 +15,27 @@ import initCollapseSidebarOnWindowResize from './collapse_sidebar_on_window_resi
import initSelect2Dropdowns from './select2'; import initSelect2Dropdowns from './select2';
installGlEmojiElement(); installGlEmojiElement();
initGFMInput();
initCopyAsGFM(); initCopyAsGFM();
initCopyToClipboard(); initCopyToClipboard();
initPageShortcuts(); initPageShortcuts();
initCollapseSidebarOnWindowResize(); initCollapseSidebarOnWindowResize();
initSelect2Dropdowns(); initSelect2Dropdowns();
document.addEventListener('DOMContentLoaded', () => {
window.requestIdleCallback(
() => {
// Check if we have to Load GFM Input
const $gfmInputs = $('.js-gfm-input:not(.js-gfm-input-initialized)');
if ($gfmInputs.length) {
import(/* webpackChunkName: 'initGFMInput' */ './markdown/gfm_auto_complete')
.then(({ default: initGFMInput }) => {
initGFMInput($gfmInputs);
})
.catch(() => {});
}
},
{ timeout: 500 },
);
});
...@@ -2,8 +2,8 @@ import $ from 'jquery'; ...@@ -2,8 +2,8 @@ import $ from 'jquery';
import GfmAutoComplete from 'ee_else_ce/gfm_auto_complete'; import GfmAutoComplete from 'ee_else_ce/gfm_auto_complete';
import { parseBoolean } from '~/lib/utils/common_utils'; import { parseBoolean } from '~/lib/utils/common_utils';
export default function initGFMInput() { export default function initGFMInput($els) {
$('.js-gfm-input:not(.js-vue-textarea)').each((i, el) => { $els.each((i, el) => {
const gfm = new GfmAutoComplete(gl.GfmAutoComplete && gl.GfmAutoComplete.dataSources); const gfm = new GfmAutoComplete(gl.GfmAutoComplete && gl.GfmAutoComplete.dataSources);
const enableGFM = parseBoolean(el.dataset.supportsAutocomplete); const enableGFM = parseBoolean(el.dataset.supportsAutocomplete);
......
...@@ -71,12 +71,15 @@ class GfmAutoComplete { ...@@ -71,12 +71,15 @@ class GfmAutoComplete {
setupLifecycle() { setupLifecycle() {
this.input.each((i, input) => { this.input.each((i, input) => {
const $input = $(input); const $input = $(input);
$input.off('focus.setupAtWho').on('focus.setupAtWho', this.setupAtWho.bind(this, $input)); if (!$input.hasClass('js-gfm-input-initialized')) {
$input.on('change.atwho', () => input.dispatchEvent(new Event('input'))); $input.off('focus.setupAtWho').on('focus.setupAtWho', this.setupAtWho.bind(this, $input));
// This triggers at.js again $input.on('change.atwho', () => input.dispatchEvent(new Event('input')));
// Needed for quick actions with suffixes (ex: /label ~) // This triggers at.js again
$input.on('inserted-commands.atwho', $input.trigger.bind($input, 'keyup')); // Needed for quick actions with suffixes (ex: /label ~)
$input.on('clear-commands-cache.atwho', () => this.clearCache()); $input.on('inserted-commands.atwho', $input.trigger.bind($input, 'keyup'));
$input.on('clear-commands-cache.atwho', () => this.clearCache());
$input.addClass('js-gfm-input-initialized');
}
}); });
} }
......
...@@ -380,7 +380,7 @@ export default { ...@@ -380,7 +380,7 @@ export default {
dir="auto" dir="auto"
:disabled="isSubmitting" :disabled="isSubmitting"
name="note[note]" name="note[note]"
class="note-textarea js-vue-comment-form js-note-text js-gfm-input js-autosize markdown-area js-vue-textarea qa-comment-input" class="note-textarea js-vue-comment-form js-note-text js-gfm-input js-autosize markdown-area qa-comment-input"
data-supports-quick-actions="true" data-supports-quick-actions="true"
:aria-label="__('Description')" :aria-label="__('Description')"
:placeholder="__('Write a comment or drag your files here…')" :placeholder="__('Write a comment or drag your files here…')"
......
...@@ -337,7 +337,7 @@ export default { ...@@ -337,7 +337,7 @@ export default {
v-model="updatedNoteBody" v-model="updatedNoteBody"
:data-supports-quick-actions="!isEditing" :data-supports-quick-actions="!isEditing"
name="note[note]" name="note[note]"
class="note-textarea js-gfm-input js-note-text js-autosize markdown-area js-vue-issue-note-form js-vue-textarea qa-reply-input" class="note-textarea js-gfm-input js-note-text js-autosize markdown-area js-vue-issue-note-form qa-reply-input"
dir="auto" dir="auto"
:aria-label="__('Description')" :aria-label="__('Description')"
:placeholder="__('Write a comment or drag your files here…')" :placeholder="__('Write a comment or drag your files here…')"
......
...@@ -41,7 +41,7 @@ exports[`Snippet Description Edit component rendering matches the snapshot 1`] = ...@@ -41,7 +41,7 @@ exports[`Snippet Description Edit component rendering matches the snapshot 1`] =
> >
<textarea <textarea
aria-label="Description" aria-label="Description"
class="note-textarea js-gfm-input js-autosize markdown-area" class="note-textarea js-gfm-input js-autosize markdown-area js-gfm-input-initialized"
data-qa-selector="snippet_description_field" data-qa-selector="snippet_description_field"
data-supports-quick-actions="false" data-supports-quick-actions="false"
dir="auto" dir="auto"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment