Browse Source

#151: + jquery binding

issue-210
RubaXa 10 years ago
parent
commit
0d162a016a
  1. 1
      .gitignore
  2. 20
      Gruntfile.js
  3. 31
      README.md
  4. 2
      Sortable.min.js
  5. 57
      jquery.binding.js

1
.gitignore vendored

@ -2,3 +2,4 @@ node_modules
mock.png
.*.sw*
.build*
jquery.fn.sortable.js

20
Gruntfile.js

@ -34,8 +34,26 @@ module.exports = function (grunt) {
'meteor-publish': {
command: 'meteor/publish.sh'
}
}
},
jquery: {}
});
grunt.registerTask('jquery', function () {
var fs = require('fs'),
filename = 'jquery.fn.sortable.js';
grunt.log.oklns(filename);
fs.writeFileSync(
filename,
(fs.readFileSync('jquery.binding.js') + '')
.replace('/* CODE */',
(fs.readFileSync('Sortable.js') + '')
.replace(/^[\s\S]*?function[\s\S]*?(var[\s\S]+)\/\/\s+Export[\s\S]+/, '$1')
)
);
});

31
README.md

@ -15,7 +15,7 @@ Demo: http://rubaxa.github.io/Sortable/
* Supports [Meteor](meteor/README.md) and [AngularJS](#ng)
* Supports any CSS library, e.g. [Bootstrap](#bs)
* Simple API
* No jQuery
* No jQuery (but there is [support](#jq))
### Usage
@ -428,9 +428,36 @@ Link to the active instance.
---
<a name="jq"></a>
### jQuery compatibility
To assemble plugin for jQuery, perform the following steps:
```bash
cd Sortable
npm install
grunt jquery
```
Now you can use `jquery.fn.sortable.js`:
```js
$("#list").sortable({ /* options */ }); // init
$("#list").sortable("widget"); // get Sortable instance
$("#list").sortable("destroy"); // destroy Sortable instance
$("#list").sortable("{method-name}"); // call an instance method
$("#list").sortable("{method-name}", "foo", "bar"); // call an instance method with parameters
```
---
## MIT LICENSE
Copyright 2013-2014 Lebedev Konstantin <ibnRubaXa@gmail.com>
Copyright 2013-2015 Lebedev Konstantin <ibnRubaXa@gmail.com>
http://rubaxa.github.io/Sortable/
Permission is hereby granted, free of charge, to any person obtaining

2
Sortable.min.js vendored

File diff suppressed because one or more lines are too long

57
jquery.binding.js

@ -0,0 +1,57 @@
/**
* jQuery plugin for Sortable
* @author RubaXa <trash@rubaxa.org>
* @license MIT
*/
(function (factory) {
"use strict";
if (typeof define === "function" && define.amd) {
define(["jquery"], factory);
}
else {
/* jshint sub:true */
factory(jQuery);
}
})(function ($) {
"use strict";
/* CODE */
/**
* jQuery plugin for Sortable
* @param {Object|String} options
* @param {..*} [args]
* @returns {jQuery|*}
*/
$.fn.sortable = function (options) {
var retVal;
this.each(function () {
var $el = $(this),
sortable = $el.data('sortable');
if (!sortable && (options instanceof Object || !options)) {
sortable = new Sortable(this, options);
$el.data('sortable', sortable);
}
if (sortable) {
if (options === 'widget') {
return sortable;
}
else if (options === 'destroy') {
sortable.destroy();
$el.removeData('sortable');
}
else if (options in sortable) {
retVal = sortable[sortable].apply(sortable, [].slice.call(arguments, 1));
}
}
});
return (retVal === void 0) ? this : retVal;
};
});
Loading…
Cancel
Save