Files
wordpress-preseed/wp-content/plugins/advanced-custom-fields/assets/build/js/_acf-unload.js
2019-09-11 19:08:46 +02:00

62 lines
1.0 KiB
JavaScript

(function($, undefined){
acf.unload = new acf.Model({
wait: 'load',
active: true,
changed: false,
actions: {
'validation_failure': 'startListening',
'validation_success': 'stopListening'
},
events: {
'change form .acf-field': 'startListening',
'submit form': 'stopListening'
},
enable: function(){
this.active = true;
},
disable: function(){
this.active = false;
},
reset: function(){
this.stopListening();
},
startListening: function(){
// bail ealry if already changed, not active
if( this.changed || !this.active ) {
return;
}
// update
this.changed = true;
// add event
$(window).on('beforeunload', this.onUnload);
},
stopListening: function(){
// update
this.changed = false;
// remove event
$(window).off('beforeunload', this.onUnload);
},
onUnload: function(){
return acf.__('The changes you made will be lost if you navigate away from this page');
}
});
})(jQuery);