[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-forums/bbpress/bb-admin/js/ -> admin-forums.js (source)

   1  jQuery( function($) { // In here $ is jQuery
   2  
   3  bbSortForums = {
   4      handleText: 'drag',
   5      handle: '',
   6      sortCfg: {
   7          accept: 'forum',
   8          handle: 'img.sort-handle',
   9          opacity: .3,
  10          helperclass: 'helper',
  11          onStop: function() {
  12              bbSortForums.place = null;
  13              bbSortForums.recolor();
  14          }
  15      },
  16      editText: 'Edit Forum Order',
  17      saveText: 'Save Forum Order',
  18      place: null,  // The id of the list item it's currently hovering before
  19      placed: null, // The id of the list item it's been made a child of
  20      rtl: 'rtl' == $('html').attr( 'dir' ),
  21  
  22      recolor: function() {
  23          $('#forum-list li:gt(0)').css( 'background-color', '' ).filter(':even').removeClass('alt').end().filter(':odd').addClass('alt');
  24      },
  25  
  26      checkHover: function(el, doit) {
  27          if ( this.place == el.id && doit )
  28              return;
  29  
  30          if ( !doit ) {
  31              this.place = null;
  32              return;
  33          }
  34  
  35          this.place = el.id;
  36          if ( $('#' + this.place).children('ul:has(li:visible)').size() ) // Don't shift over if there's already a UL with stuff in it
  37              return;
  38  
  39          var id = this.place.split('-')[1];
  40          $('#' + this.place).not(':has(ul)').append("<ul id='forum-root-" + id + "' class='list-block holder'></ul>").end().children('ul').append(jQuery.iSort.helper.get(0)); // Place in shifted box
  41          this.placed = 'forum-' + id;
  42      },
  43  
  44      serialize: function () {
  45          h = '';
  46          $('#forum-list, #forum-list ul').each( function() {
  47              var i = this.id;
  48              $('#' + i + '> .forum').each( function () {
  49                  if (h.length > 0)
  50                      h += '&';
  51                  var root = 'forum-list' == i ? 0 : i.split('-')[2];
  52                  h += 'root[' + root + '][]=' + this.id.split('-')[1];
  53              } );
  54          } );
  55          return h;
  56      },
  57  
  58      init: function() {
  59          this.handle = "<img class='sort-handle' src='images/drag.gif' alt='" + this.handleText +  "' />";
  60          var div = document.createElement('div');
  61          div.innerHTML = this.saveText; // Save the raquo!
  62          this.saveText = div.childNodes[0].nodeValue;
  63          div.innerHTML = this.editText; // Save the raquo!
  64          this.editText = div.childNodes[0].nodeValue;
  65          div = null;
  66          $('#forum-list').after("<form class='settings' action='' onsubmit='return false;'><fieldset class='submit'><input class='submit' type='submit' name='submit' id='forum-order-edit' value='" + this.editText + "' /></fieldset></form>");
  67  
  68          $('#forum-order-edit').toggle( function() {
  69              $(this).val(bbSortForums.saveText);
  70              $('#forum-list li:gt(0) div.row-title').before(bbSortForums.handle);
  71              $('#forum-list').Sortable( bbSortForums.sortCfg );
  72              $('body').addClass('sorting');
  73          }, function() {
  74              $(this).val(bbSortForums.editText);
  75              $('.sort-handle').remove();
  76  
  77              var hash = bbSortForums.serialize();
  78              hash += '&' + $.SortSerialize('forum-list').hash.replace(/forum-list/g, 'order').replace(/forum-/g, '')
  79              $('#forum-list').SortableDestroy();
  80              $('body').removeClass('sorting');
  81  
  82              $.post(
  83                  'admin-ajax.php',
  84                  'action=order-forums&_ajax_nonce=' +  $('#add-forum input[name=order-nonce]').val() + '&' + hash
  85              );
  86          } );
  87      }
  88  }
  89  
  90  // overwrite with more advanced function
  91  jQuery.iSort.checkhover = function(e,o) {
  92      if (!jQuery.iDrag.dragged)
  93          return;
  94  
  95      if ( e.dropCfg.el.size() > 0 ) {
  96          var bottom = jQuery.grep(e.dropCfg.el, function(i) { // All the list items whose bottom edges are inside the draggable
  97              var x = bbSortForums.rtl ? i.pos.x + i.pos.wb > jQuery.iDrag.dragged.dragCfg.nx + jQuery.iDrag.dragged.dragCfg.oC.wb : i.pos.x < jQuery.iDrag.dragged.dragCfg.nx;
  98              return i.pos.y + i.pos.hb > jQuery.iDrag.dragged.dragCfg.ny && i.pos.y + i.pos.hb < jQuery.iDrag.dragged.dragCfg.ny + 30 && x;
  99          } );
 100  
 101          if ( bottom.length > 0 ) { // Use the lowest one one the totem pole
 102              var x = bbSortForums.rtl ? bottom[bottom.length-1].pos.x + bottom[bottom.length-1].pos.wb - 30 > jQuery.iDrag.dragged.dragCfg.nx + jQuery.iDrag.dragged.dragCfg.oC.wb : bottom[bottom.length-1].pos.x + 30 < jQuery.iDrag.dragged.dragCfg.nx;
 103              if ( bbSortForums.placed != bottom[bottom.length-1].id || !x ) { // Testing to see if still placed in shifted box
 104                  bbSortForums.placed = null;
 105                  jQuery(bottom[bottom.length-1]).after(jQuery.iSort.helper.get(0));
 106              }
 107              bbSortForums.checkHover(bottom[bottom.length-1], x); // If far enough right, shift it over
 108              return;
 109          }
 110  
 111          // Didn't find anything by checking bottems.  Look at tops
 112          var top = jQuery.grep(e.dropCfg.el, function(i) { // All the list items whose top edges are inside the draggable
 113              var x = bbSortForums.rtl ? i.pos.x + i.pos.wb > jQuery.iDrag.dragged.dragCfg.nx : i.pos.x < jQuery.iDrag.dragged.dragCfg.nx;
 114              return i.pos.y > jQuery.iDrag.dragged.dragCfg.ny && i.pos.y < jQuery.iDrag.dragged.dragCfg.ny + 30 && x;
 115          } );
 116  
 117          if ( top.length ) { // Use the highest one (should be only one)
 118              jQuery(top[0]).before(jQuery.iSort.helper.get(0));
 119              bbSortForums.checkHover(top[0], false);
 120              return;
 121          }
 122      }
 123      jQuery.iSort.helper.get(0).style.display = 'block';
 124  }
 125  
 126  if ( 'undefined' != typeof bbSortForumsL10n )
 127      $.extend( bbSortForums, bbSortForumsL10n );
 128  
 129  bbSortForums.init();
 130  
 131  var options = $('#forum-parent').get(0).options;
 132  var addAfter = function( r, settings ) {
 133      var name = $("<span>" + $('name', r).text() + "</span>").html();
 134      var id = $('forum', r).attr('id');
 135      options[options.length] = new Option(name, id);
 136  }
 137  
 138  $('#forum-list').wpList( { addAfter: addAfter } );
 139  
 140  } );


Generated: Thu Dec 7 01:01:35 2017 Cross-referenced by PHPXref 0.7.1