-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
43301 Notification of unsaved changes (#713)
* 43301 notification of unsaved changes * 43301 refactor code * 43301 update unit test * 43301 update unit test * 43301 notification of unsaved changes * 43301 add change detection for sortable list items * 43301 format code * 43301 update notification of unsaved changes when using the admin-bar * Fix typo --------- Co-authored-by: Frederic Alpers <88546396+fredericalpers@users.noreply.github.com> Co-authored-by: andernath <chibineko@gmail.com>
- Loading branch information
1 parent
a141f59
commit 105853b
Showing
10 changed files
with
129 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
var onOffice = typeof onOffice_loc_settings !== 'undefined' ? onOffice_loc_settings : onOffice_unsaved_changes_message; | ||
|
||
jQuery(document).ready(function($){ | ||
let checkUnsavedChanges = false; | ||
let checkNavigationTriggered = false; | ||
|
||
$('#poststuff :input, form[action="options.php"] :input').on("change", function() { | ||
checkUnsavedChanges = true; | ||
}); | ||
|
||
$('#poststuff span, #poststuff li').on("click", function() { | ||
checkUnsavedChanges = true; | ||
}); | ||
|
||
$('.filter-fields-list').sortable({ | ||
update: function() { | ||
checkUnsavedChanges = true; | ||
} | ||
}); | ||
|
||
function generateUnsavedChangesMessage(href) { | ||
return $(` | ||
<div class='notice notice-error is-dismissible notice-unsaved-changes-message'> | ||
<p>${onOffice.view_unsaved_changes_message} | ||
<a id='leaveWithoutSaving' href='${href}'>${onOffice.view_leave_without_saving_text}</a></p> | ||
<button type='button' class='notice-dismiss notice-save-view'></button> | ||
</div> | ||
`); | ||
} | ||
|
||
function handleUnsavedChanges(e, href) { | ||
if (checkUnsavedChanges) { | ||
$('.notice-unsaved-changes-message').remove(); | ||
e.preventDefault(); | ||
let appendUnsavedChangesHtml = generateUnsavedChangesMessage(href); | ||
appendUnsavedChangesHtml.insertAfter('.wp-header-end'); | ||
$('html, body').animate({ scrollTop: 0 }, 1000); | ||
|
||
return false; | ||
} | ||
} | ||
|
||
$('a[href]').on('click', function(e) { | ||
if (!$(this).closest('#adminmenu, #wpadminbar').length) { | ||
checkNavigationTriggered = true; | ||
} | ||
}); | ||
|
||
$('#adminmenu a[href], #wpadminbar a[href]').on('click', function(e) { | ||
if ($(this).attr('target') === '_blank') { | ||
return; | ||
} | ||
handleUnsavedChanges(e, $(this).attr('href')); | ||
}); | ||
|
||
window.onbeforeunload = function() { | ||
if (checkUnsavedChanges && !checkNavigationTriggered) { | ||
return onOffice.view_unsaved_changes_message; | ||
} | ||
}; | ||
|
||
$('#onoffice-ajax').submit(function () { | ||
checkUnsavedChanges = false; | ||
}); | ||
|
||
$(document).on('click', '#leaveWithoutSaving, #submit', function(e) { | ||
checkUnsavedChanges = false; | ||
}); | ||
|
||
$(document).on('click', '.notice-save-view.notice-dismiss', function () { | ||
$(this).parent().remove(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters