2018-06-27 22:30:15 -04:00
|
|
|
/**
|
|
|
|
* Interim login dialog.
|
|
|
|
*
|
|
|
|
* @output wp-includes/js/wp-auth-check.js
|
|
|
|
*/
|
|
|
|
|
2020-07-06 12:14:04 -04:00
|
|
|
( function( $ ) {
|
|
|
|
var wrap,
|
|
|
|
tempHidden,
|
|
|
|
tempHiddenTimeout;
|
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() {
|
2020-07-06 12:14:04 -04:00
|
|
|
var parent = $( '#wp-auth-check' ),
|
|
|
|
form = $( '#wp-auth-check-form' ),
|
|
|
|
noframe = wrap.find( '.wp-auth-fallback-expired' ),
|
2013-12-02 13:47:09 -05:00
|
|
|
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.
|
2020-07-06 12:14:04 -04:00
|
|
|
$( window ).on( 'beforeunload.wp-auth-check', function( event ) {
|
|
|
|
event.originalEvent.returnValue = window.wp.i18n.__( 'Your session has expired. You can log in again from this page or go to the login page.' );
|
2013-03-27 04:43:11 -04:00
|
|
|
});
|
|
|
|
|
2020-07-06 12:14:04 -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 {
|
2020-07-06 12:14:04 -04:00
|
|
|
body = $( this ).contents().find( 'body' );
|
2013-03-27 04:43:11 -04:00
|
|
|
height = body.height();
|
2020-07-06 12:14:04 -04:00
|
|
|
} catch( er ) {
|
|
|
|
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 ) {
|
2020-07-06 12:14:04 -04:00
|
|
|
if ( body && body.hasClass( 'interim-login-success' ) ) {
|
2013-07-10 20:44:37 -04:00
|
|
|
hide();
|
2020-07-06 12:14:04 -04:00
|
|
|
} else {
|
2013-07-12 19:32:32 -04:00
|
|
|
parent.css( 'max-height', height + 40 + 'px' );
|
2020-07-06 12:14:04 -04:00
|
|
|
}
|
2013-07-10 20:44:37 -04:00
|
|
|
} else if ( ! body || ! body.length ) {
|
2020-01-28 19:45:18 -05:00
|
|
|
// Catch "silent" iframe origin exceptions in WebKit
|
|
|
|
// after another page is loaded in the iframe.
|
2020-07-06 12:14:04 -04:00
|
|
|
wrap.addClass( 'fallback' );
|
2013-07-10 20:44:37 -04:00
|
|
|
parent.css( 'max-height', '' );
|
|
|
|
form.remove();
|
|
|
|
noframe.focus();
|
2013-03-27 04:43:11 -04:00
|
|
|
}
|
2020-07-06 12:14:04 -04:00
|
|
|
}).attr( 'src', form.data( 'src' ) );
|
2013-03-27 04:43:11 -04:00
|
|
|
|
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' );
|
2020-07-06 12:14:04 -04:00
|
|
|
wrap.removeClass( 'hidden' );
|
2013-03-27 04:43:11 -04:00
|
|
|
|
|
|
|
if ( frame ) {
|
|
|
|
frame.focus();
|
2020-01-28 19:45:18 -05:00
|
|
|
/*
|
|
|
|
* WebKit doesn't throw an error if the iframe fails to load
|
|
|
|
* because of "X-Frame-Options: DENY" header.
|
|
|
|
* Wait for 10 seconds and switch to the fallback text.
|
|
|
|
*/
|
2013-03-27 04:43:11 -04:00
|
|
|
setTimeout( function() {
|
|
|
|
if ( ! loaded ) {
|
2020-07-06 12:14:04 -04:00
|
|
|
wrap.addClass( 'fallback' );
|
2013-03-27 04:43:11 -04:00
|
|
|
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() {
|
2020-07-06 12:14:04 -04:00
|
|
|
var adminpage = window.adminpage,
|
|
|
|
wp = window.wp;
|
|
|
|
|
|
|
|
$( window ).off( 'beforeunload.wp-auth-check' );
|
2013-06-28 21:31:44 -04:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// When on the Edit Post screen, speed up heartbeat
|
|
|
|
// after the user logs in to quickly refresh nonces.
|
2020-07-06 12:14:04 -04:00
|
|
|
if ( ( adminpage === 'post-php' || adminpage === 'post-new-php' ) && wp && wp.heartbeat ) {
|
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() {
|
2020-07-06 12:14:04 -04:00
|
|
|
wrap.addClass( 'hidden' ).css( 'display', '' );
|
|
|
|
$( '#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
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-07-06 12:14:04 -04:00
|
|
|
/**
|
|
|
|
* Set or reset the tempHidden variable used to pause showing of the modal
|
|
|
|
* after a user closes it without logging in.
|
|
|
|
*
|
|
|
|
* @since 5.5.0
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
function setShowTimeout() {
|
|
|
|
tempHidden = true;
|
|
|
|
window.clearTimeout( tempHiddenTimeout );
|
|
|
|
tempHiddenTimeout = window.setTimeout(
|
|
|
|
function() {
|
|
|
|
tempHidden = false;
|
|
|
|
},
|
|
|
|
300000 // 5 min.
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
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 ) {
|
2020-07-06 12:14:04 -04:00
|
|
|
if ( ! data['wp-auth-check'] && wrap.hasClass( 'hidden' ) && ! tempHidden ) {
|
2013-07-12 19:32:32 -04:00
|
|
|
show();
|
2020-07-06 12:14:04 -04: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
|
|
|
}
|
|
|
|
}).ready( function() {
|
2018-06-27 22:33:38 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Hides the authentication form popup when the close icon is clicked.
|
|
|
|
*
|
|
|
|
* @ignore
|
|
|
|
*
|
|
|
|
* @since 3.6.0
|
|
|
|
*/
|
2020-07-06 12:14:04 -04:00
|
|
|
wrap = $( '#wp-auth-check-wrap' );
|
|
|
|
wrap.find( '.wp-auth-check-close' ).on( 'click', function() {
|
2013-03-27 04:43:11 -04:00
|
|
|
hide();
|
2020-07-06 12:14:04 -04:00
|
|
|
setShowTimeout();
|
2013-03-27 04:43:11 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
}(jQuery));
|