From daae0d0dca24a73f0a3ecd5f27b921d4ce534f01 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Sun, 28 Jun 2020 11:25:09 +0200 Subject: [PATCH] initial memory boilerplate, move sidebar toggle into it's init, test it behaves as it should --- js/privatebin.js | 61 +++++++++++++++++++++++++++++++++++++++++------ js/test/Memory.js | 29 ++++++++++++++++++++++ tpl/bootstrap.php | 2 +- tpl/page.php | 2 +- 4 files changed, 85 insertions(+), 9 deletions(-) create mode 100644 js/test/Memory.js diff --git a/js/privatebin.js b/js/privatebin.js index aa869bc5..d3977cf1 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -4356,6 +4356,58 @@ jQuery.PrivateBin = (function($, RawDeflate) { return me; })(window, document); + /** + * (view) Handles the memory, storing paste URLs in the browser + * + * @name Memory + * @class + */ + const Memory = (function () { + const me = {}; + + /** + * adds a paste URL to the memory + * + * @name Memory.add + * @function + * @param {string} pasteUrl + * @return {bool} + */ + me.add = function(pasteUrl) + { + return true; + }; + + /** + * refresh the displayed list from memory + * + * @name Memory.refreshList + * @function + */ + me.refreshList = function() + { + }; + + /** + * initiate + * + * attaches click event to toggle memory sidepanel + * + * @name Memory.init + * @function + */ + me.init = function() + { + $("#menu-toggle").on('click', function(e) { + e.preventDefault(); + $("main").toggleClass("toggled"); + $("#menu-toggle .glyphicon").toggleClass("glyphicon glyphicon-menu-down glyphicon glyphicon-menu-up") + }); + }; + + return me; + })(); + /** * Responsible for AJAX requests, transparently handles encryption… * @@ -5361,13 +5413,6 @@ jQuery.PrivateBin = (function($, RawDeflate) { }); }); - // attach memory sidebar toggle - $("#menu-toggle").on('click', function(e) { - e.preventDefault(); - $("#menu-toggle .glyphicon").toggleClass("glyphicon glyphicon-menu-down glyphicon glyphicon-menu-up") - $("main").toggleClass("toggled"); - }); - // initialize other modules/"classes" Alert.init(); Model.init(); @@ -5379,6 +5424,7 @@ jQuery.PrivateBin = (function($, RawDeflate) { Prompt.init(); TopNav.init(); UiHelper.init(); + Memory.init(); // check for legacy browsers before going any further if (!Legacy.Check.getInit()) { @@ -5432,6 +5478,7 @@ jQuery.PrivateBin = (function($, RawDeflate) { AttachmentViewer: AttachmentViewer, DiscussionViewer: DiscussionViewer, TopNav: TopNav, + Memory: Memory, ServerInteraction: ServerInteraction, PasteEncrypter: PasteEncrypter, PasteDecrypter: PasteDecrypter, diff --git a/js/test/Memory.js b/js/test/Memory.js new file mode 100644 index 00000000..7a9d036f --- /dev/null +++ b/js/test/Memory.js @@ -0,0 +1,29 @@ +'use strict'; +require('../common'); + +describe('Memory', function () { + describe('init', function () { + it( + 'enables toggling the memory sidebar', + function() { + $('body').html( + '
' + + '
' + ); + assert.ok(!$('main').hasClass('toggled')); + + $('#menu-toggle').click(); + assert.ok(!$('main').hasClass('toggled')); + + $.PrivateBin.Memory.init(); + assert.ok(!$('main').hasClass('toggled')); + + $('#menu-toggle').click(); + assert.ok($('main').hasClass('toggled')); + + $('#menu-toggle').click(); + assert.ok(!$('main').hasClass('toggled')); + } + ); + }); +}); diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php index 0c1cb558..976787f4 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 e7b73196..f6388d09 100644 --- a/tpl/page.php +++ b/tpl/page.php @@ -50,7 +50,7 @@ endif; ?> - +