[MediaWiki-commits] [Gerrit] Add onbeforeunload handler when navigating away from unsubmi... - change (mediawiki...Flow)
SG has uploaded a new change for review. https://gerrit.wikimedia.org/r/148983 Change subject: Add onbeforeunload handler when navigating away from unsubmitted changes .. Add onbeforeunload handler when navigating away from unsubmitted changes Change-Id: I451437da738e57866b1013de3c659102da62a15d --- M Resources.php M i18n/en.json M i18n/qqq.json M modules/new/mw-ui.enhance.js 4 files changed, 29 insertions(+), 2 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow refs/changes/83/148983/1 diff --git a/Resources.php b/Resources.php index e97c61d..45ff0ad 100644 --- a/Resources.php +++ b/Resources.php @@ -316,6 +316,7 @@ 'messages' = array( 'flow-error-http', 'flow-error-fetch-after-open-close', + 'mw-ui-unsubmitted-confirm', ) ) + $mobile, 'ext.flow.vendor.storer' = $flowResourceTemplate + array( diff --git a/i18n/en.json b/i18n/en.json index a24bd22..f379ffc 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -349,5 +349,6 @@ flow-preview-warning: You are seeing a preview. Submit the form to finish posting this, or click \{{int:flow-preview-return-edit-post}}\ to continue writing., flow-preview-return-edit-post : Keep editing, flow-anonymous: Anonymous, -flow-embedding-unsupported : Discussions cannot be embedded yet. +flow-embedding-unsupported : Discussions cannot be embedded yet., +mw-ui-unsubmitted-confirm: You have unsubmitted changes on this page. Are you sure you want to navigate away and lose your work? } diff --git a/i18n/qqq.json b/i18n/qqq.json index 54993a8..dd5473d 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -353,5 +353,6 @@ flow-preview-warning: Refers to {{msg-mw|Flow-preview-return-edit-post}} (Keep editing)., flow-preview-return-edit-post: Used as text for a button that hides previewed text and returns to the editing view, flow-anonymous: {{Identical|Anonymous}}, - flow-embedding-unsupported: Error message displayed if a user tries to transclude a Flow page. + flow-embedding-unsupported: Error message displayed if a user tries to transclude a Flow page., + mw-ui-unsubmitted-confirm: You have unsubmitted changes on this page. Are you sure you want to navigate away and lose your work? } diff --git a/modules/new/mw-ui.enhance.js b/modules/new/mw-ui.enhance.js index 37c0921..056aee9 100644 --- a/modules/new/mw-ui.enhance.js +++ b/modules/new/mw-ui.enhance.js @@ -413,4 +413,28 @@ .on( 'mouseleave.mw-ui-enhance blur.mw-ui-enhance click.mw-ui-enhance', '.flow-ui-tooltip-target', onMwUiTooltipBlur ); } ); + /* +Ask a user to confirm navigating away from a page when they have entered unsubmitted changes to a form. +*/ + var _oldOnBeforeUnload = window.onbeforeunload; + window.onbeforeunload = function () { + var uncommitted; + + $( 'input, textarea' ).filter( '.mw-ui-input:visible' ).each( function () { + if ( $.trim( this.value ) this.value !== this.defaultValue ) { + uncommitted = true; + return false; + } + } ); + + // Ask the user if they want to navigate away + if ( uncommitted ) { + return mw.msg( 'mw-ui-unsubmitted-confirm' ); + } + + // Run the old on beforeunload fn if it exists + if ( _oldOnBeforeUnload ) { + return _oldOnBeforeUnload(); + } + }; }( mw, jQuery ) ); -- To view, visit https://gerrit.wikimedia.org/r/148983 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I451437da738e57866b1013de3c659102da62a15d Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Flow Gerrit-Branch: master Gerrit-Owner: SG shah...@gmail.com ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] Add onbeforeunload handler when navigating away from unsubmi... - change (mediawiki...Flow)
jenkins-bot has submitted this change and it was merged. Change subject: Add onbeforeunload handler when navigating away from unsubmitted changes .. Add onbeforeunload handler when navigating away from unsubmitted changes Change-Id: I451437da738e57866b1013de3c659102da62a15d --- M Resources.php M i18n/en.json M i18n/qqq.json M modules/new/mw-ui.enhance.js 4 files changed, 29 insertions(+), 2 deletions(-) Approvals: Jdlrobson: Looks good to me, approved jenkins-bot: Verified diff --git a/Resources.php b/Resources.php index e97c61d..45ff0ad 100644 --- a/Resources.php +++ b/Resources.php @@ -316,6 +316,7 @@ 'messages' = array( 'flow-error-http', 'flow-error-fetch-after-open-close', + 'mw-ui-unsubmitted-confirm', ) ) + $mobile, 'ext.flow.vendor.storer' = $flowResourceTemplate + array( diff --git a/i18n/en.json b/i18n/en.json index a24bd22..f379ffc 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -349,5 +349,6 @@ flow-preview-warning: You are seeing a preview. Submit the form to finish posting this, or click \{{int:flow-preview-return-edit-post}}\ to continue writing., flow-preview-return-edit-post : Keep editing, flow-anonymous: Anonymous, -flow-embedding-unsupported : Discussions cannot be embedded yet. +flow-embedding-unsupported : Discussions cannot be embedded yet., +mw-ui-unsubmitted-confirm: You have unsubmitted changes on this page. Are you sure you want to navigate away and lose your work? } diff --git a/i18n/qqq.json b/i18n/qqq.json index 54993a8..dd5473d 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -353,5 +353,6 @@ flow-preview-warning: Refers to {{msg-mw|Flow-preview-return-edit-post}} (Keep editing)., flow-preview-return-edit-post: Used as text for a button that hides previewed text and returns to the editing view, flow-anonymous: {{Identical|Anonymous}}, - flow-embedding-unsupported: Error message displayed if a user tries to transclude a Flow page. + flow-embedding-unsupported: Error message displayed if a user tries to transclude a Flow page., + mw-ui-unsubmitted-confirm: You have unsubmitted changes on this page. Are you sure you want to navigate away and lose your work? } diff --git a/modules/new/mw-ui.enhance.js b/modules/new/mw-ui.enhance.js index 37c0921..056aee9 100644 --- a/modules/new/mw-ui.enhance.js +++ b/modules/new/mw-ui.enhance.js @@ -413,4 +413,28 @@ .on( 'mouseleave.mw-ui-enhance blur.mw-ui-enhance click.mw-ui-enhance', '.flow-ui-tooltip-target', onMwUiTooltipBlur ); } ); + /* +Ask a user to confirm navigating away from a page when they have entered unsubmitted changes to a form. +*/ + var _oldOnBeforeUnload = window.onbeforeunload; + window.onbeforeunload = function () { + var uncommitted; + + $( 'input, textarea' ).filter( '.mw-ui-input:visible' ).each( function () { + if ( $.trim( this.value ) this.value !== this.defaultValue ) { + uncommitted = true; + return false; + } + } ); + + // Ask the user if they want to navigate away + if ( uncommitted ) { + return mw.msg( 'mw-ui-unsubmitted-confirm' ); + } + + // Run the old on beforeunload fn if it exists + if ( _oldOnBeforeUnload ) { + return _oldOnBeforeUnload(); + } + }; }( mw, jQuery ) ); -- To view, visit https://gerrit.wikimedia.org/r/148983 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I451437da738e57866b1013de3c659102da62a15d Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Flow Gerrit-Branch: master Gerrit-Owner: SG shah...@gmail.com Gerrit-Reviewer: Jdlrobson jrob...@wikimedia.org Gerrit-Reviewer: SG shah...@gmail.com Gerrit-Reviewer: Siebrand siebr...@kitano.nl Gerrit-Reviewer: jenkins-bot ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits