Skip to content

Instantly share code, notes, and snippets.

@sherifflight
Last active June 16, 2019 14:07
Show Gist options
  • Save sherifflight/0be78f34de99a08869203675492c0002 to your computer and use it in GitHub Desktop.
Save sherifflight/0be78f34de99a08869203675492c0002 to your computer and use it in GitHub Desktop.
ace builds ace_builds npm library enabling example js css
.ace_editor {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
.ace_editor_textarea {
height: 500px;
}
.fixed-editor {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 9999;
}
import ace from 'ace-builds/src-noconflict/ace';
import "ace-builds/webpack-resolver";
import "ace-builds/src-noconflict/ext-language_tools"; // for autocompletion
import "ace-builds/src-noconflict/ext-keybinding_menu"; // for key binding
let editor = ace.edit("editor");
editor.setTheme("ace/theme/monokai");
editor.session.setMode("ace/mode/php_laravel_blade");
editor.setOptions({
enableBasicAutocompletion: true,
enableSnippets: true,
enableLiveAutocompletion: true,
});
// bind fullscreen mode on "F11" button
editor.commands.addCommand({
name: "fullscreen",
bindKey: "F11",
exec: function (editor) {
let textarea = document.getElementsByClassName('ace_editor_textarea')[0];
if (hasClass(textarea, 'fixed-editor')) {
textarea.classList.remove('fixed-editor')
} else {
textarea.classList.add('fixed-editor')
}
editor.resize(); // resize editor after fullscreen
}
});
// super-duper mega option for sending value from editor session to hidden field...
let textarea = $("textarea[name=raw]").hide();
editor.session.setValue(textarea.val());
editor.session.on('change', function () {
textarea.val(editor.session.getValue());
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment