Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added dataTransfer object as in original drag/drop events #299

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
components
todo.TODO
.idea
13 changes: 9 additions & 4 deletions src/angular-dragdrop.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ var jqyoui = angular.module('ngDragDrop', []).service('ngDragDropService', ['$ti
callback = objExtract.callback,
constructor = objExtract.constructor,
args = [event, ui].concat(objExtract.args);

// call either $scoped method i.e. $scope.dropCallback or constructor's method i.e. this.dropCallback.
// Removing scope.$apply call that was performance intensive (especially onDrag) and does not require it
// always. So call it within the callback if needed.
return (scope[callback] || scope[constructor][callback]).apply(scope[callback] ? scope : scope[constructor], args);

function extract(callbackName) {
var atStartBracket = callbackName.indexOf('(') !== -1 ? callbackName.indexOf('(') : callbackName.length,
atEndBracket = callbackName.lastIndexOf(')') !== -1 ? callbackName.lastIndexOf(')') : callbackName.length,
Expand Down Expand Up @@ -195,7 +195,7 @@ var jqyoui = angular.module('ngDragDrop', []).service('ngDragDropService', ['$ti
toPos.top+= $toEl.outerHeight(true);
}
} else {
// Angular v1.2 uses ng-hide to hide an element
// Angular v1.2 uses ng-hide to hide an element
// so we've to remove it in order to grab its position
if (hadNgHideCls) $toEl.removeClass('ng-hide');
if (hadDNDHideCls) $toEl.removeClass('angular-dragdrop-hide');
Expand Down Expand Up @@ -314,6 +314,8 @@ var jqyoui = angular.module('ngDragDrop', []).service('ngDragDropService', ['$ti
.draggable({
start: function(event, ui) {
ngDragDropService.draggableScope = scope;
ngDragDropService.dataStransfer = {};
event.dataTransfer = ngDragDropService.dataStransfer;
zIndex = $(jqyouiOptions.helper ? ui.helper : this).css('z-index');
$(jqyouiOptions.helper ? ui.helper : this).css('z-index', 9999);
jqyoui.startXY = $(this)[dragSettings.containment || 'offset']();
Expand Down Expand Up @@ -361,12 +363,15 @@ var jqyoui = angular.module('ngDragDrop', []).service('ngDragDropService', ['$ti
.droppable(jqyouiOptions)
.droppable({
over: function(event, ui) {
event.dataTransfer = ngDragDropService.dataStransfer;
ngDragDropService.callEventCallback(scope, dropSettings.onOver, event, ui);
},
out: function(event, ui) {
event.dataTransfer = ngDragDropService.dataStransfer;
ngDragDropService.callEventCallback(scope, dropSettings.onOut, event, ui);
},
drop: function(event, ui) {
event.dataTransfer = ngDragDropService.dataStransfer;
var beforeDropPromise = null;

if (dropSettings.beforeDrop) {
Expand Down Expand Up @@ -403,7 +408,7 @@ var jqyoui = angular.module('ngDragDrop', []).service('ngDragDropService', ['$ti

killWatcher = scope.$watch(function() { return scope.$eval(attrs.drop); }, updateDroppable);
updateDroppable();

element.on('$destroy', function() {
element.droppable({disabled: true}).droppable('destroy');
});
Expand Down