Sha256: a54854594c38f02537ed05d320be649fd62b5f91aa6fceb0d8ab29477c86d97a

Contents?: true

Size: 1.94 KB

Versions: 24

Compression:

Stored size: 1.94 KB

Contents

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

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

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

    return this.each(function() {
      var obj = $(this);
      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).attr('id'));
        });
        return arr;
      }

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

      function alternateRows() {
        $('li', obj).removeClass('alternate').removeClass('normal');
        $('li:odd[class!=placeholder]', obj).addClass('alternate');
        $('li:even[class!=placeholder]', obj).addClass('normal');
      }

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

    });
 };
})(jQuery);

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
forge-cli-0.1.10 lib/forge/vendor/assets/javascripts/jquery.twoLevelSort.js
forge-cli-0.1.9 lib/forge/vendor/assets/javascripts/jquery.twoLevelSort.js
forge-cli-0.1.8 lib/forge/vendor/assets/javascripts/jquery.twoLevelSort.js
forge-cli-0.1.7 lib/forge/vendor/assets/javascripts/jquery.twoLevelSort.js
forge-cli-0.1.6 lib/forge/vendor/assets/javascripts/jquery.twoLevelSort.js
forge-cli-0.1.5 lib/forge/vendor/assets/javascripts/jquery.twoLevelSort.js
forge-cli-0.1.4 lib/forge/vendor/assets/javascripts/jquery.twoLevelSort.js
forge-cli-0.1.3 lib/forge/vendor/assets/javascripts/jquery.twoLevelSort.js
forge-cli-0.1.2 lib/forge/vendor/assets/javascripts/jquery.twoLevelSort.js
forge-cli-0.1.1 lib/forge/vendor/assets/javascripts/jquery.twoLevelSort.js
forge-cli-0.1.0 lib/forge/vendor/assets/javascripts/jquery.twoLevelSort.js
forge-cli-0.0.18 lib/forge/vendor/assets/javascripts/jquery.twoLevelSort.js
forge-cli-0.0.17 lib/forge/vendor/assets/javascripts/jquery.twoLevelSort.js
forge-cli-0.0.16 lib/forge/vendor/assets/javascripts/jquery.twoLevelSort.js
forge-cli-0.0.15 lib/forge/vendor/assets/javascripts/jquery.twoLevelSort.js
forge-cli-0.0.14 lib/forge/vendor/assets/javascripts/jquery.twoLevelSort.js
forge-cli-0.0.13 lib/forge/vendor/assets/javascripts/jquery.twoLevelSort.js
forge-cli-0.0.12 lib/forge/vendor/assets/javascripts/jquery.twoLevelSort.js
forge-cli-0.0.11 lib/forge/vendor/assets/javascripts/jquery.twoLevelSort.js
forge-cli-0.0.10 lib/forge/vendor/assets/javascripts/jquery.twoLevelSort.js