Skip to content

Commit

Permalink
update mmenu to 8.3.0, add columns, add polyfill option (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
mirkogleibe authored and fritzmg committed Sep 17, 2019
1 parent 17b12cb commit 3f49fc0
Show file tree
Hide file tree
Showing 112 changed files with 2,673 additions and 1,244 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

### 3.1.0

* Updated mmenu to 8.3.0
* Added columns as option
* Added mmenu IE10 & IE11 Polyfill as option

### 3.0.0

* Updated mmenu to 8.1.1
Expand Down
9 changes: 9 additions & 0 deletions src/Helper/MmenuHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ public static function processModuleSettings(Module $module, string $jsTemplateN
$options['counters'] = true;
}

// https://mmenujs.com/documentation/addons/columns.html
if ($module->dk_mmenuColumnsAdd) {
$options['columns'] = true;
}

// https://mmenujs.com/documentation/addons/searchfield.html
if ($module->dk_mmenuSearchfieldAdd) {
$options['navbars'] = [
Expand Down Expand Up @@ -142,6 +147,10 @@ public static function processModuleSettings(Module $module, string $jsTemplateN
}
}

if ($module->dk_mmenuPolyfillEnable) {
$options['polyfill'] = true;
}

// https://mmenujs.com/documentation/addons/icon-panels.html
if ($module->dk_mmenuIconPanels) {
$options['iconPanels'] = true;
Expand Down
18 changes: 18 additions & 0 deletions src/Resources/contao/dca/tl_module.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@
'sql' => "char(1) NOT NULL default ''",
];

$GLOBALS['TL_DCA']['tl_module']['fields']['dk_mmenuColumnsAdd'] = [
'label' => &$GLOBALS['TL_LANG']['tl_module']['dk_mmenuColumnsAdd'],
'exclude' => true,
'inputType' => 'checkbox',
'eval' => ['tl_class' => 'w50'],
'sql' => "char(1) NOT NULL default ''",
];

$GLOBALS['TL_DCA']['tl_module']['fields']['dk_mmenuSearchfieldAdd'] = [
'label' => &$GLOBALS['TL_LANG']['tl_module']['dk_mmenuSearchfieldAdd'],
'exclude' => true,
Expand Down Expand Up @@ -162,6 +170,14 @@
'sql' => "smallint(5) NOT NULL default '100'",
];

$GLOBALS['TL_DCA']['tl_module']['fields']['dk_mmenuPolyfillEnable'] = [
'label' => &$GLOBALS['TL_LANG']['tl_module']['dk_mmenuPolyfillEnable'],
'exclude' => true,
'inputType' => 'checkbox',
'eval' => ['tl_class' => 'clr'],
'sql' => "char(1) NOT NULL default ''",
];

$GLOBALS['TL_DCA']['tl_module']['fields']['dk_mmenuOnClickClose'] = [
'label' => &$GLOBALS['TL_LANG']['tl_module']['dk_mmenuOnClickClose'],
'exclude' => true,
Expand Down Expand Up @@ -232,6 +248,7 @@
->addField('dk_mmenuPageDim', 'mmenu_appearance_legend', PaletteManipulator::POSITION_APPEND)
->addField('dk_mmenuFullscreen', 'mmenu_appearance_legend', PaletteManipulator::POSITION_APPEND)
->addField('dk_mmenuCountersAdd', 'mmenu_appearance_legend', PaletteManipulator::POSITION_APPEND)
->addField('dk_mmenuColumnsAdd', 'mmenu_appearance_legend', PaletteManipulator::POSITION_APPEND)
->addField('dk_mmenuSearchfieldAdd', 'mmenu_appearance_legend', PaletteManipulator::POSITION_APPEND)
->addField('dk_mmenuIconPanels', 'mmenu_appearance_legend', PaletteManipulator::POSITION_APPEND)

Expand All @@ -245,6 +262,7 @@
->addField('dk_mmenuOnClickClose', 'mmenu_behaviour_legend', PaletteManipulator::POSITION_APPEND)
->addField('dk_mmenuPageSelector', 'mmenu_behaviour_legend', PaletteManipulator::POSITION_APPEND)
->addField('dk_mmenuDragOpenEnable', 'mmenu_behaviour_legend', PaletteManipulator::POSITION_APPEND)
->addField('dk_mmenuPolyfillEnable', 'mmenu_behaviour_legend', PaletteManipulator::POSITION_APPEND)

->addField('dk_mmenuJsTpl', 'template_legend', PaletteManipulator::POSITION_APPEND)

Expand Down
16 changes: 16 additions & 0 deletions src/Resources/contao/languages/de/tl_module.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@
<trans-unit id="tl_module.dk_mmenuCountersUpdate.1">
<source>Determines whether or not to automatically count the number of items in the submenu, updates when typing in the search field.</source>
</trans-unit>
<trans-unit id="tl_module.dk_mmenuColumnsAdd.0">
<source>Show submenu columns</source>
<target>Spalten für Untermenüs</target>
</trans-unit>
<trans-unit id="tl_module.dk_mmenuColumnsAdd.1">
<source>Determines whether the panels should be split up into multiple columns.</source>
<target>Bestimmt, ob ein die Untermenüs in mehreren Spalten dargestellt werden soll.</target>
</trans-unit>
<trans-unit id="tl_module.dk_mmenuSearchfieldAdd.0">
<source>Show searchfield</source>
<target>Suchfeld anzeigen</target>
Expand All @@ -103,6 +111,14 @@
<source>Determines the minimum amount of pixels to drag before actually opening the menu, less than 50 is not advised.</source>
<target>Bestimmt die minimale Anzahl von Pixeln, die die Seite gezogen werden muß bis sich das Menü öffnet. Weniger als 50 Pixel werden nicht empfohlen.</target>
</trans-unit>
<trans-unit id="tl_module.dk_mmenuPolyfillEnable.0">
<source>Add JavaScript Polyfill</source>
<target>JavaScript Polyfill hinzufügen</target>
</trans-unit>
<trans-unit id="tl_module.dk_mmenuPolyfillEnable.1">
<source>Determines whether or not the IE10 and IE11 JavaScript Polyfill should be available.</source>
<target>Bestimmt, ob das JavaScript Polyfill für IE10 und IE11 zur Verfügung gestellt wird.</target>
</trans-unit>
<trans-unit id="tl_module.dk_mmenuOnClickClose.0">
<source>Menu closes after click</source>
<target>Menü nach Klick schließen</target>
Expand Down
6 changes: 4 additions & 2 deletions src/Resources/contao/languages/en/tl_module.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,19 @@
$GLOBALS['TL_LANG']['tl_module']['dk_mmenuFullscreen'][1] = 'Determines whether the menu will fill up 80% (default) of the available width/height or 100% (fullscreen).';
$GLOBALS['TL_LANG']['tl_module']['dk_mmenuCountersAdd'][0] = 'Show submenu counter';
$GLOBALS['TL_LANG']['tl_module']['dk_mmenuCountersAdd'][1] = 'Determines whether or not to append a counter to each menu item if it has a submenu and automatically counting the number of items inside.';
$GLOBALS['TL_LANG']['tl_module']['dk_mmenuCountersAdd'][0] = 'Show submenu counter';
$GLOBALS['TL_LANG']['tl_module']['dk_mmenuCountersAdd'][1] = 'Determines whether or not to append a counter to each menu item if it has a submenu and automatically counting the number of items inside.';
$GLOBALS['TL_LANG']['tl_module']['dk_mmenuCountersUpdate'][0] = 'Update submenu counter';
$GLOBALS['TL_LANG']['tl_module']['dk_mmenuCountersUpdate'][1] = 'Determines whether or not to automatically count the number of items in the submenu, updates when typing in the search field.';
$GLOBALS['TL_LANG']['tl_module']['dk_mmenuColumnsAdd'][0] = 'Show submenu columns';
$GLOBALS['TL_LANG']['tl_module']['dk_mmenuColumnsAdd'][1] = 'Determines whether the panels should be split up into multiple columns.';
$GLOBALS['TL_LANG']['tl_module']['dk_mmenuSearchfieldAdd'][0] = 'Show searchfield';
$GLOBALS['TL_LANG']['tl_module']['dk_mmenuSearchfieldAdd'][1] = 'Determines whether or not to automatically prepend a searchfield to the menu.';

$GLOBALS['TL_LANG']['tl_module']['dk_mmenuDragOpenEnable'][0] = 'Drag page to open menu';
$GLOBALS['TL_LANG']['tl_module']['dk_mmenuDragOpenEnable'][1] = 'Determines whether or not the menu should open when dragging the page.';
$GLOBALS['TL_LANG']['tl_module']['dk_mmenuDragOpenThreshold'][0] = 'Amount of pixels to drag';
$GLOBALS['TL_LANG']['tl_module']['dk_mmenuDragOpenThreshold'][1] = 'Determines the minimum amount of pixels to drag before actually opening the menu, less than 50 is not advised.';
$GLOBALS['TL_LANG']['tl_module']['dk_mmenuPolyfillEnable'][0] = 'Add JavaScript Polyfill';
$GLOBALS['TL_LANG']['tl_module']['dk_mmenuPolyfillEnable'][1] = 'Determines whether or not the IE10 and IE11 JavaScript Polyfill should be available.';
$GLOBALS['TL_LANG']['tl_module']['dk_mmenuOnClickClose'][0] = 'Menu closes after click';
$GLOBALS['TL_LANG']['tl_module']['dk_mmenuOnClickClose'][1] = 'Determines whether or not the menu should close after clicking a link inside it.';
$GLOBALS['TL_LANG']['tl_module']['dk_mmenuFixedElementAdd'][0] = 'Support fixed and sticky elements';
Expand Down
19 changes: 11 additions & 8 deletions src/Resources/contao/templates/js_mmenu.html5
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
<?php

$GLOBALS['TL_CSS'][] = 'bundles/contaommenu/mmenu/mmenu.css|static';
$GLOBALS['TL_JAVASCRIPT'][] = 'bundles/contaommenu/mmenu/mmenu.js|static';
$GLOBALS['TL_CSS']['contao_dk_mmenu'] = 'bundles/contaommenu/mmenu/mmenu.css|static';

if ($this->options['polyfill']) {
$GLOBALS['TL_JAVASCRIPT']['contao_dk_mmenu.polyfill'] = 'bundles/contaommenu/mmenu/mmenu.polyfills.js|static';
}
$GLOBALS['TL_JAVASCRIPT']['contao_dk_mmenu'] = 'bundles/contaommenu/mmenu/mmenu.js|static';
if ($this->options['drag']['menu']['open']) {
$GLOBALS['TL_JAVASCRIPT'][] = 'bundles/contaommenu/hammerjs/hammer.min.js|static';
$GLOBALS['TL_JAVASCRIPT']['contao_dk_mmenu.hammerjs'] = 'bundles/contaommenu/hammerjs/hammer.min.js|static';
}

?>
<script>
document.addEventListener(
"DOMContentLoaded", () => {
new Mmenu('#<?= $this->elementId ?>', <?= json_encode($this->options) ?>, <?= json_encode($this->configuration) ?>);
}
);
document.addEventListener(
"DOMContentLoaded", () => {
new Mmenu('#<?= $this->elementId ?>', <?= json_encode($this->options) ?>, <?= json_encode($this->configuration) ?>);
},
);
</script>
132 changes: 132 additions & 0 deletions src/Resources/public/mmenu/_modules/dom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/**
* Create an element with classname.
*
* @param {string} selector The nodeName and classnames for the element to create.
* @return {HTMLElement} The created element.
*/
export function create(selector) {
var args = selector.split('.');
var elem = document.createElement(args.shift());
// IE11:
args.forEach(function (classname) {
elem.classList.add(classname);
});
// Better browsers:
// elem.classList.add(...args);
return elem;
}
/**
* Find all elements matching the selector.
* Basically the same as element.querySelectorAll() but it returns an actuall array.
*
* @param {HTMLElement} element Element to search in.
* @param {string} filter The filter to match.
* @return {array} Array of elements that match the filter.
*/
export function find(element, filter) {
return Array.prototype.slice.call(element.querySelectorAll(filter));
}
/**
* Find all child elements matching the (optional) selector.
*
* @param {HTMLElement} element Element to search in.
* @param {string} filter The filter to match.
* @return {array} Array of child elements that match the filter.
*/
export function children(element, filter) {
var children = Array.prototype.slice.call(element.children);
return filter ? children.filter(function (child) { return child.matches(filter); }) : children;
}
/**
* Find text excluding text from within child elements.
* @param {HTMLElement} element Element to search in.
* @return {string} The text.
*/
export function text(element) {
return Array.prototype.slice
.call(element.childNodes)
.filter(function (child) { return child.nodeType == 3; })
.map(function (child) { return child.textContent; })
.join(' ');
}
/**
* Find all preceding elements matching the selector.
*
* @param {HTMLElement} element Element to start searching from.
* @param {string} filter The filter to match.
* @return {array} Array of preceding elements that match the selector.
*/
export function parents(element, filter) {
/** Array of preceding elements that match the selector. */
var parents = [];
/** Array of preceding elements that match the selector. */
var parent = element.parentElement;
while (parent) {
parents.push(parent);
parent = parent.parentElement;
}
return filter ? parents.filter(function (parent) { return parent.matches(filter); }) : parents;
}
/**
* Find all previous siblings matching the selecotr.
*
* @param {HTMLElement} element Element to start searching from.
* @param {string} filter The filter to match.
* @return {array} Array of previous siblings that match the selector.
*/
export function prevAll(element, filter) {
/** Array of previous siblings that match the selector. */
var previous = [];
/** Current element in the loop */
var current = element.previousElementSibling;
while (current) {
if (!filter || current.matches(filter)) {
previous.push(current);
}
current = current.previousElementSibling;
}
return previous;
}
/**
* Get an element offset relative to the document.
*
* @param {HTMLElement} element Element to start measuring from.
* @param {string} [direction=top] Offset top or left.
* @return {number} The element offset relative to the document.
*/
export function offset(element, direction) {
return (element.getBoundingClientRect()[direction] +
document.body[direction === 'left' ? 'scrollLeft' : 'scrollTop']);
}
/**
* Filter out non-listitem listitems.
* @param {array} listitems Elements to filter.
* @return {array} The filtered set of listitems.
*/
export function filterLI(listitems) {
return listitems.filter(function (listitem) { return !listitem.matches('.mm-hidden'); });
}
/**
* Find anchors in listitems (excluding anchor that open a sub-panel).
* @param {array} listitems Elements to filter.
* @return {array} The found set of anchors.
*/
export function filterLIA(listitems) {
var anchors = [];
filterLI(listitems).forEach(function (listitem) {
anchors.push.apply(anchors, children(listitem, 'a.mm-listitem__text'));
});
return anchors.filter(function (anchor) { return !anchor.matches('.mm-btn_next'); });
}
/**
* Refactor a classname on multiple elements.
* @param {HTMLElement} element Element to refactor.
* @param {string} oldClass Classname to remove.
* @param {string} newClass Classname to add.
*/
export function reClass(element, oldClass, newClass) {
if (element.matches('.' + oldClass)) {
element.classList.remove(oldClass);
element.classList.add(newClass);
}
}
Loading

0 comments on commit 3f49fc0

Please sign in to comment.