The Tab menu module is a JavaScript library that makes developing tab menus easier in your ZnetDK 4 Mobile App.
- Add event handlers to execute custom JavaScript code before and after tab selection (see
addEventHandlermethod), - Remove event handlers (see
removeEventHandlermethod), - Enable / disable tabs (see
enableanddisablemethods), - Hide / show tabs (see
showandhidemethods), - Select a tab (see
selectmethod), - Get the selected tab (see
getSelectedIndexmethod).
This module is published under the version 3 of GPL General Public Licence.
- ZnetDK 4 Mobile version 2.0 or higher,
- PHP version 7.4 or higher,
- Add a new subdirectory named
z4m_tabmenuwithin the./engine/modules/subdirectory of your ZnetDK 4 Mobile starter App, - Copy module's code in the new
./engine/modules/z4m_tabmenu/subdirectory, or from your IDE, pull the code from this module's GitHub repository, - IN OPTION, if you want to see an example of tab menu in action, edit the App's
menu.phplocated in the./applications/default/app/subfolder and add the following code to add a menu item for thez4m_tabmenu_example.phpview.
\MenuManager::addMenuItem(NULL, 'z4m_tabmenu_example', 'Tab menu example', 'fa-folder-o');Go to the Tab menu example menu to see the example of tab menus in action.
To add a menu tab in a view or a modal dialog, adds the following HTML code.
<div id="tab-buttons" class="w3-theme-l4">
<button class="w3-button w3-hover-theme">Tab 1</button>
<button class="w3-button w3-hover-theme">Tab 2</button>
<button class="w3-button w3-hover-theme">Tab 3</button>
</div>
<div id="tab-contents">
<div class="w3-container">
<h3>Tab 1 content</h3>
</div>
<div class="w3-container">
<h3>Tab 2 content</h3>
</div>
<div class="w3-container">
<h3>Tab 3 content</h3>
</div>
</div>
<script type="module">
import { Z4M_TabMenu } from "./engine/modules/z4m_tabmenu/public/js/dynamic/z4m_tabmenu.min.js?v1.1";
const viewTabMenu = new Z4M_TabMenu('#tab-buttons > button', '#tab-contents > div');
viewTabMenu.selectFirst(); // First tab selected
</script>To add an event handler executed when a menu tab is selected, call the addEventHandler method as shown below:
const eventHandlerId = viewTabMenu.addEventHandler('beforeShow', function(tabInfos) {
console.log(tabInfos);
return true; // Tab is selected
});Important
To cancel a tab selection, return false from the beforeShow event handler.
To remove an event handler, call the removeEventHandler method as shown below.
viewTabMenu.removeEventHandler(eventHandlerId);To enable a menu tab previously disabled, call the enable method as shown below.
viewTabMenu.enable(1); // Second tab is enabledTo disable a menu tab, call the disable method as shown below.
viewTabMenu.disable(1); // Second tab is disabledTo show a menu tab previously hidden, call the show method as shown below.
viewTabMenu.show(2); // Third tab is shownTo disable a menu tab, call the disable method as shown below.
viewTabMenu.hide(2); // Third tab is hiddenTo select a menu tab, call the select method as shown below:
viewTabMenu.select(1); // Second tab is selectedTo select the first menu tab, call the selectFirst method as shown below:
viewTabMenu.selectFirst(); // First tab is selectedTo get the current selected tab, call the getSelectedIndex method as shown below:
const selectedTabIdx = viewTabMenu.getSelectedIndex();See CHANGELOG.md file.
Your contribution to the ZnetDK 4 Mobile project is welcome. Please refer to the CONTRIBUTING.md file.
