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.1.8 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-1.1.7 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-1.1.6 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-2.1.0 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-2.0.8 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-2.0.7 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-2.0.6 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-2.0.5 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-2.0.4 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-2.0.3 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-2.0.2 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-2.0.1 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-2.0.0 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-1.1.5 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-1.1.4 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-1.1.3 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-1.1.2 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-1.1.1 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-1.0.76 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-1.0.75 vendor/assets/javascripts/jquery.twoLevelSort.js