aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas <LukBukkit@users.noreply.github.com>2019-10-23 02:29:33 +0200
committerLunny Xiao <xiaolunwen@gmail.com>2019-10-23 08:29:33 +0800
commit3fe964656498e4a9d10b0d995a59b3b88afcbe9c (patch)
tree37e6c17a7fc191234fcf0d8978e12e872e6700be
parentfe41f71ba15437fad7c7e56a48678c57a995f1fa (diff)
downloadgitea-3fe964656498e4a9d10b0d995a59b3b88afcbe9c.tar.gz
gitea-3fe964656498e4a9d10b0d995a59b3b88afcbe9c.zip
Enabling and disabling the commit button to prevent empty commits (web editor) (#8590)
* Enabling and disabling the commit button to prevent empty commits Signed-off-by: LukBukkit <luk.bukkit@gmail.com> * The button won't get enabled if you change the commit message Signed-off-by: LukBukkit <luk.bukkit@gmail.com> * Fixes a spelling mistake for 'silent' Signed-off-by: LukBukkit <luk.bukkit@gmail.com>
-rw-r--r--public/js/index.js22
1 files changed, 21 insertions, 1 deletions
diff --git a/public/js/index.js b/public/js/index.js
index e9a4bcaac1..90819677a5 100644
--- a/public/js/index.js
+++ b/public/js/index.js
@@ -1572,7 +1572,27 @@ function initEditor() {
});
}).trigger('keyup');
- $('#commit-button').click(function (event) {
+ // Using events from https://github.com/codedance/jquery.AreYouSure#advanced-usage
+ // to enable or disable the commit button
+ const $commitButton = $('#commit-button');
+ const $editForm = $('.ui.edit.form');
+ const dirtyFileClass = 'dirty-file';
+
+ // Disabling the button at the start
+ $commitButton.prop('disabled', true);
+
+ // Registering a custom listener for the file path and the file content
+ $editForm.areYouSure({
+ silent: true,
+ dirtyClass: dirtyFileClass,
+ fieldSelector: ':input:not(.commit-form-wrapper :input)',
+ change: function () {
+ const dirty = $(this).hasClass(dirtyFileClass);
+ $commitButton.prop('disabled', !dirty);
+ }
+ });
+
+ $commitButton.click(function (event) {
// A modal which asks if an empty file should be committed
if ($editArea.val().length === 0) {
$('#edit-empty-content-modal').modal({