jquery.binding.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /**
  2. * jQuery plugin for Sortable
  3. * @author RubaXa <trash@rubaxa.org>
  4. * @license MIT
  5. */
  6. (function (factory) {
  7. "use strict";
  8. if (typeof define === "function" && define.amd) {
  9. define(["jquery"], factory);
  10. }
  11. else {
  12. /* jshint sub:true */
  13. factory(jQuery);
  14. }
  15. })(function ($) {
  16. "use strict";
  17. /* CODE */
  18. /**
  19. * jQuery plugin for Sortable
  20. * @param {Object|String} options
  21. * @param {..*} [args]
  22. * @returns {jQuery|*}
  23. */
  24. $.fn.sortable = function (options) {
  25. var retVal,
  26. args = arguments;
  27. this.each(function () {
  28. var $el = $(this),
  29. sortable = $el.data('sortable');
  30. if (!sortable && (options instanceof Object || !options)) {
  31. sortable = new Sortable(this, options);
  32. $el.data('sortable', sortable);
  33. }
  34. if (sortable) {
  35. if (options === 'widget') {
  36. retVal = sortable;
  37. }
  38. else if (options === 'destroy') {
  39. sortable.destroy();
  40. $el.removeData('sortable');
  41. }
  42. else if (typeof sortable[options] === 'function') {
  43. retVal = sortable[options].apply(sortable, [].slice.call(args, 1));
  44. }
  45. else if (options in sortable.options) {
  46. retVal = sortable.option.apply(sortable, args);
  47. }
  48. }
  49. });
  50. return (retVal === void 0) ? this : retVal;
  51. };
  52. });