Last active
May 13, 2016 08:13
-
-
Save krisselden/8b95fbde22b976ae3185ecf86b723388 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'; | |
export default Ember.Component.extend({ | |
tagName: 'li', | |
classNames: 'ui-state-default' | |
}); |
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', | |
classNames: 'ui-sortable', | |
didInsertElement() { | |
let $el = this.$(); | |
let updateAction = this.update; | |
let startIndex; | |
let nextSibling; | |
$el.sortable({ | |
start(evt, ui) { | |
startIndex = ui.item.index(); | |
// on start a placeholder is inserted after | |
// stash our original nextSibling | |
// since cancel doesn't undo correctly | |
nextSibling = ui.placeholder[0].nextSibling; | |
}, | |
update(evt, ui) { | |
let item = ui.item; | |
let itemEl = item[0]; | |
let endIndex = item.index(); | |
updateAction({ startIndex, endIndex }); | |
$el.sortable('cancel'); | |
// the above doesn't undo mutation correctly | |
itemEl.parentNode.insertBefore(itemEl, nextSibling); | |
} | |
}); | |
$el.disableSelection(); | |
} | |
}); |
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', | |
fruits: ['apple', 'banana', 'orange', 'pear'], | |
actions: { | |
updateFruits(evt) { | |
let { startIndex, endIndex } = evt; | |
let fruit = this.fruits[startIndex]; | |
this.fruits.removeAt(startIndex); | |
console.log('removeAt', startIndex, this.fruits); | |
this.fruits.insertAt(endIndex, fruit); | |
console.log('insertAt', endIndex, fruit); | |
} | |
} | |
}); |
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
body { | |
font-family: "Trebuchet MS", "Helvetica", "Arial", "Verdana", "sans-serif"; | |
font-size: 62.5%; | |
} | |
.ui-sortable { list-style-type: none; margin: 0; padding: 0; width: 60%; } | |
.ui-sortable li { margin: 0 3px 3px 3px; padding: 0.4em; padding-left: 1.5em; font-size: 1.4em; height: 18px; } | |
.ui-sortable li span { position: absolute; margin-left: -1.3em; } |
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.8.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"jqueryui.js": "https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js", | |
"jqueryui.css": "https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.css", | |
"ember": "2.5.1", | |
"ember-data": "2.5.2", | |
"ember-template-compiler": "2.5.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment