Skip to content

Commit 3f7203d

Browse files
committed
Changes to decrese the diffs with PR angular-ui#56.
* Formating changes * Renamed injected log to $log * Replaced apply function with inlined anonymus
1 parent 96f390b commit 3f7203d

File tree

1 file changed

+17
-25
lines changed

1 file changed

+17
-25
lines changed

src/sortable.js

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
jQuery UI Sortable plugin wrapper
33
44
@param [ui-sortable] {object} Options to pass to $.fn.sortable() merged onto ui.config
5-
*/
5+
*/
66
angular.module('ui.sortable', [])
7-
.value('uiSortableConfig', {})
7+
.value('uiSortableConfig',{})
88
.directive('uiSortable', ['uiSortableConfig', '$log',
9-
function(uiSortableConfig, log) {
9+
function(uiSortableConfig, $log) {
1010
return {
1111
require: '?ngModel',
1212
link: function(scope, element, attrs, ngModel) {
1313

14-
function combineCallbacks(first, second) {
15-
if (second && (typeof second === "function")) {
14+
function combineCallbacks(first,second){
15+
if(second && (typeof second === "function")) {
1616
return function(e, ui) {
1717
first(e, ui);
1818
second(e, ui);
@@ -25,16 +25,10 @@ angular.module('ui.sortable', [])
2525

2626
var callbacks = {
2727
receive: null,
28-
remove: null,
29-
start: null,
30-
stop: null,
31-
update: null
32-
};
33-
34-
var apply = function(e, ui) {
35-
if (ui.item.sortable.resort || ui.item.sortable.relocate) {
36-
scope.$apply();
37-
}
28+
remove:null,
29+
start:null,
30+
stop:null,
31+
update:null
3832
};
3933

4034
angular.extend(opts, uiSortableConfig);
@@ -46,12 +40,11 @@ angular.module('ui.sortable', [])
4640
};
4741

4842
callbacks.start = function(e, ui) {
49-
// Save position of dragged item
50-
ui.item.sortable = {
51-
index: ui.item.index()
52-
};
43+
// Save the starting position of dragged item
44+
ui.item.sortable = { index: ui.item.index() };
5345
};
5446

47+
5548
callbacks.update = function(e, ui) {
5649
// For some reason the reference to ngModel in stop() is wrong
5750
ui.item.sortable.resort = ngModel;
@@ -96,29 +89,28 @@ angular.module('ui.sortable', [])
9689

9790
if (key === 'stop') {
9891
// call apply after stop
99-
value = combineCallbacks(value, apply);
92+
value = combineCallbacks(
93+
value, function() { scope.$apply(); });
10094
}
10195
}
102-
10396
element.sortable('option', key, value);
10497
});
10598
}, true);
10699

107100
angular.forEach(callbacks, function(value, key) {
108-
109101
opts[key] = combineCallbacks(value, opts[key]);
110102
});
111103

112104
// call apply after stop
113-
opts.stop = combineCallbacks(opts.stop, apply);
105+
opts.stop = combineCallbacks(opts.stop, function() { scope.$apply(); });
114106

115107
} else {
116-
log.info('ui.sortable: ngModel not provided!', element);
108+
$log.info('ui.sortable: ngModel not provided!', element);
117109
}
118110

119111
// Create sortable
120112
element.sortable(opts);
121113
}
122114
};
123115
}
124-
]);
116+
]);

0 commit comments

Comments
 (0)