Skip to content
This repository was archived by the owner on Sep 8, 2020. It is now read-only.

Commit 0a94a39

Browse files
author
AngularUI (via TravisCI)
committed
Travis commit : build 115
0 parents  commit 0a94a39

File tree

4 files changed

+104
-0
lines changed

4 files changed

+104
-0
lines changed

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
# blacklist the bower branch
3+
branches:
4+
only:
5+
- master

bower.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "angular-ui-sortable",
3+
"version": "0.0.1",
4+
"main": "./src/sortable.js",
5+
"dependencies": {
6+
"angular": "~1.0.x",
7+
"jquery-ui": ">= 1.9"
8+
}
9+
}

sortable.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
'use strict';
2+
angular.module('ui.sortable', []).value('uiSortableConfig', {}).directive('uiSortable', [
3+
'uiSortableConfig',
4+
'$log',
5+
function (uiSortableConfig, log) {
6+
return {
7+
require: '?ngModel',
8+
link: function (scope, element, attrs, ngModel) {
9+
function combineCallbacks(first, second) {
10+
if (second && typeof second === 'function') {
11+
return function (e, ui) {
12+
first(e, ui);
13+
second(e, ui);
14+
};
15+
}
16+
return first;
17+
}
18+
var opts = {};
19+
var callbacks = {
20+
receive: null,
21+
remove: null,
22+
start: null,
23+
stop: null,
24+
update: null
25+
};
26+
var apply = function (e, ui) {
27+
if (ui.item.sortable.resort || ui.item.sortable.relocate) {
28+
scope.$apply();
29+
}
30+
};
31+
angular.extend(opts, uiSortableConfig);
32+
if (ngModel) {
33+
ngModel.$render = function () {
34+
element.sortable('refresh');
35+
};
36+
callbacks.start = function (e, ui) {
37+
ui.item.sortable = { index: ui.item.index() };
38+
};
39+
callbacks.update = function (e, ui) {
40+
ui.item.sortable.resort = ngModel;
41+
};
42+
callbacks.receive = function (e, ui) {
43+
ui.item.sortable.relocate = true;
44+
ngModel.$modelValue.splice(ui.item.index(), 0, ui.item.sortable.moved);
45+
};
46+
callbacks.remove = function (e, ui) {
47+
if (ngModel.$modelValue.length === 1) {
48+
ui.item.sortable.moved = ngModel.$modelValue.splice(0, 1)[0];
49+
} else {
50+
ui.item.sortable.moved = ngModel.$modelValue.splice(ui.item.sortable.index, 1)[0];
51+
}
52+
};
53+
callbacks.stop = function (e, ui) {
54+
if (ui.item.sortable.resort && !ui.item.sortable.relocate) {
55+
var end, start;
56+
start = ui.item.sortable.index;
57+
end = ui.item.index();
58+
ui.item.sortable.resort.$modelValue.splice(end, 0, ui.item.sortable.resort.$modelValue.splice(start, 1)[0]);
59+
}
60+
};
61+
scope.$watch(attrs.uiSortable, function (newVal) {
62+
angular.forEach(newVal, function (value, key) {
63+
if (callbacks[key]) {
64+
value = combineCallbacks(callbacks[key], value);
65+
if (key === 'stop') {
66+
value = combineCallbacks(value, apply);
67+
}
68+
}
69+
element.sortable('option', key, value);
70+
});
71+
}, true);
72+
angular.forEach(callbacks, function (value, key) {
73+
opts[key] = combineCallbacks(value, opts[key]);
74+
});
75+
opts.stop = combineCallbacks(opts.stop, apply);
76+
} else {
77+
log.info('ui.sortable: ngModel not provided!', element);
78+
}
79+
element.sortable(opts);
80+
}
81+
};
82+
}
83+
]);

sortable.min.js

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)