Commit 135f6f88 authored by Thibaut Frain's avatar Thibaut Frain Committed by Jérome Perrin

drag and drop relative callbacks are linked with application promise tree

parent 7a141d97
......@@ -528,20 +528,19 @@
}
function waitForDrop(gadget, config) {
var target = gadget.props.element
.querySelector('#main'),
callback;
var callback;
function canceller() {
if (callback !== undefined) {
target.removeEventListener('drop', callback, false);
gadget.props.main.removeEventListener('drop', callback, false);
}
}
function nonResolvableTrap(resolve, reject) {
/*jslint unparam: true*/
function itsANonResolvableTrap(resolve, reject) {
callback = function (evt) {
try {
var element = domParser.parseFromString(
evt.dataTransfer.getData('text/html'),
'text/html'
......@@ -564,12 +563,16 @@
"name": element_class
},
config);
} catch (e) {
reject(e);
}
};
target.addEventListener('drop', callback, false);
gadget.props.main.addEventListener('drop', callback, false);
}
return new RSVP.Promise(nonResolvableTrap, canceller);
return new RSVP.Promise(itsANonResolvableTrap, canceller);
}
initGadgetMixin(gadget_klass);
......
......@@ -8,16 +8,27 @@
tool_template = Handlebars.compile(tool_template_source);
function waitForDragstart(tool) {
var callback;
function canceller() {
if (callback !== undefined) {
tool.removeEventListener('dragstart', callback, false);
}
}
/*jslint unparam: true*/
var callback = function (evt) {
function itsANonResolvableTrap(resolve, reject) {
callback = function (evt) {
try {
evt.dataTransfer.setData('text/html', tool.outerHTML);
} catch (e) {
reject(e);
}
};
return new RSVP.Promise(function (resolve, reject) {
tool.addEventListener('dragstart', callback, false);
}, function () {
tool.removeEventListener('dragstart', callback, false);
});
}
return new RSVP.Promise(itsANonResolvableTrap, canceller);
}
initGadgetMixin(gadget_klass);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment