c98130cc08
* ui: Add the most basic workspace root in /ui * We already have a LICENSE file in the repository root * Change directory path in build scripts ui-v2 -> ui * Make yarn install flags configurable from elsewhere * Minimal workspace root makefile * Call the new docker specific target * Update yarn in the docker build image * Reconfigure the netlify target and move to the higher makefile * Move ui-v2 -> ui/packages/consul-ui * Change repo root to refleect new folder structure * Temporarily don't hoist consul-api-double * Fixup CI configuration * Fixup lint errors * Fixup Netlify target
39 lines
1 KiB
JavaScript
39 lines
1 KiB
JavaScript
/*global CodeMirror*/
|
|
|
|
// CodeMirror doesn't seem to have anyway to hook into whether a mode
|
|
// has already loaded, or when a mode has finished loading
|
|
// follow more or less what CodeMirror does but doesn't expose
|
|
// see codemirror/addon/mode/loadmode.js
|
|
|
|
export const createLoader = function(
|
|
$$ = document.getElementsByTagName.bind(document),
|
|
CM = CodeMirror
|
|
) {
|
|
CM.registerHelper('lint', 'ruby', function(text) {
|
|
return [];
|
|
});
|
|
return function(editor, mode, cb) {
|
|
let scripts = [...$$('script')];
|
|
const loaded = scripts.find(function(item) {
|
|
return item.src.indexOf(`/codemirror/mode/${mode}/${mode}.js`) !== -1;
|
|
});
|
|
CM.autoLoadMode(editor, mode);
|
|
if (loaded) {
|
|
cb();
|
|
} else {
|
|
scripts = [...$$('script')];
|
|
CM.on(scripts[0], 'load', function() {
|
|
cb();
|
|
});
|
|
}
|
|
};
|
|
};
|
|
const load = createLoader();
|
|
export default function(editor, mode) {
|
|
load(editor, mode, function() {
|
|
if (editor.getValue().trim().length) {
|
|
editor.performLint();
|
|
}
|
|
});
|
|
}
|