[ Index ]

WordPress Cross Reference

title

Body

[close]

/wp-includes/js/ -> wp-auth-check.js (source)

   1  /* global adminpage */
   2  // Interim login dialog
   3  (function($){
   4      var wrap, next;
   5  
   6  	function show() {
   7          var parent = $('#wp-auth-check'),
   8              form = $('#wp-auth-check-form'),
   9              noframe = wrap.find('.wp-auth-fallback-expired'),
  10              frame, loaded = false;
  11  
  12          if ( form.length ) {
  13              // Add unload confirmation to counter (frame-busting) JS redirects
  14              $(window).on( 'beforeunload.wp-auth-check', function(e) {
  15                  e.originalEvent.returnValue = window.authcheckL10n.beforeunload;
  16              });
  17  
  18              frame = $('<iframe id="wp-auth-check-frame" frameborder="0">').attr( 'title', noframe.text() );
  19              frame.load( function() {
  20                  var height, body;
  21  
  22                  loaded = true;
  23  
  24                  try {
  25                      body = $(this).contents().find('body');
  26                      height = body.height();
  27                  } catch(e) {
  28                      wrap.addClass('fallback');
  29                      parent.css( 'max-height', '' );
  30                      form.remove();
  31                      noframe.focus();
  32                      return;
  33                  }
  34  
  35                  if ( height ) {
  36                      if ( body && body.hasClass('interim-login-success') )
  37                          hide();
  38                      else
  39                          parent.css( 'max-height', height + 40 + 'px' );
  40                  } else if ( ! body || ! body.length ) {
  41                      // Catch "silent" iframe origin exceptions in WebKit after another page is loaded in the iframe
  42                      wrap.addClass('fallback');
  43                      parent.css( 'max-height', '' );
  44                      form.remove();
  45                      noframe.focus();
  46                  }
  47              }).attr( 'src', form.data('src') );
  48  
  49              $('#wp-auth-check-form').append( frame );
  50          }
  51  
  52          wrap.removeClass('hidden');
  53  
  54          if ( frame ) {
  55              frame.focus();
  56              // WebKit doesn't throw an error if the iframe fails to load because of "X-Frame-Options: DENY" header.
  57              // Wait for 10 sec. and switch to the fallback text.
  58              setTimeout( function() {
  59                  if ( ! loaded ) {
  60                      wrap.addClass('fallback');
  61                      form.remove();
  62                      noframe.focus();
  63                  }
  64              }, 10000 );
  65          } else {
  66              noframe.focus();
  67          }
  68      }
  69  
  70  	function hide() {
  71          $(window).off( 'beforeunload.wp-auth-check' );
  72  
  73          // When on the Edit Post screen, speed up heartbeat after the user logs in to quickly refresh nonces
  74          if ( typeof adminpage !== 'undefined' && ( adminpage === 'post-php' || adminpage === 'post-new-php' ) &&
  75              typeof wp !== 'undefined' && wp.heartbeat ) {
  76  
  77              wp.heartbeat.connectNow();
  78          }
  79  
  80          wrap.fadeOut( 200, function() {
  81              wrap.addClass('hidden').css('display', '');
  82              $('#wp-auth-check-frame').remove();
  83          });
  84      }
  85  
  86  	function schedule() {
  87          var interval = parseInt( window.authcheckL10n.interval, 10 ) || 180; // in seconds, default 3 min.
  88          next = ( new Date() ).getTime() + ( interval * 1000 );
  89      }
  90  
  91      $( document ).on( 'heartbeat-tick.wp-auth-check', function( e, data ) {
  92          if ( 'wp-auth-check' in data ) {
  93              schedule();
  94              if ( ! data['wp-auth-check'] && wrap.hasClass('hidden') ) {
  95                  show();
  96              } else if ( data['wp-auth-check'] && ! wrap.hasClass('hidden') ) {
  97                  hide();
  98              }
  99          }
 100      }).on( 'heartbeat-send.wp-auth-check', function( e, data ) {
 101          if ( ( new Date() ).getTime() > next ) {
 102              data['wp-auth-check'] = true;
 103          }
 104      }).ready( function() {
 105          schedule();
 106          wrap = $('#wp-auth-check-wrap');
 107          wrap.find('.wp-auth-check-close').on( 'click', function() {
 108              hide();
 109          });
 110      });
 111  
 112  }(jQuery));


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