Skip to content

Commit c196b32

Browse files
committed
Merge branch 'master' of github.com:RubaXa/Sortable
2 parents 66a56bf + 25e1269 commit c196b32

File tree

7 files changed

+172
-37
lines changed

7 files changed

+172
-37
lines changed

Gruntfile.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,32 @@ module.exports = function (grunt){
1717
'<%= pkg.exportName %>.min.js': ['<%= pkg.exportName %>.js']
1818
}
1919
}
20+
},
21+
22+
shell: {
23+
'meteor-test': {
24+
command: 'meteor/runtests.sh'
25+
},
26+
'meteor-publish': {
27+
command: 'meteor/publish.sh'
28+
}
2029
}
30+
2131
});
2232

2333

2434
// These plugins provide necessary tasks.
2535
grunt.loadNpmTasks('grunt-version');
2636
grunt.loadNpmTasks('grunt-contrib-uglify');
37+
grunt.loadNpmTasks('grunt-shell');
2738

39+
// Meteor tasks
40+
grunt.registerTask('meteor-test', 'shell:meteor-test');
41+
grunt.registerTask('meteor-publish', 'shell:meteor-publish');
42+
// ideally we'd run tests before publishing, but the chances of tests breaking (given that
43+
// Meteor is orthogonal to the library) are so small that it's not worth the maintainer's time
44+
// grunt.regsterTask('meteor', ['shell:meteor-test', 'shell:meteor-publish']);
45+
grunt.registerTask('meteor', 'shell:meteor-publish');
2846

2947
// Default task.
3048
grunt.registerTask('default', ['version', 'uglify']);

README.md

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

33
Sortable is a minimalist JavaScript library for reorderable drag-and-drop lists.
44

