Skip to content

Commit 4f692ff

Browse files
committed
Refactoring
1 parent f66597d commit 4f692ff

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

scripts/hashTagParser.js

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,34 @@
1-
/**
2-
* Parses href hash
3-
*
4-
* @param urlHash
5-
* @returns {*[]}
6-
*/
71
const namespaces = [
82
'display_for_',
93
];
104

5+
/**
6+
* Change link's parent DOM element visibility to hidden
7+
*
8+
* @param el
9+
*/
1110
function hideLink(el) {
1211
if (el.nodeType === 1) {
1312
el.parentNode.hidden = true;
1413
}
1514
}
1615

16+
/**
17+
* Change link's parent DOM element visibility to visible
18+
*
19+
* @param el
20+
*/
1721
function showLink(el) {
1822
if (el.nodeType === 1) {
1923
el.parentNode.hidden = false;
2024
}
2125
}
2226

27+
/**
28+
* Removes link from DEM tree
29+
*
30+
* @param el
31+
*/
2332
function removeLink(el) {
2433
if (el.nodeType === 1 && el.parentNode !== null) {
2534
el.parentNode.removeChild(el);
@@ -41,7 +50,6 @@ function parseHashTag(href) {
4150
const hashTags = href.split('#').slice(1);
4251

4352
if (hashTags) {
44-
// @TODO: optimize ( now it is going to be O(n^2) :/ )
4553
namespaces.forEach((ns) => {
4654
hashTags.forEach((tag) => {
4755
const value = tag.split(ns);
@@ -60,8 +68,9 @@ function parseHashTag(href) {
6068
/**
6169
* Applies parsed hash tags based on conditions
6270
*
63-
* @param aElement
64-
* @param hashTags
71+
* @param aElement DOM element
72+
* @param {object} hashTags parsed hash tags
73+
* @param {function} callbackFn function executing logic based on parsed hash tags
6574
*/
6675
function applyConditions(aElement, hashTags, callbackFn) {
6776
hashTags.forEach((hashTag) => {
@@ -73,7 +82,8 @@ function applyConditions(aElement, hashTags, callbackFn) {
7382
/**
7483
* Parses nav fragment; disable visible elements based on hash tags
7584
*
76-
* @param navSections
85+
* @param domEl DOM element
86+
* @param {function} callbackFn function executing logic based on parsed hash tags
7787
* @returns {*}
7888
*/
7989
function parseUrlHashTags(domEl = 'header', callbackFn = null) {

0 commit comments

Comments
 (0)