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
22 changed files
with
207 additions
and
46 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
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,15 @@ | ||
/** | ||
* 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 | ||
*/ | ||
!function(t,e){"use strict";function i(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var n=i(t),s=i(e);class o{#t;#e;#i;#n;constructor(t,e){this.#t=t,this.#e=e;const i=this.#e.querySelectorAll(":scope > button");if(1!==i.length)throw new Error("Dropdown: Expected exactly one button in dropdown element.",this.#e);[this.#i]=i;const n=this.#e.querySelectorAll(":scope > ul");if(1!==n.length)throw new Error("Dropdown: Expected exactly one ul in dropdown element.",this.#e);[this.#n]=n,this.#i.addEventListener("keydown",(t=>{13===t.which&&this.toggleVisibility()})),this.#i.addEventListener("click",this.#s)}#o=t=>{27===t.which&&this.hide()};#s=t=>{t.stopPropagation(),this.show()};#h=()=>{this.hide()};toggleVisibility(){"block"===this.#n.style.display?this.hide():this.show()}show(){this.#n.style.display="block",this.#i.setAttribute("aria-expanded","true"),this.#t.addEventListener("keydown",this.#o),this.#t.addEventListener("click",this.#h),this.#i.removeEventListener("click",this.#s)}hide(){this.#n.style.display="none",this.#i.setAttribute("aria-expanded","false"),this.#t.removeEventListener("keydown",this.#o),this.#t.removeEventListener("click",this.#h),this.#i.addEventListener("click",this.#s)}}n.default.UI=n.default.UI||{},n.default.UI.dropdown=function(t){return new o(s.default,t)}}(il,document); |
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, | ||
}, | ||
}), | ||
], | ||
}, | ||
}; |
105 changes: 105 additions & 0 deletions
105
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,105 @@ | ||
/** | ||
* 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; | ||
|
||
/** | ||
* @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) { | ||
throw new Error('Dropdown: Expected exactly one button in dropdown element.', this.#element); | ||
} | ||
[this.#button] = buttons; | ||
|
||
const lists = this.#element.querySelectorAll(':scope > ul'); | ||
if (lists.length !== 1) { | ||
throw new Error('Dropdown: Expected exactly one ul in dropdown element.', this.#element); | ||
} | ||
[this.#list] = lists; | ||
|
||
this.#button.addEventListener('keydown', (event) => { | ||
if (event.which === 13) { // Enter | ||
this.toggleVisibility(); | ||
} | ||
}); | ||
|
||
this.#button.addEventListener('click', this.#showOnClick); | ||
} | ||
|
||
#hideOnEscape = (event) => { | ||
if (event.which === 27) { // ESCAPE | ||
this.hide(); | ||
} | ||
}; | ||
|
||
#showOnClick = (event) => { | ||
event.stopPropagation(); | ||
this.show(); | ||
}; | ||
|
||
#hideOnClick = () => { | ||
this.hide(); | ||
}; | ||
|
||
toggleVisibility() { | ||
const visible = this.#list.style.display === 'block'; | ||
if (visible) { | ||
this.hide(); | ||
} else { | ||
this.show(); | ||
} | ||
} | ||
|
||
show() { | ||
this.#list.style.display = 'block'; | ||
this.#button.setAttribute('aria-expanded', 'true'); | ||
this.#document.addEventListener('keydown', this.#hideOnEscape); | ||
this.#document.addEventListener('click', this.#hideOnClick); | ||
this.#button.removeEventListener('click', this.#showOnClick); | ||
} | ||
|
||
hide() { | ||
this.#list.style.display = 'none'; | ||
this.#button.setAttribute('aria-expanded', 'false'); | ||
this.#document.removeEventListener('keydown', this.#hideOnEscape); | ||
this.#document.removeEventListener('click', this.#hideOnClick); | ||
this.#button.addEventListener('click', this.#showOnClick); | ||
} | ||
} |
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) { | ||
return 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
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
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
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
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
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
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
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
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
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
Oops, something went wrong.