[ Index ]

PHP Cross Reference of Wordpress 2.7.1

title

Body

[close]

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

   1  
   2  var wpCookies = {
   3  // The following functions are from Cookie.js class in TinyMCE, Moxiecode, used under LGPL.
   4  
   5      each : function(o, cb, s) {
   6          var n, l;
   7  
   8          if (!o)
   9              return 0;
  10  
  11          s = s || o;
  12  
  13          if (typeof(o.length) != 'undefined') {
  14              for (n=0, l = o.length; n<l; n++) {
  15                  if (cb.call(s, o[n], n, o) === false)
  16                      return 0;
  17              }
  18          } else {
  19              for (n in o) {
  20                  if (o.hasOwnProperty(n)) {
  21                      if (cb.call(s, o[n], n, o) === false)
  22                          return 0;
  23                  }
  24              }
  25          }
  26          return 1;
  27      },
  28  
  29      getHash : function(n) {
  30          var v = this.get(n), h;
  31  
  32          if (v) {
  33              this.each(v.split('&'), function(v) {
  34                  v = v.split('=');
  35                  h = h || {};
  36                  h[v[0]] = v[1];
  37              });
  38          }
  39          return h;
  40      },
  41  
  42      setHash : function(n, v, e, p, d, s) {
  43          var o = '';
  44  
  45          this.each(v, function(v, k) {
  46              o += (!o ? '' : '&') + k + '=' + v;
  47          });
  48  
  49          this.set(n, o, e, p, d, s);
  50      },
  51  
  52      get : function(n) {
  53          var c = document.cookie, e, p = n + "=", b;
  54  
  55          if (!c)
  56              return;
  57  
  58          b = c.indexOf("; " + p);
  59  
  60          if (b == -1) {
  61              b = c.indexOf(p);
  62  
  63              if (b != 0)
  64                  return null;
  65          } else
  66              b += 2;
  67  
  68          e = c.indexOf(";", b);
  69  
  70          if (e == -1)
  71              e = c.length;
  72  
  73          return decodeURIComponent(c.substring(b + p.length, e));
  74      },
  75  
  76      set : function(n, v, e, p, d, s) {
  77          document.cookie = n + "=" + encodeURIComponent(v) +
  78              ((e) ? "; expires=" + e.toGMTString() : "") +
  79              ((p) ? "; path=" + p : "") +
  80              ((d) ? "; domain=" + d : "") +
  81              ((s) ? "; secure" : "");
  82      },
  83  
  84      remove : function(n, p) {
  85          var d = new Date();
  86  
  87          d.setTime(d.getTime() - 1000);
  88  
  89          this.set(n, '', d, p, d);
  90      }
  91  };
  92  
  93  // Returns the value as string. Second arg or empty string is returned when value is not set.
  94  function getUserSetting( name, def ) {
  95      var o = getAllUserSettings();
  96  
  97      if ( o.hasOwnProperty(name) )
  98          return o[name];
  99  
 100      if ( typeof def != 'undefined' )
 101          return def;
 102  
 103      return '';
 104  }
 105  
 106  // Both name and value must be only ASCII letters, numbers or underscore
 107  // and the shorter, the better (cookies can store maximum 4KB). Not suitable to store text.
 108  function setUserSetting( name, value, del ) {
 109      var c = 'wp-settings-'+userSettings.uid, o = wpCookies.getHash(c) || {}, d = new Date();
 110      var n = name.toString().replace(/[^A-Za-z0-9_]/, ''), v = value.toString().replace(/[^A-Za-z0-9_]/, '');
 111  
 112      if ( del ) delete o[n];
 113      else o[n] = v;
 114  
 115      d.setTime( d.getTime() + 31536000000 );
 116      p = userSettings.url;
 117  
 118      wpCookies.setHash(c, o, d, p );
 119      wpCookies.set('wp-settings-time-'+userSettings.uid, userSettings.time, d, p );
 120  }
 121  
 122  function deleteUserSetting( name ) {
 123      setUserSetting( name, '', 1 );
 124  }
 125  
 126  // Returns all settings as js object.
 127  function getAllUserSettings() {
 128      return wpCookies.getHash('wp-settings-'+userSettings.uid) || {};
 129  }
 130  
 131  
 132  jQuery(document).ready( function($) {
 133      // pulse
 134      $('.fade').animate( { backgroundColor: '#ffffe0' }, 300).animate( { backgroundColor: '#fffbcc' }, 300).animate( { backgroundColor: '#ffffe0' }, 300).animate( { backgroundColor: '#fffbcc' }, 300);
 135  
 136      // show things that should be visible, hide what should be hidden
 137      $('.hide-if-no-js').removeClass('hide-if-no-js');
 138      $('.hide-if-js').hide();
 139  
 140      // Basic form validation
 141      if ( ( 'undefined' != typeof wpAjax ) && $.isFunction( wpAjax.validateForm ) ) {
 142          $('form.validate').submit( function() { return wpAjax.validateForm( $(this) ); } );
 143      }
 144  
 145      // Move .updated and .error alert boxes
 146      $('div.wrap h2 ~ div.updated, div.wrap h2 ~ div.error').addClass('below-h2');
 147      $('div.updated, div.error').not('.below-h2').insertAfter('div.wrap h2:first');
 148  
 149      // screen settings tab
 150      $('#show-settings-link').click(function () {
 151          if ( ! $('#screen-options-wrap').hasClass('screen-options-open') ) {
 152              $('#contextual-help-link-wrap').addClass('invisible');
 153          }
 154          $('#screen-options-wrap').slideToggle('fast', function(){
 155              if ( $(this).hasClass('screen-options-open') ) {
 156                  $('#show-settings-link').css({'backgroundImage':'url("images/screen-options-right.gif")'});
 157                  $('#contextual-help-link-wrap').removeClass('invisible');
 158                  $(this).removeClass('screen-options-open');
 159  
 160              } else {
 161                  $('#show-settings-link').css({'backgroundImage':'url("images/screen-options-right-up.gif")'});
 162                  $(this).addClass('screen-options-open');
 163              }
 164          });
 165          return false;
 166      });
 167  
 168      // help tab
 169      $('#contextual-help-link').click(function () {
 170          if ( ! $('#contextual-help-wrap').hasClass('contextual-help-open') ) {
 171              $('#screen-options-link-wrap').addClass('invisible');
 172          }
 173          $('#contextual-help-wrap').slideToggle('fast', function(){
 174              if ( $(this).hasClass('contextual-help-open') ) {
 175                  $('#contextual-help-link').css({'backgroundImage':'url("images/screen-options-right.gif")'});
 176                  $('#screen-options-link-wrap').removeClass('invisible');
 177                  $(this).removeClass('contextual-help-open');
 178              } else {
 179                  $('#contextual-help-link').css({'backgroundImage':'url("images/screen-options-right-up.gif")'});
 180                  $(this).addClass('contextual-help-open');
 181              }
 182          });
 183          return false;
 184      });
 185  
 186      // check all checkboxes
 187      var lastClicked = false;
 188      $( 'table:visible tbody .check-column :checkbox' ).click( function(e) {
 189          if ( 'undefined' == e.shiftKey ) { return true; }
 190          if ( e.shiftKey ) {
 191              if ( !lastClicked ) { return true; }
 192              var checks = $( lastClicked ).parents( 'form:first' ).find( ':checkbox' );
 193              var first = checks.index( lastClicked );
 194              var last = checks.index( this );
 195              var checked = $(this).attr('checked');
 196              if ( 0 < first && 0 < last && first != last ) {
 197                  checks.slice( first, last ).attr( 'checked', function(){
 198                      if ( $(this).parents('tr').is(':visible') )
 199                          return checked ? 'checked' : '';
 200  
 201                      return '';
 202                  });
 203              }
 204          }
 205          lastClicked = this;
 206          return true;
 207      } );
 208      $( 'thead :checkbox, tfoot :checkbox' ).click( function(e) {
 209          var c = $(this).attr('checked');
 210          if ( 'undefined' == typeof  toggleWithKeyboard)
 211              toggleWithKeyboard = false;
 212          var toggle = e.shiftKey || toggleWithKeyboard;
 213          $(this).parents( 'form:first' ).find( 'table tbody:visible').find( '.check-column :checkbox' ).attr( 'checked', function() {
 214              if ( $(this).parents('tr').is(':hidden') )
 215                  return '';
 216              if ( toggle )
 217                  return $(this).attr( 'checked' ) ? '' : 'checked';
 218              else if (c)
 219                  return 'checked';
 220              return '';
 221          });
 222          $(this).parents( 'form:first' ).find( 'table thead:visible, table tfoot:visible').find( '.check-column :checkbox' ).attr( 'checked', function() {
 223              if ( toggle )
 224                  return '';
 225              else if (c)
 226                  return 'checked';
 227              return '';
 228          });
 229      });
 230  });
 231  
 232  var showNotice, adminMenu, columns;
 233  
 234  // stub for doing better warnings
 235  showNotice = {
 236      warn : function(text) {
 237          if ( confirm(text) )
 238              return true;
 239  
 240          return false;
 241      },
 242  
 243      note : function(text) {
 244          alert(text);
 245      }
 246  };
 247  
 248  (function($){
 249  // sidebar admin menu
 250  adminMenu = {
 251  
 252      init : function() {
 253          $('#adminmenu div.wp-menu-toggle').each( function() {
 254              if ( $(this).siblings('.wp-submenu').length )
 255                  $(this).click(function(){ adminMenu.toggle( $(this).siblings('.wp-submenu') ); });
 256              else
 257                  $(this).hide();
 258          });
 259          $('#adminmenu li.menu-top .wp-menu-image').click( function() { window.location = $(this).siblings('a.menu-top')[0].href; } );
 260          this.favorites();
 261  
 262          $('.wp-menu-separator').click(function(){
 263              if ( $('#wpcontent').hasClass('folded') ) {
 264                  adminMenu.fold(1);
 265                  setUserSetting( 'mfold', 'o' );
 266              } else {
 267                  adminMenu.fold();
 268                  setUserSetting( 'mfold', 'f' );
 269              }
 270          });
 271  
 272          if ( 'f' != getUserSetting( 'mfold' ) ) {
 273              this.restoreMenuState();
 274          } else {
 275              this.fold();
 276          }
 277      },
 278  
 279      restoreMenuState : function() {
 280          $('#adminmenu li.wp-has-submenu').each(function(i, e) {
 281              var v = getUserSetting( 'm'+i );
 282              if ( $(e).hasClass('wp-has-current-submenu') ) return true; // leave the current parent open
 283  
 284              if ( 'o' == v ) $(e).addClass('wp-menu-open');
 285              else if ( 'c' == v ) $(e).removeClass('wp-menu-open');
 286          });
 287      },
 288  
 289      toggle : function(el) {
 290  
 291          el['slideToggle'](150, function(){el.css('display','');}).parent().toggleClass( 'wp-menu-open' );
 292  
 293          $('#adminmenu li.wp-has-submenu').each(function(i, e) {
 294              var v = $(e).hasClass('wp-menu-open') ? 'o' : 'c';
 295              setUserSetting( 'm'+i, v );
 296          });
 297  
 298          return false;
 299      },
 300  
 301      fold : function(off) {
 302          if (off) {
 303              $('#wpcontent').removeClass('folded');
 304              $('#adminmenu li.wp-has-submenu').unbind();
 305          } else {
 306              $('#wpcontent').addClass('folded');
 307              $('#adminmenu li.wp-has-submenu').hoverIntent({
 308                  over: function(e){
 309                      var m = $(this).find('.wp-submenu'), t = e.clientY, H = $(window).height(), h = m.height(), o;
 310  
 311                      if ( (t+h+10) > H ) {
 312                          o = (t+h+10) - H;
 313                          m.css({'marginTop':'-'+o+'px'});
 314                      } else if ( m.css('marginTop') ) {
 315                          m.css({'marginTop':''})
 316                      }
 317                      m.addClass('sub-open');
 318                  },
 319                  out: function(){ $(this).find('.wp-submenu').removeClass('sub-open').css({'marginTop':''}); },
 320                  timeout: 220,
 321                  sensitivity: 8,
 322                  interval: 100
 323              });
 324  
 325          }
 326      },
 327  
 328      favorites : function() {
 329          $('#favorite-inside').width($('#favorite-actions').width()-4);
 330          $('#favorite-toggle, #favorite-inside').bind( 'mouseenter', function(){$('#favorite-inside').removeClass('slideUp').addClass('slideDown'); setTimeout(function(){if ( $('#favorite-inside').hasClass('slideDown') ) { $('#favorite-inside').slideDown(100); $('#favorite-first').addClass('slide-down'); }}, 200) } );
 331  
 332          $('#favorite-toggle, #favorite-inside').bind( 'mouseleave', function(){$('#favorite-inside').removeClass('slideDown').addClass('slideUp'); setTimeout(function(){if ( $('#favorite-inside').hasClass('slideUp') ) { $('#favorite-inside').slideUp(100, function(){ $('#favorite-first').removeClass('slide-down'); } ); }}, 300) } );
 333      }
 334  };
 335  
 336  $(document).ready(function(){adminMenu.init();});
 337  })(jQuery);
 338  
 339  (function($){
 340  // show/hide/save table columns
 341  columns = {
 342      init : function(page) {
 343          $('.hide-column-tog').click( function() {
 344              var column = $(this).val();
 345              var show = $(this).attr('checked');
 346              if ( show ) {
 347                  $('.column-' + column).show();
 348              } else {
 349                  $('.column-' + column).hide();
 350              }
 351              columns.save_manage_columns_state(page);
 352          } );
 353      },
 354  
 355      save_manage_columns_state : function(page) {
 356          var hidden = $('.manage-column').filter(':hidden').map(function() { return this.id; }).get().join(',');
 357          $.post('admin-ajax.php', {
 358              action: 'hidden-columns',
 359              hidden: hidden,
 360              hiddencolumnsnonce: $('#hiddencolumnsnonce').val(),
 361              page: page
 362          });
 363      }
 364  }
 365  
 366  })(jQuery);
 367  
 368  
 369  jQuery(document).ready(function($){
 370      if ( 'undefined' != typeof google && google.gears ) return;
 371  
 372      var gf = false;
 373      if ( 'undefined' != typeof GearsFactory ) {
 374          gf = new GearsFactory();
 375      } else {
 376          try {
 377              gf = new ActiveXObject('Gears.Factory');
 378              if ( factory.getBuildInfo().indexOf('ie_mobile') != -1 )
 379                  gf.privateSetGlobalObject(this);
 380          } catch (e) {
 381              if ( ( 'undefined' != typeof navigator.mimeTypes ) && navigator.mimeTypes['application/x-googlegears'] ) {
 382                  gf = document.createElement("object");
 383                  gf.style.display = "none";
 384                  gf.width = 0;
 385                  gf.height = 0;
 386                  gf.type = "application/x-googlegears";
 387                  document.documentElement.appendChild(gf);
 388              }
 389          }
 390      }
 391      if ( gf && gf.hasPermission )
 392          return;
 393  
 394      $('.turbo-nag').show();
 395  });


Generated: Mon Mar 23 16:23:02 2009 Cross-referenced by PHPXref 0.7