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

Commit 4193363

Browse files
committed
feat(sortable): add workaround for horizontal lists
1 parent bf1e08f commit 4193363

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,12 +28,22 @@ 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
function afterStop(e, ui) {
3237
ui.item.sortable._destroy();
3338
}
3439

3540
var opts = {};
3641

42+
// directive specific options
43+
var directiveOpts = {
44+
'ui-floating': undefined
45+
};
46+
3747
var callbacks = {
3848
receive: null,
3949
remove:null,
@@ -46,7 +56,7 @@ angular.module('ui.sortable', [])
4656
helper: null
4757
};
4858

49-
angular.extend(opts, uiSortableConfig, scope.$eval(attrs.uiSortable));
59+
angular.extend(opts, directiveOpts, uiSortableConfig, scope.$eval(attrs.uiSortable));
5060

5161
if (!angular.element.fn || !angular.element.fn.jquery) {
5262
$log.error('ui.sortable: jQuery should be included before AngularJS!');
@@ -69,6 +79,13 @@ angular.module('ui.sortable', [])
6979
});
7080

7181
callbacks.start = function(e, ui) {
82+
if (opts['ui-floating'] === 'auto') {
83+
// since the drag has started, the element will be
84+
// absolutely positioned, so we check its siblings
85+
var siblings = ui.item.siblings();
86+
angular.element(e.target).data('ui-sortable').floating = isFloating(siblings);
87+
}
88+
7289
// Save the starting position of dragged item
7390
ui.item.sortable = {
7491
index: ui.item.index(),
@@ -240,7 +257,18 @@ angular.module('ui.sortable', [])
240257
// is still bound to the directive's element
241258
if (!!element.data('ui-sortable')) {
242259
angular.forEach(newVal, function(value, key) {
243-
if(callbacks[key]) {
260+
// if it's a custom option of the directive,
261+
// handle it approprietly
262+
if (key in directiveOpts) {
263+
if (key === 'ui-floating' && (value === false || value === true)) {
264+
element.data('ui-sortable').floating = value;
265+
}
266+
267+
opts[key] = value;
268+
return;
269+
}
270+
271+
if (callbacks[key]) {
244272
if( key === 'stop' ){
245273
// call apply after stop
246274
value = combineCallbacks(

0 commit comments

Comments
 (0)