Last active
October 18, 2017 15:53
-
-
Save hjdivad/11656f42f6d25de11432ee5d9d67db83 to your computer and use it in GitHub Desktop.
keyup
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.Component.extend({ | |
attributeBindings: ['tabindex'], | |
classNames: ['sortable'], | |
tagName: 'div', | |
}); |
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 ARROW_UP = 38; | |
const ARROW_DOWN = 40; | |
const RETURN = 13; | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle', | |
names: ['foo', 'bar', 'baz'], | |
actions: { | |
keyup(idx, item, evt) { | |
let names = this.get('names'); | |
if (evt.keyCode === ARROW_UP) { | |
if(idx === 0) { return; } | |
let item = names.objectAt(idx); | |
names.replace(idx, 1); | |
names.replace(idx-1, 0, item); | |
} else if (evt.keyCode === ARROW_DOWN) { | |
if (idx === names.length -1) { return; } | |
let item = names.objectAt(idx); | |
names.replace(idx, 1); | |
names.replace(idx+1, 0, item); | |
Ember.run.scheduleOnce('afterRender', this, 'refocus', idx+1); | |
} else if (evt.keyCode === RETURN) { | |
console.log('<CR>, time to save our changes'); | |
} | |
} | |
}, | |
refocus(idx) { | |
let element = Ember.$(`.sortable:nth-of-type(${idx+1})`)[0]; | |
if(element) { | |
element.focus(); | |
} | |
console.log('focus', idx); | |
} | |
}); |
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.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" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment