App = Em.Application.create({});
DragNDrop = Em.Namespace.create();
DragNDrop.cancel = function(event) {
event.preventDefault();
return false;
};
DragNDrop.Draggable = Em.Mixin.create({
attributeBindings: 'draggable',
draggable: 'true',
dragStart: function(event) {
var dataTransfer = event.originalEvent.dataTransfer;
dataTransfer.setData('Text', this.get('elementId'));
}
});
DragNDrop.Droppable = Em.Mixin.create({
dragEnter: DragNDrop.cancel,
dragOver: DragNDrop.cancel,
drop: function(event) {
event.preventDefault();
return false;
}
});
App.Object = Em.Object.extend({
name: null,
added: false,
isAdded: function(key, value) {
console.log(key, value)
if (arguments.length == 1) {
return this.get('added')
} else {
this.set('added', value)
console.log(value)
if (value) {
App.cartController.addObject(this);
} else {
App.cartController.removeObject(this);
}
return value
}
}.property()
});
App.ObjectView = Em.View.extend(DragNDrop.Draggable, {
tagName: 'div',
// .setDragImage (in #dragStart) requires an HTML element as the first argument
// so you must tell Ember to create the view and it's element and then get the
// HTML representation of that element.
dragStart: function(event) {
this._super(event);
// Let the controller know this view is dragging
this.set('content.isDragging', true);
// Set the drag image and location relative to the mouse/touch event
},
dragEnd: function(event) {
// Let the controller know this view is done dragging
this.setPath('content.isDragging', false);
},
removeObject: function(event) {
this.setPath('content.isAdded', false)
}
});
App.ObjectDropTarget = Em.View.extend(DragNDrop.Droppable, {
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.