-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate wcf.messageTabMenu (jQuery Widget) to Typescript
HTML and CSS are still a mess and should be overhauled with a future update. Closes #6088 Closes #6089
- Loading branch information
Showing
22 changed files
with
341 additions
and
143 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
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
File renamed without changes.
16 changes: 2 additions & 14 deletions
16
com.woltlab.wcf/templates/shared_wysiwygSmileyFormContainer.tpl
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 |
---|---|---|
@@ -1,19 +1,7 @@ | ||
{include file='shared_tabTabMenuFormContainer'} | ||
|
||
<script data-relocate="true"> | ||
$(function() { | ||
{if $container->children()|count > 1} | ||
new WCF.Message.SmileyCategories( | ||
'{@$container->getPrefixedWysiwygId()|encodeJS}', | ||
'{@$container->getPrefixedId()|encodeJS}Container', | ||
true | ||
); | ||
$('#{@$container->getPrefixedId()|encodeJS}Container').messageTabMenu(); | ||
{/if} | ||
require(['WoltLabSuite/Core/Ui/Smiley/Insert'], function(UiSmileyInsert) { | ||
new UiSmileyInsert('{@$container->getPrefixedWysiwygId()|encodeJS}'); | ||
}); | ||
require(['WoltLabSuite/Core/Ui/Smiley/Insert'], function(UiSmileyInsert) { | ||
new UiSmileyInsert('{@$container->getPrefixedWysiwygId()|encodeJS}'); | ||
}); | ||
</script> |
6 changes: 0 additions & 6 deletions
6
com.woltlab.wcf/templates/shared_wysiwygTabMenuFormContainer.tpl
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 |
---|---|---|
@@ -1,7 +1 @@ | ||
{include file='shared_tabMenuFormContainer' __tabMenuCSSClassName='messageTabMenuNavigation'} | ||
|
||
<script data-relocate="true"> | ||
$(function() { | ||
$('#{@$container->getPrefixedId()|encodeJS}Container').messageTabMenu(); | ||
}); | ||
</script> |
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
150 changes: 150 additions & 0 deletions
150
ts/WoltLabSuite/Core/Component/Message/MessageTabMenu.ts
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,150 @@ | ||
/** | ||
* Provides a specialized tab menu used for message options, integrates better into the editor. | ||
* | ||
* @author Marcel Werk | ||
* @copyright 2001-2024 WoltLab GmbH | ||
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> | ||
* @since 6.2 | ||
* @woltlabExcludeBundle tiny | ||
*/ | ||
|
||
import { wheneverFirstSeen } from "WoltLabSuite/Core/Helper/Selector"; | ||
import * as DomUtil from "WoltLabSuite/Core/Dom/Util"; | ||
import { listenToCkeditor } from "../Ckeditor/Event"; | ||
|
||
class TabMenu { | ||
readonly #tabs: HTMLElement[]; | ||
readonly #tabContainers: HTMLElement[]; | ||
#activeTabName = ""; | ||
#wysiwygContainerId = ""; | ||
#collapsible: boolean; | ||
|
||
constructor( | ||
tabs: HTMLElement[], | ||
tabContainers: HTMLElement[], | ||
activeTabName: string, | ||
wysiwygContainerId: string, | ||
collapsible: boolean = true, | ||
) { | ||
this.#tabs = tabs; | ||
this.#tabContainers = tabContainers; | ||
this.#wysiwygContainerId = wysiwygContainerId; | ||
this.#collapsible = collapsible; | ||
|
||
this.#init(); | ||
|
||
if (activeTabName) { | ||
this.setActiveTab(activeTabName); | ||
} else { | ||
this.#closeAllTabs(); | ||
} | ||
} | ||
|
||
setActiveTab(tabName: string): void { | ||
if (this.#activeTabName === tabName) { | ||
if (this.#collapsible) { | ||
this.#activeTabName = ""; | ||
this.#closeAllTabs(); | ||
} | ||
|
||
return; | ||
} | ||
|
||
this.#closeAllTabs(); | ||
|
||
const tab = this.#tabs.find((element) => element.dataset.name === tabName); | ||
if (!tab) { | ||
console.debug(`Unknown tab '${tabName}'.`); | ||
return; | ||
} | ||
const tabIndex = this.#tabs.indexOf(tab); | ||
tab.classList.add("active"); | ||
tab.querySelector("button")!.setAttribute("aria-expanded", "true"); | ||
this.#tabContainers[tabIndex].hidden = false; | ||
this.#tabContainers[tabIndex].classList.add("active"); | ||
this.#activeTabName = tabName; | ||
} | ||
|
||
#init(): void { | ||
for (let i = 0; i < this.#tabs.length; i++) { | ||
const tab = this.#tabs[i]; | ||
const tabContainer = this.#tabContainers[i]; | ||
|
||
const anchor = tab.querySelector("a"); | ||
if (anchor) { | ||
const buttonReplacement = document.createElement("button"); | ||
buttonReplacement.type = "button"; | ||
DomUtil.replaceElement(anchor, buttonReplacement); | ||
} | ||
|
||
const button = tab.querySelector("button")!; | ||
button.setAttribute("aria-haspopup", "true"); | ||
button.setAttribute("aria-expanded", "false"); | ||
button.setAttribute("aria-controls", tabContainer.id); | ||
button.addEventListener("click", () => { | ||
this.setActiveTab(tab.dataset.name!); | ||
}); | ||
} | ||
|
||
if (this.#wysiwygContainerId) { | ||
listenToCkeditor(document.getElementById(this.#wysiwygContainerId)!).reset(() => { | ||
this.#closeAllTabs(); | ||
}); | ||
} | ||
} | ||
|
||
#closeAllTabs(): void { | ||
for (let i = 0; i < this.#tabs.length; i++) { | ||
const tab = this.#tabs[i]; | ||
tab.classList.remove("active"); | ||
tab.querySelector("button")!.setAttribute("aria-expanded", "false"); | ||
this.#tabContainers[i].hidden = true; | ||
this.#tabContainers[i].classList.remove("active"); | ||
} | ||
} | ||
} | ||
|
||
const tabMenus = new Map<string, TabMenu>(); | ||
|
||
function initTabMenu(tabMenu: HTMLElement): void { | ||
const tabs = tabMenu.querySelectorAll<HTMLElement>(":scope > nav [data-name]"); | ||
const tabContainers = tabMenu.querySelectorAll<HTMLElement>(":scope > .messageTabMenuContent"); | ||
|
||
if (!tabs.length) { | ||
console.debug(`No tabs found in message tab menu ('${tabMenu.dataset.wysiwygContainerId}').`); | ||
return; | ||
} | ||
if (tabs.length != tabContainers.length) { | ||
console.debug(`Amount of tabs does not equal amount of tab containers ('${tabMenu.dataset.wysiwygContainerId}').`); | ||
return; | ||
} | ||
|
||
let activeTabName = ""; | ||
if (tabMenu.dataset.preselect) { | ||
if (tabMenu.dataset.preselect === "true") { | ||
activeTabName = tabs[0].dataset.name!; | ||
} else { | ||
activeTabName = tabMenu.dataset.preselect; | ||
} | ||
} | ||
|
||
const tabMenuObj = new TabMenu( | ||
Array.from(tabs), | ||
Array.from(tabContainers), | ||
activeTabName, | ||
tabMenu.dataset.wysiwygContainerId ?? "", | ||
tabMenu.dataset.collapsible !== "false", | ||
); | ||
|
||
if (tabMenu.dataset.wysiwygContainerId) { | ||
tabMenus.set(tabMenu.dataset.wysiwygContainerId, tabMenuObj); | ||
} | ||
} | ||
|
||
export function getTabMenu(identifier: string): TabMenu | undefined { | ||
return tabMenus.get(identifier); | ||
} | ||
|
||
export function setup(): void { | ||
wheneverFirstSeen(".messageTabMenu", (tabMenu) => initTabMenu(tabMenu)); | ||
} |
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
5 changes: 0 additions & 5 deletions
5
wcfsetup/install/files/acp/templates/__messageFormSmilies.tpl
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.