Changeset 48337
- Timestamp:
- 07/06/2020 04:12:24 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/js/_enqueues/lib/auth-check.js
r48285 r48337 6 6 7 7 /* global adminpage */ 8 (function($){ 9 var wrap; 8 ( function( $ ) { 9 var wrap, 10 tempHidden, 11 tempHiddenTimeout; 10 12 11 13 /** … … 16 18 */ 17 19 function show() { 18 var parent = $( '#wp-auth-check'),19 form = $( '#wp-auth-check-form'),20 noframe = wrap.find( '.wp-auth-fallback-expired'),20 var parent = $( '#wp-auth-check' ), 21 form = $( '#wp-auth-check-form' ), 22 noframe = wrap.find( '.wp-auth-fallback-expired' ), 21 23 frame, loaded = false; 22 24 23 25 if ( form.length ) { 24 26 // Add unload confirmation to counter (frame-busting) JS redirects. 25 $( window).on( 'beforeunload.wp-auth-check', function(e) {26 e .originalEvent.returnValue =wp.i18n.__( 'Your session has expired. You can log in again from this page or go to the login page.' );27 $( window ).on( 'beforeunload.wp-auth-check', function( event ) { 28 event.originalEvent.returnValue = window.wp.i18n.__( 'Your session has expired. You can log in again from this page or go to the login page.' ); 27 29 }); 28 30 29 frame = $( '<iframe id="wp-auth-check-frame" frameborder="0">').attr( 'title', noframe.text() );31 frame = $( '<iframe id="wp-auth-check-frame" frameborder="0">' ).attr( 'title', noframe.text() ); 30 32 frame.on( 'load', function() { 31 33 var height, body; … … 36 38 37 39 try { 38 body = $( this).contents().find('body');40 body = $( this ).contents().find( 'body' ); 39 41 height = body.height(); 40 } catch( e) {41 wrap.addClass( 'fallback');42 } catch( er ) { 43 wrap.addClass( 'fallback' ); 42 44 parent.css( 'max-height', '' ); 43 45 form.remove(); … … 47 49 48 50 if ( height ) { 49 if ( body && body.hasClass( 'interim-login-success') )51 if ( body && body.hasClass( 'interim-login-success' ) ) { 50 52 hide(); 51 else53 } else { 52 54 parent.css( 'max-height', height + 40 + 'px' ); 55 } 53 56 } else if ( ! body || ! body.length ) { 54 57 // Catch "silent" iframe origin exceptions in WebKit 55 58 // after another page is loaded in the iframe. 56 wrap.addClass( 'fallback');59 wrap.addClass( 'fallback' ); 57 60 parent.css( 'max-height', '' ); 58 61 form.remove(); 59 62 noframe.focus(); 60 63 } 61 }).attr( 'src', form.data( 'src') );64 }).attr( 'src', form.data( 'src' ) ); 62 65 63 66 form.append( frame ); … … 65 68 66 69 $( 'body' ).addClass( 'modal-open' ); 67 wrap.removeClass( 'hidden');70 wrap.removeClass( 'hidden' ); 68 71 69 72 if ( frame ) { … … 76 79 setTimeout( function() { 77 80 if ( ! loaded ) { 78 wrap.addClass( 'fallback');81 wrap.addClass( 'fallback' ); 79 82 form.remove(); 80 83 noframe.focus(); … … 93 96 */ 94 97 function hide() { 95 $(window).off( 'beforeunload.wp-auth-check' ); 98 var adminpage = window.adminpage, 99 wp = window.wp; 100 101 $( window ).off( 'beforeunload.wp-auth-check' ); 96 102 97 103 // When on the Edit Post screen, speed up heartbeat 98 104 // after the user logs in to quickly refresh nonces. 99 if ( typeof adminpage !== 'undefined' && ( adminpage === 'post-php' || adminpage === 'post-new-php' ) && 100 typeof wp !== 'undefined' && wp.heartbeat ) { 101 102 $(document).off( 'heartbeat-tick.wp-auth-check' ); 105 if ( ( adminpage === 'post-php' || adminpage === 'post-new-php' ) && wp && wp.heartbeat ) { 103 106 wp.heartbeat.connectNow(); 104 107 } 105 108 106 109 wrap.fadeOut( 200, function() { 107 wrap.addClass( 'hidden').css('display', '');108 $( '#wp-auth-check-frame').remove();110 wrap.addClass( 'hidden' ).css( 'display', '' ); 111 $( '#wp-auth-check-frame' ).remove(); 109 112 $( 'body' ).removeClass( 'modal-open' ); 110 113 }); 114 } 115 116 /** 117 * Set or reset the tempHidden variable used to pause showing of the modal 118 * after a user closes it without logging in. 119 * 120 * @since 5.5.0 121 * @private 122 */ 123 function setShowTimeout() { 124 tempHidden = true; 125 window.clearTimeout( tempHiddenTimeout ); 126 tempHiddenTimeout = window.setTimeout( 127 function() { 128 tempHidden = false; 129 }, 130 300000 // 5 min. 131 ); 111 132 } 112 133 … … 127 148 $( document ).on( 'heartbeat-tick.wp-auth-check', function( e, data ) { 128 149 if ( 'wp-auth-check' in data ) { 129 if ( ! data['wp-auth-check'] && wrap.hasClass( 'hidden')) {150 if ( ! data['wp-auth-check'] && wrap.hasClass( 'hidden' ) && ! tempHidden ) { 130 151 show(); 131 } else if ( data['wp-auth-check'] && ! wrap.hasClass( 'hidden') ) {152 } else if ( data['wp-auth-check'] && ! wrap.hasClass( 'hidden' ) ) { 132 153 hide(); 133 154 } … … 142 163 * @since 3.6.0 143 164 */ 144 wrap = $( '#wp-auth-check-wrap');145 wrap.find( '.wp-auth-check-close').on( 'click', function() {165 wrap = $( '#wp-auth-check-wrap' ); 166 wrap.find( '.wp-auth-check-close' ).on( 'click', function() { 146 167 hide(); 168 setShowTimeout(); 147 169 }); 148 170 });
Note: See TracChangeset
for help on using the changeset viewer.