2018-06-28 04:30:15 +02:00
|
|
|
/**
|
|
|
|
* Interim login dialog.
|
|
|
|
*
|
|
|
|
* @output wp-includes/js/wp-auth-check.js
|
|
|
|
*/
|
|
|
|
|
2013-11-15 05:42:09 +01:00
|
|
|
/* global adminpage */
|
2013-03-27 09:43:11 +01:00
|
|
|
(function($){
|
2020-06-16 09:09:09 +02:00
|
|
|
var wrap;
|
2013-03-27 09:43:11 +01:00
|
|
|
|
2018-06-28 04:33:38 +02:00
|
|
|
/**
|
|
|
|
* Shows the authentication form popup.
|
|
|
|
*
|
|
|
|
* @since 3.6.0
|
|
|
|
* @private
|
|
|
|
*/
|
2013-03-27 09:43:11 +01:00
|
|
|
function show() {
|
2013-12-02 19:47:09 +01:00
|
|
|
var parent = $('#wp-auth-check'),
|
|
|
|
form = $('#wp-auth-check-form'),
|
|
|
|
noframe = wrap.find('.wp-auth-fallback-expired'),
|
|
|
|
frame, loaded = false;
|
2013-03-27 09:43:11 +01:00
|
|
|
|
|
|
|
if ( form.length ) {
|
2018-06-28 04:33:38 +02:00
|
|
|
// Add unload confirmation to counter (frame-busting) JS redirects.
|
2013-03-27 09:43:11 +01:00
|
|
|
$(window).on( 'beforeunload.wp-auth-check', function(e) {
|
|
|
|
e.originalEvent.returnValue = window.authcheckL10n.beforeunload;
|
|
|
|
});
|
|
|
|
|
2013-05-06 23:35:50 +02:00
|
|
|
frame = $('<iframe id="wp-auth-check-frame" frameborder="0">').attr( 'title', noframe.text() );
|
2016-01-13 18:22:27 +01:00
|
|
|
frame.on( 'load', function() {
|
2013-03-27 09:43:11 +01:00
|
|
|
var height, body;
|
|
|
|
|
|
|
|
loaded = true;
|
2015-12-14 17:40:27 +01:00
|
|
|
// Remove the spinner to avoid unnecessary CPU/GPU usage.
|
|
|
|
form.removeClass( 'loading' );
|
2013-03-27 09:43:11 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
body = $(this).contents().find('body');
|
|
|
|
height = body.height();
|
|
|
|
} catch(e) {
|
|
|
|
wrap.addClass('fallback');
|
2013-07-11 02:44:37 +02:00
|
|
|
parent.css( 'max-height', '' );
|
2013-03-27 09:43:11 +01:00
|
|
|
form.remove();
|
|
|
|
noframe.focus();
|
2013-05-06 23:35:50 +02:00
|
|
|
return;
|
2013-03-27 09:43:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( height ) {
|
2013-07-11 02:44:37 +02:00
|
|
|
if ( body && body.hasClass('interim-login-success') )
|
|
|
|
hide();
|
|
|
|
else
|
2013-07-13 01:32:32 +02:00
|
|
|
parent.css( 'max-height', height + 40 + 'px' );
|
2013-07-11 02:44:37 +02:00
|
|
|
} else if ( ! body || ! body.length ) {
|
2020-01-29 01:45:18 +01:00
|
|
|
// Catch "silent" iframe origin exceptions in WebKit
|
|
|
|
// after another page is loaded in the iframe.
|
2013-07-11 02:44:37 +02:00
|
|
|
wrap.addClass('fallback');
|
|
|
|
parent.css( 'max-height', '' );
|
|
|
|
form.remove();
|
|
|
|
noframe.focus();
|
2013-03-27 09:43:11 +01:00
|
|
|
}
|
|
|
|
}).attr( 'src', form.data('src') );
|
|
|
|
|
2015-12-14 17:40:27 +01:00
|
|
|
form.append( frame );
|
2013-03-27 09:43:11 +01:00
|
|
|
}
|
|
|
|
|
2015-04-01 00:55:26 +02:00
|
|
|
$( 'body' ).addClass( 'modal-open' );
|
2013-03-27 09:43:11 +01:00
|
|
|
wrap.removeClass('hidden');
|
|
|
|
|
|
|
|
if ( frame ) {
|
|
|
|
frame.focus();
|
2020-01-29 01:45:18 +01: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 09:43:11 +01:00
|
|
|
setTimeout( function() {
|
|
|
|
if ( ! loaded ) {
|
|
|
|
wrap.addClass('fallback');
|
|
|
|
form.remove();
|
|
|
|
noframe.focus();
|
|
|
|
}
|
2013-07-11 02:44:37 +02:00
|
|
|
}, 10000 );
|
2013-03-27 09:43:11 +01:00
|
|
|
} else {
|
|
|
|
noframe.focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-28 04:33:38 +02:00
|
|
|
/**
|
|
|
|
* Hides the authentication form popup.
|
|
|
|
*
|
|
|
|
* @since 3.6.0
|
|
|
|
* @private
|
|
|
|
*/
|
2013-03-27 09:43:11 +01:00
|
|
|
function hide() {
|
|
|
|
$(window).off( 'beforeunload.wp-auth-check' );
|
2013-06-29 03:31:44 +02:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// When on the Edit Post screen, speed up heartbeat
|
|
|
|
// after the user logs in to quickly refresh nonces.
|
2013-12-02 19:47:09 +01:00
|
|
|
if ( typeof adminpage !== 'undefined' && ( adminpage === 'post-php' || adminpage === 'post-new-php' ) &&
|
|
|
|
typeof wp !== 'undefined' && wp.heartbeat ) {
|
2013-06-29 03:31:44 +02:00
|
|
|
|
2015-11-07 17:22:25 +01:00
|
|
|
$(document).off( 'heartbeat-tick.wp-auth-check' );
|
2013-12-02 19:47:09 +01:00
|
|
|
wp.heartbeat.connectNow();
|
2013-06-29 03:31:44 +02:00
|
|
|
}
|
2013-03-27 09:43:11 +01:00
|
|
|
|
|
|
|
wrap.fadeOut( 200, function() {
|
2013-07-13 01:32:32 +02:00
|
|
|
wrap.addClass('hidden').css('display', '');
|
2013-03-27 09:43:11 +01:00
|
|
|
$('#wp-auth-check-frame').remove();
|
2015-04-01 00:55:26 +02:00
|
|
|
$( 'body' ).removeClass( 'modal-open' );
|
2013-03-27 09:43:11 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-06-28 04:33:38 +02: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 09:43:11 +01:00
|
|
|
$( document ).on( 'heartbeat-tick.wp-auth-check', function( e, data ) {
|
2013-07-18 21:06:35 +02:00
|
|
|
if ( 'wp-auth-check' in data ) {
|
2013-12-02 19:47:09 +01:00
|
|
|
if ( ! data['wp-auth-check'] && wrap.hasClass('hidden') ) {
|
2013-07-13 01:32:32 +02:00
|
|
|
show();
|
2013-12-02 19:47:09 +01:00
|
|
|
} else if ( data['wp-auth-check'] && ! wrap.hasClass('hidden') ) {
|
2013-07-13 01:32:32 +02:00
|
|
|
hide();
|
2013-12-02 19:47:09 +01:00
|
|
|
}
|
2013-03-27 09:43:11 +01:00
|
|
|
}
|
|
|
|
}).ready( function() {
|
2018-06-28 04:33:38 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Hides the authentication form popup when the close icon is clicked.
|
|
|
|
*
|
|
|
|
* @ignore
|
|
|
|
*
|
|
|
|
* @since 3.6.0
|
|
|
|
*/
|
2013-07-11 02:44:37 +02:00
|
|
|
wrap = $('#wp-auth-check-wrap');
|
2013-11-15 05:42:09 +01:00
|
|
|
wrap.find('.wp-auth-check-close').on( 'click', function() {
|
2013-03-27 09:43:11 +01:00
|
|
|
hide();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
}(jQuery));
|