diff --git a/core/client/Brocfile.js b/core/client/Brocfile.js index 410dbed13e..d33c9e59e6 100644 --- a/core/client/Brocfile.js +++ b/core/client/Brocfile.js @@ -52,5 +52,12 @@ app.import('bower_components/ember-simple-auth/simple-auth-oauth2.js'); app.import('bower_components/google-caja/html-css-sanitizer-bundle.js'); app.import('bower_components/nanoscroller/bin/javascripts/jquery.nanoscroller.js'); app.import('bower_components/jqueryui-touch-punch/jquery.ui.touch-punch.js'); +app.import('bower_components/codemirror/lib/codemirror.js'); +app.import('bower_components/codemirror/lib/codemirror.css'); +app.import('bower_components/codemirror/theme/xq-light.css'); +app.import('bower_components/codemirror/mode/htmlmixed/htmlmixed.js'); +app.import('bower_components/codemirror/mode/xml/xml.js'); +app.import('bower_components/codemirror/mode/css/css.js'); +app.import('bower_components/codemirror/mode/javascript/javascript.js'); module.exports = app.toTree(); diff --git a/core/client/app/components/gh-cm-editor.js b/core/client/app/components/gh-cm-editor.js new file mode 100644 index 0000000000..9cc671f853 --- /dev/null +++ b/core/client/app/components/gh-cm-editor.js @@ -0,0 +1,48 @@ +/* global CodeMirror */ +import Ember from 'ember'; + +var CodeMirrorEditor = Ember.Component.extend({ + + // DOM stuff + classNameBindings: ['isFocused:focused'], + isFocused: false, + + value: '', // make sure a value exists + editor: null, // reference to CodeMirror editor + + // options for the editor + lineNumbers: true, + indentUnit: 4, + mode: 'htmlmixed', + theme: 'xq-light', + + didInsertElement: function () { + var options = this.getProperties('lineNumbers', 'indentUnit', 'mode', 'theme'), + self = this, + editor; + editor = new CodeMirror(this.get('element'), options); + editor.getDoc().setValue(this.get('value')); + + // events + editor.on('focus', function () { + self.set('isFocused', true); + }); + editor.on('blur', function () { + self.set('isFocused', false); + }); + editor.on('change', function () { + self.set('value', editor.getDoc().getValue()); + }); + + this.set('editor', editor); + }, + + willDestroyElement: function () { + var editor = this.get('editor').getWrapperElement(); + editor.parentNode.removeChild(editor); + this.set('editor', null); + } + +}); + +export default CodeMirrorEditor; diff --git a/core/client/app/styles/layouts/settings.scss b/core/client/app/styles/layouts/settings.scss index 1f0eacbef4..95014a6dd7 100644 --- a/core/client/app/styles/layouts/settings.scss +++ b/core/client/app/styles/layouts/settings.scss @@ -10,6 +10,7 @@ // * Headers // * Custom Permalinks // * Navigation +// * Code Injection // ------------------------------------------------------------ @@ -510,4 +511,27 @@ background: darken($green, 10%); } } +} + +// +// Code Injection +// -------------------------------------------------- + +.settings-code-editor { + width: 100%; + min-width: 250px; + max-width: 680px; + height: auto; + border: 1px solid #E0DFD7; + border-radius: $border-radius; + -webkit-appearance: none; + min-height: 300px; + transition: border-color 0.15s linear; + line-height: 22px; + + &.focused { + border-color: $brown; + outline: 0; + } + } \ No newline at end of file diff --git a/core/client/app/templates/settings/code-injection.hbs b/core/client/app/templates/settings/code-injection.hbs index 92e74022da..7941881bc6 100644 --- a/core/client/app/templates/settings/code-injection.hbs +++ b/core/client/app/templates/settings/code-injection.hbs @@ -18,13 +18,13 @@
Code here will be injected to the \{{ghost_head}} helper at the top of your page
- {{textarea id="ghost-head" name="codeInjection[ghost_head]" type="text" value=model.ghost_head}} + {{gh-cm-editor id="ghost-head" name="codeInjection[ghost_head]" class="settings-code-editor" type="text" value=model.ghost_head}}Code here will be injected to the \{{ghost_foot}} helper at the bottom of your page
- {{textarea id="ghost-foot" name="codeInjection[ghost_foot]" type="text" value=model.ghost_foot}} + {{gh-cm-editor id="ghost-foot" name="codeInjection[ghost_foot]" class="settings-code-editor" type="text" value=model.ghost_foot}}