Ticket #44364: 44364.diff
File 44364.diff, 3.8 KB (added by , 6 years ago) |
---|
-
src/js/_enqueues/lib/auth-check.js
3 3 (function($){ 4 4 var wrap, next; 5 5 6 /** 7 * Shows the authentification form popup. 8 * 9 * @since 3.6 10 */ 6 11 function show() { 7 12 var parent = $('#wp-auth-check'), 8 13 form = $('#wp-auth-check-form'), … … 10 15 frame, loaded = false; 11 16 12 17 if ( form.length ) { 13 // Add unload confirmation to counter (frame-busting) JS redirects 18 // Add unload confirmation to counter (frame-busting) JS redirects. 14 19 $(window).on( 'beforeunload.wp-auth-check', function(e) { 15 20 e.originalEvent.returnValue = window.authcheckL10n.beforeunload; 16 21 }); … … 40 45 else 41 46 parent.css( 'max-height', height + 40 + 'px' ); 42 47 } else if ( ! body || ! body.length ) { 43 // Catch "silent" iframe origin exceptions in WebKit after another page is loaded in the iframe 48 // Catch "silent" iframe origin exceptions in WebKit after another page is 49 // loaded in the iframe. 44 50 wrap.addClass('fallback'); 45 51 parent.css( 'max-height', '' ); 46 52 form.remove(); … … 56 62 57 63 if ( frame ) { 58 64 frame.focus(); 59 // WebKit doesn't throw an error if the iframe fails to load because of "X-Frame-Options: DENY" header. 65 // WebKit doesn't throw an error if the iframe fails to load because of 66 // "X-Frame-Options: DENY" header. 60 67 // Wait for 10 sec. and switch to the fallback text. 61 68 setTimeout( function() { 62 69 if ( ! loaded ) { … … 70 77 } 71 78 } 72 79 80 /** 81 * Hides the authentification form popup. 82 * 83 * @since 3.6 84 */ 73 85 function hide() { 74 86 $(window).off( 'beforeunload.wp-auth-check' ); 75 87 76 // When on the Edit Post screen, speed up heartbeat after the user logs in to quickly refresh nonces 88 // When on the Edit Post screen, speed up heartbeat after the user logs in to 89 // quickly refresh nonces. 77 90 if ( typeof adminpage !== 'undefined' && ( adminpage === 'post-php' || adminpage === 'post-new-php' ) && 78 91 typeof wp !== 'undefined' && wp.heartbeat ) { 79 92 … … 88 101 }); 89 102 } 90 103 104 /** 105 * Schedules the next time authentification check will be done. 106 * 107 * @since 3.6 108 */ 91 109 function schedule() { 92 var interval = parseInt( window.authcheckL10n.interval, 10 ) || 180; // in seconds, default 3 min. 110 // In seconds, default 3 min. 111 var interval = parseInt( window.authcheckL10n.interval, 10 ) || 180; 93 112 next = ( new Date() ).getTime() + ( interval * 1000 ); 94 113 } 95 114 115 /** 116 * Binds to the Heartbeat Tick event. 117 * Shows the authentification form popup if user is not logged in. 118 * Hides the authentification form popup if it is already visible and user 119 * is logged in. 120 * 121 * @since 3.6 122 * 123 * @param {object} e The heartbeat-tick event that has been triggered. 124 * @param {object} data Response data. 125 */ 96 126 $( document ).on( 'heartbeat-tick.wp-auth-check', function( e, data ) { 97 127 if ( 'wp-auth-check' in data ) { 98 128 schedule(); … … 102 132 hide(); 103 133 } 104 134 } 135 136 /** 137 * Binds to the Heartbeat Send event. 138 * 139 * @since 3.6 140 * 141 * @param {object} e The heartbeat-send event that has been triggered. 142 * @param {object} data Response data. 143 */ 105 144 }).on( 'heartbeat-send.wp-auth-check', function( e, data ) { 106 145 if ( ( new Date() ).getTime() > next ) { 107 146 data['wp-auth-check'] = true; 108 147 } 148 149 /** 150 * Binds to the document ready event. 151 * 152 * @since 3.6 153 */ 109 154 }).ready( function() { 110 155 schedule(); 156 157 /** 158 * Hides the authentification form popup when the close icon is clicked. 159 * 160 * @since 3.6 161 * 162 * @listens .wp-auth-check-close:click 163 */ 111 164 wrap = $('#wp-auth-check-wrap'); 112 165 wrap.find('.wp-auth-check-close').on( 'click', function() { 113 166 hide();