Skip to content

Commit

Permalink
Merge pull request #23 from Floskinner/jsdocs
Browse files Browse the repository at this point in the history
Updated docstrings
  • Loading branch information
Floskinner authored Mar 14, 2022
2 parents 875b448 + cf1af5e commit beba61c
Show file tree
Hide file tree
Showing 13 changed files with 99 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions jsdoc_conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
"database",
"handlers",
"routes",
"views"
"views",
"public/javascripts"
],
"exclude": [
"node_modules",
".vscode",
"public",
"docs"
],
"includePattern": ".+\\.js(doc|x)?$",
Expand Down
10 changes: 9 additions & 1 deletion public/javascripts/back-to-top-button.js
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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;
Expand Down
Empty file removed public/javascripts/gaming.js
Empty file.
9 changes: 9 additions & 0 deletions public/javascripts/hamburger-menu.js
Original file line number Diff line number Diff line change
@@ -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") {
Expand Down
10 changes: 9 additions & 1 deletion public/javascripts/info-modal.js
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
14 changes: 13 additions & 1 deletion public/javascripts/manage-games.js
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
17 changes: 16 additions & 1 deletion public/javascripts/new-games.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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) {
Expand Down Expand Up @@ -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();
Expand All @@ -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();

Expand Down
7 changes: 0 additions & 7 deletions public/javascripts/platforms.js

This file was deleted.

10 changes: 10 additions & 0 deletions public/javascripts/sidenav.js
Original file line number Diff line number Diff line change
@@ -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") {
Expand All @@ -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");
Expand Down
15 changes: 12 additions & 3 deletions public/javascripts/sign-in.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
/**
* @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];
}

$.ajax('/users/sign-in', {
method: 'POST',
data: data,
success: (data, textStatus, jqXHR) => {
window.location.replace("/gaming");
window.location.replace("/gaming");
},
error: (jqXHR, textStatus, errorThrown) => {
console.error('Wrong credetials');
Expand Down
19 changes: 18 additions & 1 deletion public/javascripts/userInteractions.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion views/platforms.pug
Original file line number Diff line number Diff line change
Expand Up @@ -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")

0 comments on commit beba61c

Please sign in to comment.