Last active
September 15, 2015 13:09
-
-
Save RyanHirsch/c086d2853a926c310a23 to your computer and use it in GitHub Desktop.
Simple DnD
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', | |
items: Ember.computed(function() { | |
return [ | |
Ember.Object.create({ title: 'Foo', bucket: 'first' }), | |
Ember.Object.create({ title: 'Bar', bucket: 'first' }), | |
Ember.Object.create({ title: 'Baz', bucket: 'first' }), | |
Ember.Object.create({ title: 'Quxx', bucket: 'first' }) | |
]; | |
}) | |
}); |
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({ | |
items: null, | |
registerWithWrapper: Ember.on('didInsertElement', function() { | |
this.register('bucket', { | |
component: this, | |
element: this.$('ul')[0] | |
}); | |
}), | |
filteredItems: Ember.computed('[email protected]', function() { | |
return this.get('items').filterBy('bucket', this.get('value')); | |
}) | |
}); |
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({ | |
registerWithWrapper: Ember.on('didInsertElement', function() { | |
this.register('item', { | |
component: this, | |
element: this.$()[0] | |
}); | |
}) | |
}); |
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({ | |
drake: null, | |
buckets: [], | |
items: [], | |
initDragula: Ember.on('willInsertElement', function() { | |
this.set('drake', window.dragula()); | |
}), | |
setupDragulaEvents: Ember.on('didInsertElement', function() { | |
this.get('drake').on('drop', (itemEl, destinationEl, sourceEl) => { | |
let dest = this.buckets.findBy('element', destinationEl); | |
let source = this.buckets.findBy('element', sourceEl); | |
let item = this.items.findBy('element', itemEl); | |
console.log({dest}); | |
console.log({source}); | |
console.log({item}); | |
item.component.set('item.bucket', dest.component.get('value')); | |
}); | |
}), | |
actions: { | |
register(type, obj) { | |
if(type === 'bucket') { | |
this.get('drake').containers.push(obj.element); | |
this.buckets.pushObject(obj); | |
} | |
else { | |
this.items.pushObject(obj); | |
} | |
} | |
} | |
}); |
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 { | |
margin: 12px 16px; | |
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; | |
font-size: 12pt; | |
} | |
ul { | |
background: #EEE; | |
min-height: .5rem; | |
} |
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.10", | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/1.13.9/ember.debug.js", | |
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/1.13.11/ember-data.js", | |
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/1.13.9/ember-template-compiler.js", | |
"dragula-css": "https://cdnjs.cloudflare.com/ajax/libs/dragula/3.3.0/dragula.min.css", | |
"dragula": "https://cdnjs.cloudflare.com/ajax/libs/dragula/3.3.0/dragula.min.js" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment