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

Commit 37c33d8

Browse files
committed
Merge branch 'master' of https://github.com/wuliupo/ui-sortable
2 parents a462388 + 2988412 commit 37c33d8

15 files changed

+1694
-396
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ node_modules/
33
coverage/
44
junit/
55
dist/
6-
out/
6+
out/

README.md

+23-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# UI.Sortable directive
2+
[![npm](https://img.shields.io/npm/v/angular-ui-sortable.svg)](https://www.npmjs.com/package/angular-ui-sortable)
3+
[![npm](https://img.shields.io/npm/dm/angular-ui-sortable.svg)](https://www.npmjs.com/package/angular-ui-sortable)
24
[![Build Status](https://travis-ci.org/angular-ui/ui-sortable.svg?branch=master)](https://travis-ci.org/angular-ui/ui-sortable)
35
[![Coverage Status](https://coveralls.io/repos/angular-ui/ui-sortable/badge.svg?branch=master)](https://coveralls.io/r/angular-ui/ui-sortable?branch=master)
46
[![debugInfoEnabled(false) Ready Badge](https://rawgit.com/thgreasi/ng-debugInfoDisabled-badges/master/badge1.svg)](https://docs.angularjs.org/guide/production#disabling-debug-data)
@@ -51,9 +53,9 @@ Apply the directive to your form elements:
5153
**Developing Notes:**
5254

5355
* `ng-model` is required, so that the directive knows which model to update.
54-
* `ui-sortable` element should only contain one `ng-repeat` and not any other elements (above or below).
55-
Otherwise the index matching of the generated DOM elements and the `ng-model`'s items will break.
56-
**In other words: The items of `ng-model` must match the indexes of the generated DOM elements.**
56+
* `ui-sortable` element should contain only one `ng-repeat`, but other non-repeater elements above or below may still exist.
57+
Otherwise the index matching of the `ng-model`'s items and the DOM elements generated by the `ng-repeat` will break.
58+
**In other words: The items of `ng-model` must match the indexes of the DOM elements generated by the `ng-repeat`.**
5759
* [`Filters`](https://docs.angularjs.org/guide/filter) that manipulate the model (like [filter](https://docs.angularjs.org/api/ng/filter/filter), [orderBy](https://docs.angularjs.org/api/ng/filter/orderBy), [limitTo](https://docs.angularjs.org/api/ng/filter/limitTo),...) should be applied in the `controller` instead of the `ng-repeat` (refer to [the provided examples](#examples)).
5860
This is the preferred way since it:
5961
- is performance wise better
@@ -90,15 +92,9 @@ The suggested pattern is to use callbacks for emmiting events and altering the s
9092

9193
#### Floating
9294

93-
**Update**: Issue [~~7498~~](bugs.jqueryui.com/ticket/7498) was resolved in jquery-ui v1.11.4.
94-
Calling `angular.element('ui-sortable').sortable('refresh')` (use a more appropriate selector in your use case)
95-
should make jquery-ui-sortable recognize the position and orientation of the existing and any new items.
96-
As a result, since ui-sortable makes a call to `sortable('refresh')` after the sortable items are created by the repeater, it is not any more necessary to use the `ui-floating` property if the orientation of your list is not changing dynamically.
97-
**TL;DR:** If you are using jquery-ui v1.11.4+ and you are not changing the orientation of your list dynamically, then you probably don't need to use `ui-floating` property.
98-
9995
To have a smooth horizontal-list reordering, jquery.ui.sortable needs to detect the orientation of the list.
10096
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).
101-
There is also a [known issue](bugs.jqueryui.com/ticket/7498) about initially empty horizontal lists.
97+
There is also a [known issue](https://bugs.jqueryui.com/ticket/7498) about initially empty horizontal lists.
10298

10399
To provide a solution/workaround (till jquery.ui.sortable.refresh() also tests the orientation or a more appropriate method is provided), ui-sortable directive provides a `ui-floating` option as an extra to the [jquery.ui.sortable options](http://api.jqueryui.com/sortable/).
104100

@@ -146,7 +142,19 @@ $scope.sortableOptions = {
146142
**Notes:**
147143
* `update` is the appropriate place to cancel a sorting, since it occurs before any model/scope changes but after the DOM position has been updated.
148144
So `ui.item.scope` and the directive's `ng-model`, are equal to the scope before the drag start.
149-
* To [cancel a sorting between connected lists](https://github.com/angular-ui/ui-sortable/issues/107#issuecomment-33633638), `cancel` should be called inside the `update` callback of the originating list.
145+
* To [cancel a sorting between connected lists](https://github.com/angular-ui/ui-sortable/issues/107#issuecomment-33633638), `cancel` should be called inside the `update` callback of the originating list. A simple way to is to use the `ui.item.sortable.received` property:
146+
```js
147+
update: function(event, ui) {
148+
if (// ensure we are in the first update() callback
149+
!ui.item.sortable.received &&
150+
// check that its an actual moving between the two lists
151+
ui.item.sortable.source[0] !== ui.item.sortable.droptarget[0] &&
152+
// check the size limitation
153+
ui.item.sortable.model == "can't be moved between lists") {
154+
ui.item.sortable.cancel();
155+
}
156+
}
157+
```
150158

151159
### jQueryUI Sortable Event order
152160

@@ -210,8 +218,10 @@ For more details about the events check the [jQueryUI API documentation](http://
210218
- [Draggable Handle](http://codepen.io/thgreasi/pen/ihAyr)
211219
- [Drop Zone](http://codepen.io/thgreasi/pen/LVXWeO)
212220
- [Draggable-Sortable like interaction](http://codepen.io/thgreasi/pen/LVVJgK)
221+
- [Static HTML Sorting](http://codepen.io/thgreasi/pen/qdmjwy)
213222

214223
## Integrations
224+
- [firebase](http://codepen.io/thgreasi/pen/repEZg?editors=0010)
215225
- [ui.bootstrap.accordion](http://plnkr.co/edit/TGIeeEbbvJwpJ3WRqo2z?p=preview)
216226
- [Asynchronous loading jQuery+jQueryUI with crisbeto/angular-ui-sortable-loader](https://github.com/crisbeto/angular-ui-sortable-loader)
217227

@@ -230,12 +240,12 @@ npm install && bower install
230240
grunt
231241
```
232242

233-
The karma task will try to open Firefox and Chrome as browser in which to run the tests. Make sure this is available or change the configuration in `test\karma.conf.js`
243+
The karma task will try to open Firefox and Chrome as browser in which to run the tests. Make sure this is available or change the configuration in `test\karma.conf.js`.
234244

235245

236246
### Grunt Serve
237247

238-
We have one task to serve them all !
248+
We have one task to serve them all!
239249

240250
```sh
241251
grunt serve

bower.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-ui-sortable",
3-
"version": "0.13.4",
3+
"version": "0.14.3",
44
"description": "This directive allows you to jQueryUI Sortable.",
55
"author": "https://github.com/angular-ui/ui-sortable/graphs/contributors",
66
"license": "MIT",
@@ -17,6 +17,7 @@
1717
],
1818
"dependencies": {
1919
"angular": ">=1.2.x",
20+
"jquery": "<3.0.0",
2021
"jquery-ui": ">=1.9"
2122
},
2223
"devDependencies": {

gruntFile.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ module.exports = function(grunt) {
77
require('load-grunt-tasks')(grunt);
88

99
// Default task.
10-
grunt.registerTask('default', ['jshint', 'karma:unit']);
10+
grunt.registerTask('default', ['test']);
11+
grunt.registerTask('test', ['jshint', 'karma:unit']);
1112
grunt.registerTask('serve', ['karma:continuous', 'dist', 'build:gh-pages', 'connect:continuous', 'watch']);
1213
grunt.registerTask('dist', ['ngmin', 'surround:main', 'uglify', 'surround:banner' ]);
1314
grunt.registerTask('coverage', ['jshint', 'karma:coverage']);
@@ -40,7 +41,7 @@ module.exports = function(grunt) {
4041
var testConfig = function(configFile, customOptions) {
4142
var options = { configFile: configFile, singleRun: true };
4243
var travisOptions = process.env.TRAVIS && {
43-
browsers: ['Firefox', 'PhantomJS'],
44+
browsers: ['Chrome', 'Firefox'],
4445
reporters: ['dots', 'coverage', 'coveralls'],
4546
preprocessors: { 'src/*.js': ['coverage'] },
4647
coverageReporter: {

package.json

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-ui-sortable",
3-
"version": "0.13.4",
3+
"version": "0.14.3",
44
"description": "This directive allows you to jQueryUI Sortable.",
55
"author": "https://github.com/angular-ui/ui-sortable/graphs/contributors",
66
"license": "MIT",
@@ -15,21 +15,22 @@
1515
"grunt-contrib-uglify": "0.2.x",
1616
"grunt-contrib-watch": "0.5.x",
1717
"grunt-conventional-changelog": "~1.0.0",
18-
"grunt-karma": "0.6.x",
18+
"grunt-karma": "^0.12.1",
1919
"grunt-ngmin": "0.0.x",
2020
"grunt-surround": "0.1.x",
21-
"karma": "0.10.x",
21+
"jasmine-core": "^2.4.1",
22+
"karma": "^0.13.22",
2223
"karma-chrome-launcher": "0.1.x",
23-
"karma-coffee-preprocessor": "0.1.x",
24-
"karma-coverage": "~0.2.0",
24+
"karma-coffee-preprocessor": "^0.3.0",
25+
"karma-coverage": "^0.5.5",
2526
"karma-coveralls": "~0.1.4",
2627
"karma-firefox-launcher": "0.1.x",
27-
"karma-html2js-preprocessor": "0.1.x",
28-
"karma-jasmine": "0.1.x",
29-
"karma-junit-reporter": "0.2.x",
30-
"karma-phantomjs-launcher": "0.1.x",
31-
"karma-requirejs": "0.2.x",
32-
"karma-script-launcher": "0.1.x",
28+
"karma-html2js-preprocessor": "^0.1.0",
29+
"karma-jasmine": "^0.3.7",
30+
"karma-junit-reporter": "^0.4.0",
31+
"karma-phantomjs-launcher": "^1.0.0",
32+
"karma-requirejs": "^0.2.5",
33+
"karma-script-launcher": "^0.2.0",
3334
"load-grunt-tasks": "0.2.x",
3435
"requirejs": "2.1.x",
3536
"wiredep": "1.8.x"

0 commit comments

Comments
 (0)