Skip to content

Commit

Permalink
First drag preview not showing on firefox fixed (behavior3#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
renatopp committed Nov 1, 2015
1 parent dd3f130 commit e185233
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
20 changes: 18 additions & 2 deletions src/app/directives/dragnode.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,25 @@
element.attr('draggable', 'true');

element.bind('dragstart', function(e) {
var img = $window.editor.preview(attrs.name);
var canvas = $window.editor.preview(attrs.name);
var isChrome = navigator.userAgent.toLowerCase().indexOf('chrome')>-1;

if (isChrome) {
var img = document.createElement('img');
img.src = canvas.toDataURL();

// 10ms delay in order to proper create the image object
// ugly hack =(
var time = (new Date()).getTime();
var delay = time + 10;
while (time < delay) {
time = (new Date()).getTime();
}
canvas = img;
}

e.dataTransfer.setData('name', attrs.name);
e.dataTransfer.setDragImage(img, img.width/2, img.height/2);
e.dataTransfer.setDragImage(canvas, canvas.width/2, canvas.height/2);
});
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/editor/editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,7 @@
stage.addChild(block);
stage.update();

var img = document.createElement("img");
img.src = canvas.toDataURL();

return img;
return canvas;
};

p.isDirty = function() {
Expand Down

0 comments on commit e185233

Please sign in to comment.