Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save knownasilya/c41e57f02ed05fb966cbc984d0a23168 to your computer and use it in GitHub Desktop.
Save knownasilya/c41e57f02ed05fb966cbc984d0a23168 to your computer and use it in GitHub Desktop.
mobiledoc on text input
import Ember from 'ember';
export default Ember.Component.extend({
classNames: ['my-editor'],
didInsertElement() {
let editor = new Mobiledoc.Editor({
html: 'hi',
autofocus: true,
atoms: [
{
name: 'tag',
type: 'dom',
render({ env, value, payload }) {
let span = document.createElement('span');
span.textContent = `{${value}}`;
span.classList.add('tag');
span.onclick = function () {
let name = window.prompt('What is the name?', value);
if (name !== null) {
env.save(name, payload);
}
};
return span;
}
}
]
});
editor.onTextInput({
text: '{',
run(editor) {
let position = editor.post.tailPosition();
let name = window.prompt('What is the name?');
editor.deleteAtPosition(position, -1, {});
editor.insertAtom('tag', name);
}
});
editor.render(this.element);
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Ember from 'ember';
export default Ember.Route.extend({
});
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
.my-editor {
border: 1px solid #eee;
}
.my-editor p {
padding: 0.1em;
margin: 0;
}
.tag {
color: tomato;
}
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{my-editor-wrapper}}
{{outlet}}
<br>
<br>
{
"version": "0.12.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.12.0",
"ember-template-compiler": "2.12.0",
"ember-testing": "2.12.0",
"mobiledoc-kit": "https://unpkg.com/[email protected]/dist/global/mobiledoc-kit.js"
},
"addons": {
"ember-data": "2.12.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment