Add a `beforeunload` event to prompt before leaving with unsaved changes.
This commit is contained in:
parent
29df63b767
commit
6b76f81786
|
@ -61,6 +61,24 @@
|
|||
},
|
||||
initialize : function() {
|
||||
this.qty_pages = Math.ceil( this.model.get( 'rates' ).length / this.per_page );
|
||||
this.listenTo( this.model, 'change', this.setUnloadConfirmation );
|
||||
this.listenTo( this.model, 'saved', this.clearUnloadConfirmation );
|
||||
window.addEventListener( 'beforeunload', this.unloadConfirmation );
|
||||
},
|
||||
setUnloadConfirmation : function() {
|
||||
console.log( data.strings.unload_confirmation_msg );
|
||||
this.needsUnloadConfirm = true;
|
||||
},
|
||||
clearUnloadConfirmation : function() {
|
||||
this.needsUnloadConfirm = false;
|
||||
},
|
||||
unloadConfirmation : function(e) {
|
||||
if ( this.needsUnloadConfirm ) {
|
||||
e.returnValue = data.strings.unload_confirmation_msg;
|
||||
window.event.returnValue = data.strings.unload_confirmation_msg;
|
||||
return data.strings.unload_confirmation_msg;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
sanitizePage : function( page_num ) {
|
||||
page_num = parseInt( page_num, 10 );
|
||||
|
|
|
@ -156,6 +156,7 @@ class WC_Settings_Tax extends WC_Settings_Page {
|
|||
'states' => $states,
|
||||
'strings' => array(
|
||||
'no_rows_selected' => __( 'No row(s) selected', 'woocommerce' ),
|
||||
'unload_confirmation_msg' => __( 'Your changed data will be lost if you leave this page without saving.', 'woocommerce' ),
|
||||
'csv_data_cols' => array(
|
||||
__( 'Country Code', 'woocommerce' ),
|
||||
__( 'State Code', 'woocommerce' ),
|
||||
|
|
Loading…
Reference in New Issue