2018-06-27 22:30:15 -04:00
|
|
|
/**
|
|
|
|
* Interim login dialog.
|
|
|
|
*
|
|
|
|
* @output wp-includes/js/wp-auth-check.js
|
|
|
|
*/
|
|
|
|
|
2013-11-14 23:42:09 -05:00
|
|
|
/* global adminpage */
|
2013-03-27 04:43:11 -04:00
|
|
|
(function($){
|
2013-11-14 23:42:09 -05:00
|
|
|
var wrap, next;
|
2013-03-27 04:43:11 -04:00
|
|
|
|
2018-06-27 22:33:38 -04:00
|
|
|
/**
|
|
|
|
* Shows the authentication form popup.
|
|
|
|
*
|
|
|
|
* @since 3.6.0
|
|
|
|
* @private
|
|
|
|
*/
|
2013-03-27 04:43:11 -04:00
|
|
|
function show() {
|
2013-12-02 13:47:09 -05:00
|
|
|
var parent = $('#wp-auth-check'),
|
|
|
|
form = $('#wp-auth-check-form'),
|
|
|
|
noframe = wrap.find('.wp-auth-fallback-expired'),
|
|
|
|
frame, loaded = false;
|
2013-03-27 04:43:11 -04:00
|
|
|
|
|
|
|
if ( form.length ) {
|
2018-06-27 22:33:38 -04:00
|
|
|
// Add unload confirmation to counter (frame-busting) JS redirects.
|
2013-03-27 04:43:11 -04:00
|
|
|
$(window).on( 'beforeunload.wp-auth-check', function(e) {
|
|
|
|
e.originalEvent.returnValue = window.authcheckL10n.beforeunload;
|
|
|
|
});
|
|
|
|
|
2013-05-06 17:35:50 -04:00
|
|
|
frame = $('<iframe id="wp-auth-check-frame" frameborder="0">').attr( 'title', noframe.text() );
|
2016-01-13 12:22:27 -05:00
|
|
|
frame.on( 'load', function() {
|
2013-03-27 04:43:11 -04:00
|
|
|
var height, body;
|
|
|
|
|
|
|
|
loaded = true;
|
2015-12-14 11:40:27 -05:00
|
|
|
// Remove the spinner to avoid unnecessary CPU/GPU usage.
|
|
|
|
form.removeClass( 'loading' );
|
2013-03-27 04:43:11 -04:00
|
|
|
|
|
|
|
try {
|
|
|
|
body = $(this).contents().find('body');
|
|
|
|
height = body.height();
|
|
|
|
} catch(e) {
|
|
|
|
wrap.addClass('fallback');
|
2013-07-10 20:44:37 -04:00
|
|
|
parent.css( 'max-height', '' );
|
2013-03-27 04:43:11 -04:00
|
|
|
form.remove();
|
|
|
|
noframe.focus();
|
2013-05-06 17:35:50 -04:00
|
|
|
return;
|
2013-03-27 04:43:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( height ) {
|
2013-07-10 20:44:37 -04:00
|
|
|
if ( body && body.hasClass('interim-login-success') )
|
|
|
|
hide();
|
|
|
|
else
|
2013-07-12 19:32:32 -04:00
|
|
|
parent.css( 'max-height', height + 40 + 'px' );
|
2013-07-10 20:44:37 -04:00
|
|
|
} else if ( ! body || ! body.length ) {
|
2018-06-27 22:33:38 -04:00
|
|
|
// Catch "silent" iframe origin exceptions in WebKit after another page is
|
|
|
|
// loaded in the iframe.
|
2013-07-10 20:44:37 -04:00
|
|
|
wrap.addClass('fallback');
|
|
|
|
parent.css( 'max-height', '' );
|
|
|
|
form.remove();
|
|
|
|
noframe.focus();
|
2013-03-27 04:43:11 -04:00
|
|
|
}
|
|
|
|
}).attr( 'src', form.data('src') );
|
|
|
|
|
2015-12-14 11:40:27 -05:00
|
|
|
form.append( frame );
|
2013-03-27 04:43:11 -04:00
|
|
|
}
|
|
|
|
|
2015-03-31 18:55:26 -04:00
|
|
|
$( 'body' ).addClass( 'modal-open' );
|
2013-03-27 04:43:11 -04:00
|
|
|
wrap.removeClass('hidden');
|
|
|
|
|
|
|
|
if ( frame ) {
|
|
|
|
frame.focus();
|
2018-06-27 22:33:38 -04:00
|
|
|
// WebKit doesn't throw an error if the iframe fails to load because of
|
|
|
|
// "X-Frame-Options: DENY" header.
|
2013-07-10 20:44:37 -04:00
|
|
|
// Wait for 10 sec. and switch to the fallback text.
|
2013-03-27 04:43:11 -04:00
|
|
|
setTimeout( function() {
|
|
|
|
if ( ! loaded ) {
|
|
|
|
wrap.addClass('fallback');
|
|
|
|
form.remove();
|
|
|
|
noframe.focus();
|
|
|
|
}
|
2013-07-10 20:44:37 -04:00
|
|
|
}, 10000 );
|
2013-03-27 04:43:11 -04:00
|
|
|
} else {
|
|
|
|
noframe.focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-27 22:33:38 -04:00
|
|
|
/**
|
|
|
|
* Hides the authentication form popup.
|
|
|
|
*
|
|
|
|
* @since 3.6.0
|
|
|
|
* @private
|
|
|
|
*/
|
2013-03-27 04:43:11 -04:00
|
|
|
function hide() {
|
|
|
|
$(window).off( 'beforeunload.wp-auth-check' );
|
2013-06-28 21:31:44 -04:00
|
|
|
|
2018-06-27 22:33:38 -04:00
|
|
|
// When on the Edit Post screen, speed up heartbeat after the user logs in to
|
|
|
|
// quickly refresh nonces.
|
2013-12-02 13:47:09 -05:00
|
|
|
if ( typeof adminpage !== 'undefined' && ( adminpage === 'post-php' || adminpage === 'post-new-php' ) &&
|
|
|
|
typeof wp !== 'undefined' && wp.heartbeat ) {
|
2013-06-28 21:31:44 -04:00
|
|
|
|
2015-11-07 11:22:25 -05:00
|
|
|
$(document).off( 'heartbeat-tick.wp-auth-check' );
|
2013-12-02 13:47:09 -05:00
|
|
|
wp.heartbeat.connectNow();
|
2013-06-28 21:31:44 -04:00
|
|
|
}
|
2013-03-27 04:43:11 -04:00
|
|
|
|
|
|
|
wrap.fadeOut( 200, function() {
|
2013-07-12 19:32:32 -04:00
|
|
|
wrap.addClass('hidden').css('display', '');
|
2013-03-27 04:43:11 -04:00
|
|
|
$('#wp-auth-check-frame').remove();
|
2015-03-31 18:55:26 -04:00
|
|
|
$( 'body' ).removeClass( 'modal-open' );
|
2013-03-27 04:43:11 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-06-27 22:33:38 -04:00
|
|
|
/**
|
|
|
|
* Schedules when the next time the authentication check will be done.
|
|
|
|
*
|
|
|
|
* @since 3.6.0
|
|
|
|
* @private
|
|
|
|
*/
|
2013-05-15 21:50:43 -04:00
|
|
|
function schedule() {
|
2018-06-27 22:33:38 -04:00
|
|
|
// In seconds, default 3 min.
|
|
|
|
var interval = parseInt( window.authcheckL10n.interval, 10 ) || 180;
|
2013-07-12 19:32:32 -04:00
|
|
|
next = ( new Date() ).getTime() + ( interval * 1000 );
|
2013-05-15 21:50:43 -04:00
|
|
|
}
|
|
|
|
|
2018-06-27 22:33:38 -04:00
|
|
|
/**
|
|
|
|
* Binds to the Heartbeat Tick event.
|
|
|
|
*
|
|
|
|
* - Shows the authentication form popup if user is not logged in.
|
|
|
|
* - Hides the authentication form popup if it is already visible and user is
|
|
|
|
* logged in.
|
|
|
|
*
|
|
|
|
* @ignore
|
|
|
|
*
|
|
|
|
* @since 3.6.0
|
|
|
|
*
|
|
|
|
* @param {Object} e The heartbeat-tick event that has been triggered.
|
|
|
|
* @param {Object} data Response data.
|
|
|
|
*/
|
2013-03-27 04:43:11 -04:00
|
|
|
$( document ).on( 'heartbeat-tick.wp-auth-check', function( e, data ) {
|
2013-07-18 15:06:35 -04:00
|
|
|
if ( 'wp-auth-check' in data ) {
|
2013-05-15 21:50:43 -04:00
|
|
|
schedule();
|
2013-12-02 13:47:09 -05:00
|
|
|
if ( ! data['wp-auth-check'] && wrap.hasClass('hidden') ) {
|
2013-07-12 19:32:32 -04:00
|
|
|
show();
|
2013-12-02 13:47:09 -05:00
|
|
|
} else if ( data['wp-auth-check'] && ! wrap.hasClass('hidden') ) {
|
2013-07-12 19:32:32 -04:00
|
|
|
hide();
|
2013-12-02 13:47:09 -05:00
|
|
|
}
|
2013-03-27 04:43:11 -04:00
|
|
|
}
|
2018-06-27 22:33:38 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Binds to the Heartbeat Send event.
|
|
|
|
*
|
|
|
|
* @ignore
|
|
|
|
*
|
|
|
|
* @since 3.6.0
|
|
|
|
*
|
|
|
|
* @param {Object} e The heartbeat-send event that has been triggered.
|
|
|
|
* @param {Object} data Response data.
|
|
|
|
*/
|
2013-07-12 19:32:32 -04:00
|
|
|
}).on( 'heartbeat-send.wp-auth-check', function( e, data ) {
|
2013-12-02 13:47:09 -05:00
|
|
|
if ( ( new Date() ).getTime() > next ) {
|
2013-07-18 15:06:35 -04:00
|
|
|
data['wp-auth-check'] = true;
|
2013-12-02 13:47:09 -05:00
|
|
|
}
|
2018-06-27 22:33:38 -04:00
|
|
|
|
2013-03-27 04:43:11 -04:00
|
|
|
}).ready( function() {
|
2013-05-15 21:50:43 -04:00
|
|
|
schedule();
|
2018-06-27 22:33:38 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Hides the authentication form popup when the close icon is clicked.
|
|
|
|
*
|
|
|
|
* @ignore
|
|
|
|
*
|
|
|
|
* @since 3.6.0
|
|
|
|
*/
|
2013-07-10 20:44:37 -04:00
|
|
|
wrap = $('#wp-auth-check-wrap');
|
2013-11-14 23:42:09 -05:00
|
|
|
wrap.find('.wp-auth-check-close').on( 'click', function() {
|
2013-03-27 04:43:11 -04:00
|
|
|
hide();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
}(jQuery));
|