Best JavaScript code snippet using storybook-root
MenuPromptBtn.ts
Source:MenuPromptBtn.ts
1import {2 MENU_ELEMENT_TYPE_COFFEE_TABLE,3 MENU_ELEMENT_TYPE_DESSERT_TABLE,4 MENU_ELEMENT_TYPE_DOOR_CURTAIN,5 MENU_ELEMENT_TYPE_MAT,6 MENU_ELEMENT_TYPE_PLANT,7 MENU_ELEMENT_TYPE_STOVE_1,8 MENU_ELEMENT_TYPE_STOVE_2,9 MENU_ELEMENT_TYPE_STOVE_3,10 MENU_ELEMENT_TYPE_STOVE_4,11 MENU_ELEMENT_TYPE_STOVE_5,12 MENU_ELEMENT_TYPE_STOVE_6,13 MENU_ELEMENT_TYPE_TABLE_1,14 MENU_ELEMENT_TYPE_TABLE_2,15 MENU_ELEMENT_TYPE_TABLE_3,16 MENU_ELEMENT_TYPE_TABLE_4,17 MENU_ELEMENT_TYPE_TABLE_5,18 MENU_ELEMENT_TYPE_TABLE_6,19 MENU_ELEMENT_TYPE_TIP,20 MENU_ELEMENT_TYPE_WALL_DECORATION,21 MENU_ELEMENT_TYPE_WINE_CABINET,22 TABLEWARE_PRICE,23 TABLEWARE_UNLOCK_STAR,24 TIP_PRICE,25 TIP_UNLOCK_STAR,26} from "../config/GameConstants";27import { CoffeeTable } from "../object/CoffeeTable";28import { DessertTable } from "../object/DessertTable";29import { DoorCurtain } from "../object/DoorCurtain";30import { Mat } from "../object/Mat";31import { MenuElement } from "../object/MenuElement";32import { objectCollection } from "../object/ObjectCollection";33import { Plant } from "../object/Plant";34import { Tip } from "../object/Tip";35import { WallDecoration } from "../object/WallDecoration";36import { WineCabinet } from "../object/WineCabinet";37import { Map } from "../collections/Map";38import { Table } from "../object/Table";39import { MenuPrompt } from "../object/MenuPrompt";40import { MenuList } from "../object/MenuList";41import { Currency } from "../object/Currency";42import { GapTip } from "../object/GapTip";43import { Stove } from "../object/Stove";44/*45 * @Author: ayue46 * @Date: 2020-10-19 16:47:0347 * @Last Modified by: ayue48 * @Last Modified time: 2020-10-21 19:15:2149 * ç¹å»èåäºçº§çé¢ï¼å建é¤å
·æè
æ´æ¢é¤å
·ç级50 */51const { ccclass, property } = cc._decorator;52@ccclass53export class MenuPromptBtn extends cc.Component {54 onBtn() {55 let menuPrompt: MenuPrompt = objectCollection.getMenuPrompt();56 let menuElement: MenuElement = menuPrompt.getMenuElement();57 //å建é¤å
·58 let isSuccess: boolean = this.createObject(menuElement);59 if (!isSuccess) {60 return;61 }62 //èåä¸é¤å
·ç¶ææ¾ç¤ºæ§å¶63 let menuElements: Array<MenuElement> = objectCollection.getMenuElements();64 let tablewareMap: Map<Number, any> = objectCollection.getTablewareMap();65 for (let i = 0; i < menuElements.length; i++) {66 let menuElement: MenuElement = menuElements[i];67 let menuElementNode: cc.Node = menuElement.node;68 let tableware: any = tablewareMap.get(menuElement.getType());69 let selectedNode = menuElementNode.getChildByName("selected");70 let markNode = menuElementNode.getChildByName("mark");71 let unlockNode = menuElementNode.getChildByName("unlock");72 if (tableware == null) {73 selectedNode.active = false;74 markNode.active = false;75 unlockNode.active = false;76 } else if (tableware.getLevel() != menuElement.getLevel()) {77 selectedNode.active = false;78 markNode.active = false;79 if (menuElement.getIsLock() == false) {80 unlockNode.active = true;81 } else {82 unlockNode.active = false;83 }84 } else {85 selectedNode.active = true;86 markNode.active = true;87 unlockNode.active = false;88 }89 }90 menuPrompt.node.active = false;91 let menuList: MenuList = objectCollection.getMenuList();92 menuList.node.active = false;93 }9495 onCloseBtn() {96 let menuPrompt: MenuPrompt = objectCollection.getMenuPrompt();97 menuPrompt.node.active = false;98 }99100 private createObject(menuElement: MenuElement): boolean {101 let tablewareMap = objectCollection.getTablewareMap();102 let tableware = tablewareMap.get(menuElement.getType());103 //è´§å¸å¤æ104 if (tableware == null || tableware.getLevel() < menuElement.getLevel()) {105 if (106 objectCollection.getStarCount() < TABLEWARE_UNLOCK_STAR[menuElement.getType()][menuElement.getLevel()]107 ) {108 let gapTip: GapTip = objectCollection.getGapTip();109 if (gapTip == null) {110 gapTip = new GapTip();111 gapTip.createGapTip();112 } else {113 gapTip.updateGapTip();114 }115 let tipNode = gapTip.node.getChildByName("tip_label");116 let tipLabel = tipNode.getComponent(cc.Label);117 tipLabel.string = "ææä¸å¤";118 return false;119 }120 if (objectCollection.getFishCount() < TABLEWARE_PRICE[menuElement.getType()][menuElement.getLevel()]) {121 let gapTip: GapTip = objectCollection.getGapTip();122 if (gapTip == null) {123 gapTip = new GapTip();124 gapTip.createGapTip();125 } else {126 gapTip.updateGapTip();127 }128 let tipNode = gapTip.node.getChildByName("tip_label");129 let tipLabel = tipNode.getComponent(cc.Label);130 tipLabel.string = "å°é±¼å¹²ä¸å¤";131 return false;132 }133 }134 //æ£é¤è´§å¸135 let currency: Currency = objectCollection.getCurrency();136 currency.reduceFishCount(TABLEWARE_PRICE[menuElement.getType()][menuElement.getLevel()]);137138 menuElement.unLock();139 if (menuElement.getType() == MENU_ELEMENT_TYPE_TIP) {140 this.createTip(menuElement);141 } else if (menuElement.getType() == MENU_ELEMENT_TYPE_COFFEE_TABLE) {142 this.createCoffeeTable(menuElement);143 } else if (menuElement.getType() == MENU_ELEMENT_TYPE_DESSERT_TABLE) {144 this.createDessertTable(menuElement);145 } else if (menuElement.getType() == MENU_ELEMENT_TYPE_DOOR_CURTAIN) {146 this.createDoorCurtain(menuElement);147 } else if (menuElement.getType() == MENU_ELEMENT_TYPE_MAT) {148 this.createMat(menuElement);149 } else if (menuElement.getType() == MENU_ELEMENT_TYPE_PLANT) {150 this.createPlant(menuElement);151 } else if (menuElement.getType() == MENU_ELEMENT_TYPE_WALL_DECORATION) {152 this.createWallDecoration(menuElement);153 } else if (menuElement.getType() == MENU_ELEMENT_TYPE_WINE_CABINET) {154 this.createWineCabinet(menuElement);155 } else if (156 menuElement.getType() == MENU_ELEMENT_TYPE_TABLE_1 ||157 menuElement.getType() == MENU_ELEMENT_TYPE_TABLE_2 ||158 menuElement.getType() == MENU_ELEMENT_TYPE_TABLE_3 ||159 menuElement.getType() == MENU_ELEMENT_TYPE_TABLE_4 ||160 menuElement.getType() == MENU_ELEMENT_TYPE_TABLE_5 ||161 menuElement.getType() == MENU_ELEMENT_TYPE_TABLE_6162 ) {163 this.createTable(menuElement);164 } else if (165 menuElement.getType() == MENU_ELEMENT_TYPE_STOVE_1 ||166 menuElement.getType() == MENU_ELEMENT_TYPE_STOVE_2 ||167 menuElement.getType() == MENU_ELEMENT_TYPE_STOVE_3 ||168 menuElement.getType() == MENU_ELEMENT_TYPE_STOVE_4 ||169 menuElement.getType() == MENU_ELEMENT_TYPE_STOVE_5 ||170 menuElement.getType() == MENU_ELEMENT_TYPE_STOVE_6171 ) {172 this.createStove(menuElement);173 }174 return true;175 }176177 private createTip(menuElement: MenuElement) {178 if (objectCollection.getTip() == null) {179 let tip: Tip = new Tip();180 tip.createTip(menuElement.getLevel());181 } else {182 let tip: Tip = objectCollection.getTip();183 if (tip.getLevel() != menuElement.getLevel()) {184 tip.updateTip(menuElement.getLevel());185 }186 }187 }188189 private createCoffeeTable(menuElement: MenuElement) {190 if (objectCollection.getCoffeeTable() == null) {191 let coffeeTable: CoffeeTable = new CoffeeTable();192 coffeeTable.createCoffeeTable(menuElement.getLevel());193 } else {194 let coffeeTable: CoffeeTable = objectCollection.getCoffeeTable();195 if (coffeeTable.getLevel() != menuElement.getLevel()) {196 coffeeTable.updateCoffeeTable(menuElement.getLevel());197 }198 }199 }200 private createDessertTable(menuElement: MenuElement) {201 if (objectCollection.getDessertTable() == null) {202 let dessertTable: DessertTable = new DessertTable();203 dessertTable.createDessertTable(menuElement.getLevel());204 } else {205 let dessertTable: DessertTable = objectCollection.getDessertTable();206 if (dessertTable.getLevel() != menuElement.getLevel()) {207 dessertTable.updateDessertTable(menuElement.getLevel());208 }209 }210 }211 private createDoorCurtain(menuElement: MenuElement) {212 if (objectCollection.getDoorCurtain() == null) {213 let doorCurtain: DoorCurtain = new DoorCurtain();214 doorCurtain.createDoorCurtain(menuElement.getLevel());215 } else {216 let doorCurtain: DoorCurtain = objectCollection.getDoorCurtain();217 if (doorCurtain.getLevel() != menuElement.getLevel()) {218 doorCurtain.updateDoorCurtain(menuElement.getLevel());219 }220 }221 }222 private createMat(menuElement: MenuElement) {223 if (objectCollection.getMat() == null) {224 let mat: Mat = new Mat();225 mat.createMat(menuElement.getLevel());226 } else {227 let mat: Mat = objectCollection.getMat();228 if (mat.getLevel() != menuElement.getLevel()) {229 mat.updateMat(menuElement.getLevel());230 }231 }232 }233 private createPlant(menuElement: MenuElement) {234 if (objectCollection.getPlant() == null) {235 let plant: Plant = new Plant();236 plant.createPlant(menuElement.getLevel());237 } else {238 let plant: Plant = objectCollection.getPlant();239 if (plant.getLevel() != menuElement.getLevel()) {240 plant.updatePlant(menuElement.getLevel());241 }242 }243 }244 private createWallDecoration(menuElement: MenuElement) {245 if (objectCollection.getWallDecoration() == null) {246 let wallDecoration: WallDecoration = new WallDecoration();247 wallDecoration.createWallDecoration(menuElement.getLevel());248 } else {249 let wallDecoration: WallDecoration = objectCollection.getWallDecoration();250 if (wallDecoration.getLevel() != menuElement.getLevel()) {251 wallDecoration.updateWallDecoration(menuElement.getLevel());252 }253 }254 }255 private createWineCabinet(menuElement: MenuElement) {256 if (objectCollection.getWineCabinet() == null) {257 let wineCabinet: WineCabinet = new WineCabinet();258 wineCabinet.createWineCabinet(menuElement.getLevel());259 } else {260 let wineCabinet: WineCabinet = objectCollection.getWineCabinet();261 if (wineCabinet.getLevel() != menuElement.getLevel()) {262 wineCabinet.updateWineCabinet(menuElement.getLevel());263 }264 }265 }266267 private createTable(menuElement: MenuElement) {268 if (objectCollection.getTable(menuElement.getType()) == null) {269 let table: Table = new Table();270 table.createTable(menuElement.getType(), menuElement.getLevel());271 } else {272 let table: Table = objectCollection.getTable(menuElement.getType());273 if (table.getLevel() != menuElement.getLevel()) {274 table.updateTable(menuElement.getType(), menuElement.getLevel());275 }276 }277 }278279 private createStove(menuElement: MenuElement) {280 if (objectCollection.getTable(menuElement.getType()) == null) {281 let stove: Stove = new Stove();282 stove.createStove(menuElement.getType(), menuElement.getLevel());283 } else {284 let stove: Stove = objectCollection.getStove(menuElement.getType());285 if (stove.getLevel() != menuElement.getLevel()) {286 stove.updateTable(menuElement.getType(), menuElement.getLevel());287 }288 }289 }
...
dropdown_navigation_hook.js
Source:dropdown_navigation_hook.js
1/** @odoo-module */2import { useService } from "@web/core/utils/hooks";3import { browser } from "../browser/browser";4import { localization } from "@web/core/l10n/localization";5import { scrollTo } from "../utils/scrolling";6const { useComponent, useEffect, useRef } = owl;7/**8 * @typedef {{9 * el: HTMLElement,10 * isActive: boolean,11 * makeOnlyActive: ()=>void,12 * navTarget: HTMLElement,13 * isSubDropdown: boolean,14 * isSubDropdownOpen: boolean,15 * closeSubDropdown: ()=>void,16 * openSubDropdown: (immediate?:boolean)=>void,17 * }} MenuElement18 */19const ACTIVE_MENU_ELEMENT_CLASS = "focus";20const MENU_ELEMENTS_SELECTORS = [":scope > .dropdown-item", ":scope > .dropdown"];21const NEXT_ACTIVE_INDEX_FNS = {22 FIRST: () => 0,23 LAST: (list) => list.length - 1,24 NEXT: (list, prevActiveIndex) => (prevActiveIndex + 1) % list.length,25 PREV: (list, prevActiveIndex) => (prevActiveIndex <= 0 ? list.length : prevActiveIndex) - 1,26};27export function useDropdownNavigation() {28 /** @type {import("./dropdown").Dropdown} */29 const comp = useComponent();30 // As this navigation hook relies on clicking ".dropdown-toggle" elements,31 // it is incompatible with a toggler="parent" strategy for subdropdowns.32 if (comp.parentDropdown && comp.props.toggler === "parent") {33 throw new Error("A nested Dropdown must use its standard toggler");34 }35 // Needed to avoid unwanted mouseclick behavior on a subdropdown toggler.36 const originalOnTogglerClick = comp.onTogglerClick.bind(comp);37 comp.onTogglerClick = (ev) => {38 if (comp.parentDropdown && !ev.__fromDropdownNavigation) {39 return;40 }41 originalOnTogglerClick();42 };43 // Needed to avoid unwanted mouseenter behavior on a subdropdown toggler.44 const originalOnTogglerMouseEnter = comp.onTogglerMouseEnter.bind(comp);45 comp.onTogglerMouseEnter = () => {46 if (comp.parentDropdown) {47 return;48 }49 originalOnTogglerMouseEnter();50 };51 // Needed to avoid unwanted selection when the mouse pointer is not in use52 // but still somewhere in the middle of the dropdown menu list.53 let mouseSelectionActive = true;54 // Set up menu elements logic ----------------------------------------------55 const menuRef = useRef("menuRef");56 /** @type {MenuElement[]} */57 let menuElements = [];58 useEffect(() => {59 if (!comp.state.open) {60 return;61 }62 // Prepare MenuElements63 const addedListeners = [];64 /** @type {NodeListOf<HTMLElement>} */65 const queryResult = menuRef.el.querySelectorAll(MENU_ELEMENTS_SELECTORS.join());66 for (const el of queryResult) {67 const isSubDropdown = el.classList.contains("dropdown");68 const isSubDropdownOpen = () => el.classList.contains("show");69 const navTarget = isSubDropdown ? el.querySelector(":scope > .dropdown-toggle") : el;70 let subDropdownTimeout;71 const closeSubDropdown = () => {72 browser.clearTimeout(subDropdownTimeout);73 subDropdownTimeout = browser.setTimeout(() => {74 if (isSubDropdownOpen()) {75 const ev = new MouseEvent("click", { bubbles: false });76 ev.__fromDropdownNavigation = true;77 navTarget.dispatchEvent(ev);78 }79 }, 200);80 };81 const openSubDropdown = (immediate = false) => {82 browser.clearTimeout(subDropdownTimeout);83 subDropdownTimeout = browser.setTimeout(84 () => {85 if (!isSubDropdownOpen()) {86 const ev = new MouseEvent("click", { bubbles: false });87 ev.__fromDropdownNavigation = true;88 navTarget.dispatchEvent(ev);89 }90 },91 immediate ? 0 : 20092 );93 };94 const makeOnlyActive = () => {95 // Make all others inactive96 for (const menuElement of menuElements) {97 if (menuElement.el === el) {98 continue;99 }100 menuElement.navTarget.classList.remove(ACTIVE_MENU_ELEMENT_CLASS);101 if (menuElement.isSubDropdown) {102 menuElement.closeSubDropdown();103 }104 }105 // Make myself active106 navTarget.classList.add(ACTIVE_MENU_ELEMENT_CLASS);107 };108 /** @type {MenuElement} */109 const menuElement = {110 el,111 get isActive() {112 return navTarget.classList.contains(ACTIVE_MENU_ELEMENT_CLASS);113 },114 makeOnlyActive,115 navTarget,116 get isSubDropdownOpen() {117 return isSubDropdownOpen();118 },119 isSubDropdown,120 closeSubDropdown,121 openSubDropdown,122 };123 menuElements.push(menuElement);124 // Set up selection listeners125 const elementListeners = {126 mouseenter: () => {127 if (!mouseSelectionActive) {128 mouseSelectionActive = true;129 } else {130 makeOnlyActive();131 if (isSubDropdown) {132 openSubDropdown();133 }134 }135 },136 };137 for (const [eventType, listener] of Object.entries(elementListeners)) {138 navTarget.addEventListener(eventType, listener);139 }140 addedListeners.push([navTarget, elementListeners]);141 }142 return () => {143 menuElements = [];144 mouseSelectionActive = true;145 // Clear mouse selection listeners146 for (const [navTarget, listeners] of addedListeners) {147 for (const [eventType, listener] of Object.entries(listeners)) {148 navTarget.removeEventListener(eventType, listener);149 }150 }151 };152 });153 // Set up active menu element helpers --------------------------------------154 /**155 * @returns {MenuElement|undefined}156 */157 const getActiveMenuElement = () => {158 return menuElements.find((menuElement) => menuElement.isActive);159 };160 /**161 * @param {MenuElement|keyof NEXT_ACTIVE_INDEX_FNS} menuElement162 */163 const setActiveMenuElement = (menuElement) => {164 if (menuElements.length) {165 if (typeof menuElement === "string") {166 const prevIndex = menuElements.indexOf(getActiveMenuElement());167 const nextIndex = NEXT_ACTIVE_INDEX_FNS[menuElement](menuElements, prevIndex);168 menuElement = menuElements[nextIndex];169 }170 menuElement.makeOnlyActive();171 scrollTo(menuElement.el, { scrollable: menuElement.el.parentElement });172 }173 };174 // Set up nested dropdowns - active first menu element behavior ------------175 useEffect(176 (open) => {177 // If we just opened and we are a subdropdown, make active our first menu element.178 if (open && comp.parentDropdown) {179 setActiveMenuElement("FIRST");180 }181 },182 () => [comp.state.open]183 );184 // Set up keyboard navigation ----------------------------------------------185 const hotkeyService = useService("hotkey");186 const closeSubDropdown = comp.parentDropdown ? comp.close : () => {};187 const openSubDropdown = () => {188 const menuElement = getActiveMenuElement();189 // Active menu element is a sub dropdown190 if (menuElement && menuElement.isSubDropdown) {191 menuElement.openSubDropdown(true);192 }193 };194 const selectActiveMenuElement = () => {195 const menuElement = getActiveMenuElement();196 if (menuElement) {197 if (menuElement.isSubDropdown) {198 menuElement.openSubDropdown(true);199 } else {200 menuElement.navTarget.click();201 }202 }203 };204 let hotkeyRemoves = [];205 const hotkeyCallbacks = {206 home: () => setActiveMenuElement("FIRST"),207 end: () => setActiveMenuElement("LAST"),208 tab: () => setActiveMenuElement("NEXT"),209 "shift+tab": () => setActiveMenuElement("PREV"),210 arrowdown: () => setActiveMenuElement("NEXT"),211 arrowup: () => setActiveMenuElement("PREV"),212 arrowleft: localization.direction === "rtl" ? openSubDropdown : closeSubDropdown,213 arrowright: localization.direction === "rtl" ? closeSubDropdown : openSubDropdown,214 enter: selectActiveMenuElement,215 escape: comp.close,216 };217 useEffect(218 (open) => {219 if (!open) {220 return;221 }222 // Subscribe keynav223 for (const [hotkey, callback] of Object.entries(hotkeyCallbacks)) {224 const callbackWrapper = () => {225 const hasOpenedSubDropdown = menuElements.some((m) => m.isSubDropdownOpen);226 // Leave priority to last opened sub dropdown227 if (!hasOpenedSubDropdown) {228 mouseSelectionActive = false;229 callback.call(comp);230 }231 };232 hotkeyRemoves.push(233 hotkeyService.add(hotkey, callbackWrapper, { allowRepeat: true })234 );235 }236 return () => {237 // Unsubscribe keynav238 for (const removeHotkey of hotkeyRemoves) {239 removeHotkey();240 }241 hotkeyRemoves = [];242 };243 },244 () => [comp.state.open]245 );...
responsive_menus_simple.js
Source:responsive_menus_simple.js
1/**2 * @file3 * Simple responsification of menus.4 */5(function ($) {6 /**7 * Handle clicks & toggling the menu.8 */9 var toggler_click = function() {10 $(this).parent().toggleClass('responsive-toggled');11 };12 /**13 * Unbind other mouse events on the menu items.14 *15 * @todo16 * Not sure if it works 100%.17 * Doesn't restore binds when out-of-responsive (if window dragging).18 */19 function remove_mouse_events(menuElement) {20 // Determine jQuery version and what disable options we have.21 var jqVersion = $.fn.jquery;22 if (jqVersion < 1.7) {23 $(menuElement).die('mouseover mouseout mouseenter mouseleave');24 $(menuElement + ' li').die('mouseover mouseout mouseenter mouseleave');25 $(menuElement + ' li a').die('mouseover mouseout mouseenter mouseleave');26 }27 else {28 $(menuElement).off('hover');29 $(menuElement + ' li').off('hover');30 $(menuElement + ' li a').off('hover');31 }32 $(menuElement).unbind('mouseover mouseout mouseenter mouseleave');33 $(menuElement + ' li').unbind('mouseover mouseout mouseenter mouseleave');34 $(menuElement + ' li a').unbind('mouseover mouseout mouseenter mouseleave');35 }36 /**37 * Store classes & IDs for restoring later (if window dragging).38 */39 function store_classes_ids(menuElement) {40 if (!$(menuElement).attr('id')) {41 $(menuElement).attr('id', 'rm-no-id-main');42 }43 if (!$(menuElement).attr('class')) {44 $(menuElement).attr('class', 'rm-no-class');45 }46 $(menuElement).data('removeattr', true)47 .data('rmids', $(menuElement).attr('id'))48 .data('rmclasses', $(menuElement).attr('class'));49 // Handle ULs if selector is parent div.50 var incr = 0;51 $(menuElement).find('ul').each(function() {52 incr++;53 // Prevent error if there is no id.54 if (!$(this).attr('id')) {55 $(this).attr('id', 'rm-no-id-' + incr);56 }57 // Prevent error if there is no class.58 if (!$(this).attr('class')) {59 $(this).attr('class', 'rm-no-class');60 }61 $(this).data('removeattr', true)62 .data('rmids', $(this).attr('id'))63 .data('rmclasses', $(this).attr('class'));64 });65 // Finally, add our class to the parent.66 $(menuElement).addClass('responsive-menus-simple');67 }68 /**69 * Remove classes & IDs from original menu for easier theming.70 */71 function remove_classes_ids(menuElement) {72 // Handle ULs if selector is parent div.73 $(menuElement).find('ul').each(function() {74 $(this).attr('class', 'rm-removed').attr('id', 'rm-removed');75 });76 // Remove classes/IDs.77 $(menuElement).attr('class', 'responsive-menus-simple').attr('id', 'rm-removed');78 }79 // Iterate through selectors, check window sizes, add some classes.80 Drupal.behaviors.responsive_menus = {81 attach: function (context, settings) {82 settings.responsive_menus = settings.responsive_menus || {};83 $('body').once('responsive-menus-load', function() {84 // Only doing this themes that don't include a viewport attribute.85 // e.g. Bartik for testing out-of-the-box... yeah, stupid.86 if (!$('meta[name=viewport]').length > 0) {87 $('head').append('<meta name="viewport" content="width=device-width, initial-scale=1.0">');88 }89 // Window width with legacy browsers.90 var windowWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;91 $.each(settings.responsive_menus, function(ind, iteration) {92 if (iteration.responsive_menus_style != 'responsive_menus_simple') {93 return true;94 }95 if (!iteration.selectors.length) {96 return true;97 }98 var $media_unit = iteration.media_unit || 'px';99 if ($media_unit === 'em') {100 var $base_font_size = parseFloat($('body').css('font-size'));101 var $media_size = iteration.media_size * $base_font_size || 768;102 }103 else {104 var $media_size = iteration.media_size || 768;105 }106 // Handle clicks & toggling.107 var toggler_class = '';108 var toggler_text = iteration.toggler_text;109 // Iterate through our selectors.110 $.each(iteration.selectors, function(index, value) {111 // Stop if there is no menu element.112 if ($(value).length < 1) {113 return true;114 }115 // Handle nested menus. Make sure we get the first, but not children.116 if ($(value).length > 1) {117 $(value).each(function(val_index) {118 if (!$(this).parents('ul').length) {119 if (!$(this).hasClass('responsive-menus-simple')) {120 toggler_class = 'responsive-menus-' + ind + '-' + index + '-' + val_index;121 // Store classes & IDs before removing.122 if (iteration.remove_attributes) {123 store_classes_ids(this);124 }125 $(this).wrap('<div data-mediasize="' + $media_size + '" class="responsive-menus ' + toggler_class + '" />');126 $('.' + toggler_class).prepend('<span class="toggler">' + toggler_text + '</span>');127 $('.' + toggler_class + ' .toggler').bind('click', toggler_click);128 // Unbind other mouse events.129 if (iteration.disable_mouse_events) {130 //$(this).data('disablemouse', true);131 remove_mouse_events(this);132 }133 // Use absolute positioning.134 if (iteration.absolute) {135 $('.' + toggler_class).addClass('absolute');136 }137 // Handle first size check.138 if (windowWidth <= $media_size) {139 // Remove attributes setting.140 if (iteration.remove_attributes) {141 remove_classes_ids(this);142 }143 $('.' + toggler_class).addClass('responsified');144 }145 }146 }147 });148 }149 else {150 // Single level menus.151 if (!$(value).hasClass('responsive-menus-simple')) {152 toggler_class = 'responsive-menus-' + ind + '-' + index;153 // Store classes & IDs before removing.154 if (iteration.remove_attributes) {155 store_classes_ids(value);156 }157 $(value).wrap('<div data-mediasize="' + $media_size + '" class="responsive-menus ' + toggler_class + '" />');158 $('.' + toggler_class).prepend('<span class="toggler">' + toggler_text + '</span>');159 $('.' + toggler_class + ' .toggler').bind('click', toggler_click);160 // Unbind other mouse events.161 if (iteration.disable_mouse_events) {162 // @todo For rebinding mouse events.163 /*if ($(value + ' li a').data('events')) {164 $(value).data('tmpevents', $(value + ' li a').data('events'));165 }*/166 remove_mouse_events(value);167 }168 // Use absolute positioning.169 if (iteration.absolute) {170 $('.' + toggler_class).addClass('absolute');171 }172 // Handle first size check.173 if (windowWidth <= $media_size) {174 // Remove attributes setting.175 if (iteration.remove_attributes) {176 remove_classes_ids(value);177 }178 $('.' + toggler_class).addClass('responsified');179 }180 }181 }182 });183 });184 // Handle window resizing.185 $(window).resize(function() {186 // Window width with legacy browsers.187 windowWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;188 $('.responsive-menus').each(function(menuIndex, menuValue) {189 var mediasize = $(this).data('mediasize') || 768;190 // Prevent menu from going off the screen. This only happens in191 // non-responsive themes (like Bartik default), but it looks bad.192 if ($(this).width() > windowWidth) {193 $(this).data('nonresponsive', true);194 $(this).width(windowWidth);195 }196 var menuElement = $(this).find('.responsive-menus-simple');197 if (windowWidth >= mediasize) {198 if (menuElement.data('removeattr')) {199 menuElement.addClass(menuElement.data('rmclasses'));200 menuElement.attr('id', menuElement.data('rmids'));201 menuElement.find('ul').each(function() {202 $(this).addClass($(this).data('rmclasses'));203 $(this).attr('id', $(this).data('rmids'));204 });205 }206 $(this).removeClass('responsified');207 }208 if (windowWidth <= mediasize) {209 // Now fix repercussions for handling non-responsive themes above.210 // Stretch width back out w/ the screen.211 if ($(this).data('nonresponsive') && $(this).width() < windowWidth) {212 $(this).width(windowWidth);213 }214 if (menuElement.data('removeattr')) {215 remove_classes_ids(menuElement);216 }217 $(this).addClass('responsified');218 }219 });220 });221 });222 }223 };...
Using AI Code Generation
1import { menuElement } from 'storybook-root'2import { menuElement } from 'storybook-root'3import { menuElement } from 'storybook-root'4import { menuElement } from 'storybook-root'5import { menuElement } from 'storybook-root'6import { menuElement } from 'storybook-root'7import { menuElement } from 'storybook-root'8import { menuElement } from 'storybook-root'9import { menuElement } from 'storybook-root'10import { menuElement } from 'storybook-root'11import { menuElement } from 'storybook-root'12import { menuElement } from 'storybook-root'13import { menuElement } from 'storybook-root'14import { menuElement } from 'storybook-root'15import { menuElement } from 'storybook-root'16import { menuElement } from 'storybook-root'
Using AI Code Generation
1const menuElement = await page.$('storybook-root');2const menu = await menuElement.$('button');3await menu.click();4const menuElement = await page.$('storybook-root');5const menu = await menuElement.$('button');6await menu.click();7const menuElement = await page.$('storybook-root');8const menu = await menuElement.$('button');9await menu.click();10const menuElement = await page.$('storybook-root');11const menu = await menuElement.$('button');12await menu.click();13const menuElement = await page.$('storybook-root');14const menu = await menuElement.$('button');15await menu.click();16const menuElement = await page.$('storybook-root');17const menu = await menuElement.$('button');18await menu.click();19const menuElement = await page.$('storybook-root');20const menu = await menuElement.$('button');21await menu.click();22const menuElement = await page.$('storybook-root');23const menu = await menuElement.$('button');24await menu.click();25const menuElement = await page.$('storybook-root');26const menu = await menuElement.$('button');27await menu.click();
Using AI Code Generation
1const menuElement = document.querySelector('storybook-root').menuElement;2menuElement.dispatchEvent(new CustomEvent('menuToggle', { detail: { isMenuOpen: true } }));3const menuElement = document.querySelector('storybook-root').menuElement;4menuElement.dispatchEvent(new CustomEvent('menuToggle', { detail: { isMenuOpen: false } }));5const menuElement = document.querySelector('storybook-root').menuElement;6menuElement.dispatchEvent(new CustomEvent('menuToggle', { detail: { isMenuOpen: true } }));7const menuElement = document.querySelector('storybook-root').menuElement;8menuElement.dispatchEvent(new CustomEvent('menuToggle', { detail: { isMenuOpen: false } }));9const menuElement = document.querySelector('storybook-root').menuElement;10menuElement.dispatchEvent(new CustomEvent('menuToggle', { detail: { isMenuOpen: true } }));11const menuElement = document.querySelector('storybook-root').menuElement;12menuElement.dispatchEvent(new CustomEvent('menuToggle', { detail: { isMenuOpen: false } }));13const menuElement = document.querySelector('storybook-root').menuElement;14menuElement.dispatchEvent(new CustomEvent('menuToggle', { detail: { isMenuOpen: true } }));15const menuElement = document.querySelector('storybook-root').menuElement;16menuElement.dispatchEvent(new CustomEvent('menuToggle', { detail: { isMenuOpen: false } }));17const menuElement = document.querySelector('storybook-root').menuElement;18menuElement.dispatchEvent(new CustomEvent('menuToggle', { detail: { isMenuOpen: true } }));19const menuElement = document.querySelector('storybook-root').menuElement;20menuElement.dispatchEvent(new CustomEvent('menuToggle', { detail: { isMenuOpen:
Using AI Code Generation
1var menuElement = document.querySelector('storybook-root').shadowRoot.querySelector('storybook-explorer').shadowRoot.querySelector('ul');2menuElement.querySelectorAll('li').forEach(function (item) {3 item.click();4});5var menuElement = document.querySelector('storybook-root').shadowRoot.querySelector('storybook-explorer').shadowRoot.querySelector('ul');6menuElement.querySelectorAll('li').forEach(function (item) {7 item.click();8});9var menuElement = document.querySelector('storybook-root').shadowRoot.querySelector('storybook-explorer').shadowRoot.querySelector('ul');10menuElement.querySelectorAll('li').forEach(function (item) {11 item.click();12});13var menuElement = document.querySelector('storybook-root').shadowRoot.querySelector('storybook-explorer').shadowRoot.querySelector('ul');14menuElement.querySelectorAll('li').forEach(function (item) {15 item.click();16});17var menuElement = document.querySelector('storybook-root').shadowRoot.querySelector('storybook-explorer').shadowRoot.querySelector('ul');18menuElement.querySelectorAll('li').forEach(function (item) {19 item.click();20});21var menuElement = document.querySelector('storybook-root').shadowRoot.querySelector('storybook-explorer').shadowRoot.querySelector('ul');22menuElement.querySelectorAll('li').forEach(function (item) {23 item.click();24});25var menuElement = document.querySelector('storybook-root').shadowRoot.querySelector('storybook-explorer').shadowRoot.querySelector('ul');26menuElement.querySelectorAll('li').forEach(function (item) {27 item.click();28});29var menuElement = document.querySelector('storybook-root').shadowRoot.querySelector('storybook-explorer').shadowRoot.querySelector('ul');30menuElement.querySelectorAll('li').forEach(function (item) {31 item.click();32});33var menuElement = document.querySelector('storybook-root').shadowRoot.querySelector('storybook-explorer').shadowRoot.querySelector('ul');34menuElement.querySelectorAll('li').forEach(function (item) {35 item.click();36});37var menuElement = document.querySelector('storybook-root').shadowRoot
Using AI Code Generation
1const storybookRoot = require("storybook-root");2const {menuElement} = storybookRoot;3const {getMenuElement} = menuElement;4const {getMenuElementByText} = getMenuElement;5const {getMenuElementByIndex} = getMenuElement;6const {getMenuElementByProperty} = getMenuElement;7const {getMenuElementByClass} = getMenuElement;8const {getMenuElementByClassIndex} = getMenuElement;9const {getMenuElementByClassProperty} = getMenuElement;10const {getMenuElementByClassText} = getMenuElement;11const {menuElement} = require("storybook-root");12const {getMenuElement} = menuElement;13const {getMenuElementByText} = getMenuElement;14const {getMenuElementByIndex} = getMenuElement;15const {getMenuElementByProperty} = getMenuElement;16const {getMenuElementByClass} = getMenuElement;17const {getMenuElementByClassIndex} = getMenuElement;18const {getMenuElementByClassProperty} = getMenuElement;19const {getMenuElementByClassText} = getMenuElement;20const storybookRoot = require("storybook-root");21const {menuElement} = storybookRoot;22const {getMenuElement} = menuElement;23const {getMenuElementByText} = getMenuElement;24const {getMenuElementByIndex} = getMenuElement;25const {getMenuElementByProperty} = getMenuElement;26const {getMenuElementByClass} = getMenuElement;27const {getMenuElementByClassIndex} = getMenuElement;28const {getMenuElementByClassProperty} = getMenuElement;29const {getMenuElementByClassText} = getMenuElement;30const {menuElement} = require("storybook-root");31const {getMenuElement} = menuElement;32const {getMenuElementByText} = getMenuElement;33const {getMenuElementByIndex} = getMenuElement;34const {getMenuElementByProperty} = getMenuElement;35const {getMenuElementByClass} = getMenuElement;36const {getMenuElementByClassIndex} = getMenuElement;37const {getMenuElementByClassProperty} = getMenuElement;38const {getMenuElementByClassText} = getMenuElement;
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!