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

Commit dff4e20

Browse files
author
AngularUI (via TravisCI)
committed
Travis commit : build 544
1 parent 017fbd3 commit dff4e20

File tree

3 files changed

+48
-15
lines changed

3 files changed

+48
-15
lines changed

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-ui-sortable",
3-
"version": "0.17.2",
3+
"version": "",
44
"main": ["./sortable.js"],
55
"dependencies": {
66
"angular": ">=1.2.x",

sortable.js

+45-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* angular-ui-sortable - This directive allows you to jQueryUI Sortable.
3-
* @version v0.17.2 - 2017-08-17
3+
* @version v0.18.0 - 2017-11-26
44
* @link http://angular-ui.github.com
55
* @license MIT
66
*/
@@ -71,6 +71,19 @@ angular.module('ui.sortable', [])
7171
return null;
7272
}
7373

74+
function setItemChildrenWidth(item) {
75+
item.children().each(function() {
76+
var $el = angular.element(this);
77+
78+
// Preserve the with of the element
79+
$el.width($el.width());
80+
});
81+
}
82+
83+
function dummyHelper(e, item) {
84+
return item;
85+
}
86+
7487
function patchSortableOption(key, value) {
7588
if (callbacks[key]) {
7689
if( key === 'stop' ){
@@ -94,7 +107,8 @@ angular.module('ui.sortable', [])
94107
return value;
95108
}
96109

97-
function patchUISortableOptions(newVal, oldVal, sortableWidgetInstance) {
110+
function patchUISortableOptions(newOpts, oldOpts, sortableWidgetInstance) {
111+
98112
function addDummyOptionKey(value, key) {
99113
if (!(key in opts)) {
100114
// add the key in the opts object so that
@@ -109,11 +123,11 @@ angular.module('ui.sortable', [])
109123
// update some options of the sortable
110124
var optsDiff = null;
111125

112-
if (oldVal) {
126+
if (oldOpts) {
113127
// reset deleted options to default
114128
var defaultOptions;
115-
angular.forEach(oldVal, function(oldValue, key) {
116-
if (!newVal || !(key in newVal)) {
129+
angular.forEach(oldOpts, function(oldValue, key) {
130+
if (!newOpts || !(key in newOpts)) {
117131
if (key in directiveOpts) {
118132
if (key === 'ui-floating') {
119133
opts[key] = 'auto';
@@ -138,16 +152,33 @@ angular.module('ui.sortable', [])
138152
});
139153
}
140154

155+
newOpts = angular.extend({}, newOpts);
141156
// update changed options
142-
angular.forEach(newVal, function(value, key) {
143-
// if it's a custom option of the directive,
144-
// handle it approprietly
157+
// handle the custom option of the directive first
158+
angular.forEach(newOpts, function(value, key) {
145159
if (key in directiveOpts) {
146160
if (key === 'ui-floating' && (value === false || value === true) && sortableWidgetInstance) {
147161
sortableWidgetInstance.floating = value;
148162
}
149163

164+
if (key === 'ui-preserve-size' && (value === false || value === true)) {
165+
var userProvidedHelper = opts.helper;
166+
newOpts.helper = function(e, item) {
167+
if (opts['ui-preserve-size'] === true) {
168+
setItemChildrenWidth(item);
169+
}
170+
return (userProvidedHelper || dummyHelper).apply(this, arguments);
171+
};
172+
}
173+
150174
opts[key] = patchSortableOption(key, value);
175+
}
176+
});
177+
178+
// handle the normal option of the directive
179+
angular.forEach(newOpts, function(value, key) {
180+
if (key in directiveOpts) {
181+
// the custom option of the directive are already handled
151182
return;
152183
}
153184

@@ -206,7 +237,7 @@ angular.module('ui.sortable', [])
206237
}
207238

208239
// thanks jquery-ui
209-
function isFloating (item) {
240+
function isFloating(item) {
210241
return (/left|right/).test(item.css('float')) || (/inline|table-cell/).test(item.css('display'));
211242
}
212243

@@ -237,7 +268,8 @@ angular.module('ui.sortable', [])
237268
// directive specific options
238269
var directiveOpts = {
239270
'ui-floating': undefined,
240-
'ui-model-items': uiSortableConfig.items
271+
'ui-model-items': uiSortableConfig.items,
272+
'ui-preserve-size': undefined
241273
};
242274

243275
var callbacks = {
@@ -489,6 +521,7 @@ angular.module('ui.sortable', [])
489521
return function (e, item) {
490522
var oldItemSortable = item.sortable;
491523
var index = getItemIndex(item);
524+
492525
item.sortable = {
493526
model: ngModel.$modelValue[index],
494527
index: index,
@@ -513,12 +546,12 @@ angular.module('ui.sortable', [])
513546
return inner;
514547
};
515548

516-
scope.$watchCollection('uiSortable', function(newVal, oldVal) {
549+
scope.$watchCollection('uiSortable', function(newOpts, oldOpts) {
517550
// ensure that the jquery-ui-sortable widget instance
518551
// is still bound to the directive's element
519552
var sortableWidgetInstance = getSortableWidgetInstance(element);
520553
if (!!sortableWidgetInstance) {
521-
var optsDiff = patchUISortableOptions(newVal, oldVal, sortableWidgetInstance);
554+
var optsDiff = patchUISortableOptions(newOpts, oldOpts, sortableWidgetInstance);
522555

523556
if (optsDiff) {
524557
element.sortable('option', optsDiff);

sortable.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)