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

Commit 68cd370

Browse files
committed
feat(sortable): add workaround for horizontal lists
1 parent 25c7363 commit 68cd370

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(),
@@ -228,7 +245,18 @@ angular.module('ui.sortable', [])
228245
// is still bound to the directive's element
229246
if (!!element.data('ui-sortable')) {
230247
angular.forEach(newVal, function(value, key) {
231-
if(callbacks[key]) {
248+
// if it's a custom option of the directive,
249+
// handle it approprietly
250+
if (key in directiveOpts) {
251+
if (key === 'ui-floating' && (value === false || value === true)) {
252+
element.data('ui-sortable').floating = value;
253+
}
254+
255+
opts[key] = value;
256+
return;
257+
}
258+
259+
if (callbacks[key]) {
232260
if( key === 'stop' ){
233261
// call apply after stop
234262
value = combineCallbacks(

0 commit comments

Comments
 (0)