Skip to content

Fix #144 - avoid using element.scope() #156

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

Closed
wants to merge 3 commits into from
Closed
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
3 changes: 3 additions & 0 deletions demo/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ angular.module('demoApp', [
'ui.sortable',
'ui.bootstrap'
]).
config(['$compileProvider', function ($compileProvider) {
$compileProvider.debugInfoEnabled(false); // testing issue #144
}]).
config(['$routeProvider', function ($routeProvider) {
$routeProvider.when('/', {templateUrl: 'views/kanban.html'});
$routeProvider.when('/kanban', {templateUrl: 'views/kanban.html', controller: 'KanbanController'});
Expand Down
34 changes: 24 additions & 10 deletions dist/ng-sortable.js
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@
}

scope.itemScope = itemController.scope;
element.data('_scope',scope); // #144, work with angular debugInfoEnabled(false)

scope.$watch('sortableScope.isDisabled', function (newVal) {
if (isDisabled !== newVal) {
Expand Down Expand Up @@ -710,17 +711,11 @@
var elementClicked, sourceScope, isDraggable;

elementClicked = angular.element(event.target);
sourceScope = elementClicked.scope();

// look for the handle on the current scope or parent scopes
isDraggable = false;
while (!isDraggable && sourceScope !== undefined) {
if (sourceScope.type && sourceScope.type === 'handle') {
isDraggable = true;
} else {
sourceScope = sourceScope.$parent;
}
}
sourceScope = fetchScope(elementClicked);

isDraggable = (sourceScope && sourceScope.type === 'handle');

//If a 'no-drag' element inside item-handle if any.
while (isDraggable && elementClicked[0] !== element[0]) {
Expand Down Expand Up @@ -792,7 +787,7 @@
//Set Class as dragging starts
dragElement.addClass(sortableConfig.dragging);

targetScope = targetElement.scope();
targetScope = fetchScope(targetElement);

if (!targetScope || !targetScope.type) {
return;
Expand Down Expand Up @@ -838,6 +833,24 @@
}
};


/**
* Fetch scope from element or parents
* @param {object} element Source element
* @return {object} Scope, or null if not found
*/
function fetchScope (element){
var scope;
while (!scope && element.length) {
scope = element.data('_scope');
if (!scope) {
element = element.parent();
}
}
return scope;
}


/**
* Check there is no place holder placed by itemScope.
* @param targetElement the target element to check with.
Expand Down Expand Up @@ -1065,6 +1078,7 @@
scope.modelValue = sortableController.scope.modelValue[scope.$index];
}
scope.element = element;
element.data('_scope',scope); // #144, work with angular debugInfoEnabled(false)
}
};
}]);
Expand Down
2 changes: 1 addition & 1 deletion dist/ng-sortable.min.js

Large diffs are not rendered by default.

33 changes: 23 additions & 10 deletions source/sortable-item-handle.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
}

scope.itemScope = itemController.scope;
element.data('_scope',scope); // #144, work with angular debugInfoEnabled(false)

scope.$watch('sortableScope.isDisabled', function (newVal) {
if (isDisabled !== newVal) {
Expand Down Expand Up @@ -205,17 +206,11 @@
var elementClicked, sourceScope, isDraggable;

elementClicked = angular.element(event.target);
sourceScope = elementClicked.scope();

// look for the handle on the current scope or parent scopes
isDraggable = false;
while (!isDraggable && sourceScope !== undefined) {
if (sourceScope.type && sourceScope.type === 'handle') {
isDraggable = true;
} else {
sourceScope = sourceScope.$parent;
}
}
sourceScope = fetchScope(elementClicked);

isDraggable = (sourceScope && sourceScope.type === 'handle');

//If a 'no-drag' element inside item-handle if any.
while (isDraggable && elementClicked[0] !== element[0]) {
Expand Down Expand Up @@ -287,7 +282,7 @@
//Set Class as dragging starts
dragElement.addClass(sortableConfig.dragging);

targetScope = targetElement.scope();
targetScope = fetchScope(targetElement);

if (!targetScope || !targetScope.type) {
return;
Expand Down Expand Up @@ -333,6 +328,24 @@
}
};


/**
* Fetch scope from element or parents
* @param {object} element Source element
* @return {object} Scope, or null if not found
*/
function fetchScope (element){
var scope;
while (!scope && element.length) {
scope = element.data('_scope');
if (!scope) {
element = element.parent();
}
}
return scope;
}


/**
* Check there is no place holder placed by itemScope.
* @param targetElement the target element to check with.
Expand Down
1 change: 1 addition & 0 deletions source/sortable-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
scope.modelValue = sortableController.scope.modelValue[scope.$index];
}
scope.element = element;
element.data('_scope',scope); // #144, work with angular debugInfoEnabled(false)
}
};
}]);
Expand Down