Sha256: fb57333f9bb822772795135f72142d2368fae266c603f4426a956338247b1e6e

Contents?: true

Size: 837 Bytes

Versions: 1

Compression:

Stored size: 837 Bytes

Contents

(function($) {

  $.fn.railsSortable = function(options) {
    options = options || {};
    var setting = $.extend({
      axis: 'y',
      scroll: 'true',
    }, options);

    setting.update = function(event, ui) {
      if (typeof options.update === 'function') {
        options.update(event, ui);
      }

      $.ajax({
        type: 'POST',
        url: '/sortable/reorder',
        dataType: 'json',
        contentType: 'application/json',
        data: JSON.stringify(makePostData($(this))),
      });
    }

    this.sortable(setting);
  };

  var makePostData = function($sortable) {
    var klass, id;
    var data = $.map($sortable.sortable('toArray'), function(sortableId) {
      [klass, id] = sortableId.split(/[-=_]/);
      return { klass: klass, id: id };
    });
    return { rails_sortable: data };
  };
})(jQuery);

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rails_sortable-1.2.0 vendor/assets/javascripts/plugin.js