[ Index ]

WordPress Cross Reference

title

Body

[close]

/wp-admin/js/ -> postbox.js (source)

   1  /* global ajaxurl */
   2  
   3  var postboxes;
   4  
   5  (function($) {
   6      postboxes = {
   7          add_postbox_toggles : function(page, args) {
   8              var self = this;
   9  
  10              self.init(page, args);
  11  
  12              $('.postbox h3, .postbox .handlediv').bind('click.postboxes', function() {
  13                  var p = $(this).parent('.postbox'), id = p.attr('id');
  14  
  15                  if ( 'dashboard_browser_nag' == id )
  16                      return;
  17  
  18                  p.toggleClass('closed');
  19  
  20                  if ( page != 'press-this' )
  21                      self.save_state(page);
  22  
  23                  if ( id ) {
  24                      if ( !p.hasClass('closed') && $.isFunction(postboxes.pbshow) )
  25                          self.pbshow(id);
  26                      else if ( p.hasClass('closed') && $.isFunction(postboxes.pbhide) )
  27                          self.pbhide(id);
  28                  }
  29              });
  30  
  31              $('.postbox h3 a').click( function(e) {
  32                  e.stopPropagation();
  33              });
  34  
  35              $( '.postbox a.dismiss' ).bind( 'click.postboxes', function() {
  36                  var hide_id = $(this).parents('.postbox').attr('id') + '-hide';
  37                  $( '#' + hide_id ).prop('checked', false).triggerHandler('click');
  38                  return false;
  39              });
  40  
  41              $('.hide-postbox-tog').bind('click.postboxes', function() {
  42                  var box = $(this).val();
  43  
  44                  if ( $(this).prop('checked') ) {
  45                      $('#' + box).show();
  46                      if ( $.isFunction( postboxes.pbshow ) )
  47                          self.pbshow( box );
  48                  } else {
  49                      $('#' + box).hide();
  50                      if ( $.isFunction( postboxes.pbhide ) )
  51                          self.pbhide( box );
  52                  }
  53                  self.save_state(page);
  54                  self._mark_area();
  55              });
  56  
  57              $('.columns-prefs input[type="radio"]').bind('click.postboxes', function(){
  58                  var n = parseInt($(this).val(), 10);
  59  
  60                  if ( n ) {
  61                      self._pb_edit(n);
  62                      self.save_order(page);
  63                  }
  64              });
  65          },
  66  
  67          init : function(page, args) {
  68              var isMobile = $(document.body).hasClass('mobile');
  69  
  70              $.extend( this, args || {} );
  71              $('#wpbody-content').css('overflow','hidden');
  72              $('.meta-box-sortables').sortable({
  73                  placeholder: 'sortable-placeholder',
  74                  connectWith: '.meta-box-sortables',
  75                  items: '.postbox',
  76                  handle: '.hndle',
  77                  cursor: 'move',
  78                  delay: ( isMobile ? 200 : 0 ),
  79                  distance: 2,
  80                  tolerance: 'pointer',
  81                  forcePlaceholderSize: true,
  82                  helper: 'clone',
  83                  opacity: 0.65,
  84                  stop: function() {
  85                      if ( $(this).find('#dashboard_browser_nag').is(':visible') && 'dashboard_browser_nag' != this.firstChild.id ) {
  86                          $(this).sortable('cancel');
  87                          return;
  88                      }
  89  
  90                      postboxes.save_order(page);
  91                  },
  92                  receive: function(e,ui) {
  93                      if ( 'dashboard_browser_nag' == ui.item[0].id )
  94                          $(ui.sender).sortable('cancel');
  95  
  96                      postboxes._mark_area();
  97                  }
  98              });
  99  
 100              if ( isMobile ) {
 101                  $(document.body).bind('orientationchange.postboxes', function(){ postboxes._pb_change(); });
 102                  this._pb_change();
 103              }
 104  
 105              this._mark_area();
 106          },
 107  
 108          save_state : function(page) {
 109              var closed = $('.postbox').filter('.closed').map(function() { return this.id; }).get().join(','),
 110                  hidden = $('.postbox').filter(':hidden').map(function() { return this.id; }).get().join(',');
 111  
 112              $.post(ajaxurl, {
 113                  action: 'closed-postboxes',
 114                  closed: closed,
 115                  hidden: hidden,
 116                  closedpostboxesnonce: jQuery('#closedpostboxesnonce').val(),
 117                  page: page
 118              });
 119          },
 120  
 121          save_order : function(page) {
 122              var postVars, page_columns = $('.columns-prefs input:checked').val() || 0;
 123  
 124              postVars = {
 125                  action: 'meta-box-order',
 126                  _ajax_nonce: $('#meta-box-order-nonce').val(),
 127                  page_columns: page_columns,
 128                  page: page
 129              };
 130              $('.meta-box-sortables').each( function() {
 131                  postVars[ 'order[' + this.id.split( '-' )[0] + ']' ] = $( this ).sortable( 'toArray' ).join( ',' );
 132              } );
 133              $.post( ajaxurl, postVars );
 134          },
 135  
 136          _mark_area : function() {
 137              var visible = $('div.postbox:visible').length, side = $('#post-body #side-sortables');
 138  
 139              $( '#dashboard-widgets .meta-box-sortables:visible' ).each( function() {
 140                  var t = $(this);
 141  
 142                  if ( visible == 1 || t.children('.postbox:visible').length )
 143                      t.removeClass('empty-container');
 144                  else
 145                      t.addClass('empty-container');
 146              });
 147  
 148              if ( side.length ) {
 149                  if ( side.children('.postbox:visible').length )
 150                      side.removeClass('empty-container');
 151                  else if ( $('#postbox-container-1').css('width') == '280px' )
 152                      side.addClass('empty-container');
 153              }
 154          },
 155  
 156          _pb_edit : function(n) {
 157              var el = $('.metabox-holder').get(0);
 158  
 159              if ( el ) {
 160                  el.className = el.className.replace(/columns-\d+/, 'columns-' + n);
 161              }
 162          },
 163  
 164          _pb_change : function() {
 165              var check = $( 'label.columns-prefs-1 input[type="radio"]' );
 166  
 167              switch ( window.orientation ) {
 168                  case 90:
 169                  case -90:
 170                      if ( !check.length || !check.is(':checked') )
 171                          this._pb_edit(2);
 172                      break;
 173                  case 0:
 174                  case 180:
 175                      if ( $('#poststuff').length ) {
 176                          this._pb_edit(1);
 177                      } else {
 178                          if ( !check.length || !check.is(':checked') )
 179                              this._pb_edit(2);
 180                      }
 181                      break;
 182              }
 183          },
 184  
 185          /* Callbacks */
 186          pbshow : false,
 187  
 188          pbhide : false
 189      };
 190  
 191  }(jQuery));


Generated: Tue Mar 25 01:41:18 2014 WordPress honlapkészítés: online1.hu