Added basic drag-and-drop functionality between spell lists

Closes #105
This commit is contained in:
Jacob
2017-07-26 19:23:41 +01:00
parent 73d1419ee9
commit 3599b5fbc4
3 changed files with 107 additions and 1 deletions

View File

@@ -83,7 +83,9 @@
{{#each spells ../_id ../../_id}}
{{#if showSpell ../../_id}}
<div class="item-slot">
<div class="tall spell item layout horizontal center" data-id={{_id}}>
<div class="tall spell item layout horizontal center spellItem"
data-id={{_id}}
draggable={{canEditCharacter charId}}>
<iron-icon icon="social:whatshot"
style="color: {{hexColor color}};
margin-right: 16px;"

View File

@@ -333,3 +333,26 @@ Template.spells.events({
event.stopPropagation();
},
});
Template.layout.events({
"dragstart .spellItem": function(event, instance){
event.originalEvent.dataTransfer.setData("dicecloud-id/spells", this._id);
Session.set("inventory.dragSpellId", this._id);
},
"dragend .spellItem": function(event, instance){
Session.set("inventory.dragSpellId", null);
},
"dragover .spellList, dragenter .spellList":
function(event, instance){
if (_.contains(event.originalEvent.dataTransfer.types, "dicecloud-id/spells")){
event.preventDefault();
}
},
"drop .spellList": function(event, instance){
var spellId = event.originalEvent.dataTransfer.getData("dicecloud-id/spells");
//move spell to new list
Meteor.call("moveSpellToList", spellId, this._id);
Session.set("inventory.dragSpellId", null);
},
});