Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Pado
Behira Younes
Commits
eeaa8def
Commit
eeaa8def
authored
Oct 25, 2020
by
Ratnadeep Rajendra Kharade
Browse files
added comments for improved readability
parent
4ddfbc5f
Changes
1
Hide whitespace changes
Inline
Side-by-side
public/index.js
View file @
eeaa8def
// Object which stores all the user selected/entered values
let
inputObj
=
{
textChoice
:
'
manual
'
,
text
:
''
,
textLength
:
''
,
readerLevel
:
''
,
readerCategory
:
''
textChoice
:
'
manual
'
,
// choice of text entry initially set as manual. Can have values manual, calculated
text
:
''
,
// User entered text in case of manual
textLength
:
''
,
// number of characters in text. Either from user enetered text or user entered number
readerLevel
:
''
,
// Value of reader level selected from dropdown
readerCategory
:
''
// Value of reader category selected from dropdown
};
// function handleTextRadioClick: responsible for showing or hiding text input / text length input based on selected option
function
handleTextRadioClick
()
{
let
textChoice
=
document
.
querySelector
(
'
input[name="text-input-option"]:checked
'
).
value
;
console
.
log
(
textChoice
);
inputObj
.
textChoice
=
textChoice
;
toggleElement
(
'
character-calculation-wrapper
'
);
toggleElement
(
'
manual-character-input
'
);
}
// function toggleElement: hides/shows the html element based on current visibility.
// accepts value of id attribute of element as parameter
function
toggleElement
(
id
)
{
let
x
=
document
.
getElementById
(
id
);
if
(
x
.
style
.
display
===
"
none
"
)
{
x
.
style
.
display
=
"
block
"
;
let
element
=
document
.
getElementById
(
id
);
if
(
element
.
style
.
display
===
"
none
"
)
{
element
.
style
.
display
=
"
block
"
;
}
else
{
x
.
style
.
display
=
"
none
"
;
element
.
style
.
display
=
"
none
"
;
}
}
// function handleTextAreaChange: captures the changes as user enters the text and gets the length
// and sets number of characters to property textLength on inputObj
function
handleTextAreaChange
()
{
let
value
=
document
.
getElementById
(
"
manual-text-entry
"
).
value
;
value
=
value
.
trim
();
...
...
@@ -32,23 +40,23 @@ function handleTextAreaChange() {
document
.
getElementById
(
"
calculatedTextCharacters
"
).
setAttribute
(
'
value
'
,
characters
)
}
// function handleCharacterInputChange: captures changes in number of characters input field
// and sets number of characters to property textLength on inputObj
function
handleCharacterInputChange
()
{
let
value
=
document
.
getElementById
(
"
inputTextCharacters
"
).
value
;
setCharacterLength
(
value
);
}
// function setCharacterLength: sets number of characters to property textLength on inputObj
function
setCharacterLength
(
characters
)
{
inputObj
.
textLength
=
characters
;
console
.
log
(
'
Character length:
'
+
inputObj
.
textLength
);
inputObj
.
textLength
=
parseInt
(
characters
);
}
function
calculateReadingTime
()
{
if
(
isFormValid
())
{
let
x
=
document
.
getElementById
(
'
calculate-time-element
'
);
x
.
style
.
display
=
"
block
"
;
}
}
// function isFormValid: checks for mandatory input fields and validates te form
// returns true if all values are filled else returns false
// also shows error messages for respective inputs fields
function
isFormValid
()
{
let
invalidFields
=
0
;
if
(
inputObj
.
textChoice
===
'
manual
'
&&
inputObj
.
text
===
''
)
{
...
...
@@ -80,20 +88,47 @@ function isFormValid() {
}
return
invalidFields
<
1
}
// function showFeedbackForm: displays feedback form when calculation is done
function
showFeedbackForm
()
{
let
x
=
document
.
getElementById
(
'
feedback-form
'
);
x
.
style
.
display
=
"
block
"
;
let
element
=
document
.
getElementById
(
'
feedback-form
'
);
element
.
style
.
display
=
"
block
"
;
}
// function readerLevelChangeEvent: listens for change in reader level dropdown
// and sets selected value to property readerLevel on inputObj
function
readerLevelChangeEvent
(
event
)
{
console
.
log
(
event
.
target
.
value
)
inputObj
.
readerLevel
=
event
.
target
.
value
;
}
// function readerCategoryChangeEvent: listens for change in reader category dropdown
// and sets selected value to property readerCategory on inputObj
function
readerCategoryChangeEvent
(
event
)
{
console
.
log
(
event
.
target
.
value
)
inputObj
.
readerCategory
=
event
.
target
.
value
;
}
// function calculateReadingTime: This function is responsible for calculating reading time
// reading time can be calculated if all inputs are valid
function
calculateReadingTime
()
{
if
(
isFormValid
())
{
//variable x which holds final reading time in minutes
let
x
=
0
;
console
.
log
(
inputObj
);
// TODO: logic or algorithm for calulating reading time goes here
// inputObj.textLength has number of characters (number data type)
// inputObj.readerLevel has level of reader (string data type)
// inputObj.readerCategory has category of reader (string data type)
// display html element which shows time
let
element
=
document
.
getElementById
(
'
calculate-time-element
'
);
element
.
style
.
display
=
"
block
"
;
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment