Changeset 29025
- Timestamp:
- 07/08/2014 05:03:48 PM (11 years ago)
- Location:
- trunk/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/js/customize-controls.js
r28269 r29025 916 916 var previewer, parent, topFocus, 917 917 body = $( document.body ), 918 overlay = body.children('.wp-full-overlay'); 918 overlay = body.children( '.wp-full-overlay' ), 919 backBtn = $( '.back' ), 920 saveBtn = $( '#save' ); 919 921 920 922 // Prevent the form from saving when enter is pressed on an input or select element. … … 1041 1043 1042 1044 state.bind( 'change', function() { 1043 var save = $('#save'),1044 back = $('.back');1045 1046 1045 if ( ! activated() ) { 1047 save .val( api.l10n.activate ).prop( 'disabled', false );1048 back .text( api.l10n.cancel );1046 saveBtn.val( api.l10n.activate ).prop( 'disabled', false ); 1047 backBtn.text( api.l10n.cancel ); 1049 1048 1050 1049 } else if ( saved() ) { 1051 save .val( api.l10n.saved ).prop( 'disabled', true );1052 back .text( api.l10n.close );1050 saveBtn.val( api.l10n.saved ).prop( 'disabled', true ); 1051 backBtn.text( api.l10n.close ); 1053 1052 1054 1053 } else { 1055 save .val( api.l10n.save ).prop( 'disabled', false );1056 back .text( api.l10n.cancel );1054 saveBtn.val( api.l10n.save ).prop( 'disabled', false ); 1055 backBtn.text( api.l10n.cancel ); 1057 1056 } 1058 1057 }); … … 1082 1081 1083 1082 // Button bindings. 1084 $('#save').click( function( event ) {1083 saveBtn.click( function( event ) { 1085 1084 previewer.save(); 1086 1085 event.preventDefault(); … … 1093 1092 }); 1094 1093 1095 $('.back').keydown( function( event ) {1094 backBtn.keydown( function( event ) { 1096 1095 if ( 9 === event.which ) // tab 1097 1096 return; … … 1123 1122 // Send any clicks to the 'Return' link to the parent page. 1124 1123 parent.bind( 'back', function() { 1125 $('.back').on( 'click.back', function( event ) {1124 backBtn.on( 'click.back', function( event ) { 1126 1125 event.preventDefault(); 1127 1126 parent.send( 'close' ); … … 1129 1128 }); 1130 1129 1130 // Prompt user with AYS dialog if leaving the Customizer with unsaved changes 1131 $( window ).on( 'beforeunload', function () { 1132 if ( ! api.state( 'saved' )() ) { 1133 return api.l10n.saveAlert; 1134 } 1135 } ); 1136 1131 1137 // Pass events through to the parent. 1132 api.bind( 'saved', function() { 1133 parent.send( 'saved' ); 1134 }); 1138 $.each( [ 'saved', 'change' ], function ( i, event ) { 1139 api.bind( event, function() { 1140 parent.send( event ); 1141 }); 1142 } ); 1135 1143 1136 1144 // When activated, let the loader handle redirecting the page. … … 1199 1207 1200 1208 // Make sure left column gets focus 1201 topFocus = $('.back');1209 topFocus = backBtn; 1202 1210 topFocus.focus(); 1203 1211 setTimeout(function () { -
trunk/src/wp-includes/js/customize-loader.js
r26194 r29025 1 /* global _wpCustomizeLoaderSettings */1 /* global _wpCustomizeLoaderSettings, confirm */ 2 2 window.wp = window.wp || {}; 3 3 … … 37 37 38 38 // Add navigation listeners. 39 if ( $.support.history ) 39 if ( $.support.history ) { 40 40 this.window.on( 'popstate', Loader.popstate ); 41 } 41 42 42 43 if ( $.support.hashchange ) { … … 48 49 popstate: function( e ) { 49 50 var state = e.originalEvent.state; 50 if ( state && state.customize ) 51 if ( state && state.customize ) { 51 52 Loader.open( state.customize ); 52 else if ( Loader.active )53 } else if ( Loader.active ) { 53 54 Loader.close(); 55 } 54 56 }, 55 57 … … 57 59 var hash = window.location.toString().split('#')[1]; 58 60 59 if ( hash && 0 === hash.indexOf( 'wp_customize=on' ) ) 61 if ( hash && 0 === hash.indexOf( 'wp_customize=on' ) ) { 60 62 Loader.open( Loader.settings.url + '?' + hash ); 61 62 if ( ! hash && ! $.support.history ) 63 } 64 65 if ( ! hash && ! $.support.history ){ 63 66 Loader.close(); 67 } 68 }, 69 70 beforeunload: function () { 71 if ( ! Loader.saved() ) { 72 return Loader.settings.l10n.saveAlert; 73 } 64 74 }, 65 75 66 76 open: function( src ) { 67 var hash; 68 69 if ( this.active )70 return;77 78 if ( this.active ) { 79 return; 80 } 71 81 72 82 // Load the full page on mobile devices. 73 if ( Loader.settings.browser.mobile ) 83 if ( Loader.settings.browser.mobile ) { 74 84 return window.location = src; 85 } 75 86 76 87 this.active = true; 77 88 this.body.addClass('customize-loading'); 89 90 // Dirty state of customizer in iframe 91 this.saved = new api.Value( true ); 78 92 79 93 this.iframe = $( '<iframe />', { src: src }).appendTo( this.element ); … … 93 107 94 108 this.messenger.bind( 'close', function() { 95 if ( $.support.history ) 109 if ( $.support.history ) { 96 110 history.back(); 97 else if ( $.support.hashchange )111 } else if ( $.support.hashchange ) { 98 112 window.location.hash = ''; 99 else113 } else { 100 114 Loader.close(); 101 }); 115 } 116 } ); 117 118 // Prompt AYS dialog when navigating away 119 $( window ).on( 'beforeunload', this.beforeunload ); 102 120 103 121 this.messenger.bind( 'activated', function( location ) { 104 if ( location ) 122 if ( location ) { 105 123 window.location = location; 106 }); 107 108 hash = src.split('?')[1]; 124 } 125 }); 126 127 this.messenger.bind( 'saved', function () { 128 Loader.saved( true ); 129 } ); 130 this.messenger.bind( 'change', function () { 131 Loader.saved( false ); 132 } ); 133 134 this.pushState( src ); 135 136 this.trigger( 'open' ); 137 }, 138 139 pushState: function ( src ) { 140 var hash; 109 141 110 142 // Ensure we don't call pushState if the user hit the forward button. 111 if ( $.support.history && window.location.href !== src ) 143 if ( $.support.history && window.location.href !== src ) { 112 144 history.pushState( { customize: src }, '', src ); 113 else if ( ! $.support.history && $.support.hashchange && hash ) 145 } else if ( ! $.support.history && $.support.hashchange && hash ) { 146 hash = src.split( '?' )[1]; 114 147 window.location.hash = 'wp_customize=on&' + hash; 115 116 this.trigger( 'open' ); 148 } 117 149 }, 118 150 … … 122 154 123 155 close: function() { 124 if ( ! this.active ) 125 return; 156 if ( ! this.active ) { 157 return; 158 } 159 160 // Display AYS dialog if customizer is dirty 161 if ( ! this.saved() && ! confirm( Loader.settings.l10n.saveAlert ) ) { 162 // Go forward since Customizer is exited by history.back() 163 history.forward(); 164 return; 165 } 166 126 167 this.active = false; 127 168 … … 129 170 130 171 // Return focus to link that was originally clicked. 131 if ( this.link ) 172 if ( this.link ) { 132 173 this.link.focus(); 174 } 133 175 }, 134 176 … … 138 180 Loader.iframe = null; 139 181 Loader.messenger = null; 182 Loader.saved = null; 140 183 Loader.body.removeClass( 'customize-active full-overlay-active' ).removeClass( 'customize-loading' ); 184 $( window ).off( 'beforeunload', Loader.beforeunload ); 141 185 }, 142 186 -
trunk/src/wp-includes/script-loader.php
r29020 r29025 383 383 'activate' => __( 'Save & Activate' ), 384 384 'save' => __( 'Save & Publish' ), 385 'saveAlert' => __( 'The changes you made will be lost if you navigate away from this page.' ), 385 386 'saved' => __( 'Saved' ), 386 387 'cancel' => __( 'Cancel' ), -
trunk/src/wp-includes/theme.php
r28999 r29025 1875 1875 'isCrossDomain' => $cross_domain, 1876 1876 'browser' => $browser, 1877 'l10n' => array( 1878 'saveAlert' => __( 'The changes you made will be lost if you navigate away from this page.' ), 1879 ), 1877 1880 ); 1878 1881
Note: See TracChangeset
for help on using the changeset viewer.