Created
November 17, 2015 22:03
-
-
Save wecc/0dd946cf55ebbf722e58 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 { set, computed: { sort } } = Ember; | |
| export default Ember.Controller.extend({ | |
| appName:'Ember Twiddle', | |
| sorting: ['position:asc'], | |
| sortedItems: sort('model', 'sorting'), | |
| actions: { | |
| sorted(oldIndex, newIndex) { | |
| let items = this.get('model'); | |
| let oldItem = items.findBy('position', oldIndex); | |
| let newItem = items.findBy('position', newIndex); | |
| set(oldItem, 'position', newIndex); | |
| set(newItem, 'position', oldIndex); | |
| } | |
| } | |
| }); |
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.Route.extend({ | |
| model() { | |
| return [ | |
| { position: 0, label: 'One' }, | |
| { position: 4, label: 'Five' }, | |
| { position: 1, label: 'Two' }, | |
| { position: 3, label: 'Four' }, | |
| { position: 2, label: 'Three' } | |
| ]; | |
| } | |
| }); |
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({ | |
| tagName: 'ul', | |
| didInsertElement() { | |
| this.$().sortable({ | |
| start: (event, ui) => { | |
| ui.item.oldIndex = ui.item.index(); | |
| }, | |
| update: (event, ui) => { | |
| let oldIndex = ui.item.oldIndex; | |
| let newIndex = ui.item.index(); | |
| this.$().sortable('cancel'); | |
| this.attrs['update'](oldIndex, newIndex); | |
| } | |
| }); | |
| } | |
| }); |
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.4.16", | |
| "EmberENV": { | |
| "FEATURES": {} | |
| }, | |
| "dependencies": { | |
| "jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
| "jquery-ui": "https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.js", | |
| "ember": "1.13.10", | |
| "ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.1.0/ember-data.js", | |
| "ember-template-compiler": "1.13.10" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment