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

Reliable watching of drag events. #338

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
22 changes: 6 additions & 16 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 @@ -328,12 +328,7 @@ var jqyoui = angular.module('ngDragDrop', []).service('ngDragDropService', ['$ti
}
});
} else {
element.draggable({disabled: true});
}

if (killWatcher && angular.isDefined(newValue) && (angular.equals(attrs.drag, 'true') || angular.equals(attrs.drag, 'false'))) {
killWatcher();
killWatcher = null;
dragSettings = scope.$eval(element.attr('jqyoui-draggable') || element.attr('data-jqyoui-draggable')) || {}; jqyouiOptions = scope.$eval(attrs.jqyouiOptions) || {}; element .draggable({disabled: true}) .draggable(jqyouiOptions);
}
};

Expand Down Expand Up @@ -392,18 +387,13 @@ var jqyoui = angular.module('ngDragDrop', []).service('ngDragDropService', ['$ti
}
});
} else {
element.droppable({disabled: true});
}

if (killWatcher && angular.isDefined(newValue) && (angular.equals(attrs.drop, 'true') || angular.equals(attrs.drop, 'false'))) {
killWatcher();
killWatcher = null;
dropSettings = scope.$eval($(element).attr('jqyoui-droppable') || $(element).attr('data-jqyoui-droppable')) || {}; jqyouiOptions = scope.$eval(attrs.jqyouiOptions) || {}; element .droppable({disabled: true}) .droppable(jqyouiOptions);
}
};

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

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