-
Notifications
You must be signed in to change notification settings - Fork 313
/
sortable-item.js
63 lines (52 loc) · 1.51 KB
/
sortable-item.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*jshint indent: 2 */
/*global angular: false */
(function () {
'use strict';
var mainModule = angular.module('ui.sortable');
/**
* Controller for sortable item.
*
* @param $scope - drag item scope
*/
mainModule.controller('ui.sortable.sortableItemController', ['$scope', function ($scope) {
this.scope = $scope;
$scope.sortableScope = null;
$scope.modelValue = null; // sortable item.
$scope.type = 'item';
/**
* returns the index of the drag item from the sortable list.
*
* @returns {*} - index value.
*/
$scope.index = function () {
return $scope.sortableScope.modelValue.indexOf($scope.modelValue);
};
/**
* Returns the item model data.
*
* @returns {*} - item model value.
*/
$scope.itemData = function () {
return $scope.sortableScope.modelValue[$scope.$index];
};
}]);
/**
* sortableItem directive.
*/
mainModule.directive('asSortableItem', ['sortableConfig',
function (sortableConfig) {
return {
require: '^asSortable',
restrict: 'A',
controller: 'ui.sortable.sortableItemController',
link: function (scope, element, attrs, sortableController) {
if (sortableConfig.itemClass) {
element.addClass(sortableConfig.itemClass);
}
scope.sortableScope = sortableController.scope;
scope.modelValue = sortableController.scope.modelValue[scope.$index];
scope.element = element;
}
};
}]);
}());