Last active
January 12, 2017 19:12
-
-
Save KoKuToru/71660c52cc87015cba2dc19906b8e753 to your computer and use it in GitHub Desktop.
New Twiddle
This file contains hidden or 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 events = [ | |
//keyboard | |
'keydown', | |
'keyup', | |
'keypress', | |
//im | |
'compositionstart', | |
'compositionupdate', | |
'compositionend', | |
//dnd | |
'drag', | |
'dragend', | |
'dragenter', | |
'dragexit', | |
'dragleave', | |
'dragover', | |
'dragstart', | |
'drop', | |
//actions | |
'cut', | |
'copy', | |
'past', | |
]; | |
export default Ember.Component.extend({ | |
attributeBindings: ['contenteditable'], | |
contenteditable: true, | |
init() { | |
this._super(...arguments); | |
//rebind | |
this._selection = this._selection.bind(this); | |
this._keydown = this._keydown.bind(this); | |
this._keypress = this._keypress.bind(this); | |
}, | |
willInsertElement() { | |
for (var x of events) { | |
if (this[`_${x}`]) { | |
this.$().on(x, this[`_${x}`]); | |
} | |
} | |
}, | |
willDestroyElement() { | |
//TODO: delete all events | |
}, | |
_selection() { | |
return window.getSelection() || document.getSelection(); | |
}, | |
_keydown(e) { | |
//quick and diry prevent all commands | |
if(e.ctrlKey){ | |
e.preventDefault(); | |
return; | |
} | |
}, | |
_keypress(e) { | |
//TODO: keycode into big list | |
// ignore arrow keys | |
switch (e.keyCode) { | |
case 37: //left | |
case 38: //up | |
case 39: //right | |
case 40: //down | |
return; | |
} | |
e.preventDefault(); | |
// get selection | |
const selection = this._selection(); | |
console.log("Selection ", selection); | |
//replace if not collapsed selection | |
//add if collapsed | |
//+ move cursor by one | |
} | |
}); |
This file contains hidden or 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 hidden or 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.10.7", | |
"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.10.0", | |
"ember-data": "2.10.0", | |
"ember-template-compiler": "2.10.0", | |
"ember-testing": "2.10.0" | |
}, | |
"addons": {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment