diff --git a/README.md b/README.md index 39d91f12..52e30b58 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ Install the dependencies with npm: npm install -g npm@latest # Install only production dependencies -npm install --production +npm install # Install also developer dependencies npm install --include=dev diff --git a/jsdoc_conf.json b/jsdoc_conf.json index 8f9c7550..0aadec10 100644 --- a/jsdoc_conf.json +++ b/jsdoc_conf.json @@ -8,12 +8,12 @@ "database", "handlers", "routes", - "views" + "views", + "public/javascripts" ], "exclude": [ "node_modules", ".vscode", - "public", "docs" ], "includePattern": ".+\\.js(doc|x)?$", diff --git a/public/javascripts/back-to-top-button.js b/public/javascripts/back-to-top-button.js index 55f8b309..916dc94f 100644 --- a/public/javascripts/back-to-top-button.js +++ b/public/javascripts/back-to-top-button.js @@ -1,6 +1,12 @@ +/** + * @module Client_Index + */ var btn = document.getElementById("btt-btn"); window.onscroll = function() { detectScroll() }; +/** + * Detect scrolling to make back-to-top button visible + */ function detectScroll() { if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) { btn.style.display = "block"; @@ -9,7 +15,9 @@ function detectScroll() { } } -// When the user clicks on the button, scroll to the top of the document +/** + * Scroll to the top of the site + */ function backToTop() { document.body.scrollTop = 0; document.documentElement.scrollTop = 0; diff --git a/public/javascripts/gaming.js b/public/javascripts/gaming.js deleted file mode 100644 index e69de29b..00000000 diff --git a/public/javascripts/hamburger-menu.js b/public/javascripts/hamburger-menu.js index 43e8767b..6b77c8f9 100644 --- a/public/javascripts/hamburger-menu.js +++ b/public/javascripts/hamburger-menu.js @@ -1,3 +1,12 @@ +/** + * @module Client_Nav + */ + +/** + * Make the links from the ham + * @param {object} form + * @returns {Boolean} False to not reload the page + */ function toggleHamburgerMenu() { var x = document.getElementById("hamburger-links"); if (x.style.display === "block") { diff --git a/public/javascripts/info-modal.js b/public/javascripts/info-modal.js index c0fcebe7..bccc95bc 100644 --- a/public/javascripts/info-modal.js +++ b/public/javascripts/info-modal.js @@ -1,8 +1,16 @@ +/** + * @module Client_InfoModal + */ const modal_el = document.getElementById('info-modal'); const modal_obj = new bootstrap.Modal(modal_el); -function show_modal(header, msg){ +/** + * Show the info_modal with the given params + * @param {string} header HTML-Text that will be inserted in the header + * @param {string} msg HTML-Text that will be inserted in the body + */ +function show_modal(header, msg) { document.getElementById("info-msg-header").innerHTML = header; document.getElementById("info-msg").innerHTML = msg; modal_obj.show(); diff --git a/public/javascripts/manage-games.js b/public/javascripts/manage-games.js index 8f1def49..cc4db1ca 100644 --- a/public/javascripts/manage-games.js +++ b/public/javascripts/manage-games.js @@ -1,3 +1,7 @@ +/** + * @module Client_ManageGames + */ + const checkboxes = document.querySelectorAll('input[type=checkbox]'); const submit_btn = document.querySelector('input[type=submit]'); const search = document.getElementById("searching"); @@ -74,6 +78,11 @@ function get_list_from_games(games) { return list; } +/** + * Do the delete Post request to the server + * @param {Button} btn The Button that was pressed + * @returns {Boolean} False to not reload the page + */ function delete_game(btn) { if (confirm("Wirklich das Spiel global loeschen?!") != true) { @@ -108,7 +117,10 @@ function delete_game(btn) { return false; } - +/** + * Toogle the Checkbox if you click on the image of the game + * @param {Button} btn Button to toggle + */ function toggle_game(btn) { const game_id = btn.getAttribute("data-gameId"); const checkbox = document.getElementById("checkbox" + game_id); diff --git a/public/javascripts/new-games.js b/public/javascripts/new-games.js index bf9b4497..50997c32 100644 --- a/public/javascripts/new-games.js +++ b/public/javascripts/new-games.js @@ -1,3 +1,7 @@ +/** + * @module Client_NewGame + */ + const form = document.querySelector("form"); const submit_btn = document.querySelector('input[type=submit]'); const image = document.getElementById('cropper-image'); @@ -14,6 +18,10 @@ gameName_txt.addEventListener("input", check_values); /* ####### Functions ####### */ +/** + * Binding for the input search. + * Disable or enable the submit btn depending on check_game_name() + */ function check_values() { const valid = check_game_name(); if (valid) { @@ -44,6 +52,9 @@ function check_game_name() { return valid; } +/** + * Changes the image in the cropper field when a new image is uploaded + */ function changeCover() { const file = document.querySelector('input[type=file]').files[0]; const reader = new FileReader(); @@ -58,7 +69,11 @@ function changeCover() { } } - +/** + * Creates a new game on the DB if possible + * @param form + * @returns (boolean|Redirect) False if some error or Redirect to /gaming + */ function create_game(form) { const gameName = gameName_txt.value.trim(); diff --git a/public/javascripts/platforms.js b/public/javascripts/platforms.js deleted file mode 100644 index 32ded30a..00000000 --- a/public/javascripts/platforms.js +++ /dev/null @@ -1,7 +0,0 @@ -function openNav() { - document.getElementById("side-nav-gaming").style.width = "250px"; -} - -function closeNav() { - document.getElementById("side-nav-gaming").style.width = "0"; -} \ No newline at end of file diff --git a/public/javascripts/sidenav.js b/public/javascripts/sidenav.js index e05a765a..9ab2a266 100644 --- a/public/javascripts/sidenav.js +++ b/public/javascripts/sidenav.js @@ -1,5 +1,12 @@ +/** + * @module Client_SideNav + */ + window.onload = (event) => { document.getElementById("sidenav").style.width = "0px"; }; +/** + * Open the sidenavigation and change the icon of the button + */ function openSidenav() { var sidenav = document.getElementById("sidenav"); if (sidenav.style.width == "0px") { @@ -12,6 +19,9 @@ function openSidenav() { } } +/** + * Close the sidenavigation and change the icon of the button + */ function closeSidenav() { document.getElementById("sidenav").style.width = "0px"; btn = document.getElementById("btn-sidenav"); diff --git a/public/javascripts/sign-in.js b/public/javascripts/sign-in.js index 999644eb..9b74124c 100644 --- a/public/javascripts/sign-in.js +++ b/public/javascripts/sign-in.js @@ -1,8 +1,17 @@ +/** + * @module Client_SignIn + */ + +/** + * Do the post request to sign in + * @param {object} form + * @returns {Boolean} False to not reload the page + */ function sign_in(form) { const formData = new FormData(form); - let data = {}; + let data = {}; - for(var pair of formData.entries()) { + for (var pair of formData.entries()) { data[pair[0]] = pair[1]; } @@ -10,7 +19,7 @@ function sign_in(form) { method: 'POST', data: data, success: (data, textStatus, jqXHR) => { - window.location.replace("/gaming"); + window.location.replace("/gaming"); }, error: (jqXHR, textStatus, errorThrown) => { console.error('Wrong credetials'); diff --git a/public/javascripts/userInteractions.js b/public/javascripts/userInteractions.js index bdb14bd8..89e32a90 100644 --- a/public/javascripts/userInteractions.js +++ b/public/javascripts/userInteractions.js @@ -1,5 +1,12 @@ -const checkboxes = document.querySelectorAll('.form-check input[type=checkbox]'); +/** + * @module Client_SignUp + */ +/** + * @constant checkboxes + * @type {array} + */ +const checkboxes = document.querySelectorAll('.form-check input[type=checkbox]'); checkboxes.forEach(checkbox => { checkbox.addEventListener('change', function() { if (this.checked) { @@ -19,6 +26,11 @@ checkboxes.forEach(checkbox => { }) }); +/** + * Post Request to sign up a user (uses validateRegister) + * @param {object} form element + * @returns {boolean} + */ function sign_up(form) { const formData = new FormData(form); let resultMessage = validateRegister(formData); @@ -52,6 +64,11 @@ function sign_up(form) { return false; } +/** + * Validates formData + * @param {object} formData data that contain all form data + * @returns {string} msg + */ function validateRegister(formData) { // username min length 4 if (!formData.get("username") || formData.get("username").length < 4) { diff --git a/views/platforms.pug b/views/platforms.pug index 8b625722..9ffa9e87 100644 --- a/views/platforms.pug +++ b/views/platforms.pug @@ -27,5 +27,4 @@ block content a.icon(href="/gaming/manage") img(src="/images/platforms/manage.png", alt="Manage games", srcset="") p Spiele verwalten - script(src="/javascripts/platforms.js") script(src="/javascripts/sidenav.js") \ No newline at end of file