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.53 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-1.0.52 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-1.0.51 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-1.0.50 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-1.0.49 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-1.0.48 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-1.0.47 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-1.0.46 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-1.0.45 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-1.0.44 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-1.0.43 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-1.0.42 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-1.0.41 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-1.0.40 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-1.0.39 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-1.0.38 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-1.0.37 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-1.0.36 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-1.0.35 vendor/assets/javascripts/jquery.twoLevelSort.js
tenon-1.0.33 vendor/assets/javascripts/jquery.twoLevelSort.js