Skip to content

Commit

Permalink
Update demo to insert @-mentions
Browse files Browse the repository at this point in the history
  • Loading branch information
bantic committed Apr 21, 2016
1 parent 2d9963e commit f518d91
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
16 changes: 16 additions & 0 deletions demo/app/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@ export default Ember.Controller.extend({
},

actions: {
addEditorListeners(editor) {
editor.onTextInput({
text: '@',
run(editor) {
let whom = window.prompt('Mention whom?');
let range = editor.range;
editor.run(postEditor => {
range = range.extend(-1); // include the "@"
let position = postEditor.deleteRange(range);
let atom = postEditor.builder.createAtom('mention-atom', whom);
postEditor.insertMarkers(position, [atom]);
});
}
});
},

changeMobiledoc() {
let selectElement = $('#select-mobiledoc');
let name = selectElement.val();
Expand Down
6 changes: 5 additions & 1 deletion demo/app/mobiledoc-atoms/dom/mention.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ export default {
render({value}) {
const element = document.createElement("span");
element.className = 'mention-atom';
element.appendChild(document.createTextNode(`Hello ${value}`));
let textNode = document.createTextNode('@' + value);
let link = document.createElement('a');
link.setAttribute('href', `http://github.com/${value}`);
link.appendChild(textNode);
element.appendChild(link);
return element;
}
};
1 change: 1 addition & 0 deletions demo/app/templates/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
{{#mobiledoc-editor
class='post-editor__editor'
mobiledoc=mobiledoc
did-create-editor=(action 'addEditorListeners')
cards=(mobiledoc-cards-list)
atoms=(mobiledoc-atoms-list)
on-change=(action 'didEdit')
Expand Down

0 comments on commit f518d91

Please sign in to comment.