Skip to content

Commit

Permalink
Show 'you are about to leave' message if bailing from site creation.
Browse files Browse the repository at this point in the history
  • Loading branch information
boonebgorges committed Dec 5, 2018
1 parent 96dbc9d commit 6acd4c6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
19 changes: 19 additions & 0 deletions assets/js/site-create.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
(function($){
var shouldconfirm = false;

window.onbeforeunload = function(e) {
if ( shouldconfirm ) {
e.message = CACSiteTemplatesSiteCreate.confirm;
return CACSiteTemplatesSiteCreate.confirm;
}
}

$(document).ready(function() {
var $form = $('#setupform');
$form.change(function(){
shouldconfirm = true;
}).submit(function() {
shouldconfirm = false;
});
});
}(jQuery));
17 changes: 17 additions & 0 deletions src/Frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@ public static function register_assets() {
'cac-site-template-signup-field',
CAC_SITE_TEMPLATES_PLUGIN_URL . '/assets/css/signup-field.css'
);

wp_register_script(
'cac-site-templates-site-create',
CAC_SITE_TEMPLATES_PLUGIN_URL . '/assets/js/site-create.js',
[ 'jquery' ],
false,
true
);

wp_localize_script(
'cac-site-templates-site-create',
'CACSiteTemplatesSiteCreate',
[
'confirm' => __( 'By leaving this page, you will cancel the site creation process. Are you sure you want to leave?', 'cac-site-templates' ),
]
);
}

public static function signup_field() {
Expand All @@ -22,6 +38,7 @@ public static function signup_field() {
}

wp_enqueue_style( 'cac-site-template-signup-field' );
wp_enqueue_script( 'cac-site-templates-site-create' );

$template_query = new Template\Query();
$templates = $template_query->get_results();
Expand Down

0 comments on commit 6acd4c6

Please sign in to comment.