diff --git a/.prettierrc b/.prettierrc
new file mode 100644
index 0000000..5c5237b
--- /dev/null
+++ b/.prettierrc
@@ -0,0 +1,3 @@
+{
+ "single-quote": true
+}
diff --git a/.travis.yml b/.travis.yml
index 7900299..6d05475 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,12 +1,12 @@
language: node_js
node_js:
-- '0.10'
+- '6'
addons:
- firefox: "latest"
+ firefox: "54.0.1"
before_install:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
-- npm install -qg bower grunt-cli
+- npm install -qg bower grunt grunt-cli
- npm install -q
- bower install
after_success:
diff --git a/API.md b/API.md
index 7288f81..0094f7d 100644
--- a/API.md
+++ b/API.md
@@ -1,5 +1,16 @@
# ui.item.sortable API documentation
+This refers to the additional properties that are exposed through the `ui` parameter in the provided callback hooks. eg:
+```js
+$scope.sortableOptions = {
+ update: function(e, ui) {
+ if (ui.item.sortable.model == "can't be moved") {
+ ui.item.sortable.cancel();
+ }
+ }
+};
+```
+
## Properties
**Note:**
@@ -58,3 +69,16 @@ Returns whether the current sorting is marked as canceled, by an earlier call to
### isCustomHelperUsed[()](http://api.jquery.com/Types/#Function)
Returns: [Boolean](http://api.jquery.com/Types/#Boolean)
Returns whether the [`helper`](http://api.jqueryui.com/sortable/#option-helper) element used for the current sorting, is one of the original ui-sortable list elements.
+
+
+## Events
+
+### `ui-sortable:moved`
+Is emitted after the `stop` callback.
+In connected sortables it is also emitted after the `update` on the receiving sortable.
+
+```js
+$rootScope.$on('ui-sortable:moved', function (e, ui) {
+
+});
+```
diff --git a/README.md b/README.md
index f20543e..15758cb 100644
--- a/README.md
+++ b/README.md
@@ -18,7 +18,7 @@ This directive allows you to sort an array with drag & drop.
**Notes:**
> * JQuery must be included before AngularJS.
-> * JQueryUI dependecies include [core](http://api.jqueryui.com/category/ui-core/), [widget](http://api.jqueryui.com/jQuery.widget/), [mouse](http://api.jqueryui.com/mouse/) & [sortable](http://api.jqueryui.com/sortable/). Creating a [custom build](http://jqueryui.com/download/#!version=1.10&components=1110000010000000000000000000000000) will [greatly reduce](https://github.com/angular-ui/ui-sortable/issues/154#issuecomment-40279430) the required file size. ([CDN](http://www.jsdelivr.com/) links for comparison: [full](http://cdn.jsdelivr.net/g/jquery.ui@1.10) vs [minimal](http://cdn.jsdelivr.net/g/jquery.ui@1.10%28jquery.ui.core.min.js+jquery.ui.widget.min.js+jquery.ui.mouse.min.js+jquery.ui.sortable.min.js%29))
+> * JQueryUI dependecies include [widget](http://api.jqueryui.com/jQuery.widget/), [data](http://api.jqueryui.com/data-selector/), [scroll-parent](http://api.jqueryui.com/scrollParent/), [mouse](http://api.jqueryui.com/mouse/) & [sortable](http://api.jqueryui.com/sortable/). Creating a [custom build](http://jqueryui.com/download/#!version=1.12.1&components=101000000100000010000000010000000000000000000000) will [greatly reduce](https://github.com/angular-ui/ui-sortable/issues/154#issuecomment-40279430) the required file size. ([CDN](http://www.jsdelivr.com/) links for comparison: [full](https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js) vs [minimal](https://cdn.jsdelivr.net/combine/npm/jquery-ui@1.12/ui/version.min.js,npm/jquery-ui@1.12/ui/widget.min.js,npm/jquery-ui@1.12/ui/data.min.js,npm/jquery-ui@1.12/ui/scroll-parent.min.js,npm/jquery-ui@1.12/ui/widgets/mouse.min.js,npm/jquery-ui@1.12/ui/widgets/sortable.min.js))
> * Users of AngularJS pre v1.2 can use [v0.10.x](https://github.com/angular-ui/ui-sortable/tree/v0.10.x-stable) or [v0.12.x](https://github.com/angular-ui/ui-sortable/tree/v0.12.x-stable) branches.
> * Early adopters of [Angular2](https://angular.io/) can use the [ng2 branch](https://github.com/angular-ui/ui-sortable/tree/ng2).
@@ -90,7 +90,15 @@ myAppModule.controller('MyController', function($scope) {
When using event callbacks ([start](http://api.jqueryui.com/sortable/#event-start)/[update](http://api.jqueryui.com/sortable/#event-update)/[stop](http://api.jqueryui.com/sortable/#event-stop)...), avoid manipulating DOM elements (especially the one with the ng-repeat attached).
The suggested pattern is to use callbacks for emmiting events and altering the scope (inside the 'Angular world').
-#### Floating
+#### ui-floating
+
+**ui-floating** (default: undefined)
+Description: Enables a workaround for smooth horizontal sorting.
+Type: [Boolean](http://api.jquery.com/Types/#Boolean)/[String](http://api.jquery.com/Types/#String)/`undefined`
+* **undefined**: Relies on jquery.ui to detect the list's orientation.
+* **false**: Forces jquery.ui.sortable to detect the list as vertical.
+* **true**: Forces jquery.ui.sortable to detect the list as horizontal.
+* **"auto"**: Detects on each drag `start` if the element is floating or not.
To have a smooth horizontal-list reordering, jquery.ui.sortable needs to detect the orientation of the list.
This detection takes place during the initialization of the plugin (and some of the checks include: whether the first item is floating left/right or if 'axis' parameter is 'x', etc).
@@ -118,14 +126,60 @@ $scope.sortableOptions = {
```
-**ui-floating** (default: undefined)
-Type: [Boolean](http://api.jquery.com/Types/#Boolean)/[String](http://api.jquery.com/Types/#String)/`undefined`
-* **undefined**: Relies on jquery.ui to detect the list's orientation.
-* **false**: Forces jquery.ui.sortable to detect the list as vertical.
-* **true**: Forces jquery.ui.sortable to detect the list as horizontal.
-* **"auto"**: Detects on each drag `start` if the element is floating or not.
+#### ui-model-items
+
+**ui-model-items** (default: `> [ng-repeat],> [data-ng-repeat],> [x-ng-repeat]`)
+Description: Defines which elements should be considered as part of your model.
+Type: [CSS selector](http://api.jquery.com/Types/#Selector)/[String](http://api.jquery.com/Types/#String)
+
+This is the model related counterpart option of [jQuery's items option](http://api.jqueryui.com/sortable/#option-items).
+
+#### ui-preserve-size
+
+**ui-preserve-size** (default: undefined)
+Description: Set's the size of the sorting helper to the size of the original element before the sorting.
+Type: [Boolean](http://api.jquery.com/Types/#Boolean)/`undefined`
+
+This is useful for elements that their size is dependent to other page characteristics.
+A representative example of such cases are `
` `
`s and `
`s.
+
+### Attributes For Event Handling
+
+To handle events with html bindings just define any expression to listed event attributes.
+If you defined an attribute for this events and defined callback function in sortableOptions at the same time, the attribute based callback will be called first.
+
+* **ui-sortable-start**
+* **ui-sortable-activate**
+* **ui-sortable-before-stop**
+* **ui-sortable-update**
+* **ui-sortable-remove**
+* **ui-sortable-receive**
+* **ui-sortable-deactivate**
+* **ui-sortable-stop**
+
+
+
+Expression works on update event.
+```html
+
+
{{ item }}
+
+```
+
+
+On update event callBackFunction1 if called before callBackFunction2.
+```js
+$scope.sortableOptions = {
+ 'update': callBackFunction2
+};
+```
+```html
+
+
{{ item }}
+
+```
-#### Canceling
+### Canceling
Inside the `update` callback, you can check the item that is dragged and cancel the sorting.
@@ -209,7 +263,7 @@ list A: stop
For more details about the events check the [jQueryUI API documentation](http://api.jqueryui.com/sortable/).
## Integrating with directives doing transclusion
-Wrap the transclusion directive element with the ui-sortable directive and set the `items` to target your `ng-repeat`ed elements. Following best practices, it is also highly recommended that you add a `track by` expression to your `ng-repeat`. [Angular Meterial example](http://codepen.io/thgreasi/pen/NbyLVK).
+Wrap the transclusion directive element with the ui-sortable directive and set the `items` to target your `ng-repeat`ed elements. Following best practices, it is also highly recommended that you add a `track by` expression to your `ng-repeat`. [Angular Material example](http://codepen.io/thgreasi/pen/NbyLVK).
```js
myAppModule.controller('MyController', function($scope) {
@@ -235,6 +289,7 @@ myAppModule.controller('MyController', function($scope) {
## Examples
- [Simple Demo](http://codepen.io/thgreasi/pen/wzmvgw)
+ - [Simple Attribute Handlers Demo](http://codepen.io/thgreasi/pen/JWbmjb)
- [Simple RequireJS Demo](http://codepen.io/thgreasi/pen/rrdNjj)
- [Simple Touch-Enabled Demo](http://codepen.io/thgreasi/pen/wzmvJv) using [jQuery UI Touch Punch](https://github.com/furf/jquery-ui-touch-punch/)
- [Multiple items sorting (ctrl+click)](http://codepen.io/thgreasi/pen/mJAcL) using [ui-sortable-multiselection](https://github.com/thgreasi/ui-sortable-multiselection)
@@ -257,7 +312,7 @@ myAppModule.controller('MyController', function($scope) {
## Integrations
- [firebase](http://codepen.io/thgreasi/pen/repEZg?editors=0010)
- [ui.bootstrap.accordion](http://plnkr.co/edit/TGIeeEbbvJwpJ3WRqo2z?p=preview)
-- [Angular Meterial](http://codepen.io/thgreasi/pen/NbyLVK) (thanks yenoh2)
+- [Angular Material](http://codepen.io/thgreasi/pen/NbyLVK) (thanks yenoh2)
- [Asynchronous loading jQuery+jQueryUI with crisbeto/angular-ui-sortable-loader](https://github.com/crisbeto/angular-ui-sortable-loader)
## Reporting Issues
@@ -267,7 +322,7 @@ Feel free to edit any of them for your needs (don't forget to also update the li
## Testing
-We use Karma and jshint to ensure the quality of the code. The easiest way to run these checks is to use grunt:
+We use Karma and JSHint to ensure the quality of the code. The easiest way to run these checks is to use grunt:
```sh
npm install -g grunt-cli
diff --git a/bower.json b/bower.json
index 7200b2f..db20c0c 100644
--- a/bower.json
+++ b/bower.json
@@ -1,6 +1,6 @@
{
"name": "angular-ui-sortable",
- "version": "0.16.1",
+ "version": "0.19.0",
"description": "This directive allows you to jQueryUI Sortable.",
"author": "https://github.com/angular-ui/ui-sortable/graphs/contributors",
"license": "MIT",
diff --git a/package.json b/package.json
index 4820e84..9a61e8f 100644
--- a/package.json
+++ b/package.json
@@ -1,12 +1,16 @@
{
"name": "angular-ui-sortable",
- "version": "0.16.1",
+ "version": "0.19.0",
"description": "This directive allows you to jQueryUI Sortable.",
"author": "https://github.com/angular-ui/ui-sortable/graphs/contributors",
"license": "MIT",
"homepage": "http://angular-ui.github.com",
"main": "./src/sortable.js",
- "dependencies": {},
+ "dependencies": {
+ "angular": ">=1.2.x",
+ "jquery": ">=3.1.x",
+ "jquery-ui-dist": ">=1.12.x"
+ },
"devDependencies": {
"angular-ui-publisher": "1.2.x",
"grunt": "~0.4.x",
@@ -18,6 +22,7 @@
"grunt-karma": "^0.12.1",
"grunt-ngmin": "0.0.x",
"grunt-surround": "0.1.x",
+ "husky": "^0.14.3",
"jasmine-core": "^2.4.1",
"karma": "^0.13.22",
"karma-chrome-launcher": "0.1.x",
@@ -31,13 +36,28 @@
"karma-phantomjs-launcher": "^1.0.0",
"karma-requirejs": "^0.2.5",
"karma-script-launcher": "^0.2.0",
+ "lint-staged": "^5.0.0",
"load-grunt-tasks": "0.2.x",
+ "prettier": "^1.8.2",
"requirejs": "2.1.x",
"wiredep": "1.8.x"
},
- "scripts": {},
+ "scripts": {
+ "coverage": "grunt coverage",
+ "dist": "grunt dist",
+ "precommit": "lint-staged",
+ "prettify": "prettier --write \"src/**/*.js\" \"test/**/*.js\"",
+ "serve": "grunt serve",
+ "test": "grunt test"
+ },
"repository": {
"type": "git",
"url": "git://github.com/angular-ui/ui-sortable.git"
+ },
+ "lint-staged": {
+ "*.js": [
+ "prettier --write",
+ "git add"
+ ]
}
}
diff --git a/src/sortable.js b/src/sortable.js
index 6ee75db..ed0c482 100644
--- a/src/sortable.js
+++ b/src/sortable.js
@@ -3,29 +3,48 @@
@param [ui-sortable] {object} Options to pass to $.fn.sortable() merged onto ui.config
*/
-angular.module('ui.sortable', [])
- .value('uiSortableConfig',{
+angular
+ .module('ui.sortable', [])
+ .value('uiSortableConfig', {
// the default for jquery-ui sortable is "> *", we need to restrict this to
// ng-repeat items
// if the user uses
items: '> [ng-repeat],> [data-ng-repeat],> [x-ng-repeat]'
})
.directive('uiSortable', [
- 'uiSortableConfig', '$timeout', '$log',
+ 'uiSortableConfig',
+ '$timeout',
+ '$log',
function(uiSortableConfig, $timeout, $log) {
return {
require: '?ngModel',
scope: {
ngModel: '=',
- uiSortable: '='
+ uiSortable: '=',
+ ////Expression bindings from html.
+ create: '&uiSortableCreate',
+ // helper:'&uiSortableHelper',
+ start: '&uiSortableStart',
+ activate: '&uiSortableActivate',
+ // sort:'&uiSortableSort',
+ // change:'&uiSortableChange',
+ // over:'&uiSortableOver',
+ // out:'&uiSortableOut',
+ beforeStop: '&uiSortableBeforeStop',
+ update: '&uiSortableUpdate',
+ remove: '&uiSortableRemove',
+ receive: '&uiSortableReceive',
+ deactivate: '&uiSortableDeactivate',
+ stop: '&uiSortableStop'
},
link: function(scope, element, attrs, ngModel) {
var savedNodes;
+ var helper;
- function combineCallbacks(first, second){
+ function combineCallbacks(first, second) {
var firstIsFunc = typeof first === 'function';
var secondIsFunc = typeof second === 'function';
- if(firstIsFunc && secondIsFunc) {
+ if (firstIsFunc && secondIsFunc) {
return function() {
first.apply(this, arguments);
second.apply(this, arguments);
@@ -40,18 +59,36 @@ angular.module('ui.sortable', [])
// this is a fix to support jquery-ui prior to v1.11.x
// otherwise we should be using `element.sortable('instance')`
var data = element.data('ui-sortable');
- if (data && typeof data === 'object' && data.widgetFullName === 'ui-sortable') {
+ if (
+ data &&
+ typeof data === 'object' &&
+ data.widgetFullName === 'ui-sortable'
+ ) {
return data;
}
return null;
}
+ function setItemChildrenWidth(item) {
+ item.children().each(function() {
+ var $el = angular.element(this);
+
+ // Preserve the with of the element
+ $el.width($el.width());
+ });
+ }
+
+ function dummyHelper(e, item) {
+ return item;
+ }
+
function patchSortableOption(key, value) {
if (callbacks[key]) {
- if( key === 'stop' ){
+ if (key === 'stop') {
// call apply after stop
- value = combineCallbacks(
- value, function() { scope.$apply(); });
+ value = combineCallbacks(value, function() {
+ scope.$apply();
+ });
value = combineCallbacks(value, afterStop);
}
@@ -69,7 +106,11 @@ angular.module('ui.sortable', [])
return value;
}
- function patchUISortableOptions(newVal, oldVal, sortableWidgetInstance) {
+ function patchUISortableOptions(
+ newOpts,
+ oldOpts,
+ sortableWidgetInstance
+ ) {
function addDummyOptionKey(value, key) {
if (!(key in opts)) {
// add the key in the opts object so that
@@ -84,11 +125,11 @@ angular.module('ui.sortable', [])
// update some options of the sortable
var optsDiff = null;
- if (oldVal) {
+ if (oldOpts) {
// reset deleted options to default
var defaultOptions;
- angular.forEach(oldVal, function(oldValue, key) {
- if (!newVal || !(key in newVal)) {
+ angular.forEach(oldOpts, function(oldValue, key) {
+ if (!newOpts || !(key in newOpts)) {
if (key in directiveOpts) {
if (key === 'ui-floating') {
opts[key] = 'auto';
@@ -113,16 +154,43 @@ angular.module('ui.sortable', [])
});
}
+ newOpts = angular.extend({}, newOpts);
// update changed options
- angular.forEach(newVal, function(value, key) {
- // if it's a custom option of the directive,
- // handle it approprietly
+ // handle the custom option of the directive first
+ angular.forEach(newOpts, function(value, key) {
if (key in directiveOpts) {
- if (key === 'ui-floating' && (value === false || value === true) && sortableWidgetInstance) {
+ if (
+ key === 'ui-floating' &&
+ (value === false || value === true) &&
+ sortableWidgetInstance
+ ) {
sortableWidgetInstance.floating = value;
}
+ if (
+ key === 'ui-preserve-size' &&
+ (value === false || value === true)
+ ) {
+ var userProvidedHelper = opts.helper;
+ newOpts.helper = function(e, item) {
+ if (opts['ui-preserve-size'] === true) {
+ setItemChildrenWidth(item);
+ }
+ return (userProvidedHelper || dummyHelper).apply(
+ this,
+ arguments
+ );
+ };
+ }
+
opts[key] = patchSortableOption(key, value);
+ }
+ });
+
+ // handle the normal option of the directive
+ angular.forEach(newOpts, function(value, key) {
+ if (key in directiveOpts) {
+ // the custom option of the directive are already handled
return;
}
@@ -138,15 +206,19 @@ angular.module('ui.sortable', [])
return optsDiff;
}
- function getPlaceholderElement (element) {
- var placeholder = element.sortable('option','placeholder');
+ function getPlaceholderElement(element) {
+ var placeholder = element.sortable('option', 'placeholder');
// placeholder.element will be a function if the placeholder, has
// been created (placeholder will be an object). If it hasn't
// been created, either placeholder will be false if no
// placeholder class was given or placeholder.element will be
// undefined if a class was given (placeholder will be a string)
- if (placeholder && placeholder.element && typeof placeholder.element === 'function') {
+ if (
+ placeholder &&
+ placeholder.element &&
+ typeof placeholder.element === 'function'
+ ) {
var result = placeholder.element();
// workaround for jquery ui 1.9.x,
// not returning jquery collection
@@ -156,34 +228,48 @@ angular.module('ui.sortable', [])
return null;
}
- function getPlaceholderExcludesludes (element, placeholder) {
+ function getPlaceholderExcludesludes(element, placeholder) {
// exact match with the placeholder's class attribute to handle
// the case that multiple connected sortables exist and
// the placeholder option equals the class of sortable items
var notCssSelector = opts['ui-model-items'].replace(/[^,]*>/g, '');
- var excludes = element.find('[class="' + placeholder.attr('class') + '"]:not(' + notCssSelector + ')');
+ var excludes = element.find(
+ '[class="' +
+ placeholder.attr('class') +
+ '"]:not(' +
+ notCssSelector +
+ ')'
+ );
return excludes;
}
- function hasSortingHelper (element, ui) {
- var helperOption = element.sortable('option','helper');
- return helperOption === 'clone' || (typeof helperOption === 'function' && ui.item.sortable.isCustomHelperUsed());
+ function hasSortingHelper(element, ui) {
+ var helperOption = element.sortable('option', 'helper');
+ return (
+ helperOption === 'clone' ||
+ (typeof helperOption === 'function' &&
+ ui.item.sortable.isCustomHelperUsed())
+ );
}
- function getSortingHelper (element, ui, savedNodes) {
+ function getSortingHelper(element, ui /*, savedNodes*/) {
var result = null;
- if (hasSortingHelper(element, ui) &&
- element.sortable( 'option', 'appendTo' ) === 'parent') {
+ if (
+ hasSortingHelper(element, ui) &&
+ element.sortable('option', 'appendTo') === 'parent'
+ ) {
// The .ui-sortable-helper element (that's the default class name)
- // is placed last.
- result = savedNodes.last();
+ result = helper;
}
return result;
}
// thanks jquery-ui
- function isFloating (item) {
- return (/left|right/).test(item.css('float')) || (/inline|table-cell/).test(item.css('display'));
+ function isFloating(item) {
+ return (
+ /left|right/.test(item.css('float')) ||
+ /inline|table-cell/.test(item.css('display'))
+ );
}
function getElementContext(elementScopes, element) {
@@ -203,7 +289,8 @@ angular.module('ui.sortable', [])
// we can't just do ui.item.index() because there it might have siblings
// which are not items
function getItemIndex(item) {
- return item.parent()
+ return item
+ .parent()
.find(opts['ui-model-items'])
.index(item);
}
@@ -213,40 +300,60 @@ angular.module('ui.sortable', [])
// directive specific options
var directiveOpts = {
'ui-floating': undefined,
- 'ui-model-items': uiSortableConfig.items
+ 'ui-model-items': uiSortableConfig.items,
+ 'ui-preserve-size': undefined
};
var callbacks = {
- receive: null,
- remove: null,
+ create: null,
start: null,
- stop: null,
- update: null
+ activate: null,
+ // sort: null,
+ // change: null,
+ // over: null,
+ // out: null,
+ beforeStop: null,
+ update: null,
+ remove: null,
+ receive: null,
+ deactivate: null,
+ stop: null
};
var wrappers = {
helper: null
};
- angular.extend(opts, directiveOpts, uiSortableConfig, scope.uiSortable);
+ angular.extend(
+ opts,
+ directiveOpts,
+ uiSortableConfig,
+ scope.uiSortable
+ );
if (!angular.element.fn || !angular.element.fn.jquery) {
- $log.error('ui.sortable: jQuery should be included before AngularJS!');
+ $log.error(
+ 'ui.sortable: jQuery should be included before AngularJS!'
+ );
return;
}
- function wireUp () {
+ function wireUp() {
// When we add or remove elements, we need the sortable to 'refresh'
// so it can find the new/removed elements.
scope.$watchCollection('ngModel', function() {
// Timeout to let ng-repeat modify the DOM
- $timeout(function() {
- // ensure that the jquery-ui-sortable widget instance
- // is still bound to the directive's element
- if (!!getSortableWidgetInstance(element)) {
- element.sortable('refresh');
- }
- }, 0, false);
+ $timeout(
+ function() {
+ // ensure that the jquery-ui-sortable widget instance
+ // is still bound to the directive's element
+ if (!!getSortableWidgetInstance(element)) {
+ element.sortable('refresh');
+ }
+ },
+ 0,
+ false
+ );
});
callbacks.start = function(e, ui) {
@@ -254,7 +361,9 @@ angular.module('ui.sortable', [])
// since the drag has started, the element will be
// absolutely positioned, so we check its siblings
var siblings = ui.item.siblings();
- var sortableWidgetInstance = getSortableWidgetInstance(angular.element(e.target));
+ var sortableWidgetInstance = getSortableWidgetInstance(
+ angular.element(e.target)
+ );
sortableWidgetInstance.floating = isFloating(siblings);
}
@@ -266,24 +375,24 @@ angular.module('ui.sortable', [])
source: element,
sourceList: ui.item.parent(),
sourceModel: ngModel.$modelValue,
- cancel: function () {
+ cancel: function() {
ui.item.sortable._isCanceled = true;
},
- isCanceled: function () {
+ isCanceled: function() {
return ui.item.sortable._isCanceled;
},
- isCustomHelperUsed: function () {
+ isCustomHelperUsed: function() {
return !!ui.item.sortable._isCustomHelperUsed;
},
_isCanceled: false,
_isCustomHelperUsed: ui.item.sortable._isCustomHelperUsed,
- _destroy: function () {
+ _destroy: function() {
angular.forEach(ui.item.sortable, function(value, key) {
ui.item.sortable[key] = undefined;
});
},
_connectedSortables: [],
- _getElementContext: function (element) {
+ _getElementContext: function(element) {
return getElementContext(this._connectedSortables, element);
}
};
@@ -291,9 +400,9 @@ angular.module('ui.sortable', [])
callbacks.activate = function(e, ui) {
var isSourceContext = ui.item.sortable.source === element;
- var savedNodesOrigin = isSourceContext ?
- ui.item.sortable.sourceList :
- element;
+ var savedNodesOrigin = isSourceContext
+ ? ui.item.sortable.sourceList
+ : element;
var elementContext = {
element: element,
scope: scope,
@@ -308,12 +417,16 @@ angular.module('ui.sortable', [])
// This is inside activate (instead of start) in order to save
// both lists when dragging between connected lists.
savedNodes = savedNodesOrigin.contents();
+ helper = ui.helper;
// If this list has a placeholder (the connected lists won't),
// don't inlcude it in saved nodes.
var placeholder = getPlaceholderElement(element);
if (placeholder && placeholder.length) {
- var excludes = getPlaceholderExcludesludes(element, placeholder);
+ var excludes = getPlaceholderExcludesludes(
+ element,
+ placeholder
+ );
savedNodes = savedNodes.not(excludes);
}
};
@@ -322,14 +435,21 @@ angular.module('ui.sortable', [])
// Save current drop position but only if this is not a second
// update that happens when moving between lists because then
// the value will be overwritten with the old value
- if(!ui.item.sortable.received) {
+ if (!ui.item.sortable.received) {
ui.item.sortable.dropindex = getItemIndex(ui.item);
- var droptarget = ui.item.closest('[ui-sortable], [data-ui-sortable], [x-ui-sortable]');
+ var droptarget = ui.item
+ .parent()
+ .closest(
+ '[ui-sortable], [data-ui-sortable], [x-ui-sortable]'
+ );
ui.item.sortable.droptarget = droptarget;
ui.item.sortable.droptargetList = ui.item.parent();
- var droptargetContext = ui.item.sortable._getElementContext(droptarget);
- ui.item.sortable.droptargetModel = droptargetContext.scope.ngModel;
+ var droptargetContext = ui.item.sortable._getElementContext(
+ droptarget
+ );
+ ui.item.sortable.droptargetModel =
+ droptargetContext.scope.ngModel;
// Cancel the sort (let ng-repeat do the sort for us)
// Don't cancel if this is the received list because it has
@@ -343,7 +463,9 @@ angular.module('ui.sortable', [])
// the start and stop of repeat sections and sortable doesn't
// respect their order (even if we cancel, the order of the
// comments are still messed up).
- var sortingHelper = !ui.item.sortable.received && getSortingHelper(element, ui, savedNodes);
+ var sortingHelper =
+ !ui.item.sortable.received &&
+ getSortingHelper(element, ui, savedNodes);
if (sortingHelper && sortingHelper.length) {
// Restore all the savedNodes except from the sorting helper element.
// That way it will be garbage collected.
@@ -356,7 +478,7 @@ angular.module('ui.sortable', [])
// it's safe to clear the restored nodes since:
// update is currently running and
// stop is not called for the target list.
- if(ui.item.sortable.received) {
+ if (ui.item.sortable.received) {
savedNodes = null;
}
@@ -364,11 +486,15 @@ angular.module('ui.sortable', [])
// then we add the new item to this list otherwise wait until the
// stop event where we will know if it was a sort or item was
// moved here from another list
- if(ui.item.sortable.received && !ui.item.sortable.isCanceled()) {
- scope.$apply(function () {
- ngModel.$modelValue.splice(ui.item.sortable.dropindex, 0,
- ui.item.sortable.moved);
+ if (ui.item.sortable.received && !ui.item.sortable.isCanceled()) {
+ scope.$apply(function() {
+ ngModel.$modelValue.splice(
+ ui.item.sortable.dropindex,
+ 0,
+ ui.item.sortable.moved
+ );
});
+ scope.$emit('ui-sortable:moved', ui);
}
};
@@ -376,18 +502,26 @@ angular.module('ui.sortable', [])
// If the received flag hasn't be set on the item, this is a
// normal sort, if dropindex is set, the item was moved, so move
// the items in the list.
- var wasMoved = ('dropindex' in ui.item.sortable) &&
- !ui.item.sortable.isCanceled();
+ var wasMoved =
+ 'dropindex' in ui.item.sortable &&
+ !ui.item.sortable.isCanceled();
if (wasMoved && !ui.item.sortable.received) {
-
- scope.$apply(function () {
+ scope.$apply(function() {
ngModel.$modelValue.splice(
- ui.item.sortable.dropindex, 0,
- ngModel.$modelValue.splice(ui.item.sortable.index, 1)[0]);
+ ui.item.sortable.dropindex,
+ 0,
+ ngModel.$modelValue.splice(ui.item.sortable.index, 1)[0]
+ );
});
- } else if (!wasMoved &&
- !angular.equals(element.contents().toArray(), savedNodes.toArray())) {
+ scope.$emit('ui-sortable:moved', ui);
+ } else if (
+ !wasMoved &&
+ !angular.equals(
+ element.contents().toArray(),
+ savedNodes.toArray()
+ )
+ ) {
// if the item was not moved
// and the DOM element order has changed,
// then restore the elements
@@ -399,13 +533,16 @@ angular.module('ui.sortable', [])
// That way it will be garbage collected.
savedNodes = savedNodes.not(sortingHelper);
}
- var elementContext = ui.item.sortable._getElementContext(element);
+ var elementContext = ui.item.sortable._getElementContext(
+ element
+ );
savedNodes.appendTo(elementContext.savedNodesOrigin);
}
- // It's now safe to clear the savedNodes
+ // It's now safe to clear the savedNodes and helper
// since stop is the last callback.
savedNodes = null;
+ helper = null;
};
callbacks.receive = function(e, ui) {
@@ -426,25 +563,47 @@ angular.module('ui.sortable', [])
// Remove the item from this list's model and copy data into item,
// so the next list can retrive it
if (!ui.item.sortable.isCanceled()) {
- scope.$apply(function () {
+ scope.$apply(function() {
ui.item.sortable.moved = ngModel.$modelValue.splice(
- ui.item.sortable.index, 1)[0];
+ ui.item.sortable.index,
+ 1
+ )[0];
});
}
};
- wrappers.helper = function (inner) {
+ // setup attribute handlers
+ angular.forEach(callbacks, function(value, key) {
+ callbacks[key] = combineCallbacks(callbacks[key], function() {
+ var attrHandler = scope[key];
+ var attrHandlerFn;
+ if (
+ typeof attrHandler === 'function' &&
+ (
+ 'uiSortable' +
+ key.substring(0, 1).toUpperCase() +
+ key.substring(1)
+ ).length &&
+ typeof (attrHandlerFn = attrHandler()) === 'function'
+ ) {
+ attrHandlerFn.apply(this, arguments);
+ }
+ });
+ });
+
+ wrappers.helper = function(inner) {
if (inner && typeof inner === 'function') {
- return function (e, item) {
+ return function(e, item) {
var oldItemSortable = item.sortable;
var index = getItemIndex(item);
+
item.sortable = {
model: ngModel.$modelValue[index],
index: index,
source: element,
sourceList: item.parent(),
sourceModel: ngModel.$modelValue,
- _restore: function () {
+ _restore: function() {
angular.forEach(item.sortable, function(value, key) {
item.sortable[key] = undefined;
});
@@ -462,23 +621,31 @@ angular.module('ui.sortable', [])
return inner;
};
- scope.$watchCollection('uiSortable', function(newVal, oldVal) {
- // ensure that the jquery-ui-sortable widget instance
- // is still bound to the directive's element
- var sortableWidgetInstance = getSortableWidgetInstance(element);
- if (!!sortableWidgetInstance) {
- var optsDiff = patchUISortableOptions(newVal, oldVal, sortableWidgetInstance);
-
- if (optsDiff) {
- element.sortable('option', optsDiff);
+ scope.$watchCollection(
+ 'uiSortable',
+ function(newOpts, oldOpts) {
+ // ensure that the jquery-ui-sortable widget instance
+ // is still bound to the directive's element
+ var sortableWidgetInstance = getSortableWidgetInstance(element);
+ if (!!sortableWidgetInstance) {
+ var optsDiff = patchUISortableOptions(
+ newOpts,
+ oldOpts,
+ sortableWidgetInstance
+ );
+
+ if (optsDiff) {
+ element.sortable('option', optsDiff);
+ }
}
- }
- }, true);
+ },
+ true
+ );
patchUISortableOptions(opts);
}
- function init () {
+ function init() {
if (ngModel) {
wireUp();
} else {
@@ -489,7 +656,7 @@ angular.module('ui.sortable', [])
element.sortable(opts);
}
- function initIfEnabled () {
+ function initIfEnabled() {
if (scope.uiSortable && scope.uiSortable.disabled) {
return false;
}
@@ -506,7 +673,10 @@ angular.module('ui.sortable', [])
initIfEnabled.cancelWatcher = angular.noop;
if (!initIfEnabled()) {
- initIfEnabled.cancelWatcher = scope.$watch('uiSortable.disabled', initIfEnabled);
+ initIfEnabled.cancelWatcher = scope.$watch(
+ 'uiSortable.disabled',
+ initIfEnabled
+ );
}
}
};
diff --git a/test/karma.conf.js b/test/karma.conf.js
index a803dcc..1067454 100644
--- a/test/karma.conf.js
+++ b/test/karma.conf.js
@@ -7,7 +7,9 @@ module.exports = function(config) {
var wiredep = require('wiredep');
var fs = require('fs');
- var bowerOverrides = JSON.parse(fs.readFileSync('./test/bower_overrides.json'));
+ var bowerOverrides = JSON.parse(
+ fs.readFileSync('./test/bower_overrides.json')
+ );
var devJSDependencies = wiredep({
devDependencies: true,
@@ -15,15 +17,12 @@ module.exports = function(config) {
}).js;
config.set({
-
// base path, that will be used to resolve files and exclude
basePath: '..',
-
// frameworks to use
frameworks: ['jasmine'],
-
// list of files / patterns to load in the browser
files: devJSDependencies.concat([
'test/libs/jquery.simulate.dragandrevert.js',
@@ -34,35 +33,26 @@ module.exports = function(config) {
'test/sortable.tests.css'
]),
-
// list of files to exclude
- exclude: [
-
- ],
-
+ exclude: [],
// test results reporter to use
// possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
reporters: ['progress'],
-
// web server port
port: 9876,
-
// enable / disable colors in the output (reporters and logs)
colors: true,
-
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
-
// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,
-
// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
@@ -71,13 +61,11 @@ module.exports = function(config) {
// - Safari (only Mac; has to be installed with `npm install karma-safari-launcher`)
// - PhantomJS
// - IE (only Windows; has to be installed with `npm install karma-ie-launcher`)
- browsers: ['Chrome', 'Firefox'/*, 'PhantomJS'*/],
-
+ browsers: ['Chrome', 'Firefox' /*, 'PhantomJS'*/],
// If browser does not capture in given timeout [ms], kill it
captureTimeout: 60000,
-
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: false
diff --git a/test/libs/jquery.simulate.dragandrevert.js b/test/libs/jquery.simulate.dragandrevert.js
index 03cda66..5ca102f 100644
--- a/test/libs/jquery.simulate.dragandrevert.js
+++ b/test/libs/jquery.simulate.dragandrevert.js
@@ -1,60 +1,60 @@
-;(function($, undefined) {
- function findCenter(elem) {
- var offset,
- document = $(elem.ownerDocument);
- elem = $(elem);
- offset = elem.offset();
-
- return {
- x: offset.left + elem.outerWidth() / 2 - document.scrollLeft(),
- y: offset.top + elem.outerHeight() / 2 - document.scrollTop()
- };
- }
-
- $.extend($.simulate.prototype, {
- simulateDragAndRevert: function() {
- var i = 0,
- target = this.target,
- options = this.options,
- center = findCenter(target),
- x = Math.floor(center.x),
- y = Math.floor(center.y),
- dx = options.dx || 0,
- dy = options.dy || 0,
- moves = options.moves || 3,
- coord = {
- clientX: x,
- clientY: y
- };
-
- this.simulateEvent(target, "mousedown", coord);
-
- for (; i < moves; i++) {
- x += dx / moves;
- y += dy / moves;
-
- coord = {
- clientX: Math.round(x),
- clientY: Math.round(y)
- };
-
- this.simulateEvent(document, "mousemove", coord);
- }
-
- for (i = 0; i < moves; i++) {
- x -= dx / moves;
- y -= dy / moves;
-
- coord = {
- clientX: Math.round(x),
- clientY: Math.round(y)
- };
-
- this.simulateEvent(document, "mousemove", coord);
- }
-
- this.simulateEvent(target, "mouseup", coord);
- this.simulateEvent(target, "click", coord);
- }
- });
+(function($, undefined) {
+ function findCenter(elem) {
+ var offset,
+ document = $(elem.ownerDocument);
+ elem = $(elem);
+ offset = elem.offset();
+
+ return {
+ x: offset.left + elem.outerWidth() / 2 - document.scrollLeft(),
+ y: offset.top + elem.outerHeight() / 2 - document.scrollTop()
+ };
+ }
+
+ $.extend($.simulate.prototype, {
+ simulateDragAndRevert: function() {
+ var i = 0,
+ target = this.target,
+ options = this.options,
+ center = findCenter(target),
+ x = Math.floor(center.x),
+ y = Math.floor(center.y),
+ dx = options.dx || 0,
+ dy = options.dy || 0,
+ moves = options.moves || 3,
+ coord = {
+ clientX: x,
+ clientY: y
+ };
+
+ this.simulateEvent(target, 'mousedown', coord);
+
+ for (; i < moves; i++) {
+ x += dx / moves;
+ y += dy / moves;
+
+ coord = {
+ clientX: Math.round(x),
+ clientY: Math.round(y)
+ };
+
+ this.simulateEvent(document, 'mousemove', coord);
+ }
+
+ for (i = 0; i < moves; i++) {
+ x -= dx / moves;
+ y -= dy / moves;
+
+ coord = {
+ clientX: Math.round(x),
+ clientY: Math.round(y)
+ };
+
+ this.simulateEvent(document, 'mousemove', coord);
+ }
+
+ this.simulateEvent(target, 'mouseup', coord);
+ this.simulateEvent(target, 'click', coord);
+ }
+ });
})(jQuery);
diff --git a/test/sortable.e2e.callbacks.attr.spec.js b/test/sortable.e2e.callbacks.attr.spec.js
new file mode 100644
index 0000000..f09f8ff
--- /dev/null
+++ b/test/sortable.e2e.callbacks.attr.spec.js
@@ -0,0 +1,215 @@
+'use strict';
+
+describe('uiSortable', function() {
+ beforeEach(
+ module(function($compileProvider) {
+ if (typeof $compileProvider.debugInfoEnabled === 'function') {
+ $compileProvider.debugInfoEnabled(false);
+ }
+ })
+ );
+
+ // Ensure the sortable angular module is loaded
+ beforeEach(module('ui.sortable'));
+ beforeEach(module('ui.sortable.testHelper'));
+
+ var EXTRA_DY_PERCENTAGE,
+ listContent,
+ hasUndefinedProperties,
+ beforeLiElement,
+ afterLiElement;
+
+ beforeEach(
+ inject(function(sortableTestHelper) {
+ EXTRA_DY_PERCENTAGE = sortableTestHelper.EXTRA_DY_PERCENTAGE;
+ listContent = sortableTestHelper.listContent;
+ hasUndefinedProperties = sortableTestHelper.hasUndefinedProperties;
+ beforeLiElement =
+ sortableTestHelper.extraElements &&
+ sortableTestHelper.extraElements.beforeLiElement;
+ afterLiElement =
+ sortableTestHelper.extraElements &&
+ sortableTestHelper.extraElements.afterLiElement;
+ })
+ );
+
+ tests.description = 'Attribute Callbacks related';
+ function tests(useExtraElements) {
+ var host;
+
+ beforeEach(
+ inject(function() {
+ host = $('');
+ $('body').append(host);
+
+ if (!useExtraElements) {
+ beforeLiElement = afterLiElement = '';
+ }
+ })
+ );
+
+ afterEach(function() {
+ host.remove();
+ host = null;
+ });
+
+ it('should cancel sorting of node "Two"', function() {
+ inject(function($compile, $rootScope) {
+ var element;
+ element = $compile(
+ ''.concat(
+ '
'))($rootScope);
+ element = $compile(
+ ''.concat(
+ '
',
+ beforeLiElement,
+ '
{{ item }}
',
+ afterLiElement,
+ '
'
+ )
+ )($rootScope);
$rootScope.$apply(function() {
$rootScope.opts = {
'ui-floating': false
@@ -83,12 +106,15 @@ describe('uiSortable', function() {
it('should work when "ui-floating: true" option is used', function() {
inject(function($compile, $rootScope) {
var element;
- element = $compile(''.concat(
- '
',
- beforeLiElement.replace('
', '
'),
- '
{{ item }}
',
- afterLiElement.replace('
', '
'),
- '
'))($rootScope);
+ element = $compile(
+ ''.concat(
+ '
',
+ beforeLiElement.replace('
', '
'),
+ '
{{ item }}
',
+ afterLiElement.replace('
', '
'),
+ '
'
+ )
+ )($rootScope);
$rootScope.$apply(function() {
$rootScope.opts = {
'ui-floating': true
@@ -123,12 +149,15 @@ describe('uiSortable', function() {
it('should work when "ui-floating: \'auto\'" option is used and elements are "float"ing', function() {
inject(function($compile, $rootScope) {
var element;
- element = $compile(''.concat(
- '
',
- beforeLiElement.replace('
', '
'),
- '
{{ item }}
',
- afterLiElement.replace('
', '
'),
- '
'))($rootScope);
+ element = $compile(
+ ''.concat(
+ '
',
+ beforeLiElement.replace('
', '
'),
+ '
{{ item }}
',
+ afterLiElement.replace('
', '
'),
+ '
'
+ )
+ )($rootScope);
$rootScope.$apply(function() {
$rootScope.opts = {
'ui-floating': 'auto'
@@ -163,12 +192,15 @@ describe('uiSortable', function() {
it('should work when "ui-floating: \'auto\'" option is used and elements are "display: inline-block"', function() {
inject(function($compile, $rootScope) {
var element;
- element = $compile(''.concat(
- '
',
- beforeLiElement.replace('
', '
'),
- '
{{ item }}
',
- afterLiElement.replace('
', '
'),
- '
'))($rootScope);
+ element = $compile(
+ ''.concat(
+ '
'))($rootScope);
+ element = $compile(
+ ''.concat(
+ '
',
+ beforeLiElement,
+ '
{{ item }}
',
+ afterLiElement + '
'
+ )
+ )($rootScope);
$rootScope.$apply(function() {
$rootScope.opts = {
'ui-floating': true,
@@ -220,11 +254,11 @@ describe('uiSortable', function() {
host.append(element).append(logsElement);
var sortableWidgetInstance = element.data('ui-sortable');
-
+
expect(sortableWidgetInstance.floating).toBe(true);
$rootScope.$digest();
-
+
$rootScope.$apply(function() {
$rootScope.opts = {};
});
@@ -244,12 +278,15 @@ describe('uiSortable', function() {
it('should work when custom "ui-model-items" option is used with an attribute selector', function() {
inject(function($compile, $rootScope) {
var element;
- element = $compile(''.concat(
- '
',
- beforeLiElement,
- '
{{ item }}
',
- afterLiElement,
- '
'))($rootScope);
+ element = $compile(
+ ''.concat(
+ '
',
+ beforeLiElement,
+ '
{{ item }}
',
+ afterLiElement,
+ '
'
+ )
+ )($rootScope);
var itemsSelector = '[ui-sortable-item]';
$rootScope.$apply(function() {
@@ -281,12 +318,15 @@ describe('uiSortable', function() {
it('should work when custom "ui-model-items" option is used with a class selector', function() {
inject(function($compile, $rootScope) {
var element;
- element = $compile(''.concat(
- '
',
- beforeLiElement,
- '
{{ item }}
',
- afterLiElement,
- '
'))($rootScope);
+ element = $compile(
+ ''.concat(
+ '
',
+ beforeLiElement,
+ '
{{ item }}
',
+ afterLiElement,
+ '
'
+ )
+ )($rootScope);
var itemsSelector = '.ui-sortable-item';
$rootScope.$apply(function() {
@@ -318,14 +358,23 @@ describe('uiSortable', function() {
xit('should work with multiple [ng-repeat] when attribute "ui-model-items" selector', function() {
inject(function($compile, $rootScope) {
var element;
- element = $compile(''.concat(
- '
',
- beforeLiElement,
- beforeLiElement.replace('
', '
{{ item }}'),
- '
{{ item }}
',
- afterLiElement.replace('
', '
{{ item }}'),
- afterLiElement,
- '
'))($rootScope);
+ element = $compile(
+ ''.concat(
+ '
'))($rootScope);
+ element = $compile(
+ ''.concat(
+ '
',
+ beforeLiElement,
+ '
{{ item }}
',
+ afterLiElement,
+ '
'
+ )
+ )($rootScope);
$rootScope.$apply(function() {
$rootScope.opts = {
helper: 'clone'
@@ -435,12 +509,15 @@ describe('uiSortable', function() {
it('should work when "helper: clone" option is used and a drag is reverted', function() {
inject(function($compile, $rootScope) {
var element;
- element = $compile(''.concat(
- '
',
- beforeLiElement,
- '
{{ item }}
',
- afterLiElement,
- '
'))($rootScope);
+ element = $compile(
+ ''.concat(
+ '
',
+ beforeLiElement,
+ '
{{ item }}
',
+ afterLiElement,
+ '
'
+ )
+ )($rootScope);
$rootScope.$apply(function() {
$rootScope.opts = {
helper: 'clone'
@@ -481,12 +558,15 @@ describe('uiSortable', function() {
it('should work when "helper: clone" and "appendTo [selector]" options are used together', function() {
inject(function($compile, $rootScope) {
var element;
- element = $compile(''.concat(
- '
',
- beforeLiElement,
- '
{{ item }}
',
- afterLiElement,
- '
'))($rootScope);
+ element = $compile(
+ ''.concat(
+ '
',
+ beforeLiElement,
+ '
{{ item }}
',
+ afterLiElement,
+ '
'
+ )
+ )($rootScope);
$rootScope.$apply(function() {
$rootScope.opts = {
helper: 'clone',
@@ -516,12 +596,15 @@ describe('uiSortable', function() {
it('should work when "helper: clone" and "appendTo [element]" options are used together', function() {
inject(function($compile, $rootScope) {
var element;
- element = $compile(''.concat(
- '
',
- beforeLiElement,
- '
{{ item }}
',
- afterLiElement,
- '
'))($rootScope);
+ element = $compile(
+ ''.concat(
+ '
',
+ beforeLiElement,
+ '
{{ item }}
',
+ afterLiElement,
+ '
'
+ )
+ )($rootScope);
$rootScope.$apply(function() {
$rootScope.opts = {
helper: 'clone',
@@ -551,12 +634,15 @@ describe('uiSortable', function() {
it('should work when "helper: clone" and "appendTo [jQuery object]" options are used together', function() {
inject(function($compile, $rootScope) {
var element;
- element = $compile(''.concat(
- '
',
- beforeLiElement,
- '
{{ item }}
',
- afterLiElement,
- '
'))($rootScope);
+ element = $compile(
+ ''.concat(
+ '
',
+ beforeLiElement,
+ '
{{ item }}
',
+ afterLiElement,
+ '
'
+ )
+ )($rootScope);
$rootScope.$apply(function() {
$rootScope.opts = {
helper: 'clone',
@@ -586,12 +672,15 @@ describe('uiSortable', function() {
it('should work when "helper: clone" and "placeholder" options are used together.', function() {
inject(function($compile, $rootScope) {
var element;
- element = $compile(''.concat(
- '
',
- beforeLiElement,
- '
{{ item }}
',
- afterLiElement,
- '
'))($rootScope);
+ element = $compile(
+ ''.concat(
+ '
',
+ beforeLiElement,
+ '
{{ item }}
',
+ afterLiElement,
+ '
'
+ )
+ )($rootScope);
$rootScope.$apply(function() {
$rootScope.opts = {
helper: 'clone',
@@ -639,15 +728,18 @@ describe('uiSortable', function() {
it('should work when "helper: function" option is used', function() {
inject(function($compile, $rootScope) {
var element;
- element = $compile(''.concat(
- '
',
- beforeLiElement,
- '
{{ item }}
',
- afterLiElement,
- '
'))($rootScope);
+ element = $compile(
+ ''.concat(
+ '
',
+ beforeLiElement,
+ '
{{ item }}
',
+ afterLiElement,
+ '
'
+ )
+ )($rootScope);
$rootScope.$apply(function() {
$rootScope.opts = {
- helper: function (e, item) {
+ helper: function(e, item) {
return item.clone().text('helper');
}
};
@@ -675,15 +767,18 @@ describe('uiSortable', function() {
it('should work when "helper: function" option is used and a drag is reverted', function() {
inject(function($compile, $rootScope) {
var element;
- element = $compile(''.concat(
- '
',
- beforeLiElement,
- '
{{ item }}
',
- afterLiElement,
- '
'))($rootScope);
+ element = $compile(
+ ''.concat(
+ '
',
+ beforeLiElement,
+ '
{{ item }}
',
+ afterLiElement,
+ '
'
+ )
+ )($rootScope);
$rootScope.$apply(function() {
$rootScope.opts = {
- helper: function (e, item) {
+ helper: function(e, item) {
return item.clone().text('helper');
}
};
@@ -723,15 +818,18 @@ describe('uiSortable', function() {
it('should work when "helper: function" and "placeholder" options are used together.', function() {
inject(function($compile, $rootScope) {
var element;
- element = $compile(''.concat(
- '
',
- beforeLiElement,
- '
{{ item }}
',
- afterLiElement,
- '
'))($rootScope);
+ element = $compile(
+ ''.concat(
+ '
',
+ beforeLiElement,
+ '
{{ item }}
',
+ afterLiElement,
+ '
'
+ )
+ )($rootScope);
$rootScope.$apply(function() {
$rootScope.opts = {
- helper: function (e, item) {
+ helper: function(e, item) {
return item.clone().text('helper');
},
placeholder: 'sortable-item'
@@ -778,15 +876,18 @@ describe('uiSortable', function() {
it('should work when "helper: function" that returns a list element is used', function() {
inject(function($compile, $rootScope) {
var element;
- element = $compile(''.concat(
- '
',
- beforeLiElement,
- '
{{ item }}
',
- afterLiElement,
- '
'))($rootScope);
+ element = $compile(
+ ''.concat(
+ '
',
+ beforeLiElement,
+ '
{{ item }}
',
+ afterLiElement,
+ '
'
+ )
+ )($rootScope);
$rootScope.$apply(function() {
$rootScope.opts = {
- helper: function (e, item) {
+ helper: function(e, item) {
return item;
}
};
@@ -826,15 +927,18 @@ describe('uiSortable', function() {
it('should work when "helper: function" that returns a list element and "placeholder" options are used together.', function() {
inject(function($compile, $rootScope) {
var element;
- element = $compile(''.concat(
- '
',
- beforeLiElement,
- '
{{ item }}
',
- afterLiElement,
- '
'))($rootScope);
+ element = $compile(
+ ''.concat(
+ '