forked from ILIAS-eLearning/ILIAS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
201 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
components/ILIAS/UI/resources/js/Dropdown/dist/dropdown.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
27 changes: 27 additions & 0 deletions
27
components/ILIAS/UI/resources/js/Dropdown/rollup.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import terser from '@rollup/plugin-terser'; | ||
import copyright from '../../../../../../scripts/Copyright-Checker/copyright'; | ||
import preserveCopyright from '../../../../../../scripts/Copyright-Checker/preserveCopyright'; | ||
|
||
export default { | ||
external: [ | ||
'document', | ||
'ilias', | ||
], | ||
input: './src/dropdown.js', | ||
output: { | ||
file: './dist/dropdown.js', | ||
format: 'iife', | ||
banner: copyright, | ||
globals: { | ||
document: 'document', | ||
ilias: 'il', | ||
}, | ||
plugins: [ | ||
terser({ | ||
format: { | ||
comments: preserveCopyright, | ||
}, | ||
}), | ||
], | ||
}, | ||
}; |
129 changes: 129 additions & 0 deletions
129
components/ILIAS/UI/resources/js/Dropdown/src/dropdown.class.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/** | ||
* This file is part of ILIAS, a powerful learning management system | ||
* published by ILIAS open source e-Learning e.V. | ||
* | ||
* ILIAS is licensed with the GPL-3.0, | ||
* see https://www.gnu.org/licenses/gpl-3.0.en.html | ||
* You should have received a copy of said license along with the | ||
* source code, too. | ||
* | ||
* If this is not the case or you just want to try ILIAS, you'll find | ||
* us at: | ||
* https://www.ilias.de | ||
* https://github.com/ILIAS-eLearning | ||
*/ | ||
|
||
export default class Dropdown { | ||
/** | ||
* @type {DOMDocument} | ||
*/ | ||
#document; | ||
|
||
/** | ||
* @type {HTMLElement} | ||
*/ | ||
#element; | ||
|
||
/** | ||
* @type {HTMLElement} | ||
*/ | ||
#button; | ||
|
||
/** | ||
* @type {HTMLElement} | ||
*/ | ||
#list; | ||
|
||
/** | ||
* @type {function} | ||
*/ | ||
#makeInvisibleOnEscape; | ||
|
||
/** | ||
* @type {function} | ||
*/ | ||
#makeVisibleOnClick; | ||
|
||
/** | ||
* @type {function} | ||
*/ | ||
#makeInvisibleOnClick; | ||
|
||
/** | ||
* @param {DOMDocument} document | ||
* @param {HTMLElement} element | ||
*/ | ||
constructor(document, element) { | ||
this.#document = document; | ||
this.#element = element; | ||
|
||
const buttons = this.#element.querySelectorAll(':scope > button'); | ||
if (buttons.length !== 1) { | ||
console.log('Dropdown: Expected exactly one button in dropdown element.', this.#element); | ||
return; | ||
} | ||
this.#button = buttons[0]; | ||
|
||
const lists = this.#element.querySelectorAll(':scope > ul'); | ||
if (lists.length !== 1) { | ||
console.log('Dropdown: Expected exactly one ul in dropdown element.', this.#element); | ||
return; | ||
} | ||
this.#list = lists[0]; | ||
|
||
this.initEvents(); | ||
} | ||
|
||
initEvents() { | ||
const self = this; | ||
this.#button.addEventListener('keydown', (event) => { | ||
if (event.which === 13) { // Enter | ||
event.preventDefault(); | ||
self.toggleVisibility(); | ||
} | ||
}); | ||
|
||
this.#makeInvisibleOnEscape = function (event) { | ||
if (event.which === 27) { // ESCAPE | ||
event.preventDefault(); | ||
self.makeInvisible(); | ||
} | ||
}; | ||
|
||
this.#makeVisibleOnClick = function (event) { | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
self.makeVisible(); | ||
}; | ||
this.#button.addEventListener('click', this.#makeVisibleOnClick); | ||
|
||
this.#makeInvisibleOnClick = function () { | ||
self.makeInvisible(); | ||
}; | ||
} | ||
|
||
toggleVisibility() { | ||
const visible = this.#list.style.display === 'block'; | ||
if (visible) { | ||
this.makeInvisible(); | ||
} else { | ||
this.makeVisible(); | ||
} | ||
} | ||
|
||
makeVisible() { | ||
this.#list.style.display = 'block'; | ||
this.#button.setAttribute('aria-expanded', 'true'); | ||
this.#document.addEventListener('keydown', this.#makeInvisibleOnEscape); | ||
this.#document.addEventListener('click', this.#makeInvisibleOnClick); | ||
this.#button.removeEventListener('click', this.#makeVisibleOnClick); | ||
} | ||
|
||
makeInvisible() { | ||
this.#list.style.display = 'none'; | ||
this.#button.setAttribute('aria-expanded', 'false'); | ||
this.#document.removeEventListener('keydown', this.#makeInvisibleOnEscape); | ||
this.#document.removeEventListener('click', this.#makeInvisibleOnClick); | ||
this.#button.addEventListener('click', this.#makeVisibleOnClick); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* This file is part of ILIAS, a powerful learning management system | ||
* published by ILIAS open source e-Learning e.V. | ||
* | ||
* ILIAS is licensed with the GPL-3.0, | ||
* see https://www.gnu.org/licenses/gpl-3.0.en.html | ||
* You should have received a copy of said license along with the | ||
* source code, too. | ||
* | ||
* If this is not the case or you just want to try ILIAS, you'll find | ||
* us at: | ||
* https://www.ilias.de | ||
* https://github.com/ILIAS-eLearning | ||
*/ | ||
|
||
import il from 'ilias'; | ||
import document from 'document'; | ||
import Dropdown from './dropdown.class'; | ||
|
||
il.UI = il.UI || {}; | ||
il.UI.dropdown = function (htmlElement) { | ||
new Dropdown(document, htmlElement); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
components/ILIAS/UI/src/templates/default/Dropdown/tpl.standard.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters