Update MegaMenu Application Customizer: Version bump to 1.1.0, localization support added, and unnecessary files removed
- Deleted obsolete localization file for English (en-us). - Updated version number from 1.0.4 to 1.1.0 in manifests.js and manifests.json. - Added localization support for German (de-de) in a new localization file. - Removed unnecessary dependencies from manifests. - Added .gitignore to exclude build artifacts and temporary files.
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -1,5 +1,2 @@
|
||||
declare const styles: {
|
||||
mmSlideIn: string;
|
||||
mmFadeIn: string;
|
||||
};
|
||||
declare const styles: {};
|
||||
export default styles;
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
/* tslint:disable */
|
||||
require('./MegaMenu.module.css');
|
||||
var styles = {
|
||||
mmSlideIn: 'mmSlideIn_09a8e1a7',
|
||||
mmFadeIn: 'mmFadeIn_09a8e1a7',
|
||||
};
|
||||
var styles = {};
|
||||
export default styles;
|
||||
/* tslint:enable */
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"sources":["extensions/megaMenu/MegaMenu.module.scss.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB,OAAO,CAAC,uBAAuB,CAAC,CAAC;AACjC,IAAM,MAAM,GAAG;IACb,SAAS,EAAE,oBAAoB;IAC/B,QAAQ,EAAE,mBAAmB;CAC9B,CAAC;AAEF,eAAe,MAAM,CAAC;AACtB,mBAAmB","file":"extensions/megaMenu/MegaMenu.module.scss.js","sourcesContent":["/* tslint:disable */\r\nrequire('./MegaMenu.module.css');\r\nconst styles = {\r\n mmSlideIn: 'mmSlideIn_09a8e1a7',\r\n mmFadeIn: 'mmFadeIn_09a8e1a7',\r\n};\r\n\r\nexport default styles;\r\n/* tslint:enable */"],"sourceRoot":"..\\..\\..\\src"}
|
||||
{"version":3,"sources":["extensions/megaMenu/MegaMenu.module.scss.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB,OAAO,CAAC,uBAAuB,CAAC,CAAC;AACjC,IAAM,MAAM,GAAG,EACd,CAAC;AAEF,eAAe,MAAM,CAAC;AACtB,mBAAmB","file":"extensions/megaMenu/MegaMenu.module.scss.js","sourcesContent":["/* tslint:disable */\r\nrequire('./MegaMenu.module.css');\r\nconst styles = {\r\n};\r\n\r\nexport default styles;\r\n/* tslint:enable */"],"sourceRoot":"..\\..\\..\\src"}
|
||||
@@ -1,27 +1,27 @@
|
||||
import { BaseApplicationCustomizer } from '@microsoft/sp-application-base';
|
||||
import './MegaMenu.module.scss';
|
||||
export declare const UserCustomActionMegaMenuId: string;
|
||||
/**
|
||||
* Properties for the MegaMenu Application Customizer
|
||||
*/
|
||||
export interface IMegaMenuApplicationCustomizerProperties {
|
||||
/**
|
||||
* The name of the termset to load menu items from
|
||||
*/
|
||||
termSetName: string;
|
||||
/**
|
||||
* Optional URL to an external CSS file
|
||||
*/
|
||||
termSetName?: string;
|
||||
termSetId?: string;
|
||||
cacheMinutes?: number;
|
||||
cssUrl?: string;
|
||||
debug?: boolean;
|
||||
}
|
||||
/** A Custom Action which can be run during execution of a Client Side Application */
|
||||
export default class MegaMenuApplicationCustomizer extends BaseApplicationCustomizer<IMegaMenuApplicationCustomizerProperties> {
|
||||
private _topPlaceholder;
|
||||
private _menuContainer;
|
||||
private _renderer;
|
||||
onInit(): Promise<void>;
|
||||
private _renderPlaceHolders();
|
||||
private _updateCallback;
|
||||
private _renderMegaMenu(termSetName);
|
||||
private _renderMegaMenu(termSetIdentifier, debug?);
|
||||
private _getOrCreateContainer(id, placeholder);
|
||||
private _loadExternalCss(cssUrl);
|
||||
private _onDispose();
|
||||
private _loadExternalCss(cssUrl?, debug?);
|
||||
private _onDispose;
|
||||
private _getTermSetIdentifier();
|
||||
private _getCacheMinutes();
|
||||
private _validateCssUrl(cssUrl);
|
||||
private _renderStatus(message);
|
||||
private _isGuid(value);
|
||||
private _isDebugEnabled(debugOverride?);
|
||||
}
|
||||
|
||||
@@ -54,59 +54,67 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
}
|
||||
};
|
||||
import { override } from '@microsoft/decorators';
|
||||
import { Log } from '@microsoft/sp-core-library';
|
||||
import { BaseApplicationCustomizer, PlaceholderName } from '@microsoft/sp-application-base';
|
||||
import * as strings from 'MegaMenuApplicationCustomizerStrings';
|
||||
import { TaxonomyNavigationService } from '../../services/TaxonomyNavigationService';
|
||||
import { MegaMenuRenderer } from './MegaMenuRenderer';
|
||||
// Import SCSS module
|
||||
import { debugError, debugLog, debugWarn } from '../../services/MegaMenuDebug';
|
||||
import './MegaMenu.module.scss';
|
||||
var LOG_SOURCE = 'MegaMenuApplicationCustomizer';
|
||||
export var UserCustomActionMegaMenuId = 'abc3361f-bb2d-491f-aba3-cd51c19a299b';
|
||||
/** A Custom Action which can be run during execution of a Client Side Application */
|
||||
var MegaMenuApplicationCustomizer = (function (_super) {
|
||||
__extends(MegaMenuApplicationCustomizer, _super);
|
||||
function MegaMenuApplicationCustomizer() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this._updateCallback = function (data) {
|
||||
_this._loadExternalCss(data.cssUrl);
|
||||
_this._renderMegaMenu(data.termSetName);
|
||||
_this._onDispose = function () {
|
||||
_this.context.placeholderProvider.changedEvent.remove(_this, _this._renderPlaceHolders);
|
||||
if (_this._renderer) {
|
||||
_this._renderer.dispose();
|
||||
_this._renderer = undefined;
|
||||
}
|
||||
var externalCssLink = document.getElementById('mega-menu-additional-css-34FAB720');
|
||||
if (externalCssLink) {
|
||||
externalCssLink.remove();
|
||||
}
|
||||
_this._menuContainer = undefined;
|
||||
_this._topPlaceholder = undefined;
|
||||
debugLog(_this._isDebugEnabled(), LOG_SOURCE, 'Disposed custom top placeholder.');
|
||||
};
|
||||
return _this;
|
||||
}
|
||||
MegaMenuApplicationCustomizer.prototype.onInit = function () {
|
||||
Log.info(LOG_SOURCE, "Initialized " + strings.Title);
|
||||
// Load external CSS if provided
|
||||
debugLog(this._isDebugEnabled(), LOG_SOURCE, 'Initialized ' + strings.Title);
|
||||
if (this.properties.cssUrl) {
|
||||
this._loadExternalCss(this.properties.cssUrl);
|
||||
}
|
||||
// Wait for the page to be ready
|
||||
this.context.placeholderProvider.changedEvent.add(this, this._renderPlaceHolders);
|
||||
// Initial render
|
||||
this._renderPlaceHolders();
|
||||
return Promise.resolve();
|
||||
};
|
||||
MegaMenuApplicationCustomizer.prototype._renderPlaceHolders = function () {
|
||||
console.log('Available placeholders: ', this.context.placeholderProvider.placeholderNames.map(function (name) { return PlaceholderName[name]; }).join(', '));
|
||||
// Handling the top placeholder
|
||||
var availablePlaceholders = this.context.placeholderProvider.placeholderNames
|
||||
.map(function (name) { return PlaceholderName[name]; })
|
||||
.join(', ');
|
||||
debugLog(this._isDebugEnabled(), LOG_SOURCE, 'Available placeholders:', availablePlaceholders);
|
||||
if (!this._topPlaceholder) {
|
||||
this._topPlaceholder = this.context.placeholderProvider.tryCreateContent(PlaceholderName.Top, { onDispose: this._onDispose });
|
||||
// The extension should not assume that the expected placeholder is available.
|
||||
if (!this._topPlaceholder) {
|
||||
console.error('The expected placeholder (Top) was not found.');
|
||||
debugError(this._isDebugEnabled(), LOG_SOURCE, 'The expected placeholder (Top) was not found.');
|
||||
return;
|
||||
}
|
||||
if (!this.properties.termSetName) {
|
||||
console.error('TermSetName property is required but not provided.');
|
||||
1;
|
||||
var termSetIdentifier = this._getTermSetIdentifier();
|
||||
if (!termSetIdentifier) {
|
||||
debugWarn(this._isDebugEnabled(), LOG_SOURCE, 'No termSetId or termSetName configured. Mega Menu rendering is skipped.');
|
||||
this._renderStatus(strings.ConfigurationMissing);
|
||||
return;
|
||||
}
|
||||
this._renderMegaMenu(this.properties.termSetName);
|
||||
this._renderMegaMenu(termSetIdentifier);
|
||||
}
|
||||
};
|
||||
MegaMenuApplicationCustomizer.prototype._renderMegaMenu = function (termSetName) {
|
||||
MegaMenuApplicationCustomizer.prototype._renderMegaMenu = function (termSetIdentifier, debug) {
|
||||
if (debug === void 0) { debug = this._isDebugEnabled(); }
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var taxonomyService, menuItems, renderer, container, error_1;
|
||||
var taxonomyService, menuItems, error_1;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
@@ -116,23 +124,27 @@ var MegaMenuApplicationCustomizer = (function (_super) {
|
||||
_a.label = 1;
|
||||
case 1:
|
||||
_a.trys.push([1, 3, , 4]);
|
||||
taxonomyService = new TaxonomyNavigationService(this.context, termSetName);
|
||||
taxonomyService = new TaxonomyNavigationService(this.context, termSetIdentifier, debug, this._getCacheMinutes());
|
||||
return [4 /*yield*/, taxonomyService.getMenuItems()];
|
||||
case 2:
|
||||
menuItems = _a.sent();
|
||||
renderer = new MegaMenuRenderer(this.context, menuItems, this._updateCallback);
|
||||
container = this._getOrCreateContainer('CustomHeader', this._topPlaceholder);
|
||||
if (container) {
|
||||
renderer.render(container);
|
||||
if (this._renderer) {
|
||||
this._renderer.dispose();
|
||||
}
|
||||
this._renderer = new MegaMenuRenderer(menuItems, debug);
|
||||
this._menuContainer = this._getOrCreateContainer('CustomHeader', this._topPlaceholder);
|
||||
if (this._menuContainer) {
|
||||
this._renderer.render(this._menuContainer);
|
||||
}
|
||||
else {
|
||||
renderer.render(this._topPlaceholder.domElement);
|
||||
this._renderer.render(this._topPlaceholder.domElement);
|
||||
}
|
||||
Log.info(LOG_SOURCE, "MegaMenu rendered successfully with " + menuItems.length + " top-level items");
|
||||
debugLog(debug, LOG_SOURCE, 'MegaMenu rendered successfully with ' + menuItems.length + ' top-level items.');
|
||||
return [3 /*break*/, 4];
|
||||
case 3:
|
||||
error_1 = _a.sent();
|
||||
console.error('Error rendering MegaMenu:', error_1);
|
||||
debugError(debug, LOG_SOURCE, 'Error rendering MegaMenu.', error_1);
|
||||
this._renderStatus(strings.LoadError);
|
||||
return [3 /*break*/, 4];
|
||||
case 4: return [2 /*return*/];
|
||||
}
|
||||
@@ -142,19 +154,29 @@ var MegaMenuApplicationCustomizer = (function (_super) {
|
||||
MegaMenuApplicationCustomizer.prototype._getOrCreateContainer = function (id, placeholder) {
|
||||
var container = document.getElementById(id);
|
||||
if (container) {
|
||||
var div = document.createElement('div');
|
||||
container.appendChild(div);
|
||||
return div;
|
||||
}
|
||||
else {
|
||||
return placeholder.domElement;
|
||||
var host = document.getElementById('MegaMenuHost');
|
||||
if (!host) {
|
||||
host = document.createElement('div');
|
||||
host.id = 'MegaMenuHost';
|
||||
container.appendChild(host);
|
||||
}
|
||||
return host;
|
||||
}
|
||||
return placeholder.domElement;
|
||||
};
|
||||
MegaMenuApplicationCustomizer.prototype._loadExternalCss = function (cssUrl) {
|
||||
MegaMenuApplicationCustomizer.prototype._loadExternalCss = function (cssUrl, debug) {
|
||||
if (debug === void 0) { debug = this._isDebugEnabled(); }
|
||||
var externalCssLinkId = 'mega-menu-additional-css-34FAB720';
|
||||
var link = document.getElementById(externalCssLinkId);
|
||||
if (cssUrl && cssUrl.trim() !== '') {
|
||||
// update previous link, if present
|
||||
var validatedUrl = this._validateCssUrl(cssUrl);
|
||||
if (!validatedUrl) {
|
||||
debugWarn(debug, LOG_SOURCE, 'Rejected unsafe external CSS URL:', cssUrl);
|
||||
if (link) {
|
||||
link.remove();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!link) {
|
||||
var head = document.getElementsByTagName('head')[0];
|
||||
link = document.createElement('link');
|
||||
@@ -162,21 +184,69 @@ var MegaMenuApplicationCustomizer = (function (_super) {
|
||||
link.type = 'text/css';
|
||||
link.id = externalCssLinkId;
|
||||
link.onload = function () {
|
||||
Log.info(LOG_SOURCE, "External CSS loaded successfully from: " + cssUrl);
|
||||
debugLog(debug, LOG_SOURCE, 'External CSS loaded successfully from:', cssUrl);
|
||||
};
|
||||
link.onerror = function () {
|
||||
console.warn("Failed to load external CSS from: " + cssUrl);
|
||||
debugWarn(debug, LOG_SOURCE, 'Failed to load external CSS from:', cssUrl);
|
||||
};
|
||||
head.appendChild(link);
|
||||
}
|
||||
link.href = cssUrl;
|
||||
link.href = validatedUrl;
|
||||
}
|
||||
else if (link) {
|
||||
link.remove();
|
||||
}
|
||||
};
|
||||
MegaMenuApplicationCustomizer.prototype._onDispose = function () {
|
||||
console.log('[MegaMenuApplicationCustomizer._onDispose] Disposed custom top placeholder.');
|
||||
MegaMenuApplicationCustomizer.prototype._getTermSetIdentifier = function () {
|
||||
var termSetId = this.properties && this.properties.termSetId
|
||||
? this.properties.termSetId.trim()
|
||||
: '';
|
||||
if (termSetId && this._isGuid(termSetId)) {
|
||||
return termSetId;
|
||||
}
|
||||
return this.properties && this.properties.termSetName
|
||||
? this.properties.termSetName.trim()
|
||||
: '';
|
||||
};
|
||||
MegaMenuApplicationCustomizer.prototype._getCacheMinutes = function () {
|
||||
var value = this.properties ? Number(this.properties.cacheMinutes) : 15;
|
||||
return isFinite(value) ? Math.min(Math.max(Math.floor(value), 1), 1440) : 15;
|
||||
};
|
||||
MegaMenuApplicationCustomizer.prototype._validateCssUrl = function (cssUrl) {
|
||||
try {
|
||||
var parsed = new URL(cssUrl.trim(), window.location.origin);
|
||||
var isHttp = parsed.protocol === 'http:' || parsed.protocol === 'https:';
|
||||
var isSameOrigin = parsed.origin === window.location.origin;
|
||||
if (!isHttp || (!isSameOrigin && parsed.protocol !== 'https:')) {
|
||||
return undefined;
|
||||
}
|
||||
return parsed.href;
|
||||
}
|
||||
catch (error) {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
MegaMenuApplicationCustomizer.prototype._renderStatus = function (message) {
|
||||
if (!this._topPlaceholder) {
|
||||
return;
|
||||
}
|
||||
this._menuContainer = this._getOrCreateContainer('CustomHeader', this._topPlaceholder);
|
||||
var container = this._menuContainer || this._topPlaceholder.domElement;
|
||||
container.innerHTML = '';
|
||||
var status = document.createElement('div');
|
||||
status.className = 'mega-menu-status';
|
||||
status.setAttribute('role', 'status');
|
||||
status.textContent = message;
|
||||
container.appendChild(status);
|
||||
};
|
||||
MegaMenuApplicationCustomizer.prototype._isGuid = function (value) {
|
||||
return /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/.test(value);
|
||||
};
|
||||
MegaMenuApplicationCustomizer.prototype._isDebugEnabled = function (debugOverride) {
|
||||
if (typeof debugOverride === 'boolean') {
|
||||
return debugOverride;
|
||||
}
|
||||
return !!(this.properties && this.properties.debug === true);
|
||||
};
|
||||
__decorate([
|
||||
override
|
||||
|
||||
File diff suppressed because one or more lines are too long
28
lib/extensions/megaMenu/MegaMenuRenderer.d.ts
vendored
28
lib/extensions/megaMenu/MegaMenuRenderer.d.ts
vendored
@@ -1,17 +1,18 @@
|
||||
import { ApplicationCustomizerContext } from '@microsoft/sp-application-base';
|
||||
import { IMenuItem } from '../../services/IMenuItem';
|
||||
import { IMegaMenuApplicationCustomizerProperties } from './MegaMenuApplicationCustomizer';
|
||||
export declare class MegaMenuRenderer {
|
||||
private context;
|
||||
private menuItems;
|
||||
private updateCallback;
|
||||
private _settingsPanel?;
|
||||
constructor(context: ApplicationCustomizerContext, menuItems: IMenuItem[], updateCallback: (data: IMegaMenuApplicationCustomizerProperties) => void);
|
||||
private debug;
|
||||
private static readonly hoverOpenDelayMs;
|
||||
private static readonly hoverCloseDelayMs;
|
||||
private _container;
|
||||
private _documentKeydownHandler;
|
||||
private _documentClickHandler;
|
||||
private _announcer;
|
||||
constructor(menuItems: IMenuItem[], debug?: boolean);
|
||||
render(container: HTMLElement): void;
|
||||
private createSettingsItem();
|
||||
private openSettings();
|
||||
dispose(): void;
|
||||
private createTopLevelItem(item);
|
||||
private createTopLevelElement(item);
|
||||
private createTopLevelElement(item, hasChildren, isActive, isCurrent);
|
||||
private createMegaMenu(parentItem);
|
||||
private createCategorySection(item);
|
||||
private attachEventListeners();
|
||||
@@ -19,10 +20,17 @@ export declare class MegaMenuRenderer {
|
||||
private attachMouseEvents(heading, megaMenu);
|
||||
private attachFocusManagement(heading, megaMenu);
|
||||
private attachGlobalKeyboardNavigation();
|
||||
private attachGlobalClickOutsideHandler();
|
||||
private openMegaMenu(trigger, menu);
|
||||
private closeMegaMenu(trigger, menu);
|
||||
private toggleMegaMenu(trigger, menu);
|
||||
private closeAllMegaMenus();
|
||||
private closeAllMegaMenus(exceptMenu?);
|
||||
private focusFirstLink(megaMenu);
|
||||
private isItemActive(item);
|
||||
private isCurrentUrl(url?);
|
||||
private normalizePath(url?);
|
||||
private getColumnCount(items?);
|
||||
private joinClasses(...classNames);
|
||||
private createScreenReaderAnnouncer();
|
||||
private announce(message);
|
||||
}
|
||||
|
||||
@@ -2,109 +2,88 @@
|
||||
// tslint:disable:match-default-export-name
|
||||
// tslint:disable:typedef
|
||||
// tslint:disable:variable-name
|
||||
import { SPPermission } from '@microsoft/sp-page-context';
|
||||
import { MegaMenuSettingsPanel } from './MegaMenuSettings';
|
||||
import { debugLog } from '../../services/MegaMenuDebug';
|
||||
var LOG_SOURCE = 'MegaMenuRenderer';
|
||||
var MegaMenuRenderer = (function () {
|
||||
function MegaMenuRenderer(context, menuItems, updateCallback) {
|
||||
this.context = context;
|
||||
function MegaMenuRenderer(menuItems, debug) {
|
||||
if (debug === void 0) { debug = false; }
|
||||
this.menuItems = menuItems;
|
||||
this.updateCallback = updateCallback;
|
||||
this.debug = debug;
|
||||
}
|
||||
MegaMenuRenderer.prototype.render = function (container) {
|
||||
var _this = this;
|
||||
// Clear any existing content
|
||||
this.dispose();
|
||||
this._container = container;
|
||||
container.innerHTML = '';
|
||||
container.id = 'CustomNavigation';
|
||||
// Create the main nav element
|
||||
var nav = document.createElement('nav');
|
||||
nav.id = 'Mega-Menu';
|
||||
nav.className = 'mega-menu-main';
|
||||
nav.setAttribute('role', 'navigation');
|
||||
nav.setAttribute('aria-label', 'Hauptnavigation');
|
||||
// Create the top-level menubar
|
||||
var topLevelUl = document.createElement('ul');
|
||||
topLevelUl.setAttribute('role', 'menubar');
|
||||
// Process each top-level menu item
|
||||
topLevelUl.className = 'mega-menu-top-level';
|
||||
this.menuItems.forEach(function (topLevelItem) {
|
||||
var topLevelLi = _this.createTopLevelItem(topLevelItem);
|
||||
topLevelUl.appendChild(topLevelLi);
|
||||
});
|
||||
// Only if current user has ManageWeb permissions in this website can they access the settings
|
||||
if (this.context.pageContext.web.permissions.hasPermission(SPPermission.manageWeb)) {
|
||||
topLevelUl.appendChild(this.createSettingsItem());
|
||||
}
|
||||
nav.appendChild(topLevelUl);
|
||||
container.appendChild(nav);
|
||||
// Attach accessibility event listeners after rendering
|
||||
this.attachEventListeners();
|
||||
this.createScreenReaderAnnouncer();
|
||||
};
|
||||
MegaMenuRenderer.prototype.createSettingsItem = function () {
|
||||
var _this = this;
|
||||
var li = document.createElement('li');
|
||||
li.setAttribute('role', 'none');
|
||||
// Verwenden eines Links-ähnlichen Buttons damit Styling identisch zu Top-Level Items ist
|
||||
var btn = document.createElement('button');
|
||||
btn.type = 'button';
|
||||
btn.className = 'menu-item-link menu-item-settings'; // reuse same base styles
|
||||
btn.setAttribute('role', 'menuitem');
|
||||
btn.setAttribute('tabindex', '0');
|
||||
btn.setAttribute('aria-haspopup', 'false');
|
||||
btn.setAttribute('aria-label', 'Einstellungen');
|
||||
btn.title = 'Einstellungen';
|
||||
// Nur EIN Icon: Wenn Fabric Icons geladen sind, zeigt ms-Icon das Symbol. Fallback via aria-label für Screenreader
|
||||
var icon = document.createElement('span');
|
||||
icon.className = 'ms-Icon ms-Icon--Settings menu-item-settings__icon';
|
||||
icon.setAttribute('aria-hidden', 'true');
|
||||
btn.appendChild(icon);
|
||||
btn.addEventListener('click', function () { return _this.openSettings(); });
|
||||
btn.addEventListener('keydown', function (e) {
|
||||
if (e.key === 'Enter' || e.key === ' ') {
|
||||
e.preventDefault();
|
||||
_this.openSettings();
|
||||
}
|
||||
});
|
||||
li.appendChild(btn);
|
||||
return li;
|
||||
};
|
||||
MegaMenuRenderer.prototype.openSettings = function () {
|
||||
if (!this._settingsPanel) {
|
||||
this._settingsPanel = new MegaMenuSettingsPanel(this.context, this.updateCallback);
|
||||
MegaMenuRenderer.prototype.dispose = function () {
|
||||
if (this._documentKeydownHandler) {
|
||||
document.removeEventListener('keydown', this._documentKeydownHandler);
|
||||
this._documentKeydownHandler = undefined;
|
||||
}
|
||||
this._settingsPanel.open();
|
||||
if (this._documentClickHandler) {
|
||||
document.removeEventListener('click', this._documentClickHandler);
|
||||
this._documentClickHandler = undefined;
|
||||
}
|
||||
if (this._announcer && this._announcer.parentElement) {
|
||||
this._announcer.parentElement.removeChild(this._announcer);
|
||||
}
|
||||
this._announcer = undefined;
|
||||
if (this._container) {
|
||||
this._container.innerHTML = '';
|
||||
}
|
||||
this._container = undefined;
|
||||
};
|
||||
// Panel logic moved to MegaMenuSettingsPanel
|
||||
MegaMenuRenderer.prototype.createTopLevelItem = function (item) {
|
||||
var li = document.createElement('li');
|
||||
li.setAttribute('role', 'none');
|
||||
// Create the top-level element (link or span)
|
||||
var topElement = this.createTopLevelElement(item);
|
||||
var hasChildren = item.hasChildren() && item.items && item.items.length > 0;
|
||||
var isActive = this.isItemActive(item);
|
||||
var isCurrent = this.isCurrentUrl(item.url);
|
||||
li.className = this.joinClasses('mega-menu-top-item', hasChildren ? 'has-children' : undefined, isActive ? 'is-active' : undefined, isCurrent ? 'is-current' : undefined);
|
||||
var topElement = this.createTopLevelElement(item, hasChildren, isActive, isCurrent);
|
||||
li.appendChild(topElement);
|
||||
// If the item has children, create the mega menu
|
||||
if (item.hasChildren() && item.items && item.items.length > 0) {
|
||||
if (hasChildren) {
|
||||
var megaMenu = this.createMegaMenu(item);
|
||||
li.appendChild(megaMenu);
|
||||
}
|
||||
return li;
|
||||
};
|
||||
MegaMenuRenderer.prototype.createTopLevelElement = function (item) {
|
||||
MegaMenuRenderer.prototype.createTopLevelElement = function (item, hasChildren, isActive, isCurrent) {
|
||||
var element;
|
||||
if (item.url) {
|
||||
// Create as link
|
||||
element = document.createElement('a');
|
||||
element.href = item.url;
|
||||
element.className = 'menu-item-link';
|
||||
}
|
||||
else {
|
||||
// Create as span (no link)
|
||||
element = document.createElement('span');
|
||||
element.className = 'menu-item-text';
|
||||
element.setAttribute('tabindex', '0');
|
||||
}
|
||||
element.setAttribute('role', 'menuitem');
|
||||
element.setAttribute('aria-haspopup', 'true');
|
||||
element.setAttribute('aria-expanded', 'false');
|
||||
element.textContent = item.label;
|
||||
element.className = this.joinClasses(element.className, hasChildren ? 'menu-item-has-children' : undefined, isActive ? 'is-active' : undefined, isCurrent ? 'is-current' : undefined);
|
||||
if (hasChildren) {
|
||||
element.setAttribute('aria-haspopup', 'true');
|
||||
element.setAttribute('aria-expanded', 'false');
|
||||
}
|
||||
if (isCurrent && item.url) {
|
||||
element.setAttribute('aria-current', 'page');
|
||||
}
|
||||
if (item.hoverText) {
|
||||
element.title = item.hoverText;
|
||||
}
|
||||
@@ -114,11 +93,11 @@ var MegaMenuRenderer = (function () {
|
||||
var _this = this;
|
||||
var megaMenuDiv = document.createElement('div');
|
||||
megaMenuDiv.className = 'mega-menu';
|
||||
megaMenuDiv.setAttribute('role', 'menu');
|
||||
megaMenuDiv.setAttribute('aria-label', parentItem.label + " Unterkategorien");
|
||||
megaMenuDiv.setAttribute('aria-expanded', 'false');
|
||||
megaMenuDiv.setAttribute('aria-label', parentItem.label + ' Unterkategorien');
|
||||
var gridDiv = document.createElement('div');
|
||||
gridDiv.className = 'mega-menu-grid';
|
||||
// Process second-level items (categories)
|
||||
gridDiv.style.setProperty('--megaMenuColumnCount', this.getColumnCount(parentItem.items));
|
||||
if (parentItem.items) {
|
||||
parentItem.items.forEach(function (secondLevelItem) {
|
||||
var categoryDiv = _this.createCategorySection(secondLevelItem);
|
||||
@@ -129,38 +108,51 @@ var MegaMenuRenderer = (function () {
|
||||
return megaMenuDiv;
|
||||
};
|
||||
MegaMenuRenderer.prototype.createCategorySection = function (item) {
|
||||
var _this = this;
|
||||
var categoryDiv = document.createElement('div');
|
||||
categoryDiv.className = 'mega-menu-category';
|
||||
// Create the category header (h3)
|
||||
var isActive = this.isItemActive(item);
|
||||
var isCurrent = this.isCurrentUrl(item.url);
|
||||
categoryDiv.className = this.joinClasses('mega-menu-category', isActive ? 'is-active' : undefined, isCurrent ? 'is-current' : undefined);
|
||||
var h3 = document.createElement('h3');
|
||||
h3.className = 'mega-menu-category-title';
|
||||
if (item.url) {
|
||||
// Category header as link
|
||||
var link = document.createElement('a');
|
||||
link.href = item.url;
|
||||
link.textContent = item.label;
|
||||
link.className = this.joinClasses(isActive ? 'is-active' : undefined, isCurrent ? 'is-current' : undefined);
|
||||
if (isCurrent) {
|
||||
link.setAttribute('aria-current', 'page');
|
||||
}
|
||||
if (item.hoverText) {
|
||||
link.title = item.hoverText;
|
||||
}
|
||||
h3.appendChild(link);
|
||||
}
|
||||
else {
|
||||
// Category header as span (no link)
|
||||
var span = document.createElement('span');
|
||||
span.textContent = item.label;
|
||||
span.className = this.joinClasses(isActive ? 'is-active' : undefined);
|
||||
if (item.hoverText) {
|
||||
span.title = item.hoverText;
|
||||
}
|
||||
h3.appendChild(span);
|
||||
}
|
||||
categoryDiv.appendChild(h3);
|
||||
// Create the third-level items list if they exist
|
||||
if (item.hasChildren() && item.items && item.items.length > 0) {
|
||||
var ul_1 = document.createElement('ul');
|
||||
ul_1.className = 'mega-menu-links';
|
||||
item.items.forEach(function (thirdLevelItem) {
|
||||
var li = document.createElement('li');
|
||||
var link = document.createElement('a');
|
||||
var isLinkActive = _this.isItemActive(thirdLevelItem);
|
||||
var isLinkCurrent = _this.isCurrentUrl(thirdLevelItem.url);
|
||||
li.className = _this.joinClasses(isLinkActive ? 'is-active' : undefined, isLinkCurrent ? 'is-current' : undefined);
|
||||
link.href = thirdLevelItem.url || '#';
|
||||
link.textContent = thirdLevelItem.label;
|
||||
link.className = _this.joinClasses(isLinkActive ? 'is-active' : undefined, isLinkCurrent ? 'is-current' : undefined);
|
||||
if (isLinkCurrent && thirdLevelItem.url) {
|
||||
link.setAttribute('aria-current', 'page');
|
||||
}
|
||||
if (thirdLevelItem.hoverText) {
|
||||
link.title = thirdLevelItem.hoverText;
|
||||
}
|
||||
@@ -172,7 +164,7 @@ var MegaMenuRenderer = (function () {
|
||||
return categoryDiv;
|
||||
};
|
||||
MegaMenuRenderer.prototype.attachEventListeners = function () {
|
||||
var headings = document.querySelectorAll('#Mega-Menu > ul > li > a, #Mega-Menu > ul > li > span[role="menuitem"]');
|
||||
var headings = document.querySelectorAll('#Mega-Menu > ul > li > a, #Mega-Menu > ul > li > .menu-item-text');
|
||||
for (var i = 0; i < headings.length; i++) {
|
||||
var heading = headings[i];
|
||||
var megaMenu = heading.nextElementSibling;
|
||||
@@ -182,86 +174,101 @@ var MegaMenuRenderer = (function () {
|
||||
this.attachFocusManagement(heading, megaMenu);
|
||||
}
|
||||
}
|
||||
// Global keyboard navigation
|
||||
this.attachGlobalKeyboardNavigation();
|
||||
this.attachGlobalClickOutsideHandler();
|
||||
};
|
||||
MegaMenuRenderer.prototype.attachKeyboardNavigation = function (heading, megaMenu) {
|
||||
var _this = this;
|
||||
heading.addEventListener('keydown', function (e) {
|
||||
if (e.key === 'Enter') {
|
||||
// Enter: Navigation (nur bei Links ohne Mega-Menu-Override)
|
||||
if (heading.tagName === 'A') {
|
||||
// Lasse normale Link-Navigation zu (KEIN preventDefault!)
|
||||
return;
|
||||
}
|
||||
else {
|
||||
// Bei span: Toggle Menu
|
||||
e.preventDefault();
|
||||
_this.toggleMegaMenu(heading, megaMenu);
|
||||
}
|
||||
e.preventDefault();
|
||||
_this.toggleMegaMenu(heading, megaMenu);
|
||||
}
|
||||
else if (e.key === ' ') {
|
||||
// Space: Toggle Dropdown (immer)
|
||||
e.preventDefault();
|
||||
_this.toggleMegaMenu(heading, megaMenu);
|
||||
}
|
||||
else if (e.key === 'ArrowDown') {
|
||||
// Pfeil runter: Menü öffnen + erster Link
|
||||
e.preventDefault();
|
||||
_this.openMegaMenu(heading, megaMenu);
|
||||
_this.focusFirstLink(megaMenu);
|
||||
}
|
||||
else if (e.key === 'ArrowUp') {
|
||||
// Pfeil hoch: Menü schließen
|
||||
e.preventDefault();
|
||||
_this.closeMegaMenu(heading, megaMenu);
|
||||
}
|
||||
else if (e.key === 'Escape') {
|
||||
// Escape: Menü schließen
|
||||
e.preventDefault();
|
||||
_this.closeMegaMenu(heading, megaMenu);
|
||||
heading.focus();
|
||||
}
|
||||
});
|
||||
// Click Event für Top-Level Links - NORMALE Navigation erlauben
|
||||
if (heading.tagName === 'A') {
|
||||
heading.addEventListener('click', function (e) {
|
||||
// Links sollen normal navigieren, nicht das Mega-Menu toglen
|
||||
// Wenn der User das Menu öffnen will, soll er Space oder Pfeil↓ nutzen
|
||||
console.log('Link geklickt:', heading.href);
|
||||
// KEIN preventDefault() - normale Link-Navigation
|
||||
heading.addEventListener('click', function () {
|
||||
debugLog(_this.debug, LOG_SOURCE, 'Link clicked:', heading.href);
|
||||
});
|
||||
}
|
||||
// Focus Management - KEIN automatisches Öffnen oder Schließen
|
||||
heading.addEventListener('focus', function () {
|
||||
console.log('Focus auf:', heading.textContent);
|
||||
// Einfach nur fokussiert - keine automatischen Aktionen!
|
||||
debugLog(_this.debug, LOG_SOURCE, 'Focus moved to:', heading.textContent);
|
||||
});
|
||||
};
|
||||
MegaMenuRenderer.prototype.attachMouseEvents = function (heading, megaMenu) {
|
||||
var _this = this;
|
||||
var parentLi = heading.parentElement;
|
||||
var openTimeout;
|
||||
var closeTimeout;
|
||||
var clearOpenTimeout = function () {
|
||||
if (typeof openTimeout === 'number') {
|
||||
window.clearTimeout(openTimeout);
|
||||
openTimeout = undefined;
|
||||
}
|
||||
};
|
||||
var clearCloseTimeout = function () {
|
||||
if (typeof closeTimeout === 'number') {
|
||||
window.clearTimeout(closeTimeout);
|
||||
closeTimeout = undefined;
|
||||
}
|
||||
};
|
||||
parentLi.addEventListener('mouseenter', function () {
|
||||
_this.openMegaMenu(heading, megaMenu);
|
||||
clearCloseTimeout();
|
||||
if (megaMenu.classList.contains('js-open')) {
|
||||
return;
|
||||
}
|
||||
clearOpenTimeout();
|
||||
openTimeout = window.setTimeout(function () {
|
||||
_this.openMegaMenu(heading, megaMenu);
|
||||
openTimeout = undefined;
|
||||
}, MegaMenuRenderer.hoverOpenDelayMs);
|
||||
});
|
||||
parentLi.addEventListener('mouseleave', function () {
|
||||
_this.closeMegaMenu(heading, megaMenu);
|
||||
clearOpenTimeout();
|
||||
clearCloseTimeout();
|
||||
closeTimeout = window.setTimeout(function () {
|
||||
_this.closeMegaMenu(heading, megaMenu);
|
||||
closeTimeout = undefined;
|
||||
}, MegaMenuRenderer.hoverCloseDelayMs);
|
||||
});
|
||||
heading.addEventListener('focus', function () {
|
||||
clearCloseTimeout();
|
||||
});
|
||||
megaMenu.addEventListener('mouseenter', function () {
|
||||
clearCloseTimeout();
|
||||
});
|
||||
};
|
||||
MegaMenuRenderer.prototype.attachFocusManagement = function (heading, megaMenu) {
|
||||
var _this = this;
|
||||
// Focus-Verlust-Behandlung - vereinfacht
|
||||
megaMenu.addEventListener('focusout', function (e) {
|
||||
// Kurz warten, um zu prüfen ob Focus innerhalb des Mega-Menus bleibt
|
||||
megaMenu.addEventListener('focusout', function () {
|
||||
setTimeout(function () {
|
||||
var focusedElement = document.activeElement;
|
||||
var isInsideThisMenu = megaMenu.contains(focusedElement);
|
||||
var isOnThisTrigger = focusedElement === heading;
|
||||
var isInAnyMegaMenu = focusedElement.closest('.mega-menu');
|
||||
var isOnAnyTopLevel = focusedElement.closest('#Mega-Menu > ul > li > a, #Mega-Menu > ul > li > span');
|
||||
// Nur schließen wenn Focus komplett außerhalb der Navigation ist
|
||||
if (!isInsideThisMenu && !isOnThisTrigger && !isInAnyMegaMenu && !isOnAnyTopLevel) {
|
||||
console.log('Schließe Menu wegen Focus-Verlust');
|
||||
debugLog(_this.debug, LOG_SOURCE, 'Closing menu because focus left the navigation.');
|
||||
_this.closeMegaMenu(heading, megaMenu);
|
||||
}
|
||||
}, 150);
|
||||
@@ -269,7 +276,7 @@ var MegaMenuRenderer = (function () {
|
||||
};
|
||||
MegaMenuRenderer.prototype.attachGlobalKeyboardNavigation = function () {
|
||||
var _this = this;
|
||||
document.addEventListener('keydown', function (e) {
|
||||
this._documentKeydownHandler = function (e) {
|
||||
var activeElement = document.activeElement;
|
||||
if (e.key === 'Escape') {
|
||||
var openMenu = document.querySelector('.mega-menu[aria-expanded="true"]');
|
||||
@@ -279,16 +286,13 @@ var MegaMenuRenderer = (function () {
|
||||
triggerLink.focus();
|
||||
}
|
||||
}
|
||||
// Tab-Navigation: Nur bei spezifischen Übergängen eingreifen
|
||||
if (e.key === 'Tab') {
|
||||
// Von Top-Level zum ersten Link im offenen Menu
|
||||
if (!e.shiftKey) {
|
||||
var currentTopLevel = activeElement.closest('#Mega-Menu > ul > li > a, #Mega-Menu > ul > li > span');
|
||||
if (currentTopLevel) {
|
||||
var parentLi = currentTopLevel.closest('li');
|
||||
var megaMenu = parentLi.querySelector('.mega-menu.js-open');
|
||||
if (megaMenu) {
|
||||
// Nur eingreifen wenn wir vom Trigger weg-tabben
|
||||
e.preventDefault();
|
||||
var firstLink = megaMenu.querySelector('a');
|
||||
if (firstLink) {
|
||||
@@ -298,13 +302,11 @@ var MegaMenuRenderer = (function () {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Shift+Tab: Vom ersten Link im Menu zurück zum Trigger
|
||||
if (e.shiftKey) {
|
||||
var megaMenu = activeElement.closest('.mega-menu');
|
||||
if (megaMenu && megaMenu.classList.contains('js-open')) {
|
||||
var allLinksInMenu = megaMenu.querySelectorAll('a');
|
||||
var firstLinkInMenu = allLinksInMenu[0];
|
||||
// Nur eingreifen wenn wir beim ersten Link sind
|
||||
if (activeElement === firstLinkInMenu) {
|
||||
e.preventDefault();
|
||||
var triggerElement = megaMenu.previousElementSibling;
|
||||
@@ -313,21 +315,41 @@ var MegaMenuRenderer = (function () {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Ansonsten: Normale Tab-Navigation nicht unterbrechen!
|
||||
}
|
||||
});
|
||||
};
|
||||
document.addEventListener('keydown', this._documentKeydownHandler);
|
||||
};
|
||||
MegaMenuRenderer.prototype.attachGlobalClickOutsideHandler = function () {
|
||||
var _this = this;
|
||||
this._documentClickHandler = function (e) {
|
||||
var eventTarget = e.target;
|
||||
var isInsideNavigation = !!(eventTarget && typeof eventTarget.closest === 'function' &&
|
||||
eventTarget.closest('#CustomNavigation'));
|
||||
if (isInsideNavigation) {
|
||||
return;
|
||||
}
|
||||
var openMenu = document.querySelector('.mega-menu.js-open');
|
||||
if (openMenu) {
|
||||
debugLog(_this.debug, LOG_SOURCE, 'Closing menu because of outside click.');
|
||||
_this.closeAllMegaMenus();
|
||||
}
|
||||
};
|
||||
document.addEventListener('click', this._documentClickHandler);
|
||||
};
|
||||
MegaMenuRenderer.prototype.openMegaMenu = function (trigger, menu) {
|
||||
this.closeAllMegaMenus(menu);
|
||||
trigger.setAttribute('aria-expanded', 'true');
|
||||
menu.setAttribute('aria-expanded', 'true');
|
||||
menu.classList.add('js-open');
|
||||
console.log('Menu geöffnet:', trigger.textContent);
|
||||
this.announce((trigger.textContent || '') + ' geöffnet');
|
||||
debugLog(this.debug, LOG_SOURCE, 'Menu opened:', trigger.textContent);
|
||||
};
|
||||
MegaMenuRenderer.prototype.closeMegaMenu = function (trigger, menu) {
|
||||
trigger.setAttribute('aria-expanded', 'false');
|
||||
menu.setAttribute('aria-expanded', 'false');
|
||||
menu.classList.remove('js-open');
|
||||
console.log('Menu geschlossen:', trigger.textContent);
|
||||
this.announce((trigger.textContent || '') + ' geschlossen');
|
||||
debugLog(this.debug, LOG_SOURCE, 'Menu closed:', trigger.textContent);
|
||||
};
|
||||
MegaMenuRenderer.prototype.toggleMegaMenu = function (trigger, menu) {
|
||||
var isOpen = trigger.getAttribute('aria-expanded') === 'true';
|
||||
@@ -335,36 +357,112 @@ var MegaMenuRenderer = (function () {
|
||||
this.closeMegaMenu(trigger, menu);
|
||||
}
|
||||
else {
|
||||
this.closeAllMegaMenus();
|
||||
this.openMegaMenu(trigger, menu);
|
||||
}
|
||||
};
|
||||
MegaMenuRenderer.prototype.closeAllMegaMenus = function () {
|
||||
MegaMenuRenderer.prototype.closeAllMegaMenus = function (exceptMenu) {
|
||||
var allTriggers = document.querySelectorAll('#Mega-Menu > ul > li > a[aria-expanded="true"], #Mega-Menu > ul > li > span[aria-expanded="true"]');
|
||||
for (var i = 0; i < allTriggers.length; i++) {
|
||||
var trigger = allTriggers[i];
|
||||
var menu = trigger.nextElementSibling;
|
||||
if (menu) {
|
||||
if (menu && menu !== exceptMenu) {
|
||||
this.closeMegaMenu(trigger, menu);
|
||||
}
|
||||
}
|
||||
};
|
||||
// removed unused closeOtherMegaMenus (was previously declared but not used)
|
||||
MegaMenuRenderer.prototype.focusFirstLink = function (megaMenu) {
|
||||
var firstLink = megaMenu.querySelector('a');
|
||||
if (firstLink) {
|
||||
firstLink.focus();
|
||||
}
|
||||
};
|
||||
MegaMenuRenderer.prototype.isItemActive = function (item) {
|
||||
if (this.isCurrentUrl(item.url)) {
|
||||
return true;
|
||||
}
|
||||
if (!item.items || item.items.length === 0) {
|
||||
return false;
|
||||
}
|
||||
for (var i = 0; i < item.items.length; i++) {
|
||||
if (this.isItemActive(item.items[i])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
MegaMenuRenderer.prototype.isCurrentUrl = function (url) {
|
||||
var currentPath = this.normalizePath(window.location.href);
|
||||
var itemPath = this.normalizePath(url);
|
||||
if (!currentPath || !itemPath) {
|
||||
return false;
|
||||
}
|
||||
if (itemPath === '/') {
|
||||
return currentPath === '/';
|
||||
}
|
||||
if (currentPath === itemPath) {
|
||||
return true;
|
||||
}
|
||||
return currentPath.indexOf(itemPath + '/') === 0;
|
||||
};
|
||||
MegaMenuRenderer.prototype.normalizePath = function (url) {
|
||||
if (!url) {
|
||||
return '';
|
||||
}
|
||||
try {
|
||||
var parsedUrl = new URL(url, window.location.origin);
|
||||
var pathname = (parsedUrl.pathname || '/').replace(/\/+$/, '');
|
||||
return (pathname || '/').toLowerCase();
|
||||
}
|
||||
catch (error) {
|
||||
return '';
|
||||
}
|
||||
};
|
||||
MegaMenuRenderer.prototype.getColumnCount = function (items) {
|
||||
var itemCount = items ? items.length : 0;
|
||||
var columnCount = Math.min(Math.max(itemCount, 1), 4);
|
||||
return columnCount.toString();
|
||||
};
|
||||
MegaMenuRenderer.prototype.joinClasses = function () {
|
||||
var classNames = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
classNames[_i] = arguments[_i];
|
||||
}
|
||||
var filteredClassNames = [];
|
||||
for (var i = 0; i < classNames.length; i++) {
|
||||
if (classNames[i]) {
|
||||
filteredClassNames.push(classNames[i]);
|
||||
}
|
||||
}
|
||||
return filteredClassNames.join(' ');
|
||||
};
|
||||
MegaMenuRenderer.prototype.createScreenReaderAnnouncer = function () {
|
||||
// Screenreader-Ankündigungen
|
||||
var existingAnnouncer = document.getElementById('mega-menu-sr-announcer');
|
||||
if (existingAnnouncer) {
|
||||
this._announcer = existingAnnouncer;
|
||||
return;
|
||||
}
|
||||
var srAnnouncer = document.createElement('div');
|
||||
srAnnouncer.id = 'mega-menu-sr-announcer';
|
||||
srAnnouncer.setAttribute('aria-live', 'polite');
|
||||
srAnnouncer.setAttribute('aria-atomic', 'true');
|
||||
srAnnouncer.className = 'sr-only';
|
||||
document.body.appendChild(srAnnouncer);
|
||||
console.log('Screenreader-Ankündigungen sind jetzt bereit');
|
||||
this._announcer = srAnnouncer;
|
||||
debugLog(this.debug, LOG_SOURCE, 'Screen reader announcer is ready.');
|
||||
};
|
||||
MegaMenuRenderer.prototype.announce = function (message) {
|
||||
var _this = this;
|
||||
if (this._announcer) {
|
||||
this._announcer.textContent = '';
|
||||
window.setTimeout(function () {
|
||||
if (_this._announcer) {
|
||||
_this._announcer.textContent = message;
|
||||
}
|
||||
}, 20);
|
||||
}
|
||||
};
|
||||
MegaMenuRenderer.hoverOpenDelayMs = 140;
|
||||
MegaMenuRenderer.hoverCloseDelayMs = 180;
|
||||
return MegaMenuRenderer;
|
||||
}());
|
||||
export { MegaMenuRenderer };
|
||||
|
||||
File diff suppressed because one or more lines are too long
25
lib/extensions/megaMenu/MegaMenuSettings.d.ts
vendored
25
lib/extensions/megaMenu/MegaMenuSettings.d.ts
vendored
@@ -1,25 +0,0 @@
|
||||
import { ApplicationCustomizerContext } from '@microsoft/sp-application-base';
|
||||
import { IMegaMenuApplicationCustomizerProperties } from './MegaMenuApplicationCustomizer';
|
||||
export declare class MegaMenuSettingsPanel {
|
||||
private context;
|
||||
private dataUpdated;
|
||||
private _service;
|
||||
private _ucaId;
|
||||
private _panelElement;
|
||||
private _overlayElement;
|
||||
constructor(context: ApplicationCustomizerContext, dataUpdated: (data: IMegaMenuApplicationCustomizerProperties) => void);
|
||||
open(): Promise<void>;
|
||||
close(): void;
|
||||
private readApplicationCustomizerProps();
|
||||
private saveApplicationCustomizerProps(componentProps);
|
||||
private _createPanel(props);
|
||||
private _getMarkup(termSet, cssUrl);
|
||||
private _save();
|
||||
/**
|
||||
* Hält den Fokus innerhalb des Settings-Panels gefangen (Focus Trapping).
|
||||
* Wichtig für Accessibility: Verhindert, dass Tab-Navigation aus dem modalen Dialog herausführt.
|
||||
* Bei Tab am letzten Element → springt zum ersten, bei Shift+Tab am ersten → springt zum letzten.
|
||||
*/
|
||||
private _trapFocus(e);
|
||||
private _escape(value);
|
||||
}
|
||||
@@ -1,223 +0,0 @@
|
||||
// tslint:disable:max-line-length export-name
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [0, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
import { UserCustomActionMegaMenuId } from './MegaMenuApplicationCustomizer';
|
||||
import { UserCustomActionService } from '../../services/UserCustomActionService/UserCustomActionService';
|
||||
import { UserCustomActionScope } from '../../services/UserCustomActionService/UserCustomActionScope';
|
||||
var MegaMenuSettingsPanel = (function () {
|
||||
function MegaMenuSettingsPanel(context, dataUpdated) {
|
||||
this.context = context;
|
||||
this.dataUpdated = dataUpdated;
|
||||
this._panelElement = undefined;
|
||||
this._overlayElement = undefined;
|
||||
this._service = new UserCustomActionService(this.context);
|
||||
}
|
||||
MegaMenuSettingsPanel.prototype.open = function () {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var currentProps;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
if (this._panelElement) {
|
||||
return [2 /*return*/];
|
||||
}
|
||||
return [4 /*yield*/, this.readApplicationCustomizerProps()];
|
||||
case 1:
|
||||
currentProps = _a.sent();
|
||||
this._createPanel(currentProps);
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
MegaMenuSettingsPanel.prototype.close = function () {
|
||||
if (this._panelElement) {
|
||||
this._panelElement.remove();
|
||||
this._panelElement = undefined;
|
||||
}
|
||||
if (this._overlayElement) {
|
||||
this._overlayElement.remove();
|
||||
this._overlayElement = undefined;
|
||||
}
|
||||
// Fokus entfernen (kein sichtbarer Fokus-Rahmen nach Dialog-Schließung)
|
||||
document.body.focus();
|
||||
document.body.blur();
|
||||
};
|
||||
MegaMenuSettingsPanel.prototype.readApplicationCustomizerProps = function () {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var ucas, candidates, uca;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, this._service.getUserCustomActions(UserCustomActionScope.Site)];
|
||||
case 1:
|
||||
ucas = _a.sent();
|
||||
candidates = ucas.filter(function (uca) { return uca.ClientSideComponentId === UserCustomActionMegaMenuId; });
|
||||
if (candidates.length) {
|
||||
uca = candidates[0];
|
||||
this._ucaId = uca.Id;
|
||||
return [2 /*return*/, JSON.parse(uca.ClientSideComponentProperties)];
|
||||
}
|
||||
else {
|
||||
console.error('UserCustomAction für das Megamenü nicht gefunden. Alles ist sinnlos.');
|
||||
return [2 /*return*/, {
|
||||
termSetName: '',
|
||||
cssUrl: ''
|
||||
}];
|
||||
}
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
MegaMenuSettingsPanel.prototype.saveApplicationCustomizerProps = function (componentProps) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var newUserCustomActionsProperty, e_1;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
_a.trys.push([0, 2, , 3]);
|
||||
newUserCustomActionsProperty = {
|
||||
ClientSideComponentProperties: JSON.stringify(componentProps)
|
||||
};
|
||||
return [4 /*yield*/, this._service.updateUserCustomAction(UserCustomActionScope.Site, this._ucaId, newUserCustomActionsProperty)];
|
||||
case 1:
|
||||
_a.sent();
|
||||
this.dataUpdated(componentProps);
|
||||
return [3 /*break*/, 3];
|
||||
case 2:
|
||||
e_1 = _a.sent();
|
||||
console.error(e_1);
|
||||
return [3 /*break*/, 3];
|
||||
case 3: return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
MegaMenuSettingsPanel.prototype._createPanel = function (props) {
|
||||
var _this = this;
|
||||
var overlay = document.createElement('div');
|
||||
overlay.className = 'mm-settings-overlay';
|
||||
overlay.tabIndex = -1;
|
||||
overlay.onclick = function () { return _this.close(); };
|
||||
this._overlayElement = overlay;
|
||||
var panel = document.createElement('div');
|
||||
panel.className = 'mm-settings-panel';
|
||||
panel.setAttribute('role', 'dialog');
|
||||
panel.setAttribute('aria-modal', 'true');
|
||||
panel.setAttribute('aria-label', 'MegaMenu Einstellungen');
|
||||
panel.innerHTML = this._getMarkup(props.termSetName, props.cssUrl);
|
||||
this._panelElement = panel;
|
||||
document.body.appendChild(overlay);
|
||||
document.body.appendChild(panel);
|
||||
var closeBtn = panel.querySelector('.mm-settings-close');
|
||||
var cancelBtn = panel.querySelector('.mm-settings-cancel');
|
||||
var saveBtn = panel.querySelector('.mm-settings-save');
|
||||
var firstInput = panel.querySelector('#mm-setting-termset');
|
||||
if (closeBtn) {
|
||||
closeBtn.onclick = function () { return _this.close(); };
|
||||
}
|
||||
if (cancelBtn) {
|
||||
cancelBtn.onclick = function () { return _this.close(); };
|
||||
}
|
||||
if (saveBtn) {
|
||||
saveBtn.onclick = function () { return _this._save(); };
|
||||
}
|
||||
panel.addEventListener('keydown', function (e) {
|
||||
if (e.key === 'Escape') {
|
||||
e.preventDefault();
|
||||
_this.close();
|
||||
}
|
||||
else if (e.key === 'Tab') {
|
||||
_this._trapFocus(e);
|
||||
}
|
||||
});
|
||||
setTimeout(function () { if (firstInput) {
|
||||
firstInput.focus();
|
||||
} }, 0);
|
||||
};
|
||||
MegaMenuSettingsPanel.prototype._getMarkup = function (termSet, cssUrl) {
|
||||
return "<div class='mm-settings-header'>\n <h2 class='mm-settings-title'>Einstellungen</h2>\n <button type='button' class='mm-settings-close' aria-label='Schlie\u00DFen'>\u00D7</button>\n </div>\n <div class='mm-settings-body'>\n <div class='mm-settings-field'>\n <label for='mm-setting-termset'>Name des Navigations-Termsets</label>\n <input id='mm-setting-termset' type='text' value='" + this._escape(termSet) + "' />\n </div>\n <div class='mm-settings-field'>\n <label for='mm-setting-css'>Pfad zu zus\u00E4tzlicher CSS-Datei</label>\n <input id='mm-setting-css' type='text' value='" + this._escape(cssUrl) + "' />\n </div>\n </div>\n <div class='mm-settings-footer'>\n <button type='button' class='mm-settings-save ms-Button ms-Button--primary'><span>Speichern</span></button>\n <button type='button' class='mm-settings-cancel ms-Button'><span>Abbrechen</span></button>\n </div>";
|
||||
};
|
||||
MegaMenuSettingsPanel.prototype._save = function () {
|
||||
if (!this._panelElement) {
|
||||
return;
|
||||
}
|
||||
var termSetInput = this._panelElement.querySelector('#mm-setting-termset');
|
||||
var cssInput = this._panelElement.querySelector('#mm-setting-css');
|
||||
this.saveApplicationCustomizerProps({
|
||||
termSetName: termSetInput && termSetInput.value ? termSetInput.value : '',
|
||||
cssUrl: cssInput && cssInput.value ? cssInput.value : ''
|
||||
});
|
||||
this.close();
|
||||
};
|
||||
/**
|
||||
* Hält den Fokus innerhalb des Settings-Panels gefangen (Focus Trapping).
|
||||
* Wichtig für Accessibility: Verhindert, dass Tab-Navigation aus dem modalen Dialog herausführt.
|
||||
* Bei Tab am letzten Element → springt zum ersten, bei Shift+Tab am ersten → springt zum letzten.
|
||||
*/
|
||||
MegaMenuSettingsPanel.prototype._trapFocus = function (e) {
|
||||
if (!this._panelElement) {
|
||||
return;
|
||||
}
|
||||
var focusable = this._panelElement.querySelectorAll('button, input');
|
||||
if (!focusable || focusable.length === 0) {
|
||||
return;
|
||||
}
|
||||
var first = focusable[0];
|
||||
var last = focusable[focusable.length - 1];
|
||||
var active = document.activeElement;
|
||||
if (e.shiftKey && active === first) {
|
||||
e.preventDefault();
|
||||
last.focus();
|
||||
}
|
||||
else if (!e.shiftKey && active === last) {
|
||||
e.preventDefault();
|
||||
first.focus();
|
||||
}
|
||||
};
|
||||
MegaMenuSettingsPanel.prototype._escape = function (value) {
|
||||
if (value) {
|
||||
return value.replace(/&/g, '&').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>');
|
||||
}
|
||||
else {
|
||||
return '';
|
||||
}
|
||||
};
|
||||
return MegaMenuSettingsPanel;
|
||||
}());
|
||||
export { MegaMenuSettingsPanel };
|
||||
|
||||
//# sourceMappingURL=MegaMenuSettings.js.map
|
||||
File diff suppressed because one or more lines are too long
@@ -1,5 +1,7 @@
|
||||
define([], function() {
|
||||
return {
|
||||
"Title": "MegaMenuApplicationCustomizer"
|
||||
"Title": "MegaMenuApplicationCustomizer",
|
||||
"ConfigurationMissing": "Navigation is not configured.",
|
||||
"LoadError": "Navigation could not be loaded."
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user