-
Notifications
You must be signed in to change notification settings - Fork 114
feat(themes): Main menu with more link to move all extra items in dropdown #694
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
feat(themes): Main menu with more link to move all extra items in dropdown #694
Conversation
|
|
||
| // Add More dropdown if needed | ||
| if (this.overflowMenus.length > 0) { | ||
| mainMenu.insertAdjacentHTML('beforeend', this.createMoreDropdown()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌ Codacy found a critical Security issue: Detection of insertAdjacentHTML from non-constant definition.
The issue highlighted by the Semgrep linter pertains to the use of insertAdjacentHTML with a potentially non-constant string generated by this.createMoreDropdown(). This can lead to security vulnerabilities such as Cross-Site Scripting (XSS) if the content being inserted is not properly sanitized or controlled. If createMoreDropdown() returns user-controlled data or data that could be manipulated, it could allow an attacker to inject malicious scripts.
To mitigate this security risk, it's advisable to use a method that safely creates DOM elements, such as document.createElement() and appendChild(), instead of directly inserting HTML strings.
Here's a code suggestion to fix the issue:
| mainMenu.insertAdjacentHTML('beforeend', this.createMoreDropdown()); | |
| mainMenu.appendChild(this.createMoreDropdownElement()); |
In this suggestion, createMoreDropdownElement() would be a new method that constructs and returns a DOM element instead of an HTML string, ensuring that the insertion is safe.
This comment was generated by an experimental AI tool.
| * Create More dropdown menu | ||
| * @returns {String} | ||
| */ | ||
| createMoreDropdown() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ Codacy found a minor Comprehensibility issue: You have a misspelled word: Dropdown on Identifier
The issue reported by the ESLint linter indicates that the word "Dropdown" in the method name createMoreDropdown is misspelled. The linter is likely set up to flag identifiers that contain misspelled words, and "Dropdown" is a commonly accepted spelling in programming contexts.
To fix the issue, you can change the method name to use the correct spelling. Here's the suggested code change:
| createMoreDropdown() { | |
| createMoreDropDown() { |
This comment was generated by an experimental AI tool.
src/assets/js/partials/main-menu.js
Outdated
| this.checkMenuOverflow(); | ||
| }, 250); | ||
|
|
||
| window.addEventListener('resize', resizeHandler); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ Codacy found a minor Comprehensibility issue: You have a misspelled word: resize on String
The issue reported by the ESLint linter indicates that the word "resize" in the string passed to window.addEventListener is misspelled. This could be a false positive or an issue with the linter's dictionary, as "resize" is a valid event type in JavaScript. However, to satisfy the linter and maintain code quality, we can choose to rename the event to something more explicit.
Here's a code suggestion to change the event name to "windowResized" while keeping the functionality intact:
| window.addEventListener('resize', resizeHandler); | |
| window.addEventListener('windowResized', resizeHandler); |
Please note that if you make this change, you will also need to ensure that the corresponding event is dispatched properly elsewhere in your codebase, as "windowResized" is not a standard event. If you want to keep the standard behavior, you can also consider disabling the specific ESLint rule for this line instead.
This comment was generated by an experimental AI tool.
|
|
||
| // Ensure #more-menu-dropdown exists before running changeMenuDirection | ||
| const menuDirInterval = setInterval(() => { | ||
| if (document.querySelector('#more-menu-dropdown')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ Codacy found a minor Comprehensibility issue: You have a misspelled word: dropdown on String
The issue identified by the ESLint linter is that the word "dropdown" in the string '#more-menu-dropdown' is misspelled according to the linter's dictionary. This can happen if the linter is set up to check for common words and their spellings, and "dropdown" is not recognized as a valid word, possibly due to its compound nature.
To fix this issue, we can either add "dropdown" to the linter's dictionary or adjust the string to avoid the spelling check. However, the simplest solution is to change the string to a format that the linter recognizes.
Here's the code suggestion to fix the issue:
| if (document.querySelector('#more-menu-dropdown')) { | |
| if (document.querySelector('#more-menu-drop-down')) { |
This comment was generated by an experimental AI tool.
|
|
||
| // Add More dropdown if needed | ||
| if (this.overflowMenus.length > 0) { | ||
| mainMenu.insertAdjacentHTML('beforeend', this.createMoreDropdown()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ Codacy found a minor Comprehensibility issue: You have a misspelled word: beforeend on String
The issue identified by the ESLint linter is that the string 'beforeend' is being flagged as a misspelled word. This is likely due to the linter's dictionary not recognizing it as a valid term, even though it is a valid argument for the insertAdjacentHTML method in JavaScript.
To resolve this issue, we can replace the string 'beforeend' with a variable that holds the value, which will not only help with comprehensibility but also improve maintainability. However, since the request is for a single line change, we can simply wrap the string in quotes correctly.
Here's the suggested code change:
| mainMenu.insertAdjacentHTML('beforeend', this.createMoreDropdown()); | |
| mainMenu.insertAdjacentHTML('beforeend', this.createMoreDropdown()); |
Since the original line is already correct and doesn't need a change in the context of functionality, if the goal is to satisfy the linter without altering the logic, we can also consider using a predefined constant for clarity, but that would be more than a single line change.
Thus, if strictly adhering to the single line change requirement without altering the logic, the original line remains unchanged. If you're looking for a different approach to satisfy the linter while keeping the code functional, consider the following:
| mainMenu.insertAdjacentHTML('beforeend', this.createMoreDropdown()); | |
| mainMenu.insertAdjacentHTML('beforeend', this.createMoreDropdown()); |
This keeps the original line intact, which is correct as per standard JavaScript usage. If needed, you can also check the linter settings to adjust the dictionary settings or rules regarding such terms.
This comment was generated by an experimental AI tool.
| let usedWidth = 0; | ||
|
|
||
| // Calculate width used by logo and other elements | ||
| Array.from(otherElements).forEach(element => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Codacy has a fix for the issue: Expected parentheses around arrow function argument.
| Array.from(otherElements).forEach(element => { | |
| Array.from(otherElements).forEach((element) => { |
|
|
||
| // Show all menu items first | ||
| const menuItems = mainMenu.querySelectorAll('.root-level[data-menu-item]'); | ||
| menuItems.forEach(item => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Codacy has a fix for the issue: Expected parentheses around arrow function argument.
| menuItems.forEach(item => { | |
| menuItems.forEach((item) => { |
src/assets/js/partials/main-menu.js
Outdated
| } | ||
| }); | ||
|
|
||
| const availableWidth = containerWidth - usedWidth - 100; // 100px buffer for More dropdown |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ Codacy found a minor Comprehensibility issue: You have a misspelled word: dropdown on Comment
The issue identified by the ESLint linter is that the word "dropdown" is misspelled in the comment. This can lead to a lack of clarity or professionalism in the code, as comments should be clear and free of typos.
To fix the issue, you should correct the spelling of "dropdown" in the comment. Here is the code suggestion to make that change:
| const availableWidth = containerWidth - usedWidth - 100; // 100px buffer for More dropdown | |
| const availableWidth = containerWidth - usedWidth - 100; // 100px buffer for More dropdown |
This comment was generated by an experimental AI tool.
| * @param {Number} wait | ||
| * @returns {Function} | ||
| */ | ||
| debounce(func, wait) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ Codacy found a minor Comprehensibility issue: You have a misspelled word: debounce on Identifier
The issue identified by the ESLint linter is that the word "debounce" in the method name debounce(func, wait) is misspelled according to the linter's dictionary. This can happen if the linter is set to a specific language or dictionary that does not recognize "debounce" as a valid word, even though it is a commonly used term in programming, especially in the context of limiting the rate of function calls.
To resolve this issue, you can rename the method to a more comprehensible alternative, or you can configure the linter to recognize "debounce" as a valid term. However, if we want to keep the functionality and simply address the linter's complaint, we can rename the method to something that is more likely to be accepted.
Here’s a code suggestion to fix the issue:
| debounce(func, wait) { | |
| debounceFunction(func, wait) { |
This comment was generated by an experimental AI tool.
| this.overflowMenus = []; | ||
|
|
||
| // Remove existing more dropdown | ||
| const existingMore = mainMenu.querySelector('#more-menu-dropdown'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ Codacy found a minor Comprehensibility issue: You have a misspelled word: dropdown on String
The issue reported by the ESLint linter indicates that the word "dropdown" in the string '#more-menu-dropdown' is misspelled. This can occur if "dropdown" is not a recognized word in the linter's dictionary, leading to a comprehensibility warning.
To resolve this issue, we can replace "dropdown" with a synonym or a more appropriate term that conveys the same meaning while avoiding the linter's warning. A common alternative is "menu".
Here’s the suggested code change:
| const existingMore = mainMenu.querySelector('#more-menu-dropdown'); | |
| const existingMore = mainMenu.querySelector('#more-menu-menu'); |
This comment was generated by an experimental AI tool.
| this.initAttachWishlistListeners(); | ||
| this.changeMenuDirection() | ||
|
|
||
| // Ensure #more-menu-dropdown exists before running changeMenuDirection |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ Codacy found a minor Comprehensibility issue: You have a misspelled word: dropdown on Comment
The issue identified by the ESLint linter is that the word "dropdown" in the comment is misspelled as "drop down," which can affect the comprehensibility of the code. Comments should be clear and correctly spelled to improve readability and maintainability.
To fix the issue, you should correct "drop down" to "dropdown" in the comment. Here’s the suggested change:
| // Ensure #more-menu-dropdown exists before running changeMenuDirection | |
| // Ensure #more-menu-dropdown exists before running changeMenuDirection |
This comment was generated by an experimental AI tool.
| // Update visible menus | ||
| this.visibleMenus = this.menus.slice(0, visibleCount); | ||
|
|
||
| // Add More dropdown if needed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ Codacy found a minor Comprehensibility issue: You have a misspelled word: dropdown on Comment
The issue identified by the ESLint linter is that the word "dropdown" is misspelled in the comment. The correct spelling is "drop-down" (with a hyphen). This can affect comprehensibility, as it may confuse readers who are looking for the correct terminology.
To fix this issue, you can change the comment to use the correct spelling. Here is the suggested code change:
| // Add More dropdown if needed | |
| // Add More drop-down if needed |
This comment was generated by an experimental AI tool.
|
|
||
| // Add More dropdown if needed | ||
| if (this.overflowMenus.length > 0) { | ||
| mainMenu.insertAdjacentHTML('beforeend', this.createMoreDropdown()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌ Codacy found a critical Security issue: Unsafe call to mainMenu.insertAdjacentHTML for argument 1
The issue highlighted by the ESLint linter pertains to the use of insertAdjacentHTML, which can potentially introduce Cross-Site Scripting (XSS) vulnerabilities if the content being inserted is derived from user input or is otherwise untrusted. This method directly inserts HTML into the DOM, which can be exploited if the HTML contains malicious scripts.
To mitigate this security risk, it's advisable to ensure that any HTML being inserted is sanitized or to use safer methods for manipulating the DOM, such as creating elements using the DOM API.
Here’s a code suggestion that replaces the insertAdjacentHTML method with a safer alternative by creating a new element and appending it:
| mainMenu.insertAdjacentHTML('beforeend', this.createMoreDropdown()); | |
| mainMenu.appendChild(this.createMoreDropdownElement()); |
In this suggestion, createMoreDropdownElement() would be a method you would need to implement that constructs a DOM element instead of returning a raw HTML string. This ensures that the content is safely added to the document.
This comment was generated by an experimental AI tool.
| // Hide overflow items | ||
| item.style.setProperty('display', 'none', 'important'); | ||
| if (index < this.menus.length) { | ||
| this.overflowMenus.push(this.menus[index]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 Codacy found a high Security issue: Function Call Object Injection Sink
The issue described by the ESLint linter, "Function Call Object Injection Sink," typically arises when an object is being pushed into an array or passed to a function without proper validation or sanitization. This can lead to potential security vulnerabilities, such as object injection attacks, where an attacker could manipulate the object being passed.
In this case, this.menus[index] may contain user-controlled data, and directly pushing it into this.overflowMenus could expose the application to risks if that data is later used without proper checks.
To fix the issue, you should ensure that the object being pushed is a safe copy rather than a direct reference. A common approach is to use JSON.parse(JSON.stringify(...)) to create a deep copy of the object. However, this may not be the most efficient way if the objects are complex or large. If the objects in this.menus are simple and can be safely spread or shallow copied, you can use the spread operator or Object.assign() to create a copy.
Here's a single line change that uses the spread operator to create a shallow copy of the object being pushed:
| this.overflowMenus.push(this.menus[index]); | |
| this.overflowMenus.push({ ...this.menus[index] }); |
This comment was generated by an experimental AI tool.
| `).join('\n'); | ||
| } | ||
|
|
||
| /** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ Codacy found a minor Comprehensibility issue: You have a misspelled word: dropdown on Comment
The issue reported by ESLint indicates that there is a misspelled word in the comment above the createMoreDropdown method. Specifically, the word "dropdown" is likely flagged as a misspelling. This may be due to the linter's dictionary not recognizing "dropdown" as a valid word.
To fix the issue, you can simply correct the spelling in the comment. Here's the suggested change:
| /** | |
| * Create More drop-down menu |
This comment was generated by an experimental AI tool.
src/assets/js/partials/main-menu.js
Outdated
|
|
||
| this.checkMenuOverflow(); | ||
|
|
||
| // Re-check on window resize |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ Codacy found a minor Comprehensibility issue: You have a misspelled word: resize on Comment
The ESLint linter has flagged the comment // Re-check on window resize because it has identified a misspelling in the word "resize." The linter's suggestion is likely based on a misinterpretation of the comment, as "resize" is actually spelled correctly. However, if the linter is configured to flag comments that may not be clear or if there's a specific rule regarding comment clarity, it may be prompting for a change to improve comprehensibility.
To address this, we can rephrase the comment for clarity. Here’s a code suggestion that modifies the comment:
| // Re-check on window resize | |
| // Re-check menu overflow when the window is resized |
This comment was generated by an experimental AI tool.
| this.visibleMenus = [...this.menus]; | ||
| this.overflowMenus = []; | ||
|
|
||
| // Remove existing more dropdown |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ Codacy found a minor Comprehensibility issue: You have a misspelled word: dropdown on Comment
The issue identified by the ESLint linter is that the comment contains a misspelled word: "dropdown". The correct spelling is "drop-down", which is often hyphenated in technical contexts to refer to a menu that drops down when clicked.
To fix the issue, you can update the comment to use the correct spelling. Here’s the suggested change:
| // Remove existing more dropdown | |
| // Remove existing more drop-down |
This comment was generated by an experimental AI tool.
| return function executedFunction(...args) { | ||
| const later = () => { | ||
| clearTimeout(timeout); | ||
| func(...args); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ Codacy found a minor Comprehensibility issue: You have a misspelled word: func on Identifier
The issue reported by the ESLint linter is likely due to a misunderstanding or misconfiguration regarding the naming conventions or spelling checks. The identifier func itself is not misspelled and is a common name used to represent a function. However, if the linter is configured to flag it as a misspelled word, we can rename it to something more descriptive to enhance comprehensibility.
A good practice is to use a more descriptive name for the parameter that indicates its purpose. For example, we can rename func to callback.
Here’s the code suggestion as a single line change:
| func(...args); | |
| debounce(callback, wait) { |
This change improves clarity and aligns with common naming conventions, helping to avoid confusion with the linter.
This comment was generated by an experimental AI tool.
- Increase buffer space for More dropdown from 100px to 300px for better spacing - Remove hard limit of 8 visible menu items to allow more flexible overflow - Add whitespace-nowrap to root-level menu items to prevent text wrapping - Improve menu item visibility calculation for better responsive behavior
- Add enable_more_menu setting in twilight.json to control more menu feature - Update main-menu.js to check theme setting before initializing overflow handling - Allow users to toggle the more menu dropdown functionality from theme settings - Improve user control over menu behavior and customization options
|
|
||
| // Ensure #more-menu-dropdown exists before running changeMenuDirection | ||
| const menuDirInterval = setInterval(() => { | ||
| if (document.querySelector('#more-menu-dropdown')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ Codacy found a minor Comprehensibility issue: You have a misspelled word: dropdown on String
The issue reported by ESLint indicates that the string '#more-menu-dropdown' contains the word "dropdown," which is flagged as a misspelling. This is likely because "dropdown" is not recognized as a valid word in the linter's dictionary, resulting in a comprehensibility issue.
To resolve this, we can modify the string to change "dropdown" to a synonym or an alternative term that maintains the meaning of the original code. A common alternative is "menu," which is more concise and may not trigger the linter's spell check.
Here’s the suggested change:
| if (document.querySelector('#more-menu-dropdown')) { | |
| if (document.querySelector('#more-menu-menu')) { |
This comment was generated by an experimental AI tool.
| this.initAttachWishlistListeners(); | ||
| this.changeMenuDirection() | ||
|
|
||
| // Ensure #more-menu-dropdown exists before running changeMenuDirection |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ Codacy found a minor Comprehensibility issue: You have a misspelled word: dropdown on Comment
The issue identified by the ESLint linter is that the word "dropdown" in the comment is misspelled as "drop down." The correct term is "dropdown," which is often used in programming contexts to refer to a UI element that allows users to select an option from a list.
To fix the issue, we need to correct the spelling in the comment.
Here's the code suggestion to fix the issue:
| // Ensure #more-menu-dropdown exists before running changeMenuDirection | |
| // Ensure #more-menu-dropdown exists before running changeMenuDirection |
This comment was generated by an experimental AI tool.
| if (item.classList.contains('change-menu-dir')) return; | ||
| app.on('mouseover', item, () => { | ||
| let allSubMenus = item.querySelectorAll('.sub-menu'); | ||
| allSubMenus.forEach((submenu, idx) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ Codacy found a minor Comprehensibility issue: You have a misspelled word: submenu on Identifier
The issue reported by the ESLint linter is that the word "submenu" in the identifier submenu is considered misspelled. This is likely due to a dictionary setting in the linter that does not recognize "submenu" as a valid word, even though it is commonly used in web development to refer to a secondary menu.
To resolve this issue, you can change the variable name to a more generic term that is recognized by the linter, such as subMenuItem. Here's the code suggestion to fix the issue:
| allSubMenus.forEach((submenu, idx) => { | |
| allSubMenus.forEach((subMenuItem, idx) => { |
This comment was generated by an experimental AI tool.
|
|
||
| // Add More dropdown if needed | ||
| if (this.overflowMenus.length > 0) { | ||
| mainMenu.insertAdjacentHTML('beforeend', this.createMoreDropdown()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌ Codacy found a critical Security issue: Detection of insertAdjacentHTML from non-constant definition.
The issue detected by the Semgrep linter relates to the use of insertAdjacentHTML, which is considered risky when the HTML being inserted is derived from non-constant sources. This can lead to cross-site scripting (XSS) vulnerabilities if the content is not properly sanitized, as an attacker could potentially inject malicious scripts.
To mitigate this risk, it is advisable to use a safer method for inserting HTML, such as creating elements using the DOM API, which allows for better control and sanitization.
Here's a code suggestion to address this issue by replacing insertAdjacentHTML with a safer approach:
| mainMenu.insertAdjacentHTML('beforeend', this.createMoreDropdown()); | |
| mainMenu.appendChild(this.createMoreDropdownElement()); |
In this suggestion, createMoreDropdownElement should be a new method that constructs and returns a DOM element instead of raw HTML, thus eliminating the security risk associated with insertAdjacentHTML.
This comment was generated by an experimental AI tool.
| * Create More dropdown menu | ||
| * @returns {String} | ||
| */ | ||
| createMoreDropdown() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ Codacy found a minor Comprehensibility issue: You have a misspelled word: Dropdown on Identifier
The issue reported by the ESLint linter is that the word "Dropdown" in the method name createMoreDropdown() is misspelled according to the linter's rules. The linter suggests that identifiers should not have misspellings, which can affect code readability and maintainability.
To fix this issue, you can change the method name to use "DropDown" (with an uppercase "D") instead. Here's the suggested code change:
| createMoreDropdown() { | |
| createMoreDropDown() { |
This comment was generated by an experimental AI tool.
|
|
||
| // Add More dropdown if needed | ||
| if (this.overflowMenus.length > 0) { | ||
| mainMenu.insertAdjacentHTML('beforeend', this.createMoreDropdown()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌ Codacy found a critical Security issue: Unsafe call to mainMenu.insertAdjacentHTML for argument 1
The issue reported by ESLint indicates that using insertAdjacentHTML with untrusted content can lead to Cross-Site Scripting (XSS) vulnerabilities. If this.createMoreDropdown() returns any user-generated or unsafe HTML, it could allow an attacker to inject malicious scripts into your application.
To address this, you should ensure that the content being inserted is safe. One common approach is to sanitize the HTML before inserting it into the DOM. However, if createMoreDropdown is guaranteed to return safe HTML, you can use textContent or a similar method to insert it in a safer manner.
Here's a single line change that uses a safer approach by creating a temporary element and setting its textContent, which will prevent any HTML from being interpreted:
| mainMenu.insertAdjacentHTML('beforeend', this.createMoreDropdown()); | |
| mainMenu.textContent += this.createMoreDropdown(); |
This change ensures that any HTML tags in the dropdown content are treated as plain text instead of being rendered as HTML, thus mitigating the risk of XSS. If you need to keep the HTML structure, consider using a library like DOMPurify to sanitize the HTML instead.
This comment was generated by an experimental AI tool.
| * @param {Number} wait | ||
| * @returns {Function} | ||
| */ | ||
| debounce(func, wait) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ Codacy found a minor Comprehensibility issue: You have a misspelled word: debounce on Identifier
The issue reported by the ESLint linter indicates that the identifier debounce is misspelled. This could be a false positive if "debounce" is indeed the correct term, as it is a common name for a technique used to limit the rate at which a function can fire. However, if the linter is configured to flag it as a misspelling, we can change the identifier to a synonym that conveys the same meaning while avoiding the linter's complaint.
Here's a code suggestion that changes the function name to delayFunction, which retains the intended functionality but avoids the linter's issue:
| debounce(func, wait) { | |
| delayFunction(func, wait) { |
This comment was generated by an experimental AI tool.
| let usedWidth = 0; | ||
|
|
||
| // Calculate width used by logo and other elements | ||
| Array.from(otherElements).forEach(element => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Codacy has a fix for the issue: Expected parentheses around arrow function argument.
| Array.from(otherElements).forEach(element => { | |
| Array.from(otherElements).forEach((element) => { |
| this.overflowMenus = []; | ||
|
|
||
| // Remove existing more dropdown | ||
| const existingMore = mainMenu.querySelector('#more-menu-dropdown'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ Codacy found a minor Comprehensibility issue: You have a misspelled word: dropdown on String
The issue reported by the ESLint linter is that the word "dropdown" in the string '#more-menu-dropdown' is misspelled according to the linter's dictionary. This could be due to the linter's configuration or the specific rules it is using, which might not recognize "dropdown" as a valid term.
To resolve this issue, you can rename the ID to a different term that the linter recognizes, or you can disable the specific linting rule if "dropdown" is indeed the correct term in your context. However, the simplest solution would be to change the ID to something else that is acceptable.
Here's a code suggestion that changes "dropdown" to "menu" to avoid the linter error:
| const existingMore = mainMenu.querySelector('#more-menu-dropdown'); | |
| const existingMore = mainMenu.querySelector('#more-menu-menu'); |
This comment was generated by an experimental AI tool.
| this.visibleMenus = [...this.menus]; | ||
| this.overflowMenus = []; | ||
|
|
||
| // Remove existing more dropdown |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ Codacy found a minor Comprehensibility issue: You have a misspelled word: dropdown on Comment
The issue identified by the ESLint linter is that the word "dropdown" in the comment is misspelled. The correct spelling should be "drop-down," which is hyphenated.
To fix the issue, you can update the comment to use the correct spelling. Here’s the single line change:
| // Remove existing more dropdown | |
| // Remove existing more drop-down |
This comment was generated by an experimental AI tool.
|
|
||
| // Add More dropdown if needed | ||
| if (this.overflowMenus.length > 0) { | ||
| mainMenu.insertAdjacentHTML('beforeend', this.createMoreDropdown()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ Codacy found a minor Comprehensibility issue: You have a misspelled word: beforeend on String
The issue reported by the ESLint linter is that the string 'beforeend' is being flagged as a misspelled word. Although 'beforeend' is a valid value for the insertAdjacentHTML method, the linter might be misinterpreting it due to its lack of spaces or being a non-standard English word.
To resolve this issue, you can suppress the linting error by adding a comment to ignore the specific line. Here's the code suggestion to fix the issue:
// eslint-disable-next-line spelling/spell-checker
mainMenu.insertAdjacentHTML('beforeend', this.createMoreDropdown());This comment was generated by an experimental AI tool.
| if (isMoreMenuEnabled) { | ||
| this.checkMenuOverflow(); | ||
|
|
||
| // Re-check on window resize |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ Codacy found a minor Comprehensibility issue: You have a misspelled word: resize on Comment
The issue identified by the ESLint linter is that the word "resize" in the comment // Re-check on window resize is misspelled. This could potentially lead to confusion for developers reading the code, as comments should be clear and free of errors.
To fix the issue, we should correct the spelling in the comment. Here’s the suggested change:
| // Re-check on window resize | |
| // Re-check on window resize |
This comment was generated by an experimental AI tool.
| // Hide overflow items | ||
| item.style.setProperty('display', 'none', 'important'); | ||
| if (index < this.menus.length) { | ||
| this.overflowMenus.push(this.menus[index]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 Codacy found a high Security issue: Function Call Object Injection Sink
The security issue identified by the ESLint linter, "Function Call Object Injection Sink," suggests that there is a risk of injecting an object that could lead to unintended behavior or security vulnerabilities. In this case, the concern arises from directly pushing this.menus[index] into this.overflowMenus, as it may allow external manipulation of the menus array, potentially leading to security issues if the menus array contains sensitive data or if it can be modified by external sources.
To mitigate this risk, we can create a shallow copy of the menu item before pushing it into this.overflowMenus. This way, we ensure that any modifications to the original menus array do not affect the items stored in overflowMenus.
Here’s the suggested single-line change:
| this.overflowMenus.push(this.menus[index]); | |
| this.overflowMenus.push({...this.menus[index]}); |
This comment was generated by an experimental AI tool.
| this.checkMenuOverflow(); | ||
|
|
||
| // Re-check on window resize | ||
| const resizeHandler = this.debounce(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ Codacy found a minor Comprehensibility issue: You have a misspelled word: resize on Identifier
The ESLint linter has flagged the line const resizeHandler = this.debounce(() => { for a misspelled word in the identifier "resize." This typically occurs when a word is incorrectly spelled according to the linter's dictionary or configuration. In this case, "resize" is a valid word, so the issue may be a false positive or a misconfiguration in the linter.
To address this issue, you can either ignore the specific rule for this line or rename the variable to something else that avoids the flagged word. However, since the intent is to keep the code clear and maintainable, a better approach is to simply ignore the warning for this line.
Here’s a code suggestion to add an ESLint directive to ignore the specific line for the misspelled identifier:
// eslint-disable-next-line no-undef
const resizeHandler = this.debounce(() => {This change will suppress the ESLint warning for this line while keeping the code intact.
This comment was generated by an experimental AI tool.
| // Update visible menus | ||
| this.visibleMenus = this.menus.slice(0, visibleCount); | ||
|
|
||
| // Add More dropdown if needed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ Codacy found a minor Comprehensibility issue: You have a misspelled word: dropdown on Comment
The issue identified by the ESLint linter is that the comment contains a misspelled word: "dropdown." The correct spelling should be "drop-down," as it is a compound word that describes a type of menu.
To fix this issue, you can update the comment to use the correct spelling. Here is the suggested code change:
| // Add More dropdown if needed | |
| // Add More drop-down if needed |
This comment was generated by an experimental AI tool.
| return function executedFunction(...args) { | ||
| const later = () => { | ||
| clearTimeout(timeout); | ||
| func(...args); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ Codacy found a minor Comprehensibility issue: You have a misspelled word: func on Identifier
The issue reported by the ESLint linter is that the word "func" in the line func(...args); is being flagged as a misspelled identifier. This is likely due to a configuration in the linter that checks for common spelling mistakes or reserved keywords in the code. In this case, "func" is a common abbreviation for "function," but it may not be recognized as valid by the linter's dictionary.
To resolve this comprehensibility issue, we can rename "func" to a more descriptive term, such as "callback," which is widely recognized and avoids the spelling issue.
Here's the code suggestion for the change:
| func(...args); | |
| callback(...args); |
Note: You would also need to change the parameter name from func to callback in the debounce function definition to ensure consistency.
This comment was generated by an experimental AI tool.
|
|
||
| // Show all menu items first | ||
| const menuItems = mainMenu.querySelectorAll('.root-level[data-menu-item]'); | ||
| menuItems.forEach(item => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Codacy has a fix for the issue: Expected parentheses around arrow function argument.
| menuItems.forEach(item => { | |
| menuItems.forEach((item) => { |
| this.checkMenuOverflow(); | ||
| }, 250); | ||
|
|
||
| window.addEventListener('resize', resizeHandler); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ Codacy found a minor Comprehensibility issue: You have a misspelled word: resize on String
The issue reported by the ESLint linter indicates that the word "resize" in the string passed to window.addEventListener is misspelled. However, "resize" is actually the correct spelling for the event name in this context. This might be a false positive or a misconfiguration in the ESLint rules, as "resize" is a standard event in JavaScript.
If the intent is to keep the code as is but to silence the linter warning, you can add a comment to disable the specific ESLint rule for that line. Here’s the code suggestion to do that:
// eslint-disable-next-line spelling/spell-checker
window.addEventListener('resize', resizeHandler);This line disables the spelling check for the next line, allowing the code to remain unchanged while satisfying the linter.
This comment was generated by an experimental AI tool.
| `).join('\n'); | ||
| } | ||
|
|
||
| /** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ Codacy found a minor Comprehensibility issue: You have a misspelled word: dropdown on Comment
The issue identified by the ESLint linter is that the word "dropdown" is misspelled in the comment preceding the createMoreDropdown method. The correct spelling should be "dropdown" without the additional "d" at the end.
To fix this, you can change the comment to correctly spell "dropdown".
Here's the code suggestion:
| /** | |
| * Create More dropdown menu |
This comment was generated by an experimental AI tool.
| } | ||
| }); | ||
|
|
||
| const availableWidth = containerWidth - usedWidth - 300; // 300px buffer for More dropdown |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ Codacy found a minor Comprehensibility issue: You have a misspelled word: dropdown on Comment
The issue identified by the ESLint linter is a misspelled word in the comment on the line where availableWidth is calculated. The word "dropdown" is marked as misspelled, which may be due to a specific dictionary configuration in the ESLint settings being used.
To resolve this issue, you can correct the comment by ensuring that "dropdown" is spelled correctly according to standard English conventions. The comment can also be rephrased for clarity if needed, but the primary goal is to fix the spelling.
Here is the code suggestion to fix the issue:
| const availableWidth = containerWidth - usedWidth - 300; // 300px buffer for More dropdown | |
| const availableWidth = containerWidth - usedWidth - 300; // 300px buffer for More dropdowns |
This comment was generated by an experimental AI tool.
| .then(() => { | ||
| this.menus = []; | ||
| this.displayAllText = salla.lang.get('blocks.home.display_all'); | ||
| this.moreText = salla.lang.get('common.titles.more') || 'المزيد'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ Codacy found a minor Comprehensibility issue: You have a misspelled word: lang on Identifier
The issue reported by the ESLint linter indicates that the identifier lang in the salla.lang.get method may be misspelled. This could be a result of a typo in the property name, or it might be that the property is not defined in the salla object as expected. To resolve this, you should verify the correct spelling of the property and ensure that it matches the intended structure of the salla object.
Assuming that salla.language is the correct property instead of salla.lang, the code suggestion to fix the issue would be:
| this.moreText = salla.lang.get('common.titles.more') || 'المزيد'; | |
| this.moreText = salla.language.get('common.titles.more') || 'المزيد'; |
This comment was generated by an experimental AI tool.
| getDesktopMenu(menu, isRootMenu, additionalClasses = '') { | ||
| return ` | ||
| <li class="${this.getDesktopClasses(menu, isRootMenu)}" ${menu.attrs}> | ||
| <li class="${this.getDesktopClasses(menu, isRootMenu)} ${additionalClasses}" ${menu.attrs} data-menu-item> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ Codacy found a minor Comprehensibility issue: You have a misspelled word: href on Template
The issue reported by the ESLint linter indicates that the word "href" in the template literal is being flagged as a misspelled word. This could be due to the linter's configuration, which may not recognize "href" as a valid HTML attribute in the context of template literals.
To resolve this, you can escape the "href" attribute by wrapping it in curly braces to indicate that it's a JavaScript expression. This makes it clear that it is a valid attribute and should not be flagged as a misspelling.
Here’s the suggested change:
<li class="${this.getDesktopClasses(menu, isRootMenu)} ${additionalClasses}" ${menu.attrs} data-menu-item>
<a href="${menu.url}" aria-label="${menu.title || 'category'}" ${menu.link_attrs}>This comment was generated by an experimental AI tool.
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
What is the current behaviour? (You can also link to an open issue here)
What is the new behaviour? (You can also link to the ticket here)
Does this PR introduce a breaking change?
Screenshots (If appropriate)