5+
Demo: http://rubaxa.github.io/Sortable/
6+
57
## Features
68
* Supports touch devices and [modern](http://caniuse.com/#search=drag) browsers
79
* Built using native HTML5 drag and drop API
810
* Can drag from one list to another or within the same list
11+
* Supports drag handles *and selectable text* (better than voidberg's html5sortable)
912
* Simple API
1013
* Lightweight, 2KB gzipped
1114
* No jQuery
@@ -34,8 +37,8 @@ new Sortable(el);
3437
new Sortable(el, {
3538
group: "name",
3639
store: null, // @see Store
37-
handle: ".my-handle", // Restricts sort start click/touch to the specified element
38-
filter: ".ignor-elements", // Selectors that do not lead to dragging (String or Function)
40+
handle: ".my-handle", // Drag handle selector within list items
41+
filter: ".ignore-elements", // Selectors that do not lead to dragging (String or Function)
3942
draggable: ".item", // Specifies which items inside the element should be sortable
4043
ghostClass: "sortable-ghost",
4144

@@ -60,10 +63,33 @@ new Sortable(el, {
6063
});
6164
```
6265

66+
#### handle
67+
68+
To make list items draggable, Sortable disables text selection by the user. That's not always desirable. To allow text selection, define a drag handler, which is an area of every list element that allows it to be dragged around.
69+
70+
```js
71+
new Sortable(el, {
72+
handle: ".my-handle",
73+
});
74+
```
75+
76+
```html
77+
<ul>
78+
<li><span class="my-handle">:: </span> list item text one
79+
<li><span class="my-handle">:: </span> list item text two
80+
</ul>
81+
```
82+
83+
```css
84+
.my-handle {
85+
cursor: move
86+
}
87+
```
88+
6389
---
6490

6591

66-
### Method
92+
### Methods
6793

6894
##### closest(el:`String`[, selector:`HTMLElement`]):`HTMLElement|null`
6995
For each element in the set, get the first element that matches the selector by testing the element itself and traversing up through its ancestors in the DOM tree.

meteor/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Packaging [Sortable](http://rubaxa.github.io/Sortable/) for [Meteor.js](http://meteor.com).
2+
3+
4+
# Meteor
5+
6+
If you're new to Meteor, here's what the excitement is all about -
7+
[watch the first two minutes](https://www.youtube.com/watch?v=fsi0aJ9yr2o); you'll be hooked by 1:28.
8+
9+
That screencast is from 2012. In the meantime, Meteor has become a mature JavaScript-everywhere web
10+
development framework. Read more at [Why Meteor](http://www.meteorpedia.com/read/Why_Meteor).
11+
12+
13+
# Issues
14+
15+
If you encounter an issue while using this package, please CC @dandv when you file it in this repo.
16+
17+
18+
# DONE
19+
20+
* Instantiation test
21+
22+
23+
# TODO
24+
25+
* Meteor collection backing
26+
* Tests ensuring correct rendering with Meteor dynamic templates

meteor/package.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
1-
var packageName = 'rubaxa:sortable';
1+
// package metadata file for Meteor.js
2+
'use strict';
3+
4+
var packageName = 'rubaxa:sortable'; // http://atmospherejs.com/sortable/sortable
5+
var where = 'client'; // where to install: 'client', 'server', or ['client', 'server']
6+
7+
var packageJson = JSON.parse(Npm.require("fs").readFileSync('package.json'));
28

39
Package.describe({
410
name: packageName,
511
summary: 'Sortable (official): minimalist reorderable drag-and-drop lists on modern browsers and touch devices',
6-
version: '0.5.2',
12+
version: packageJson.version,
713
git: 'https://github.com/RubaXa/Sortable.git'
814
});
915

1016
Package.onUse(function (api) {
11-
api.versionsFrom('0.9.0');
17+
api.versionsFrom('METEOR@0.9.0');
1218
api.export('Sortable');
1319
api.addFiles([
1420
'Sortable.js'
15-
], 'client'
21+
], where
1622
);
1723
});
1824

1925
Package.onTest(function (api) {
20-
api.use(packageName, 'client');
21-
api.use('tinytest', 'client');
26+
api.use(packageName, where);
27+
api.use('tinytest', where);
2228

23-
api.addFiles('meteor/test.js', 'client');
29+
api.addFiles('meteor/test.js', where);
2430
});

meteor/publish.sh

Lines changed: 62 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,72 @@
1+
#!/bin/bash
12
# Publish package on Meteor's Atmosphere.js
23

34
# Make sure Meteor is installed, per https://www.meteor.com/install. The curl'ed script is totally safe; takes 2 minutes to read its source and check.
45
type meteor >/dev/null 2>&1 || { curl https://install.meteor.com/ | sh; }
56

67
# sanity check: make sure we're in the root directory of the checkout
7-
DIR=$( cd "$( dirname "$0" )" && pwd )
8-
cd $DIR/..
8+
cd "$( dirname "$0" )/.."
99

10-
# Meteor expects package.js to be in the root directory of the checkout, so copy it there temporarily
11-
cp meteor/package.js ./
1210

13-
# publish package, creating it if it's the first time we're publishing
14-
PACKAGE_NAME=$(grep -i name package.js | head -1 | cut -d "'" -f 2)
15-
PACKAGE_EXISTS=$(meteor search $PACKAGE_NAME 2>/dev/null | wc -l)
11+
function cleanup() {
12+
# we copied the file as package.js, regardless of its original name
13+
rm package.js
1614

17-
if [ $PACKAGE_EXISTS -gt 0 ]; then
18-
meteor publish
19-
else
20-
meteor publish --create
21-
fi
15+
# temporary build files
16+
rm -rf ".build.$PACKAGE_NAME" versions.json
17+
}
2218

23-
rm package.js
19+
20+
# publish separately any package*.js files we have, e.g. package.js, package-compat.js
21+
for PACKAGE_FILE in meteor/package*.js; do
22+
23+
# Meteor expects package.js to be in the root directory of the checkout, so copy there our package file under that name, temporarily
24+
cp $PACKAGE_FILE ./package.js
25+
26+
# publish package, creating it if it's the first time we're publishing
27+
PACKAGE_NAME=$(grep -i name $PACKAGE_FILE | head -1 | cut -d "'" -f 2)
28+
ATMOSPHERE_NAME=${PACKAGE_NAME/://}
29+
30+
echo "Publishing $PACKAGE_NAME..."
31+
32+
# attempt to re-publish the package - the most common operation once the initial release has been made
33+
POTENTIAL_ERROR=$( meteor publish 2>&1 )
34+
35+
if [[ $POTENTIAL_ERROR =~ "There is no package named" ]]; then
36+
# actually this is the first time the package is created, so pass the special --create flag and congratulate the maintainer
37+
echo "Thank you for creating the official Meteor package for this library!"
38+
if meteor publish --create; then
39+
echo "Please post the following to https://github.com/raix/Meteor-community-discussions/issues/14:
40+
41+
--------------------------------------------- 8< --------------------------------------------------------
42+
43+
Happy to announce that I've published the official $PACKAGE_NAME to Atmosphere. Please star!
44+
https://atmospherejs.com/$ATMOSPHERE_NAME
45+
46+
--------------------------------------------- >8 --------------------------------------------------------
47+
48+
"
49+
else
50+
echo "We got an error. Please post it at https://github.com/raix/Meteor-community-discussions/issues/14"
51+
cleanup
52+
exit 1
53+
fi
54+
else
55+
if (( $? > 0 )); then
56+
# the error wasn't that the package didn't exist, so we need to ask for help
57+
echo "We got an error. Please post it at https://github.com/raix/Meteor-community-discussions/issues/14:
58+
--------------------------------------------- 8< --------------------------------------------------------
59+
$POTENTIAL_ERROR
60+
--------------------------------------------- >8 --------------------------------------------------------
61+
"
62+
cleanup
63+
exit 1
64+
else
65+
echo "Thanks for releasing a new version of $PACKAGE_NAME! You can see it at
66+
https://atmospherejs.com/$ATMOSPHERE_NAME"
67+
fi
68+
fi
69+
70+
cleanup
71+
72+
done

meteor/runtests.sh

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,37 @@
1-
# Test Meteor package before publishing to Atmosphere.js
1+
#!/bin/sh
2+
# Test Meteor package before publishing to Atmospherejs.com
23

34
# Make sure Meteor is installed, per https://www.meteor.com/install. The curl'ed script is totally safe; takes 2 minutes to read its source and check.
45
type meteor >/dev/null 2>&1 || { curl https://install.meteor.com/ | sh; }
56

67
# sanity check: make sure we're in the root directory of the checkout
7-
DIR=$( cd "$( dirname "$0" )" && pwd )
8-
cd $DIR/..
9-
10-
# Meteor expects package.js to be in the root directory of the checkout, so copy it there temporarily
11-
cp meteor/package.js ./
8+
cd "$( dirname "$0" )/.."
129

1310
# run tests and delete the temporary package.js even if Ctrl+C is pressed
1411
int_trap() {
1512
echo
16-
echo "Tests interrupted."
13+
printf "Tests interrupted. Hopefully you verified in the browser that tests pass?\n\n"
1714
}
1815

1916
trap int_trap INT
2017

21-
meteor test-packages ./
18+
# test any package*.js packages we may have, e.g. package.js, package-compat.js
19+
for PACKAGE_FILE in meteor/package*.js; do
20+
21+
PACKAGE_NAME=$(grep -i name $PACKAGE_FILE | head -1 | cut -d "'" -f 2)
22+
23+
echo "Testing $PACKAGE_NAME..."
24+
25+
# Meteor expects package.js to be in the root directory of the checkout, so copy there our package file under that name, temporarily
26+
cp $PACKAGE_FILE ./package.js
27+
28+
# provide an invalid MONGO_URL so Meteor doesn't bog us down with an empty Mongo database
29+
MONGO_URL=mongodb:// meteor test-packages ./
30+
31+
rm -rf ".build.$PACKAGE_NAME"
32+
rm -rf ".build.local-test:$PACKAGE_NAME"
33+
rm versions.json 2>/dev/null
2234

23-
PACKAGE_NAME=$(grep -i name package.js | head -1 | cut -d "'" -f 2)
24-
rm -rf ".build.$PACKAGE_NAME"
25-
rm -rf ".build.local-test:$PACKAGE_NAME"
26-
rm versions.json
35+
rm package.js
2736

28-
rm package.js
37+
done

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"devDependencies": {
66
"grunt": "*",
77
"grunt-version": "*",
8-
"grunt-contrib-uglify": "*"
8+
"grunt-contrib-uglify": "*",
9+
"grunt-shell": "*"
910
},
1011
"description": "Minimalist library for reorderable drag-and-drop lists on modern browsers and touch devices. No jQuery.",
1112
"main": "Sortable.js",

0 commit comments

Comments
 (0)