Encapsulate directive functions in anonymous functions - avoid the global namespace

This commit is contained in:
Kevin Gisi
2015-06-21 23:52:08 -04:00
parent b4c4b891a1
commit 78b424e247
10 changed files with 278 additions and 258 deletions

View File

@@ -1,32 +1,34 @@
'use strict';
angular
.module('habitrpg')
.directive('hrpgSortTasks', hrpgSortTasks);
(function(){
angular
.module('habitrpg')
.directive('hrpgSortTasks', hrpgSortTasks);
hrpgSortTasks.$inject = [
'User'
];
hrpgSortTasks.$inject = [
'User'
];
function hrpgSortTasks(User) {
return function($scope, element, attrs, ngModel) {
$(element).sortable({
axis: "y",
distance: 5,
start: function (event, ui) {
ui.item.data('startIndex', ui.item.index());
},
stop: function (event, ui) {
var task = angular.element(ui.item[0]).scope().task;
var startIndex = ui.item.data('startIndex');
User.user.ops.sortTask({
params: { id: task.id },
query: {
from: startIndex,
to: ui.item.index()
}
});
}
});
function hrpgSortTasks(User) {
return function($scope, element, attrs, ngModel) {
$(element).sortable({
axis: "y",
distance: 5,
start: function (event, ui) {
ui.item.data('startIndex', ui.item.index());
},
stop: function (event, ui) {
var task = angular.element(ui.item[0]).scope().task;
var startIndex = ui.item.data('startIndex');
User.user.ops.sortTask({
params: { id: task.id },
query: {
from: startIndex,
to: ui.item.index()
}
});
}
});
}
}
}
}());