diff --git a/jquery.mmenu/jquery.mmenu-tests.ts b/jquery.mmenu/jquery.mmenu-tests.ts new file mode 100644 index 000000000..9fbb9b776 --- /dev/null +++ b/jquery.mmenu/jquery.mmenu-tests.ts @@ -0,0 +1,85 @@ +/// +/// + + +// -------------------------------------------------------- +// ---------------- TEST DEFAULT OPTIONS ------------------ +// -------------------------------------------------------- + +var menu: JQuery = $("#my-menu"); +menu.mmenu( + // options + { + extensions: [], + navbar: { + add: true, + title: "Menu", + titleLink: "parent" + }, + onClick: { + close: true, + preventDefault: false, + setSelected: false + }, + slidingSubmenus: true + }, + // configurations + { + classNames: { + divider: "Divider", + inset: "Inset", + panel: "Panel", + selected: "Selected", + vertical: "vertical" + }, + clone: false, + openingInterval: 25, + panelNodetype: "div, ul, ol", + transitionDuration: 400 + } +); + + +// -------------------------------------------------------- +// ------------------- TEST MMENU API --------------------- +// -------------------------------------------------------- + +var api: JQueryMmenu.API = menu.data("mmenu"); +var myPanel: JQuery = $("#panel"); +var listItem: JQuery = $(".list-item"); + +api.closeAllPanels(); +api.bind("closeAllPanels", function() { + console.log("close all opened panels and go back to the first panel."); +}); + +api.closePanel(myPanel); +api.bind("closePanel", function(panel) { + console.log("close this ", panel); +}); + +api.getInstance(); +api.bind("getInstance", function() { + console.log("get the class instance for the menu."); +}); + +api.init(myPanel); +api.bind("init", function(panel) { + console.log("method to (re)initialize a newly added ", panel); +}); + +api.openPanel(myPanel); +api.bind("openPanel", function(panel) { + console.log("This panel is now opened ", panel); +}); + +api.setSelected(listItem, true); +api.bind("setSelected", function(listItem, selected) { + console.log("set or unset a list item as selected ", listItem); + console.log("has selected ", selected); +}); + +api.update(); +api.bind("update", function() { + console.log("update the appearance for the menu"); +}); diff --git a/jquery.mmenu/jquery.mmenu.d.ts b/jquery.mmenu/jquery.mmenu.d.ts new file mode 100644 index 000000000..97874f8f0 --- /dev/null +++ b/jquery.mmenu/jquery.mmenu.d.ts @@ -0,0 +1,229 @@ +// Type definitions for jQuery mmenu v5.5.3 +// Project: http://mmenu.frebsite.nl/ +// Definitions by: John Gouigouix +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +declare module JQueryMmenu { + + interface NavbarOptions { + + /** + * Whether or not to add a navbar above the panels. + * Default: true + */ + add?: boolean; + + /** + * The title above the main panel. + * Default: "Menu" + */ + title?: string; + + /** + * The type of link to set for the title. + * Possible values: "parent", "anchor" or "none". + * Default: "parent" + */ + titleLink?: string; + + } + + interface OnclickOptions { + + /** + * Whether or not the menu should close after clicking a link inside it. + * The default value varies per link: true if the default behavior for + * the clicked link is prevented, false otherwise. + * Default: null + */ + close?: boolean | any; + + /** + * Whether or not to prevent the default behavior for the clicked link. + * The default value varies per link: true if its href is equal to + * or starts with a hash (#), false otherwise. + * Default: null + */ + preventDefault?: boolean | any; + + /** + * Whether or not the clicked link should be visibly "selected". + * Default: true + */ + setSelected?: boolean | any; + + } + + interface Options { + + /** + * A collection of extension names to enable for the menu. + * You'll need this option when using the extensions. + * Default: [] + */ + extensions?: Array; + + /** + * navbar options + */ + navbar?: NavbarOptions; + + /** + * onClick options + */ + onClick?: OnclickOptions; + + /** + * Whether or not submenus should come sliding in from the right. + * If false, submenus expand below their parent. + * To expand a single submenu below its parent item, add the class "Vertical" to it. + * Default: true + */ + slidingSubmenus?: boolean; + + } + + interface ClassnamesConfigurations { + + /** + * The classname on a LI that should be displayed as a divider. + * Default: "Divider" + */ + divider?: string; + + /** + * The classname on a submenu (a nested UL) that should be displayed as a default list. + * Default: "Inset" + */ + inset?: string; + + /** + * The classname on an element (for example a DIV) that should be considered to be a panel. + * Only applies if the "isMenu" option is set to false. + * Default: "Panel" + */ + panel?: string; + + /** + * The classname on the LI that should be displayed as selected. + * Default: "Selected" + */ + selected?: string; + + /** + * The classname on a submenu (a nested UL) that should expand below + * their parent instead of slide in from the right. + * Default: "vertical" + */ + vertical?: string; + + } + + interface Configurations { + + /** + * the CSS class names object + */ + classNames?: ClassnamesConfigurations; + + /** + * Whether or not the menu should be cloned (and the original menu kept intact). + * Default: false + */ + clone?: boolean; + + /** + * The number of milliseconds between opening/closing the menu and panels, + * needed to force CSS transitions. + * Default: 25 + */ + openingInterval?: number; + + /** + * jQuery selector containing the node-type of panels. + * Default: "div, ul, ol" + */ + panelNodetype?: string; + + /** + * The number of milliseconds used in the CSS transitions. + * Default: 400 (The value should match the associated CSS value.) + */ + transitionDuration?: number; + + } + + interface API { + + /** + * Trigger this method to close all opened panels and go back to the first panel. + */ + closeAllPanels(): JQuery; + /** @see closeAllPanels() */ + bind(methodName: "closeAllPanels", callback: () => void): JQuery; + + /** + * Trigger this method to close a panel + * (only available if the "slidingSubmenus" option is set to false). + * @param panel + */ + closePanel(panel: JQuery); + /** @see closePanel() */ + bind(methodName: "closePanel", callback: (panel: JQuery) => void); + + /** + * Trigger this method to get the class instance for the menu. + */ + getInstance(); + /** @see getInstance() */ + bind(methodName: "getInstance", callback: () => void); + + /** + * Trigger this method to (re)initialize a newly added panel. + * @param panel The panel to (re)initialize. + */ + init(panel: JQuery); + /** @see init() */ + bind(methodName: "init", callback: (panel: JQuery) => void); + + /** + * Trigger this method to open a panel. + * @param panel The panel to open. + */ + openPanel(panel: JQuery); + /** @see openPanel() */ + bind(methodName: "openPanel", callback: (panel: JQuery) => void); + + /** + * Trigger this method to set or unset a list item as "selected". + * @param li The list item to set or unset as "selected". + * @param selected Whether to set or unset the list item as "selected". Default: true + */ + setSelected(li: JQuery, selected?: boolean); + /** @see setSelected() */ + bind(methodName: "setSelected", callback: (li: JQuery, selected?: boolean) => void); + + /** + * Trigger this method to update the appearance for the menu. + */ + update(); + /** @see update() */ + bind(methodName: "update", callback: () => void); + + } + +} + + +interface JQuery { + + /** + * Create mmenu component + */ + mmenu(): JQuery; + mmenu(options: JQueryMmenu.Options): JQuery; + mmenu(options: JQueryMmenu.Options, configurations: JQueryMmenu.Configurations): JQuery; + +}