[ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 /** 2 * Interim login dialog. 3 * 4 * @output wp-includes/js/wp-auth-check.js 5 */ 6 7 ( function( $ ) { 8 var wrap, 9 tempHidden, 10 tempHiddenTimeout; 11 12 /** 13 * Shows the authentication form popup. 14 * 15 * @since 3.6.0 16 * @private 17 */ 18 function show() { 19 var parent = $( '#wp-auth-check' ), 20 form = $( '#wp-auth-check-form' ), 21 noframe = wrap.find( '.wp-auth-fallback-expired' ), 22 frame, loaded = false; 23 24 if ( form.length ) { 25 // Add unload confirmation to counter (frame-busting) JS redirects. 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.' ); 28 }); 29 30 frame = $( '<iframe id="wp-auth-check-frame" frameborder="0">' ).attr( 'title', noframe.text() ); 31 frame.on( 'load', function() { 32 var height, body; 33 34 loaded = true; 35 // Remove the spinner to avoid unnecessary CPU/GPU usage. 36 form.removeClass( 'loading' ); 37 38 try { 39 body = $( this ).contents().find( 'body' ); 40 height = body.height(); 41 } catch( er ) { 42 wrap.addClass( 'fallback' ); 43 parent.css( 'max-height', '' ); 44 form.remove(); 45 noframe.focus(); 46 return; 47 } 48 49 if ( height ) { 50 if ( body && body.hasClass( 'interim-login-success' ) ) { 51 hide(); 52 } else { 53 parent.css( 'max-height', height + 40 + 'px' ); 54 } 55 } else if ( ! body || ! body.length ) { 56 // Catch "silent" iframe origin exceptions in WebKit 57 // after another page is loaded in the iframe. 58 wrap.addClass( 'fallback' ); 59 parent.css( 'max-height', '' ); 60 form.remove(); 61 noframe.focus(); 62 } 63 }).attr( 'src', form.data( 'src' ) ); 64 65 form.append( frame ); 66 } 67 68 $( 'body' ).addClass( 'modal-open' ); 69 wrap.removeClass( 'hidden' ); 70 71 if ( frame ) { 72 frame.focus(); 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 */ 78 setTimeout( function() { 79 if ( ! loaded ) { 80 wrap.addClass( 'fallback' ); 81 form.remove(); 82 noframe.focus(); 83 } 84 }, 10000 ); 85 } else { 86 noframe.focus(); 87 } 88 } 89 90 /** 91 * Hides the authentication form popup. 92 * 93 * @since 3.6.0 94 * @private 95 */ 96 function hide() { 97 var adminpage = window.adminpage, 98 wp = window.wp; 99 100 $( window ).off( 'beforeunload.wp-auth-check' ); 101 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 ) { 105 wp.heartbeat.connectNow(); 106 } 107 108 wrap.fadeOut( 200, function() { 109 wrap.addClass( 'hidden' ).css( 'display', '' ); 110 $( '#wp-auth-check-frame' ).remove(); 111 $( 'body' ).removeClass( 'modal-open' ); 112 }); 113 } 114 115 /** 116 * Set or reset the tempHidden variable used to pause showing of the modal 117 * after a user closes it without logging in. 118 * 119 * @since 5.5.0 120 * @private 121 */ 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 ); 131 } 132 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 */ 147 $( function() { 148 149 /** 150 * Hides the authentication form popup when the close icon is clicked. 151 * 152 * @ignore 153 * 154 * @since 3.6.0 155 */ 156 wrap = $( '#wp-auth-check-wrap' ); 157 wrap.find( '.wp-auth-check-close' ).on( 'click', function() { 158 hide(); 159 setShowTimeout(); 160 }); 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 } 169 }); 170 171 }(jQuery));
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated : Sat Dec 21 08:20:01 2024 | Cross-referenced by PHPXref |