Sha256: 28a6293884f47473ecf2e3203b26e65f9cb9b5b73adf74f93af44dfef17eb235

Contents?: true

Size: 1.78 KB

Versions: 91

Compression:

Stored size: 1.78 KB

Contents

(function($){
 $.fn.tenonTwoLevelSort = function(options) {

    var defaults = {
      subSelector: '.subpages',
      topSelector: 'li:not(.subpage)',
      topClass: 'top',
      subClass: 'subpage',
      promoteSelector: '.promote',
      itemArray: 'item_list[]'
    };

    var options = $.extend(defaults, options);

    return this.each(function() {
      var obj = $(this);
      options.callbackPath = obj.data('reorder-path');
      obj.sortable({ items: options.topSelector, update: function(event, ui) { updateTopOrder(this); } });
      $('ul', obj).sortable({ connectWith: options.subSelector, update: function(event, ui) { updateSubpageOrder(this); } });


      $(options.promoteSelector, obj).click(function(e) {
        e.preventDefault();
        page = $(this).closest('li');
        page.remove().appendTo(obj).addClass(options.topClass).removeClass(options.subClass);
        var ul = $('<ul />').addClass(options.subSelector).append("<li class='placeholder'></li>");
        page.append(ul);
        $(this).parent().remove();

        updateTopOrder(obj);
      });


      function showValues(object) {
        var arr = new Array;
        $(object).children().each(function() {
          arr.push($(this).data('record-id'));
        });
        return arr;
      }

      function updateTopOrder(object) {
        var data = {};
        data[options.itemArray] = showValues(object);
        $.ajax({type: "POST", url: options.callbackPath, data: data});
      }

      function updateSubpageOrder(object) {
        Tenon.features.nestedLists.setSubpageTitleSize();
        var data = {parent_id: $(object).closest('li').data('record-id')};
        data[options.itemArray] = showValues(object);
        $.ajax({type: "POST", url: options.callbackPath, data: data});
      }

    });
 };
})(jQuery);

Version data entries

91 entries across 91 versions & 1 rubygems

Version Path
tenon-1.0.32 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-1.0.31 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-1.0.30 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-1.0.29 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-1.0.28 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-1.0.27 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-1.0.26 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-1.0.25 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-1.0.24 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-1.0.23 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-1.0.22 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-1.0.21 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-1.0.20 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-1.0.19 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-1.0.18 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-1.0.17 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-1.0.16 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-1.0.15 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-1.0.14 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-1.0.13 vendor/assets/javascripts/jquery.twoLevelSort.js