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

Commit 104405b

Browse files
committed
feat(sortable): add workaround for horizontal lists
1 parent 2fb4240 commit 104405b

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

src/sortable.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,18 @@ angular.module('ui.sortable', [])
2828
return helperOption === 'clone' || (typeof helperOption === 'function' && ui.item.sortable.isCustomHelperUsed());
2929
}
3030

31+
// thanks jquery-ui
32+
function isFloating (item) {
33+
return (/left|right/).test(item.css('float')) || (/inline|table-cell/).test(item.css('display'));
34+
}
35+
3136
var opts = {};
3237

38+
// directive specific options
39+
var directiveOpts = {
40+
'ui-floating': undefined
41+
};
42+
3343
var callbacks = {
3444
receive: null,
3545
remove:null,
@@ -42,7 +52,7 @@ angular.module('ui.sortable', [])
4252
helper: null
4353
};
4454

45-
angular.extend(opts, uiSortableConfig, scope.$eval(attrs.uiSortable));
55+
angular.extend(opts, directiveOpts, uiSortableConfig, scope.$eval(attrs.uiSortable));
4656

4757
if (!angular.element.fn || !angular.element.fn.jquery) {
4858
$log.error('ui.sortable: jQuery should be included before AngularJS!');
@@ -65,6 +75,13 @@ angular.module('ui.sortable', [])
6575
});
6676

6777
callbacks.start = function(e, ui) {
78+
if (opts['ui-floating'] === 'auto') {
79+
// since the drag has started, the element will be
80+
// absolutely positioned, so we check its siblings
81+
var siblings = ui.item.siblings();
82+
angular.element(e.target).data('ui-sortable').floating = isFloating(siblings);
83+
}
84+
6885
// Save the starting position of dragged item
6986
ui.item.sortable = {
7087
index: ui.item.index(),
@@ -229,7 +246,18 @@ angular.module('ui.sortable', [])
229246
// is still bound to the directive's element
230247
if (!!element.data('ui-sortable')) {
231248
angular.forEach(newVal, function(value, key) {
232-
if(callbacks[key]) {
249+
// if it's a custom option of the directive,
250+
// handle it approprietly
251+
if (key in directiveOpts) {
252+
if (key === 'ui-floating' && (value === false || value === true)) {
253+
element.data('ui-sortable').floating = value;
254+
}
255+
256+
opts[key] = value;
257+
return;
258+
}
259+
260+
if (callbacks[key]) {
233261
if( key === 'stop' ){
234262
// call apply after stop
235263
value = combineCallbacks(

0 commit comments

Comments
 (0)