Last active
April 11, 2017 00:47
-
-
Save poteto/611606709a33c405da755c56338487ce to your computer and use it in GitHub Desktop.
atmentions
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'; | |
const { | |
String: { capitalize }, | |
$, | |
Component, | |
get, | |
set | |
} = Ember; | |
export default Component.extend({ | |
tagName: '', | |
storeLastPosition(lastPos) { | |
return set(this, 'lastPosition', lastPos); | |
}, | |
setAtomComponent(editor, atomName) { | |
return set(this, 'atomToDisplay', atomName); | |
}, | |
didReceiveAttrs() { | |
this._super(...arguments); | |
let editor = get(this, 'editor.editor'); | |
let component = this; | |
let atKeyCommand = { | |
str: 'SHIFT+2', | |
run(editor) { | |
component.storeLastPosition(editor.range.focusedPosition); | |
component.setAtomComponent(editor, 'mention-dropdown'); | |
} | |
}; | |
editor.registerKeyCommand(atKeyCommand); | |
}, | |
closeAtomMenu() { | |
$('.mobiledoc-editor__editor').focus(); | |
set(this, 'atomToDisplay', undefined); | |
}, | |
refocusEditor() { | |
get(this, 'editor.editor').run(postEditor => { | |
postEditor.insertText(get(this, 'lastPosition'), ''); | |
}); | |
}, | |
handleMention(payload) { | |
let { fullName } = payload; | |
this.closeAtomMenu(); | |
this.refocusEditor(); | |
get(this, 'editor').addAtom('mention-atom', fullName, payload); | |
}, | |
actions: { | |
atomAction(atomName, ...args) { | |
let handler = this[`handle${capitalize(atomName)}`].bind(this); | |
return handler(...args); | |
} | |
} | |
}); |
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'; | |
const { get } = Ember; | |
export default Ember.Component.extend({ | |
tagName: '' | |
}); |
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'; | |
const { $, run: { scheduleOnce } } = Ember; | |
export default Ember.Component.extend({ | |
users: [ | |
{id: 1, fullName: 'Colin Kennedy', email: '[email protected]'}, | |
{id: 2, fullName: 'Ryan Soo', email: '[email protected]'}, | |
{id: 3, fullName: 'Lauren Tan', email: '[email protected]'}, | |
{id: 4, fullName: 'Jacob Jin', email: '[email protected]'}, | |
{id: 5, fullName: 'Zach Wentz', email: '[email protected]'}, | |
], | |
didInsertElement() { | |
this._super(...arguments); | |
scheduleOnce('afterRender', this, function() { | |
this.$('input').focus(); | |
}); | |
} | |
}); |
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'; | |
import createComponentAtom from 'ember-mobiledoc-editor/utils/create-component-atom'; | |
const { computed, get, set } = Ember; | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle', | |
atoms: computed(function() { | |
return [ | |
createComponentAtom('mention-atom') | |
]; | |
}), | |
actions: { | |
updated(mobiledoc) { | |
set(this, 'mobiledoc', mobiledoc); | |
}, | |
submit() { | |
console.log(get(this, 'mobiledoc')); | |
} | |
} | |
}); |
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" | |
}, | |
"addons": { | |
"ember-data": "2.12.1", | |
"ember-mobiledoc-editor": "*" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment