From 77ee40909f144afceb6c24ad2233f3bc83b638bd Mon Sep 17 00:00:00 2001 From: El RIDO Date: Mon, 5 Apr 2021 13:24:53 +0200 Subject: [PATCH] record defaults during initialization, fixes #682 --- js/privatebin.js | 15 +++++++++------ js/test/TopNav.js | 45 ++++++++++++++++++++++++++++++++++++++++++--- tpl/bootstrap.php | 2 +- tpl/page.php | 2 +- 4 files changed, 53 insertions(+), 11 deletions(-) diff --git a/js/privatebin.js b/js/privatebin.js index 9beb3d9..c18bdfe 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -3508,6 +3508,8 @@ jQuery.PrivateBin = (function($, RawDeflate) { let createButtonsDisplayed = false, viewButtonsDisplayed = false, + burnAfterReadingDefault = false, + openDiscussionDefault = false, $attach, $burnAfterReading, $burnAfterReadingOption, @@ -4152,11 +4154,10 @@ jQuery.PrivateBin = (function($, RawDeflate) { me.resetInput = function() { clearAttachmentInput(); - - $openDiscussion.prop('checked', false); - $burnAfterReading.prop('checked', false); - $openDiscussionOption.removeClass('buttondisabled'); - $burnAfterReadingOption.removeClass('buttondisabled'); + $burnAfterReading.prop('checked', burnAfterReadingDefault); + $openDiscussion.prop('checked', openDiscussionDefault); + if (openDiscussionDefault) $openDiscussionOption.removeClass('buttondisabled'); + if (burnAfterReadingDefault) $burnAfterReadingOption.removeClass('buttondisabled'); // TODO: reset expiration time }; @@ -4356,7 +4357,9 @@ jQuery.PrivateBin = (function($, RawDeflate) { changeBurnAfterReading(); changeOpenDiscussion(); - // get default value from template or fall back to set value + // get default values from template or fall back to set value + burnAfterReadingDefault = me.getBurnAfterReading(); + openDiscussionDefault = me.getOpenDiscussion(); pasteExpiration = Model.getExpirationDefault() || pasteExpiration; createButtonsDisplayed = false; diff --git a/js/test/TopNav.js b/js/test/TopNav.js index 314d5ce..2963964 100644 --- a/js/test/TopNav.js +++ b/js/test/TopNav.js @@ -363,7 +363,7 @@ describe('TopNav', function () { ); it( - 'reset inputs to defaults (options on)', + 'reset inputs to defaults (burnafterreading on)', function () { var results = []; $('body').html( @@ -380,10 +380,9 @@ describe('TopNav', function () { $.PrivateBin.TopNav.getBurnAfterReading() ); results.push( - $.PrivateBin.TopNav.getOpenDiscussion() + !$.PrivateBin.TopNav.getOpenDiscussion() ); $('#burnafterreading').removeAttr('checked'); - $('#opendiscussion').removeAttr('checked'); results.push( !$.PrivateBin.TopNav.getBurnAfterReading() ); @@ -394,6 +393,46 @@ describe('TopNav', function () { results.push( $.PrivateBin.TopNav.getBurnAfterReading() ); + results.push( + !$.PrivateBin.TopNav.getOpenDiscussion() + ); + cleanup(); + assert.ok(results.every(element => element)); + } + ); + + it( + 'reset inputs to defaults (opendiscussion on)', + function () { + var results = []; + $('body').html( + '' + ); + $.PrivateBin.TopNav.init(); + results.push( + !$.PrivateBin.TopNav.getBurnAfterReading() + ); + results.push( + $.PrivateBin.TopNav.getOpenDiscussion() + ); + $('#opendiscussion').removeAttr('checked'); + $('#burnafterreading').prop('checked', true); + results.push( + $.PrivateBin.TopNav.getBurnAfterReading() + ); + results.push( + !$.PrivateBin.TopNav.getOpenDiscussion() + ); + $.PrivateBin.TopNav.resetInput(); + results.push( + !$.PrivateBin.TopNav.getBurnAfterReading() + ); results.push( $.PrivateBin.TopNav.getOpenDiscussion() ); diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php index 7fed83f..81bc355 100644 --- a/tpl/bootstrap.php +++ b/tpl/bootstrap.php @@ -72,7 +72,7 @@ endif; ?> - + diff --git a/tpl/page.php b/tpl/page.php index 8361a53..c139f9c 100644 --- a/tpl/page.php +++ b/tpl/page.php @@ -50,7 +50,7 @@ endif; ?> - +