Forked from bantic/components.my-editor-wrapper.js
Last active
August 8, 2017 17:53
-
-
Save knownasilya/c41e57f02ed05fb966cbc984d0a23168 to your computer and use it in GitHub Desktop.
mobiledoc on text input
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle' | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Route.extend({ | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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