author | ymh <ymh.work@gmail.com> |
Fri, 05 Sep 2025 18:52:52 +0200 | |
changeset 22 | 8c2e4d02f4ef |
parent 18 | be944660c56a |
permissions | -rw-r--r-- |
9 | 1 |
/** |
2 |
* Interim login dialog. |
|
3 |
* |
|
4 |
* @output wp-includes/js/wp-auth-check.js |
|
5 |
*/ |
|
6 |
||
16 | 7 |
( function( $ ) { |
8 |
var wrap, |
|
9 |
tempHidden, |
|
10 |
tempHiddenTimeout; |
|
0 | 11 |
|
9 | 12 |
/** |
13 |
* Shows the authentication form popup. |
|
14 |
* |
|
15 |
* @since 3.6.0 |
|
16 |
* @private |
|
17 |
*/ |
|
0 | 18 |
function show() { |
16 | 19 |
var parent = $( '#wp-auth-check' ), |
20 |
form = $( '#wp-auth-check-form' ), |
|
21 |
noframe = wrap.find( '.wp-auth-fallback-expired' ), |
|
5 | 22 |
frame, loaded = false; |
0 | 23 |
|
24 |
if ( form.length ) { |
|
9 | 25 |
// Add unload confirmation to counter (frame-busting) JS redirects. |
16 | 26 |
$( window ).on( 'beforeunload.wp-auth-check', function( event ) { |
27 |
event.originalEvent.returnValue = window.wp.i18n.__( 'Your session has expired. You can log in again from this page or go to the login page.' ); |
|
0 | 28 |
}); |
29 |
||
16 | 30 |
frame = $( '<iframe id="wp-auth-check-frame" frameborder="0">' ).attr( 'title', noframe.text() ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
31 |
frame.on( 'load', function() { |
0 | 32 |
var height, body; |
33 |
||
34 |
loaded = true; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
35 |
// Remove the spinner to avoid unnecessary CPU/GPU usage. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
36 |
form.removeClass( 'loading' ); |
0 | 37 |
|
38 |
try { |
|
16 | 39 |
body = $( this ).contents().find( 'body' ); |
0 | 40 |
height = body.height(); |
16 | 41 |
} catch( er ) { |
42 |
wrap.addClass( 'fallback' ); |
|
0 | 43 |
parent.css( 'max-height', '' ); |
44 |
form.remove(); |
|
45 |
noframe.focus(); |
|
46 |
return; |
|
47 |
} |
|
48 |
||
49 |
if ( height ) { |
|
16 | 50 |
if ( body && body.hasClass( 'interim-login-success' ) ) { |
0 | 51 |
hide(); |
16 | 52 |
} else { |
0 | 53 |
parent.css( 'max-height', height + 40 + 'px' ); |
16 | 54 |
} |
0 | 55 |
} else if ( ! body || ! body.length ) { |
16 | 56 |
// Catch "silent" iframe origin exceptions in WebKit |
57 |
// after another page is loaded in the iframe. |
|
58 |
wrap.addClass( 'fallback' ); |
|
0 | 59 |
parent.css( 'max-height', '' ); |
60 |
form.remove(); |
|
61 |
noframe.focus(); |
|
62 |
} |
|
16 | 63 |
}).attr( 'src', form.data( 'src' ) ); |
0 | 64 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
65 |
form.append( frame ); |
0 | 66 |
} |
67 |
||
5 | 68 |
$( 'body' ).addClass( 'modal-open' ); |
16 | 69 |
wrap.removeClass( 'hidden' ); |
0 | 70 |
|
71 |
if ( frame ) { |
|
72 |
frame.focus(); |
|
16 | 73 |
/* |
74 |
* WebKit doesn't throw an error if the iframe fails to load |
|
75 |
* because of "X-Frame-Options: DENY" header. |
|
76 |
* Wait for 10 seconds and switch to the fallback text. |
|
77 |
*/ |
|
0 | 78 |
setTimeout( function() { |
79 |
if ( ! loaded ) { |
|
16 | 80 |
wrap.addClass( 'fallback' ); |
0 | 81 |
form.remove(); |
82 |
noframe.focus(); |
|
83 |
} |
|
84 |
}, 10000 ); |
|
85 |
} else { |
|
86 |
noframe.focus(); |
|
87 |
} |
|
88 |
} |
|
89 |
||
9 | 90 |
/** |
91 |
* Hides the authentication form popup. |
|
92 |
* |
|
93 |
* @since 3.6.0 |
|
94 |
* @private |
|
95 |
*/ |
|
0 | 96 |
function hide() { |
16 | 97 |
var adminpage = window.adminpage, |
98 |
wp = window.wp; |
|
0 | 99 |
|
16 | 100 |
$( window ).off( 'beforeunload.wp-auth-check' ); |
0 | 101 |
|
16 | 102 |
// When on the Edit Post screen, speed up heartbeat |
103 |
// after the user logs in to quickly refresh nonces. |
|
104 |
if ( ( adminpage === 'post-php' || adminpage === 'post-new-php' ) && wp && wp.heartbeat ) { |
|
5 | 105 |
wp.heartbeat.connectNow(); |
0 | 106 |
} |
107 |
||
108 |
wrap.fadeOut( 200, function() { |
|
16 | 109 |
wrap.addClass( 'hidden' ).css( 'display', '' ); |
110 |
$( '#wp-auth-check-frame' ).remove(); |
|
5 | 111 |
$( 'body' ).removeClass( 'modal-open' ); |
0 | 112 |
}); |
113 |
} |
|
114 |
||
9 | 115 |
/** |
16 | 116 |
* Set or reset the tempHidden variable used to pause showing of the modal |
117 |
* after a user closes it without logging in. |
|
9 | 118 |
* |
16 | 119 |
* @since 5.5.0 |
9 | 120 |
* @private |
121 |
*/ |
|
16 | 122 |
function setShowTimeout() { |
123 |
tempHidden = true; |
|
124 |
window.clearTimeout( tempHiddenTimeout ); |
|
125 |
tempHiddenTimeout = window.setTimeout( |
|
126 |
function() { |
|
127 |
tempHidden = false; |
|
128 |
}, |
|
129 |
300000 // 5 min. |
|
130 |
); |
|
0 | 131 |
} |
132 |
||
9 | 133 |
/** |
134 |
* Binds to the Heartbeat Tick event. |
|
135 |
* |
|
136 |
* - Shows the authentication form popup if user is not logged in. |
|
137 |
* - Hides the authentication form popup if it is already visible and user is |
|
138 |
* logged in. |
|
139 |
* |
|
140 |
* @ignore |
|
141 |
* |
|
142 |
* @since 3.6.0 |
|
143 |
* |
|
144 |
* @param {Object} e The heartbeat-tick event that has been triggered. |
|
145 |
* @param {Object} data Response data. |
|
146 |
*/ |
|
18 | 147 |
$( function() { |
9 | 148 |
|
149 |
/** |
|
150 |
* Hides the authentication form popup when the close icon is clicked. |
|
151 |
* |
|
152 |
* @ignore |
|
153 |
* |
|
154 |
* @since 3.6.0 |
|
155 |
*/ |
|
16 | 156 |
wrap = $( '#wp-auth-check-wrap' ); |
157 |
wrap.find( '.wp-auth-check-close' ).on( 'click', function() { |
|
0 | 158 |
hide(); |
16 | 159 |
setShowTimeout(); |
0 | 160 |
}); |
18 | 161 |
}).on( 'heartbeat-tick.wp-auth-check', function( e, data ) { |
162 |
if ( 'wp-auth-check' in data ) { |
|
163 |
if ( ! data['wp-auth-check'] && wrap.hasClass( 'hidden' ) && ! tempHidden ) { |
|
164 |
show(); |
|
165 |
} else if ( data['wp-auth-check'] && ! wrap.hasClass( 'hidden' ) ) { |
|
166 |
hide(); |
|
167 |
} |
|
168 |
} |
|
0 | 169 |
}); |
170 |
||
171 |
}(jQuery)); |