1/*! 2 * SmartMenus jQuery Plugin - v1.1.0 - September 17, 2017 3 * http://www.smartmenus.org/ 4 * 5 * Copyright Vasil Dinkov, Vadikom Web Ltd. 6 * http://vadikom.com 7 * 8 * Licensed MIT 9 */ 10 11(function(factory) { 12 if (typeof define === 'function' && define.amd) { 13 // AMD 14 define(['jquery'], factory); 15 } else if (typeof module === 'object' && typeof module.exports === 'object') { 16 // CommonJS 17 module.exports = factory(require('jquery')); 18 } else { 19 // Global jQuery 20 factory(jQuery); 21 } 22} (function($) { 23 24 var menuTrees = [], 25 mouse = false, // optimize for touch by default - we will detect for mouse input 26 touchEvents = 'ontouchstart' in window, // we use this just to choose between toucn and pointer events, not for touch screen detection 27 mouseDetectionEnabled = false, 28 requestAnimationFrame = window.requestAnimationFrame || function(callback) { return setTimeout(callback, 1000 / 60); }, 29 cancelAnimationFrame = window.cancelAnimationFrame || function(id) { clearTimeout(id); }, 30 canAnimate = !!$.fn.animate; 31 32 // Handle detection for mouse input (i.e. desktop browsers, tablets with a mouse, etc.) 33 function initMouseDetection(disable) { 34 var eNS = '.smartmenus_mouse'; 35 if (!mouseDetectionEnabled && !disable) { 36 // if we get two consecutive mousemoves within 2 pixels from each other and within 300ms, we assume a real mouse/cursor is present 37 // in practice, this seems like impossible to trick unintentianally with a real mouse and a pretty safe detection on touch devices (even with older browsers that do not support touch events) 38 var firstTime = true, 39 lastMove = null, 40 events = { 41 'mousemove': function(e) { 42 var thisMove = { x: e.pageX, y: e.pageY, timeStamp: new Date().getTime() }; 43 if (lastMove) { 44 var deltaX = Math.abs(lastMove.x - thisMove.x), 45 deltaY = Math.abs(lastMove.y - thisMove.y); 46 if ((deltaX > 0 || deltaY > 0) && deltaX <= 2 && deltaY <= 2 && thisMove.timeStamp - lastMove.timeStamp <= 300) { 47 mouse = true; 48 // if this is the first check after page load, check if we are not over some item by chance and call the mouseenter handler if yes 49 if (firstTime) { 50 var $a = $(e.target).closest('a'); 51 if ($a.is('a')) { 52 $.each(menuTrees, function() { 53 if ($.contains(this.$root[0], $a[0])) { 54 this.itemEnter({ currentTarget: $a[0] }); 55 return false; 56 } 57 }); 58 } 59 firstTime = false; 60 } 61 } 62 } 63 lastMove = thisMove; 64 } 65 }; 66 events[touchEvents ? 'touchstart' : 'pointerover pointermove pointerout MSPointerOver MSPointerMove MSPointerOut'] = function(e) { 67 if (isTouchEvent(e.originalEvent)) { 68 mouse = false; 69 } 70 }; 71 $(document).on(getEventsNS(events, eNS)); 72 mouseDetectionEnabled = true; 73 } else if (mouseDetectionEnabled && disable) { 74 $(document).off(eNS); 75 mouseDetectionEnabled = false; 76 } 77 } 78 79 function isTouchEvent(e) { 80 return !/^(4|mouse)$/.test(e.pointerType); 81 } 82 83 // returns a jQuery on() ready object 84 function getEventsNS(events, eNS) { 85 if (!eNS) { 86 eNS = ''; 87 } 88 var eventsNS = {}; 89 for (var i in events) { 90 eventsNS[i.split(' ').join(eNS + ' ') + eNS] = events[i]; 91 } 92 return eventsNS; 93 } 94 95 $.SmartMenus = function(elm, options) { 96 this.$root = $(elm); 97 this.opts = options; 98 this.rootId = ''; // internal 99 this.accessIdPrefix = ''; 100 this.$subArrow = null; 101 this.activatedItems = []; // stores last activated A's for each level 102 this.visibleSubMenus = []; // stores visible sub menus UL's (might be in no particular order) 103 this.showTimeout = 0; 104 this.hideTimeout = 0; 105 this.scrollTimeout = 0; 106 this.clickActivated = false; 107 this.focusActivated = false; 108 this.zIndexInc = 0; 109 this.idInc = 0; 110 this.$firstLink = null; // we'll use these for some tests 111 this.$firstSub = null; // at runtime so we'll cache them 112 this.disabled = false; 113 this.$disableOverlay = null; 114 this.$touchScrollingSub = null; 115 this.cssTransforms3d = 'perspective' in elm.style || 'webkitPerspective' in elm.style; 116 this.wasCollapsible = false;
117 this.init(); 118 }; 119 120 $.extend($.SmartMenus, { 121 hideAll: function() { 122 $.each(menuTrees, function() { 123 this.menuHideAll(); 124 }); 125 }, 126 destroy: function() { 127 while (menuTrees.length) { 128 menuTrees[0].destroy(); 129 } 130 initMouseDetection(true); 131 }, 132 prototype: { 133 init: function(refresh) { 134 var self = this; 135 136 if (!refresh) { 137 menuTrees.push(this); 138 139 this.rootId = (new Date().getTime() + Math.random() + '').replace(/\D/g, ''); 140 this.accessIdPrefix = 'sm-' + this.rootId + '-'; 141 142 if (this.$root.hasClass('sm-rtl')) { 143 this.opts.rightToLeftSubMenus = true; 144 } 145 146 // init root (main menu) 147 var eNS = '.smartmenus'; 148 this.$root 149 .data('smartmenus', this) 150 .attr('data-smartmenus-id', this.rootId) 151 .dataSM('level', 1) 152 .on(getEventsNS({ 153 'mouseover focusin': $.proxy(this.rootOver, this), 154 'mouseout focusout': $.proxy(this.rootOut, this), 155 'keydown': $.proxy(this.rootKeyDown, this) 156 }, eNS)) 157 .on(getEventsNS({ 158 'mouseenter': $.proxy(this.itemEnter, this), 159 'mouseleave': $.proxy(this.itemLeave, this), 160 'mousedown': $.proxy(this.itemDown, this), 161 'focus': $.proxy(this.itemFocus, this), 162 'blur': $.proxy(this.itemBlur, this), 163 'click': $.proxy(this.itemClick, this) 164 }, eNS), 'a'); 165 166 // hide menus on tap or click outside the root UL 167 eNS += this.rootId; 168 if (this.opts.hideOnClick) { 169 $(document).on(getEventsNS({ 170 'touchstart': $.proxy(this.docTouchStart, this), 171 'touchmove': $.proxy(this.docTouchMove, this), 172 'touchend': $.proxy(this.docTouchEnd, this), 173 // for Opera Mobile < 11.5, webOS browser, etc. we'll check click too 174 'click': $.proxy(this.docClick, this) 175 }, eNS)); 176 } 177 // hide sub menus on resize 178 $(window).on(getEventsNS({ 'resize orientationchange': $.proxy(this.winResize, this) }, eNS)); 179 180 if (this.opts.subIndicators) { 181 this.$subArrow = $('<span/>').addClass('sub-arrow'); 182 if (this.opts.subIndicatorsText) { 183 this.$subArrow.html(this.opts.subIndicatorsText); 184 } 185 } 186 187 // make sure mouse detection is enabled 188 initMouseDetection(); 189 } 190 191 // init sub menus 192 this.$firstSub = this.$root.find('ul').each(function() { self.menuInit($(this)); }).eq(0); 193 194 this.$firstLink = this.$root.find('a').eq(0); 195 196 // find current item 197 if (this.opts.markCurrentItem) { 198 var reDefaultDoc = /(index|default)\.[^#\?\/]*/i, 199 reHash = /#.*/, 200 locHref = window.location.href.replace(reDefaultDoc, ''), 201 locHrefNoHash = locHref.replace(reHash, ''); 202 this.$root.find('a').each(function() { 203 var href = this.href.replace(reDefaultDoc, ''), 204 $this = $(this); 205 if (href == locHref || href == locHrefNoHash) { 206 $this.addClass('current'); 207 if (self.opts.markCurrentTree) { 208 $this.parentsUntil('[data-smartmenus-id]', 'ul').each(function() { 209 $(this).dataSM('parent-a').addClass('current'); 210 }); 211 } 212 } 213 }); 214 } 215 216 // save initial state 217 this.wasCollapsible = this.isCollapsible(); 218 }, 219 destroy: function(refresh) { 220 if (!refresh) { 221 var eNS = '.smartmenus'; 222 this.$root 223 .removeData('smartmenus') 224 .removeAttr('data-smartmenus-id') 225 .removeDataSM('level') 226 .off(eNS); 227 eNS += this.rootId; 228 $(document).off(eNS); 229 $(window).off(eNS); 230 if (this.opts.subIndicators) { 231 this.$subArrow = null; 232 } 233 } 234 this.menuHideAll(); 235 var self = this; 236 this.$root.find('ul').each(function() { 237 var $this = $(this); 238 if ($this.dataSM('scroll-arrows')) { 239 $this.dataSM('scroll-arrows').remove(); 240 } 241 if ($this.dataSM('shown-before')) { 242 if (self.opts.subMenusMinWidth || self.opts.subMenusMaxWidth) { 243 $this.css({ width: '', minWidth: '', maxWidth: '' }).removeClass('sm-nowrap'); 244 } 245 if ($this.dataSM('scroll-arrows')) { 246 $this.dataSM('scroll-arrows').remove(); 247 } 248 $this.css({ zIndex: '', top: '', left: '', marginLeft: '', marginTop: '', display: '' }); 249 } 250 if (($this.attr('id') || '').indexOf(self.accessIdPrefix) == 0) { 251 $this.removeAttr('id'); 252 } 253 }) 254 .removeDataSM('in-mega') 255 .removeDataSM('shown-before') 256 .removeDataSM('scroll-arrows') 257 .removeDataSM('parent-a') 258 .removeDataSM('level') 259 .removeDataSM('beforefirstshowfired') 260 .removeAttr('role') 261 .removeAttr('aria-hidden') 262 .removeAttr('aria-labelledby') 263 .removeAttr('aria-expanded'); 264 this.$root.find('a.has-submenu').each(function() { 265 var $this = $(this); 266 if ($this.attr('id').indexOf(self.accessIdPrefix) == 0) { 267 $this.removeAttr('id'); 268 } 269 }) 270 .removeClass('has-submenu') 271 .removeDataSM('sub') 272 .removeAttr('aria-haspopup') 273 .removeAttr('aria-controls') 274 .removeAttr('aria-expanded') 275 .closest('li').removeDataSM('sub'); 276 if (this.opts.subIndicators) { 277 this.$root.find('span.sub-arrow').remove(); 278 } 279 if (this.opts.markCurrentItem) { 280 this.$root.find('a.current').removeClass('current'); 281 } 282 if (!refresh) { 283 this.$root = null; 284 this.$firstLink = null; 285 this.$firstSub = null; 286 if (this.$disableOverlay) { 287 this.$disableOverlay.remove(); 288 this.$disableOverlay = null; 289 } 290 menuTrees.splice($.inArray(this, menuTrees), 1); 291 } 292 }, 293 disable: function(noOverlay) { 294 if (!this.disabled) { 295 this.menuHideAll(); 296 // display overlay over the menu to prevent interaction 297 if (!noOverlay && !this.opts.isPopup && this.$root.is(':visible')) { 298 var pos = this.$root.offset(); 299 this.$disableOverlay = $('<div class="sm-jquery-disable-overlay"/>').css({ 300 position: 'absolute', 301 top: pos.top, 302 left: pos.left, 303 width: this.$root.outerWidth(), 304 height: this.$root.outerHeight(),
305 zIndex: this.getStartZIndex(true), 306 opacity: 0 307 }).appendTo(document.body); 308 } 309 this.disabled = true; 310 } 311 }, 312 docClick: function(e) { 313 if (this.$touchScrollingSub) { 314 this.$touchScrollingSub = null; 315 return; 316 } 317 // hide on any click outside the menu or on a menu link 318 if (this.visibleSubMenus.length && !$.contains(this.$root[0], e.target) || $(e.target).closest('a').length) { 319 this.menuHideAll(); 320 } 321 }, 322 docTouchEnd: function(e) { 323 if (!this.lastTouch) { 324 return; 325 } 326 if (this.visibleSubMenus.length && (this.lastTouch.x2 === undefined || this.lastTouch.x1 == this.lastTouch.x2) && (this.lastTouch.y2 === undefined || this.lastTouch.y1 == this.lastTouch.y2) && (!this.lastTouch.target || !$.contains(this.$root[0], this.lastTouch.target))) { 327 if (this.hideTimeout) { 328 clearTimeout(this.hideTimeout); 329 this.hideTimeout = 0; 330 } 331 // hide with a delay to prevent triggering accidental unwanted click on some page element 332 var self = this; 333 this.hideTimeout = setTimeout(function() { self.menuHideAll(); }, 350); 334 } 335 this.lastTouch = null; 336 }, 337 docTouchMove: function(e) { 338 if (!this.lastTouch) { 339 return; 340 } 341 var touchPoint = e.originalEvent.touches[0]; 342 this.lastTouch.x2 = touchPoint.pageX; 343 this.lastTouch.y2 = touchPoint.pageY; 344 }, 345 docTouchStart: function(e) { 346 var touchPoint = e.originalEvent.touches[0]; 347 this.lastTouch = { x1: touchPoint.pageX, y1: touchPoint.pageY, target: touchPoint.target }; 348 }, 349 enable: function() { 350 if (this.disabled) { 351 if (this.$disableOverlay) { 352 this.$disableOverlay.remove(); 353 this.$disableOverlay = null; 354 } 355 this.disabled = false; 356 } 357 }, 358 getClosestMenu: function(elm) { 359 var $closestMenu = $(elm).closest('ul'); 360 while ($closestMenu.dataSM('in-mega')) { 361 $closestMenu = $closestMenu.parent().closest('ul'); 362 } 363 return $closestMenu[0] || null; 364 }, 365 getHeight: function($elm) { 366 return this.getOffset($elm, true); 367 }, 368 // returns precise width/height float values 369 getOffset: function($elm, height) { 370 var old; 371 if ($elm.css('display') == 'none') { 372 old = { position: $elm[0].style.position, visibility: $elm[0].style.visibility }; 373 $elm.css({ position: 'absolute', visibility: 'hidden' }).show(); 374 } 375 var box = $elm[0].getBoundingClientRect && $elm[0].getBoundingClientRect(), 376 val = box && (height ? box.height || box.bottom - box.top : box.width || box.right - box.left); 377 if (!val && val !== 0) { 378 val = height ? $elm[0].offsetHeight : $elm[0].offsetWidth; 379 } 380 if (old) { 381 $elm.hide().css(old); 382 } 383 return val; 384 }, 385 getStartZIndex: function(root) { 386 var zIndex = parseInt(this[root ? '$root' : '$firstSub'].css('z-index')); 387 if (!root && isNaN(zIndex)) { 388 zIndex = parseInt(this.$root.css('z-index')); 389 } 390 return !isNaN(zIndex) ? zIndex : 1; 391 }, 392 getTouchPoint: function(e) { 393 return e.touches && e.touches[0] || e.changedTouches && e.changedTouches[0] || e; 394 }, 395 getViewport: function(height) { 396 var name = height ? 'Height' : 'Width', 397 val = document.documentElement['client' + name], 398 val2 = window['inner' + name]; 399 if (val2) { 400 val = Math.min(val, val2); 401 } 402 return val; 403 }, 404 getViewportHeight: function() { 405 return this.getViewport(true); 406 }, 407 getViewportWidth: function() { 408 return this.getViewport(); 409 }, 410 getWidth: function($elm) { 411 return this.getOffset($elm); 412 }, 413 handleEvents: function() { 414 return !this.disabled && this.isCSSOn(); 415 }, 416 handleItemEvents: function($a) { 417 return this.handleEvents() && !this.isLinkInMegaMenu($a); 418 }, 419 isCollapsible: function() { 420 return this.$firstSub.css('position') == 'static'; 421 }, 422 isCSSOn: function() { 423 return this.$firstLink.css('display') != 'inline'; 424 }, 425 isFixed: function() { 426 var isFixed = this.$root.css('position') == 'fixed'; 427 if (!isFixed) { 428 this.$root.parentsUntil('body').each(function() { 429 if ($(this).css('position') == 'fixed') { 430 isFixed = true; 431 return false;
432 } 433 }); 434 } 435 return isFixed; 436 }, 437 isLinkInMegaMenu: function($a) { 438 return $(this.getClosestMenu($a[0])).hasClass('mega-menu'); 439 }, 440 isTouchMode: function() { 441 return !mouse || this.opts.noMouseOver || this.isCollapsible(); 442 }, 443 itemActivate: function($a, hideDeeperSubs) { 444 var $ul = $a.closest('ul'), 445 level = $ul.dataSM('level'); 446 // if for some reason the parent item is not activated (e.g. this is an API call to activate the item), activate all parent items first 447 if (level > 1 && (!this.activatedItems[level - 2] || this.activatedItems[level - 2][0] != $ul.dataSM('parent-a')[0])) { 448 var self = this; 449 $($ul.parentsUntil('[data-smartmenus-id]', 'ul').get().reverse()).add($ul).each(function() { 450 self.itemActivate($(this).dataSM('parent-a')); 451 }); 452 } 453 // hide any visible deeper level sub menus 454 if (!this.isCollapsible() || hideDeeperSubs) { 455 this.menuHideSubMenus(!this.activatedItems[level - 1] || this.activatedItems[level - 1][0] != $a[0] ? level - 1 : level); 456 } 457 // save new active item for this level 458 this.activatedItems[level - 1] = $a; 459 if (this.$root.triggerHandler('activate.smapi', $a[0]) === false) { 460 return; 461 } 462 // show the sub menu if this item has one 463 var $sub = $a.dataSM('sub'); 464 if ($sub && (this.isTouchMode() || (!this.opts.showOnClick || this.clickActivated))) { 465 this.menuShow($sub); 466 } 467 }, 468 itemBlur: function(e) { 469 var $a = $(e.currentTarget); 470 if (!this.handleItemEvents($a)) { 471 return; 472 } 473 this.$root.triggerHandler('blur.smapi', $a[0]); 474 }, 475 itemClick: function(e) { 476 var $a = $(e.currentTarget); 477 if (!this.handleItemEvents($a)) { 478 return; 479 } 480 if (this.$touchScrollingSub && this.$touchScrollingSub[0] == $a.closest('ul')[0]) { 481 this.$touchScrollingSub = null; 482 e.stopPropagation(); 483 return false; 484 } 485 if (this.$root.triggerHandler('click.smapi', $a[0]) === false) { 486 return false; 487 } 488 var subArrowClicked = $(e.target).is('.sub-arrow'), 489 $sub = $a.dataSM('sub'), 490 firstLevelSub = $sub ? $sub.dataSM('level') == 2 : false, 491 collapsible = this.isCollapsible(), 492 behaviorToggle = /toggle$/.test(this.opts.collapsibleBehavior), 493 behaviorLink = /link$/.test(this.opts.collapsibleBehavior), 494 behaviorAccordion = /^accordion/.test(this.opts.collapsibleBehavior); 495 // if the sub is hidden, try to show it 496 if ($sub && !$sub.is(':visible')) { 497 if (!behaviorLink || !collapsible || subArrowClicked) { 498 if (this.opts.showOnClick && firstLevelSub) { 499 this.clickActivated = true; 500 } 501 // try to activate the item and show the sub 502 this.itemActivate($a, behaviorAccordion); 503 // if "itemActivate" showed the sub, prevent the click so that the link is not loaded 504 // if it couldn't show it, then the sub menus are disabled with an !important declaration (e.g. via mobile styles) so let the link get loaded 505 if ($sub.is(':visible')) { 506 this.focusActivated = true; 507 return false; 508 } 509 } 510 // if the sub is visible and we are in collapsible mode 511 } else if (collapsible && (behaviorToggle || subArrowClicked)) { 512 this.itemActivate($a, behaviorAccordion); 513 this.menuHide($sub); 514 if (behaviorToggle) { 515 this.focusActivated = false; 516 } 517 return false; 518 } 519 if (this.opts.showOnClick && firstLevelSub || $a.hasClass('disabled') || this.$root.triggerHandler('select.smapi', $a[0]) === false) { 520 return false; 521 } 522 }, 523 itemDown: function(e) { 524 var $a = $(e.currentTarget); 525 if (!this.handleItemEvents($a)) { 526 return; 527 } 528 $a.dataSM('mousedown', true); 529 }, 530 itemEnter: function(e) { 531 var $a = $(e.currentTarget); 532 if (!this.handleItemEvents($a)) { 533 return; 534 } 535 if (!this.isTouchMode()) { 536 if (this.showTimeout) { 537 clearTimeout(this.showTimeout); 538 this.showTimeout = 0; 539 } 540 var self = this; 541 this.showTimeout = setTimeout(function() { self.itemActivate($a); }, this.opts.showOnClick && $a.closest('ul').dataSM('level') == 1 ? 1 : this.opts.showTimeout); 542 } 543 this.$root.triggerHandler('mouseenter.smapi', $a[0]); 544 }, 545 itemFocus: function(e) { 546 var $a = $(e.currentTarget); 547 if (!this.handleItemEvents($a)) { 548 return; 549 } 550 // fix (the mousedown check): in some browsers a tap/click produces consecutive focus + click events so we don't need to activate the item on focus 551 if (this.focusActivated && (!this.isTouchMode() || !$a.dataSM('mousedown')) && (!this.activatedItems.length || this.activatedItems[this.activatedItems.length - 1][0] != $a[0])) { 552 this.itemActivate($a, true); 553 } 554 this.$root.triggerHandler('focus.smapi', $a[0]); 555 }, 556 itemLeave: function(e) { 557 var $a = $(e.currentTarget); 558 if (!this.handleItemEvents($a)) { 559 return; 560 } 561 if (!this.isTouchMode()) { 562 $a[0].blur(); 563 if (this.showTimeout) { 564 clearTimeout(this.showTimeout); 565 this.showTimeout = 0; 566 } 567 } 568 $a.removeDataSM('mousedown');
569 this.$root.triggerHandler('mouseleave.smapi', $a[0]); 570 }, 571 menuHide: function($sub) { 572 if (this.$root.triggerHandler('beforehide.smapi', $sub[0]) === false) { 573 return; 574 } 575 if (canAnimate) { 576 $sub.stop(true, true); 577 } 578 if ($sub.css('display') != 'none') { 579 var complete = function() { 580 // unset z-index 581 $sub.css('z-index', ''); 582 }; 583 // if sub is collapsible (mobile view) 584 if (this.isCollapsible()) { 585 if (canAnimate && this.opts.collapsibleHideFunction) { 586 this.opts.collapsibleHideFunction.call(this, $sub, complete); 587 } else { 588 $sub.hide(this.opts.collapsibleHideDuration, complete); 589 } 590 } else { 591 if (canAnimate && this.opts.hideFunction) { 592 this.opts.hideFunction.call(this, $sub, complete); 593 } else { 594 $sub.hide(this.opts.hideDuration, complete); 595 } 596 } 597 // deactivate scrolling if it is activated for this sub 598 if ($sub.dataSM('scroll')) { 599 this.menuScrollStop($sub); 600 $sub.css({ 'touch-action': '', '-ms-touch-action': '', '-webkit-transform': '', transform: '' }) 601 .off('.smartmenus_scroll').removeDataSM('scroll').dataSM('scroll-arrows').hide(); 602 } 603 // unhighlight parent item + accessibility 604 $sub.dataSM('parent-a').removeClass('highlighted').attr('aria-expanded', 'false'); 605 $sub.attr({ 606 'aria-expanded': 'false', 607 'aria-hidden': 'true' 608 }); 609 var level = $sub.dataSM('level'); 610 this.activatedItems.splice(level - 1, 1); 611 this.visibleSubMenus.splice($.inArray($sub, this.visibleSubMenus), 1); 612 this.$root.triggerHandler('hide.smapi', $sub[0]); 613 } 614 }, 615 menuHideAll: function() { 616 if (this.showTimeout) { 617 clearTimeout(this.showTimeout); 618 this.showTimeout = 0; 619 } 620 // hide all subs 621 // if it's a popup, this.visibleSubMenus[0] is the root UL 622 var level = this.opts.isPopup ? 1 : 0; 623 for (var i = this.visibleSubMenus.length - 1; i >= level; i--) { 624 this.menuHide(this.visibleSubMenus[i]); 625 } 626 // hide root if it's popup 627 if (this.opts.isPopup) { 628 if (canAnimate) { 629 this.$root.stop(true, true); 630 } 631 if (this.$root.is(':visible')) { 632 if (canAnimate && this.opts.hideFunction) { 633 this.opts.hideFunction.call(this, this.$root); 634 } else { 635 this.$root.hide(this.opts.hideDuration); 636 } 637 } 638 } 639 this.activatedItems = []; 640 this.visibleSubMenus = []; 641 this.clickActivated = false; 642 this.focusActivated = false; 643 // reset z-index increment 644 this.zIndexInc = 0; 645 this.$root.triggerHandler('hideAll.smapi'); 646 }, 647 menuHideSubMenus: function(level) { 648 for (var i = this.activatedItems.length - 1; i >= level; i--) { 649 var $sub = this.activatedItems[i].dataSM('sub'); 650 if ($sub) { 651 this.menuHide($sub); 652 } 653 } 654 }, 655 menuInit: function($ul) { 656 if (!$ul.dataSM('in-mega')) { 657 // mark UL's in mega drop downs (if any) so we can neglect them 658 if ($ul.hasClass('mega-menu')) { 659 $ul.find('ul').dataSM('in-mega', true); 660 } 661 // get level (much faster than, for example, using parentsUntil) 662 var level = 2, 663 par = $ul[0]; 664 while ((par = par.parentNode.parentNode) != this.$root[0]) { 665 level++; 666 } 667 // cache stuff for quick access 668 var $a = $ul.prevAll('a').eq(-1); 669 // if the link is nested (e.g. in a heading) 670 if (!$a.length) { 671 $a = $ul.prevAll().find('a').eq(-1); 672 } 673 $a.addClass('has-submenu').dataSM('sub', $ul); 674 $ul.dataSM('parent-a', $a) 675 .dataSM('level', level) 676 .parent().dataSM('sub', $ul); 677 // accessibility 678 var aId = $a.attr('id') || this.accessIdPrefix + (++this.idInc), 679 ulId = $ul.attr('id') || this.accessIdPrefix + (++this.idInc); 680 $a.attr({ 681 id: aId, 682 'aria-haspopup': 'true', 683 'aria-controls': ulId, 684 'aria-expanded': 'false' 685 }); 686 $ul.attr({ 687 id: ulId, 688 'role': 'group', 689 'aria-hidden': 'true', 690 'aria-labelledby': aId, 691 'aria-expanded': 'false' 692 }); 693 // add sub indicator to parent item 694 if (this.opts.subIndicators) { 695 $a[this.opts.subIndicatorsPos](this.$subArrow.clone()); 696 } 697 } 698 }, 699 menuPosition: function($sub) { 700 var $a = $sub.dataSM('parent-a'), 701 $li = $a.closest('li'), 702 $ul = $li.parent(), 703 level = $sub.dataSM('level'), 704 subW = this.getWidth($sub), 705 subH = this.getHeight($sub), 706 itemOffset = $a.offset(), 707 itemX = itemOffset.left, 708 itemY = itemOffset.top, 709 itemW = this.getWidth($a), 710 itemH = this.getHeight($a), 711 $win = $(window), 712 winX = $win.scrollLeft(), 713 winY = $win.scrollTop(), 714 winW = this.getViewportWidth(),
715 winH = this.getViewportHeight(), 716 horizontalParent = $ul.parent().is('[data-sm-horizontal-sub]') || level == 2 && !$ul.hasClass('sm-vertical'), 717 rightToLeft = this.opts.rightToLeftSubMenus && !$li.is('[data-sm-reverse]') || !this.opts.rightToLeftSubMenus && $li.is('[data-sm-reverse]'), 718 subOffsetX = level == 2 ? this.opts.mainMenuSubOffsetX : this.opts.subMenusSubOffsetX, 719 subOffsetY = level == 2 ? this.opts.mainMenuSubOffsetY : this.opts.subMenusSubOffsetY, 720 x, y; 721 if (horizontalParent) { 722 x = rightToLeft ? itemW - subW - subOffsetX : subOffsetX; 723 y = this.opts.bottomToTopSubMenus ? -subH - subOffsetY : itemH + subOffsetY; 724 } else { 725 x = rightToLeft ? subOffsetX - subW : itemW - subOffsetX; 726 y = this.opts.bottomToTopSubMenus ? itemH - subOffsetY - subH : subOffsetY; 727 } 728 if (this.opts.keepInViewport) { 729 var absX = itemX + x, 730 absY = itemY + y; 731 if (rightToLeft && absX < winX) { 732 x = horizontalParent ? winX - absX + x : itemW - subOffsetX; 733 } else if (!rightToLeft && absX + subW > winX + winW) { 734 x = horizontalParent ? winX + winW - subW - absX + x : subOffsetX - subW; 735 } 736 if (!horizontalParent) { 737 if (subH < winH && absY + subH > winY + winH) { 738 y += winY + winH - subH - absY; 739 } else if (subH >= winH || absY < winY) { 740 y += winY - absY; 741 } 742 } 743 // do we need scrolling? 744 // 0.49 used for better precision when dealing with float values 745 if (horizontalParent && (absY + subH > winY + winH + 0.49 || absY < winY) || !horizontalParent && subH > winH + 0.49) { 746 var self = this; 747 if (!$sub.dataSM('scroll-arrows')) { 748 $sub.dataSM('scroll-arrows', $([$('<span class="scroll-up"><span class="scroll-up-arrow"></span></span>')[0], $('<span class="scroll-down"><span class="scroll-down-arrow"></span></span>')[0]]) 749 .on({ 750 mouseenter: function() { 751 $sub.dataSM('scroll').up = $(this).hasClass('scroll-up'); 752 self.menuScroll($sub); 753 }, 754 mouseleave: function(e) { 755 self.menuScrollStop($sub); 756 self.menuScrollOut($sub, e); 757 }, 758 'mousewheel DOMMouseScroll': function(e) { e.preventDefault(); } 759 }) 760 .insertAfter($sub) 761 ); 762 } 763 // bind scroll events and save scroll data for this sub 764 var eNS = '.smartmenus_scroll'; 765 $sub.dataSM('scroll', { 766 y: this.cssTransforms3d ? 0 : y - itemH, 767 step: 1, 768 // cache stuff for faster recalcs later 769 itemH: itemH, 770 subH: subH, 771 arrowDownH: this.getHeight($sub.dataSM('scroll-arrows').eq(1)) 772 }) 773 .on(getEventsNS({ 774 'mouseover': function(e) { self.menuScrollOver($sub, e); }, 775 'mouseout': function(e) { self.menuScrollOut($sub, e); }, 776 'mousewheel DOMMouseScroll': function(e) { self.menuScrollMousewheel($sub, e); } 777 }, eNS)) 778 .dataSM('scroll-arrows').css({ top: 'auto', left: '0', marginLeft: x + (parseInt($sub.css('border-left-width')) || 0), width: subW - (parseInt($sub.css('border-left-width')) || 0) - (parseInt($sub.css('border-right-width')) || 0), zIndex: $sub.css('z-index') }) 779 .eq(horizontalParent && this.opts.bottomToTopSubMenus ? 0 : 1).show(); 780 // when a menu tree is fixed positioned we allow scrolling via touch too 781 // since there is no other way to access such long sub menus if no mouse is present 782 if (this.isFixed()) { 783 var events = {}; 784 events[touchEvents ? 'touchstart touchmove touchend' : 'pointerdown pointermove pointerup MSPointerDown MSPointerMove MSPointerUp'] = function(e) { 785 self.menuScrollTouch($sub, e); 786 }; 787 $sub.css({ 'touch-action': 'none', '-ms-touch-action': 'none' }).on(getEventsNS(events, eNS)); 788 } 789 } 790 } 791 $sub.css({ top: 'auto', left: '0', marginLeft: x, marginTop: y - itemH }); 792 }, 793 menuScroll: function($sub, once, step) { 794 var data = $sub.dataSM('scroll'), 795 $arrows = $sub.dataSM('scroll-arrows'), 796 end = data.up ? data.upEnd : data.downEnd, 797 diff; 798 if (!once && data.momentum) { 799 data.momentum *= 0.92; 800 diff = data.momentum; 801 if (diff < 0.5) { 802 this.menuScrollStop($sub); 803 return; 804 } 805 } else { 806 diff = step || (once || !this.opts.scrollAccelerate ? this.opts.scrollStep : Math.floor(data.step)); 807 } 808 // hide any visible deeper level sub menus 809 var level = $sub.dataSM('level'); 810 if (this.activatedItems[level - 1] && this.activatedItems[level - 1].dataSM('sub') && this.activatedItems[level - 1].dataSM('sub').is(':visible')) {
811 this.menuHideSubMenus(level - 1); 812 } 813 data.y = data.up && end <= data.y || !data.up && end >= data.y ? data.y : (Math.abs(end - data.y) > diff ? data.y + (data.up ? diff : -diff) : end); 814 $sub.css(this.cssTransforms3d ? { '-webkit-transform': 'translate3d(0, ' + data.y + 'px, 0)', transform: 'translate3d(0, ' + data.y + 'px, 0)' } : { marginTop: data.y }); 815 // show opposite arrow if appropriate 816 if (mouse && (data.up && data.y > data.downEnd || !data.up && data.y < data.upEnd)) { 817 $arrows.eq(data.up ? 1 : 0).show(); 818 } 819 // if we've reached the end 820 if (data.y == end) { 821 if (mouse) { 822 $arrows.eq(data.up ? 0 : 1).hide(); 823 } 824 this.menuScrollStop($sub); 825 } else if (!once) { 826 if (this.opts.scrollAccelerate && data.step < this.opts.scrollStep) { 827 data.step += 0.2; 828 } 829 var self = this; 830 this.scrollTimeout = requestAnimationFrame(function() { self.menuScroll($sub); }); 831 } 832 }, 833 menuScrollMousewheel: function($sub, e) { 834 if (this.getClosestMenu(e.target) == $sub[0]) { 835 e = e.originalEvent; 836 var up = (e.wheelDelta || -e.detail) > 0; 837 if ($sub.dataSM('scroll-arrows').eq(up ? 0 : 1).is(':visible')) { 838 $sub.dataSM('scroll').up = up; 839 this.menuScroll($sub, true); 840 } 841 } 842 e.preventDefault(); 843 }, 844 menuScrollOut: function($sub, e) { 845 if (mouse) { 846 if (!/^scroll-(up|down)/.test((e.relatedTarget || '').className) && ($sub[0] != e.relatedTarget && !$.contains($sub[0], e.relatedTarget) || this.getClosestMenu(e.relatedTarget) != $sub[0])) { 847 $sub.dataSM('scroll-arrows').css('visibility', 'hidden'); 848 } 849 } 850 }, 851 menuScrollOver: function($sub, e) { 852 if (mouse) { 853 if (!/^scroll-(up|down)/.test(e.target.className) && this.getClosestMenu(e.target) == $sub[0]) { 854 this.menuScrollRefreshData($sub); 855 var data = $sub.dataSM('scroll'), 856 upEnd = $(window).scrollTop() - $sub.dataSM('parent-a').offset().top - data.itemH; 857 $sub.dataSM('scroll-arrows').eq(0).css('margin-top', upEnd).end() 858 .eq(1).css('margin-top', upEnd + this.getViewportHeight() - data.arrowDownH).end() 859 .css('visibility', 'visible'); 860 } 861 } 862 }, 863 menuScrollRefreshData: function($sub) { 864 var data = $sub.dataSM('scroll'), 865 upEnd = $(window).scrollTop() - $sub.dataSM('parent-a').offset().top - data.itemH; 866 if (this.cssTransforms3d) { 867 upEnd = -(parseFloat($sub.css('margin-top')) - upEnd); 868 } 869 $.extend(data, { 870 upEnd: upEnd, 871 downEnd: upEnd + this.getViewportHeight() - data.subH 872 }); 873 }, 874 menuScrollStop: function($sub) { 875 if (this.scrollTimeout) { 876 cancelAnimationFrame(this.scrollTimeout); 877 this.scrollTimeout = 0; 878 $sub.dataSM('scroll').step = 1; 879 return true; 880 } 881 }, 882 menuScrollTouch: function($sub, e) { 883 e = e.originalEvent; 884 if (isTouchEvent(e)) { 885 var touchPoint = this.getTouchPoint(e); 886 // neglect event if we touched a visible deeper level sub menu 887 if (this.getClosestMenu(touchPoint.target) == $sub[0]) { 888 var data = $sub.dataSM('scroll'); 889 if (/(start|down)$/i.test(e.type)) { 890 if (this.menuScrollStop($sub)) { 891 // if we were scrolling, just stop and don't activate any link on the first touch 892 e.preventDefault(); 893 this.$touchScrollingSub = $sub; 894 } else { 895 this.$touchScrollingSub = null; 896 } 897 // update scroll data since the user might have zoomed, etc. 898 this.menuScrollRefreshData($sub); 899 // extend it with the touch properties 900 $.extend(data, { 901 touchStartY: touchPoint.pageY, 902 touchStartTime: e.timeStamp 903 }); 904 } else if (/move$/i.test(e.type)) { 905 var prevY = data.touchY !== undefined ? data.touchY : data.touchStartY; 906 if (prevY !== undefined && prevY != touchPoint.pageY) { 907 this.$touchScrollingSub = $sub; 908 var up = prevY < touchPoint.pageY; 909 // changed direction? reset... 910 if (data.up !== undefined && data.up != up) { 911 $.extend(data, { 912 touchStartY: touchPoint.pageY, 913 touchStartTime: e.timeStamp 914 }); 915 } 916 $.extend(data, { 917 up: up, 918 touchY: touchPoint.pageY 919 }); 920 this.menuScroll($sub, true, Math.abs(touchPoint.pageY - prevY)); 921 } 922 e.preventDefault(); 923 } else { // touchend/pointerup 924 if (data.touchY !== undefined) { 925 if (data.momentum = Math.pow(Math.abs(touchPoint.pageY - data.touchStartY) / (e.timeStamp - data.touchStartTime), 2) * 15) { 926 this.menuScrollStop($sub); 927 this.menuScroll($sub); 928 e.preventDefault(); 929 } 930 delete data.touchY; 931 } 932 } 933 } 934 } 935 }, 936 menuShow: function($sub) { 937 if (!$sub.dataSM('beforefirstshowfired')) { 938 $sub.dataSM('beforefirstshowfired', true); 939 if (this.$root.triggerHandler('beforefirstshow.smapi', $sub[0]) === false) { 940 return; 941 } 942 } 943 if (this.$root.triggerHandler('beforeshow.smapi', $sub[0]) === false) { 944 return; 945 } 946 $sub.dataSM('shown-before', true); 947 if (canAnimate) { 948 $sub.stop(true, true); 949 } 950 if (!$sub.is(':visible')) { 951 // highlight parent item 952 var $a = $sub.dataSM('parent-a'), 953 collapsible = this.isCollapsible(); 954 if (this.opts.keepHighlighted || collapsible) { 955 $a.addClass('highlighted'); 956 } 957 if (collapsible) { 958 $sub.removeClass('sm-nowrap').css({ zIndex: '', width: 'auto', minWidth: '', maxWidth: '', top: '', left: '', marginLeft: '', marginTop: '' }); 959 } else { 960 // set z-index 961 $sub.css('z-index', this.zIndexInc = (this.zIndexInc || this.get
961StartZIndex()) + 1); 962 // min/max-width fix - no way to rely purely on CSS as all UL's are nested 963 if (this.opts.subMenusMinWidth || this.opts.subMenusMaxWidth) { 964 $sub.css({ width: 'auto', minWidth: '', maxWidth: '' }).addClass('sm-nowrap'); 965 if (this.opts.subMenusMinWidth) { 966 $sub.css('min-width', this.opts.subMenusMinWidth); 967 } 968 if (this.opts.subMenusMaxWidth) { 969 var noMaxWidth = this.getWidth($sub); 970 $sub.css('max-width', this.opts.subMenusMaxWidth); 971 if (noMaxWidth > this.getWidth($sub)) { 972 $sub.removeClass('sm-nowrap').css('width', this.opts.subMenusMaxWidth); 973 } 974 } 975 } 976 this.menuPosition($sub); 977 } 978 var complete = function() { 979 // fix: "overflow: hidden;" is not reset on animation complete in jQuery < 1.9.0 in Chrome when global "box-sizing: border-box;" is used 980 $sub.css('overflow', ''); 981 }; 982 // if sub is collapsible (mobile view) 983 if (collapsible) { 984 if (canAnimate && this.opts.collapsibleShowFunction) { 985 this.opts.collapsibleShowFunction.call(this, $sub, complete); 986 } else { 987 $sub.show(this.opts.collapsibleShowDuration, complete); 988 } 989 } else { 990 if (canAnimate && this.opts.showFunction) { 991 this.opts.showFunction.call(this, $sub, complete); 992 } else { 993 $sub.show(this.opts.showDuration, complete); 994 } 995 } 996 // accessibility 997 $a.attr('aria-expanded', 'true'); 998 $sub.attr({ 999 'aria-expanded': 'true', 1000 'aria-hidden': 'false' 1001 }); 1002 // store sub menu in visible array 1003 this.visibleSubMenus.push($sub); 1004 this.$root.triggerHandler('show.smapi', $sub[0]); 1005 } 1006 }, 1007 popupHide: function(noHideTimeout) { 1008 if (this.hideTimeout) { 1009 clearTimeout(this.hideTimeout); 1010 this.hideTimeout = 0; 1011 } 1012 var self = this; 1013 this.hideTimeout = setTimeout(function() { 1014 self.menuHideAll(); 1015 }, noHideTimeout ? 1 : this.opts.hideTimeout); 1016 }, 1017 popupShow: function(left, top) { 1018 if (!this.opts.isPopup) { 1019 alert('SmartMenus jQuery Error:\n\nIf you want to show this menu via the "popupShow" method, set the isPopup:true option.'); 1020 return; 1021 } 1022 if (this.hideTimeout) { 1023 clearTimeout(this.hideTimeout); 1024 this.hideTimeout = 0; 1025 } 1026 this.$root.dataSM('shown-before', true); 1027 if (canAnimate) { 1028 this.$root.stop(true, true); 1029 } 1030 if (!this.$root.is(':visible')) { 1031 this.$root.css({ left: left, top: top }); 1032 // show menu 1033 var self = this, 1034 complete = function() { 1035 self.$root.css('overflow', ''); 1036 }; 1037 if (canAnimate && this.opts.showFunction) { 1038 this.opts.showFunction.call(this, this.$root, complete); 1039 } else { 1040 this.$root.show(this.opts.showDuration, complete); 1041 } 1042 this.visibleSubMenus[0] = this.$root; 1043 } 1044 }, 1045 refresh: function() { 1046 this.destroy(true); 1047 this.init(true); 1048 }, 1049 rootKeyDown: function(e) { 1050 if (!this.handleEvents()) { 1051 return; 1052 } 1053 switch (e.keyCode) { 1054 case 27: // reset on Esc 1055 var $activeTopItem = this.activatedItems[0]; 1056 if ($activeTopItem) { 1057 this.menuHideAll(); 1058 $activeTopItem[0].focus(); 1059 var $sub = $activeTopItem.dataSM('sub'); 1060 if ($sub) { 1061 this.menuHide($sub); 1062 } 1063 } 1064 break; 1065 case 32: // activate item's sub on Space 1066 var $target = $(e.target); 1067 if ($target.is('a') && this.handleItemEvents($target)) { 1068 var $sub = $target.dataSM('sub'); 1069 if ($sub && !$sub.is(':visible')) { 1070 this.itemClick({ currentTarget: e.target }); 1071 e.preventDefault(); 1072 } 1073 } 1074 break; 1075 } 1076 }, 1077 rootOut: function(e) { 1078 if (!this.handleEvents() || this.isTouchMode() || e.target == this.$root[0]) { 1079 return; 1080 } 1081 if (this.hideTimeout) { 1082 clearTimeout(this.hideTimeout); 1083 this.hideTimeout = 0; 1084 } 1085 if (!this.opts.showOnClick || !this.opts.hideOnClick) { 1086 var self = this; 1087 this.hideTimeout = setTimeout(function() { self.menuHideAll(); }, this.opts.hideTimeout); 1088 } 1089 }, 1090 rootOver: function(e) { 1091 if (!this.handleEvents() || this.isTouchMode() || e.target == this.$root[0]) { 1092 return; 1093 } 1094 if (this.hideTimeout) { 1095 clearTimeout(this.hideTimeout); 1096 this.hideTimeout = 0; 1097 } 1098 }, 1099 winResize: function(e) { 1100 if (!this.handleEvents()) { 1101 // we still need to resize the disable overlay if it's visible 1102 if (this.$disableOverlay) { 1103 var pos = this.$root.offset(); 1104 this.$disableOverlay.css({ 1105 top: pos.top, 1106 left: pos.left, 1107 width: this.$root.outerWidth(), 1108 height: this.$root.outerHeight() 1109 }); 1110 } 1111 return; 1112 } 1113 // hide sub menus on resize - on mobile do it only on orientation change 1114 if (!('onorientationchange' in window) || e.type == 'orientationchange') { 1115 var collapsible = this.isCollapsible(); 1116 // if it was collapsible before resize and still is, don't do it 1117 if (!(this.wasCollapsible && collapsible)) { 1118 if (this.activatedItems.length) { 1119 this.activatedItems[this.activatedItems.length - 1][0].blur(); 1120 } 1121 this.menuHideAll(); 1122 } 1123 this.wasCollapsible = collapsible; 1124 } 1125 } 1126 } 1127 }); 1128 1129 $.fn.dataSM = function(key, val) { 1130 if (val) { 1131 return this.data(key + '_smartmenus', val); 1132 } 1133 return this.data(key + '_smartmenus'); 1134 }; 1135 1136 $.fn.removeDataSM = function(key) { 1137 return this.removeData(key + '_smartmenus'); 1138 }; 1139 1140 $.fn.smartmenus = function(options) { 1141 if (typeof options == 'string') { 1142 var args = arguments, 1143 method = options; 1144 Array.prototype.shift.call(args); 1145 return this.each(function() { 1146 var smartmenus = $(this).data('smartmenus'); 1147 if (smartmenus && smartmenus[method]) { 1148 smartmenus[method].apply(smartmenus, args); 1149 } 1150 }); 1151 } 1152 return this.each(function() { 1153 // [data-sm-options] attribute on the root UL 1154 var dataOpts = $(this).data('sm-options') || null; 1155 if (dataOpts) { 1156 try { 1157 dataOpts = eval('(' + dataOpts + ')'); 1158 } catch(e) { 1159 dataOpts = null;
1160 alert('ERROR\n\nSmartMenus jQuery init:\nInvalid "data-sm-options" attribute value syntax.'); 1161 }; 1162 } 1163 new $.SmartMenus(this, $.extend({}, $.fn.smartmenus.defaults, options, dataOpts)); 1164 }); 1165 }; 1166 1167 // default settings 1168 $.fn.smartmenus.defaults = { 1169 isPopup: false, // is this a popup menu (can be shown via the popupShow/popupHide methods) or a permanent menu bar 1170 mainMenuSubOffsetX: 0, // pixels offset from default position 1171 mainMenuSubOffsetY: 0, // pixels offset from default position 1172 subMenusSubOffsetX: 0, // pixels offset from default position 1173 subMenusSubOffsetY: 0, // pixels offset from default position 1174 subMenusMinWidth: '10em', // min-width for the sub menus (any CSS unit) - if set, the fixed width set in CSS will be ignored 1175 subMenusMaxWidth: '20em', // max-width for the sub menus (any CSS unit) - if set, the fixed width set in CSS will be ignored 1176 subIndicators: true, // create sub menu indicators - creates a SPAN and inserts it in the A 1177 subIndicatorsPos: 'append', // position of the SPAN relative to the menu item content ('append', 'prepend') 1178 subIndicatorsText: '', // [optionally] add text in the SPAN (e.g. '+') (you may want to check the CSS for the sub indicators too) 1179 scrollStep: 30, // pixels step when scrolling long sub menus that do not fit in the viewport height 1180 scrollAccelerate: true, // accelerate scrolling or use a fixed step 1181 showTimeout: 250, // timeout before showing the sub menus 1182 hideTimeout: 500, // timeout before hiding the sub menus 1183 showDuration: 0, // duration for show animation - set to 0 for no animation - matters only if showFunction:null 1184 showFunction: null, // custom function to use when showing a sub menu (the default is the jQuery 'show') 1185 // don't forget to call complete() at the end of whatever you do 1186 // e.g.: function($ul, complete) { $ul.fadeIn(250, complete); } 1187 hideDuration: 0, // duration for hide animation - set to 0 for no animation - matters only if hideFunction:null 1188 hideFunction: function($ul, complete) { $ul.fadeOut(200, complete); }, // custom function to use when hiding a sub menu (the default is the jQuery 'hide') 1189 // don't forget to call complete() at the end of whatever you do 1190 // e.g.: function($ul, complete) { $ul.fadeOut(250, complete); } 1191 collapsibleShowDuration:0, // duration for show animation for collapsible sub menus - matters only if collapsibleShowFunction:null 1192 collapsibleShowFunction:function($ul, complete) { $ul.slideDown(200, complete); }, // custom function to use when showing a collapsible sub menu 1193 // (i.e. when mobile styles are used to make the sub menus collapsible) 1194 collapsibleHideDuration:0, // duration for hide animation for collapsible sub menus - matters only if collapsibleHideFunction:null 1195 collapsibleHideFunction:function($ul, complete) { $ul.slideUp(200, complete); }, // custom function to use when hiding a collapsible sub menu 1196 // (i.e. when mobile styles are used to make the sub menus collapsible) 1197 showOnClick: false, // show the first-level sub menus onclick instead of onmouseover (i.e. mimic desktop app menus) (matters only for mouse input) 1198 hideOnClick: true, // hide the sub menus on click/tap anywhere on the page 1199 noMouseOver: false, // disable sub menus activation onmouseover (i.e. behave like in touch mode - use just mouse clicks) (matters only for mouse input) 1200 keepInViewport: true, // reposition the sub menus if needed to make sure they always appear inside the viewport 1201 keepHighlighted: true, // keep all ancestor items of the current sub menu highlighted (adds the 'highlighted' class to the A's) 1202 markCurrentItem: false, // automatically add the 'current' class to the A element of the item linking to the current URL 1203 markCurrentTree: true, // add the 'current' class also to the A elements of all ancestor items of the current item 1204 rightToLeftSubMenus: false, // right to left display of the sub menus (check the CSS for the sub indicators' position) 1205 bottomToTopSubMenus: false, // bottom to top display of the sub menus 1206 collapsibleBehavior: 'default' // parent items behavior in collapsible (mobile) view ('default', 'toggle', 'link', 'accordion', 'accordion-toggle', 'accordion-link') 1207 // 'default' - first tap on parent item expands sub, second tap loads its link 1208 // 'toggle' - the whole parent item acts just as a toggle button for its sub menu (expands/collapses on each tap) 1209 // 'link' - the parent item acts as a regular item (first tap loads its link), the sub menu can be expanded only via the +/- button 1210 // 'accordion' - like 'default' but on expand also resets any visible sub menus from deeper levels or other branches 1211 // 'accordion-toggle' - like 'toggle' but on expand also resets any visible sub menus from deeper levels or other branches 1212 // 'accordion-link' - like 'link' but on expand also resets any visible sub menus from deeper levels or other branches 1213 }; 1214 1215 return $; 1216}));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.