From ddd657ddf26ba8d320496520d99e84e856b7af92 Mon Sep 17 00:00:00 2001 From: LukBukkit Date: Sun, 20 Oct 2019 17:44:59 +0200 Subject: [PATCH 1/3] Enabling and disabling the commit button to prevent empty commits Signed-off-by: LukBukkit --- public/js/index.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/public/js/index.js b/public/js/index.js index a903b219e712..b0bb143123c6 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -1572,7 +1572,21 @@ 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'); + + // Disabling the button at the start + $commitButton.prop('disabled', true); + $editForm.on('dirty.areYouSure', function() { + $commitButton.prop('disabled', false); + }); + $editForm.on('clean.areYouSure', function() { + $commitButton.prop('disabled', true); + }); + + $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({ From 1b990c3a42fda26df1c213efd2b2b2605a9b468f Mon Sep 17 00:00:00 2001 From: LukBukkit Date: Sun, 20 Oct 2019 22:36:09 +0200 Subject: [PATCH 2/3] The button won't get enabled if you change the commit message Signed-off-by: LukBukkit --- public/js/index.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/public/js/index.js b/public/js/index.js index b0bb143123c6..572615fe2ef9 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -1576,14 +1576,20 @@ function initEditor() { // 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); - $editForm.on('dirty.areYouSure', function() { - $commitButton.prop('disabled', false); - }); - $editForm.on('clean.areYouSure', function() { - $commitButton.prop('disabled', true); + + // Registering a custom listener for the file path and the file content + $editForm.areYouSure({ + slient: 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) { From e1a8d2f2169cd53beb9410133a627576c2d96705 Mon Sep 17 00:00:00 2001 From: LukBukkit Date: Tue, 22 Oct 2019 22:30:18 +0200 Subject: [PATCH 3/3] Fixes a spelling mistake for 'silent' Signed-off-by: LukBukkit --- public/js/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/js/index.js b/public/js/index.js index 572615fe2ef9..6390a6186c41 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -1583,7 +1583,7 @@ function initEditor() { // Registering a custom listener for the file path and the file content $editForm.areYouSure({ - slient: true, + silent: true, dirtyClass: dirtyFileClass, fieldSelector: ':input:not(.commit-form-wrapper :input)', change: function () {