1/*------------------------------------------------------------------------- 2# mod_vertical_menu - Vertical Menu 3# ------------------------------------------------------------------------- 4# @ author Balint Polgarfi 5# @ copyright Copyright (C) 2018 Offlajn.com All Rights Reserved. 6# @ license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL 7# @ website http://www.offlajn.com 8-------------------------------------------------------------------------*/ 9 10;(function($, undefined) { 11 12var Hlpr = { 13 width: $.fn.width, 14 hackWidth: function(reduce) { 15 return function(arg) { 16 var value = Hlpr.width.apply(this, arguments); 17 if (this[0] == window && !$.isNumeric(arg) && value > 767) value -= reduce; 18 return value; 19 } 20 }, 21 preventDefault: function(e) { 22 e.preventDefault(); 23 }, 24 stopPropagation: function(e) { 25 e.stopPropagation(); 26 }, 27 cancelTransitionEnd: function(e) { 28 if(e.target.tagName != "NAV") e.stopPropagation(); 29 }, 30 loadImage: function(src) { 31 new Image().src = src; 32 }, 33 calcOrigin: function(origin, w, dir) { 34 var o = origin.split(/\s+/); 35 if (o[2] && o[2].indexOf("%") > 0) // convert originZ to px 36 o[2] = parseFloat(o[2]) / 100 * w + "px"; 37 if (dir < 0) { // invert 38 if (o[0].indexOf("%") < 0) 39 o[0] = (parseInt(o[0]) / w * 100).toPrecision(3); 40 o[0] = (parseInt(o[0]) - 50) * dir + 50 + "%"; 41 } 42 return o.join(" "); 43 } 44}; 45 46var Target = { 47 hide: function() { 48 this.target.style.display = "none"; 49 }, 50 remove: function() { 51 this.target.parentNode.removeChild(this.target); 52 }, 53 scrollUp: function() { 54 $(this.target.children[0]).scrollTop(0); 55 this.target.style.display = "none"; 56 }, 57 autoMaxWidth: function() { 58 this.target.attributes["class"].value = "sm-title"; 59 this.target.style.maxWidth = ""; 60 }, 61 autoHeight: function() { 62 this.target.style.height = ""; 63 } 64}; 65 66// calc scrollWidth 67$(function() { 68 var outer = document.createElement("div"); 69 outer.style.visibility = "hidden"; 70 outer.style.width = "100px"; 71 document.body.appendChild(outer); 72 var widthNoScroll = outer.offsetWidth; 73 outer.style.overflow = "scroll"; 74 var inner = document.createElement("div"); 75 inner.style.width = "100%"; 76 outer.appendChild(inner); 77 var widthWithScroll = inner.offsetWidth; 78 outer.parentNode.removeChild(outer); 79 80 Hlpr.scrollWidth = widthNoScroll - widthWithScroll; 81}); 82 83smTransform = (function() { 84 var tr, trs = {transform: 0, WebkitTransform: 0, MozTransform: 0, msTransform: 0, OTransform: 0}; 85 for (tr in trs) if (tr in document.documentElement.style) return tr; 86})(); 87 88smTransition = (function() { 89 var tr, trs = {transition: 0, WebkitTransition: 0, MozTransition: 0, OTransition: 0}; 90 for (tr in trs) if (tr in document.documentElement.style) return tr; 91})(); 92 93smTransitionEnd = smTransition && smTransition + (smTransition[0] == 't' ? 'end' : 'End'); 94 95var $body, 96 $win = $(window), 97 $html = $(document.documentElement), 98 oldIE = navigator.userAgent.match(/MSIE ([6-9])/), 99 backScale = 0.75; 100if (smMobile) $html.addClass('sm-mobile'); 101 102$.fn._center = function(bi) { 103 var x, w, prev; 104 if (bi) 105 prev = this[0].parentNode.children[1] == this[0] ? 0 : $(this[0].parentNode.children[0]).outerWidth(); 106 else 107 prev = this.prev().outerWidth() * backScale || 0; 108 w = this.css("maxWidth", "none").width() + 30; 109 this[0].style.maxWidth = ""; 110 x = Math.floor((this.parent().outerWidth() - w) / 2); 111 return prev > x ? prev : x; 112}; 113 114function deleteMediaRules(match) { 115 var css = ''; 116 for (var j = 0; j < document.styleSheets.length; j++) { 117 var style = document.styleSheets[j]; 118 if (!style.href || style.href.indexOf('mod_vertical_menu') < 0) try { 119 for (var i = 0; i < style.cssRules.length; i++) { 120 var rule = style.cssRules[i]; 121 if (rule.media && rule.media.mediaText.match(match)) { 122 if (style.href) 123 css += rule.cssText.replace(/(url\(['"]?)([^)]+)/i, function(m, url, href) { 124 return href.match(/^\/|^https?:|^data:/i) ? m : url + style.href.replace(/[^/]+$/, '') + href; 125 }) + '\n'; 126 else css += rule.cssText + '\n'; 127 style.deleteRule(i--);
128 } 129 } 130 } catch(ex) {} 131 } 132 return css; 133} 134function hackMediaWidths(width) { 135 width = width || 0; 136 if (!hackMediaWidths.hasOwnProperty('css')) { 137 hackMediaWidths.css = [deleteMediaRules('width')]; 138 hackMediaWidths.$css = $('<style id="hack-media">').appendTo(document.head); 139 } 140 if (!hackMediaWidths.css.hasOwnProperty(width)) { 141 hackMediaWidths.css[width] = hackMediaWidths.css[0].replace(/\((\w+-width:\s*)(\d+)px\)/g, function() { 142 return '('+ arguments[1] + (parseInt(arguments[2]) + width) +'px)'; 143 }); 144 } 145 hackMediaWidths.$css.html(hackMediaWidths.css[width]); 146}; 147 148$.fn.VerticalMenu = function(args) { return args ? new VerticalSlideMenu(args) : this.eq(0).data("VerticalMenu") }; 149 150( VerticalSlideMenu = function(o) {this.init(o)} ).prototype = { 151 $drop: $(), 152 $overlay: $(), 153 minSwipe: 2, 154 titleWidth: "66%", 155 fullClass: "sm-full-", 156 openClass: "sm-open-", 157 closeClass: "sm-close", 158 effect: 1, // [1 - 14] 159 effectEx: {'-1':1, '1':1, '6':1, '9':1, '11':1, '12':1}, 160 popupDur: 0.6, 161 baseCSS: { 162 x: 0, y: 0, 163 opacity: 1, 164 rotationX: 0, 165 rotationY: 0, 166 rotationZ: 0, 167 skewX: 0, scaleX: 1, 168 skewY: 0, scaleY: 1 169 }, 170 171 init: function(obj) { 172 $.extend(this, obj); 173 $body = $body || $(document.body); 174 this.$node = $('#off-menu_'+this.id).data("VerticalMenu", this); 175 this.$parent = this.$node.parent().addClass("sm-parent"); 176 this.$head = this.$node.find(".sm-head"); 177 this.$back = this.$head.find(".sm-back"); 178 this.$title = this.$head.children(":last"); 179 this.$lvls = this.$node.find(".sm-levels"); 180 this.$filter = this.$node.find(".sm-filter").attr("value", ""); 181 this.$dt = this.$lvls.find("dt.parent, dt.notparent"); 182 this.fullClass += this.id; 183 this.openClass += this.id; 184 this.menuPadding = parseInt(this.$lvls.children(':first').css('paddingLeft')); 185 this.bindUpdateScrollbar = smMobile ? undefined : this.updateScrollbar.bind(this, 0); 186 this.$lvls.find('a').map(function(i, a) { // scrollspy 187 var hash = a.href.match(/#([\w-]+)$/); 188 return hash ? document.getElementById(hash[1]) : undefined; 189 }).menuspy().length && $body.on('scrollEnter.menuspy', function(e) { 190 this.$lvls.find('a[href$="#'+ e.target.id +'"]').closest('dt').addClass('active').siblings('.active').removeClass('active'); 191 }.bind(this)).on('scrollLeave.menuspy', function(e) { 192 this.$lvls.find('a[href$="#'+ e.target.id +'"]').closest('dt').removeClass('active'); 193 }.bind(this)); 194 195 this.dropmenu = this.navtype == 'drop'; 196 this.accordion = this.navtype == 'accordion'; 197 this.treemenu = this.navtype == 'tree' || this.accordion; 198 this.expand = this.navtype == 'expand' || this.treemenu; 199 200 if (this.overlay && !this.expand) { // override menu type 201 this.dropmenu = 0; 202 this.expand = 1; 203 this.treemenu = this.navtype != 'expand'; 204 } 205 if ((this.treemenu || this.expand) && !this.$filter.length) this.backItem = ''; 206 if (this.popup || this.overlay) this.sidebarUnder = 0; 207 if (this.treemenu) 208 this.$node.addClass("sm-tree").on("click.sm touchend.sm", "dt.parent", $.proxy(this, "onClickTree")); 209 this.build(); 210 this.onResize(); 211 if (!this.sidebar && this.winWidth >= this.sidebarUnder) this.$lvls.height(''); // height fix for webkit 212 if (this.filterMinChar < 1) this.filterMinChar = 1; 213 214 this.bg = this[this.overlay ? "$overlay" : "$node"].css("backgroundImage").match(/url\(['"]?(.+?)['"]?\)/i); 215 216 if (this.popup || this.sidebar || this.overlay || this.winWidth < this.sidebarUnder) { 217 // only make the autoopen work if the menu is not in module position 218 var w = $(window).width(), visible = true; 219 if (!+this.visibility[4]) { // basic 220 if (w < 768 && !+this.visibility[0]) visible = false; 221 if (w >= 768 && w < 992 && !+this.visibility[1]) visible = false; 222 if (w >= 992 && w < 1200 && !+this.visibility[2]) visible = false; 223 if (w >= 1200 && !+this.visibility[3]) visible = false; 224 } else { // advanced 225 if (this.visibility[5][0] > w || this.visibility[6][0] < w) visible = false; 226 } 227 if (visible) switch (this.autoOpen) { 228 case 1: // Only once 229 if (!window.sessionStorage || sessionStorage.smAutoOpen) break; 230 sessionStorage.smAutoOpen = 1; 231 case 2: // Always 232 if (w < 768 && this.autoOpen == 2) break; // disable always auto open on mobile 233 if (this.autoOpenAnim) // animate auto open 234 $win.on('load', $.proxy(this, this.popup ? "openPopup" : "openMenu")); 235 else { // don't animate auto open 236 if (this.popup) { 237 this.$button.eq(1).hide(); 238 this.$noTrans = function() { this.$button.eq(1).show(), delete this.$noTrans }.bind(this); 239 $($.proxy(this, "openPopup")); 240 } else {
241 this.$noTrans = this.$node.add(this.$pusher).add(this.$content) 242 .add(this.$overlay.parent()).add(this.$button.hide()).css(smTransition+'Duration', '1ms'); 243 $($.proxy(this, "openMenu")); 244 } 245 } 246 } 247 } 248 249 // add events 250 if (this.parentHref) // don't slide to submenu 251 this.$node.on("click.sm touchend.sm", "dt.parent a", $.proxy(this, "onRedirect")); 252 else // disable redirection when pointer-events:none isn't supported 253 this.$node.on("click.sm", "dl:not(.sm-result) dt.parent a", Hlpr.preventDefault); 254 this.$node 255 .on("click.sm touchend.sm", this.expand && !this.treemenu ? "dt" : ".notparent", $.proxy(this, "onRedirect")) 256 .on("click.sm touchend.sm", ".sm-back, .sm-back-item", $.proxy(this, "onBack")) 257 .on("click.sm touchend.sm", ".sm-reset", $.proxy(this, "onResetFilter")) 258 .on("click.sm", Hlpr.stopPropagation); 259 if (!this.expand) this.$node.on("click.sm touchend.sm", "dt.parent", $.proxy(this, "onOpen")); 260 this.$filter 261 .on("keydown.sm", function disableTab(e) {if (e.keyCode == 9) e.currentTarget.blur()}) 262 .on("keyup.sm", $.proxy(this, "onFilter")); 263 this.$button.on("click.sm touchstart.sm", $.proxy(this, "onClickButton")); // touchend causes problems on scroll 264 this.$lvls 265 .on("touchmove.sm", $.proxy(this, "onTouchMove")) 266 .on("touchend.sm touchcancel.sm", $.proxy(this, "onTouchEnd")) 267 .on("mousedown.sm", $.proxy(this, "onMouseDown")); 268 $win 269 .on("resize.sm", $.proxy(this, "onResize")) 270 .on("keyup.sm", $.proxy(this, "onEsc")); 271 if (this.bg) $win.on("load.sm", Hlpr.loadImage.bind(0, this.bg[1])); 272 $body.one("touchend.sm", $.proxy(this, "touchOptimize")); 273 }, 274 275 touchOptimize: function() { 276 this.$node 277 .off("click.sm", "dt.parent") 278 .off("click.sm", "dt") 279 .off("click.sm", ".notparent") 280 .off("click.sm", ".sm-back, .sm-back-item"); 281 if (this.dropmenu) 282 this.$drop.off("click.sm", "dt"); 283 }, 284 285 build: function() { 286 // build menu icon 287 this.$button = $('<div class="menu-icon-cont sm-btn-'+this.id+'">') 288 .html('<div class="menu-icon3"><span></span><span></span><span></span></div>'); 289 290 if (this.dropmenu) { 291 this.anim.inRotationY = this.anim.inCSS.rotationY; 292 this.anim.outRotationY = this.anim.outCSS.rotationY; 293 this.miRotationY = this.miCSS.rotationY; 294 this.$drop = $('<nav>').css({ 295 position: 'absolute', 296 left: 0, right: 0, 297 top: 0, zIndex: 999 298 }).addClass("sm-drop off-menu_"+this.id) 299 .appendTo($body) 300 .on("click.sm touchend.sm", "dt", $.proxy(this, "onRedirect")) 301 } 302 303 //add logo link 304 var link = this.logoUrl; 305 if (link) $("nav.off-menu_" + this.id +" .sm-logo img").css("cursor", "pointer").click(function(e) { 306 document.location.href = link; 307 }); 308 309 if (this.popup) { // POPUP 310 this.initPopup(); 311 } else if (this.sidebar || this.sidebarUnder) { // SIDEBAR 312 this.initContainer(); 313 this.initSidebar(); 314 } else if (this.overlay) { // OVERLAY 315 this.initContainer(); 316 this.initOverlay(); 317 } 318 319 // build submenus 320 var $div = this.$lvls.find(".sm-level"); 321 $div.push( // add level for search results 322 $('<div class="sm-level level2"><dl class="sm-result level2">') 323 .css('display', 'none').appendTo(this.$lvls)[0]); 324 this.opened = $div[0]; 325 this.mainmenu = this.opened; 326 if (this.treemenu) this.$lvls.find('dd.opened').css('display', 'block'); // init tree/accordion animation 327 if (this.backItem) { 328 var $backItem = $("dt:first", $div[0]).clone().removeClass("parent notparent active").addClass("sm-back-item"); 329 $backItem.find("a").removeAttr("href").html(this.backItem); 330 $backItem.find(".desc, .sm-icon, .productnum").remove(); 331 } 332 if (!this.expand) { 333 var level, div, i; 334 for (i = 1; i < $div.length; i++) { 335 if (this.backItem && (!this.dropmenu || i == $div.length - 1)) // if drop, add only for search results 336 $backItem.clone().prependTo($div[i].children[0]); // add back menu-item to sublevels 337 div = $div[i]; 338 div.style.display = "none"; 339 div.parent = $(div.parentNode).closest(".sm-level")[0]; 340 div.parentItem = $(div.parentNode).prev()[0]; 341 if (div.parentNode.tagName == "DD") 342 $(div.parentNode).prev()[0].menu = div; 343 } 344 } 345 this.$result = this.$lvls.children(":last"); 346 if (this.expand && this.backItem) $backItem.clone().prependTo(this.$result[0].children[0]); // add back to search result 347 }, 348 349 initPopup: function() { 350 var $clone = this.$button.clone() 351 .css(smTransform, "translateX(-100%)") 352 .css("zIndex", -1).appendTo(this.$node); 353 this.$node.css({ 354 display: "block", position: "absolute",
355 visibility: "hidden", opacity: 0, 356 left: 0, top: 0, 357 width: this.width, 358 margin: 0, zIndex: 99999, 359 WebkitTransition: "none", MozTransition: "none", msTransition: "none", transition: "none" 360 }).addClass("sm-popup"); 361 if (this.menuIconCorner) { // button in corner 362 this.$node.appendTo(this.$button); 363 this.$button.appendTo($body); 364 } else { // button in module position 365 this.$node.appendTo($body); 366 this.$button.appendTo(this.$parent); 367 } 368 this.$button.addClass('sm-popup-burger').push($clone[0]); 369 }, 370 371 initContainer: function() { 372 this.htmlCSS = { 373 background: $html.css("backgroundColor")+" "+$html.css("backgroundImage")+" "+$html.css("backgroundRepeat")+" "+ 374 $html.css("backgroundAttachment")+" "+$html.css("backgroundPosition")+" / "+$html.css("backgroundSize") 375 }; 376 this.bodyCSS = { 377 overflowY : $body.css("overflowY"), 378 borderTop: $body.css("borderTopWidth")+" "+$body.css("borderTopStyle")+" "+$body.css("borderTopColor"), 379 borderBottom: $body.css("borderBottomWidth")+" "+$body.css("borderBottomStyle")+" "+$body.css("borderBottomColor"), 380 borderLeft: $body.css("borderLeftWidth")+" "+$body.css("borderLeftStyle")+" "+$body.css("borderLeftColor"), 381 borderRight: $body.css("borderRightWidth")+" "+$body.css("borderRightStyle")+" "+$body.css("borderRightColor"), 382 padding: $body.css("paddingTop")+" "+$body.css("paddingRight")+" "+$body.css("paddingBottom")+" "+$body.css("paddingLeft"), 383 background: $body.css("backgroundColor")+" "+$body.css("backgroundImage")+" "+$body.css("backgroundRepeat")+" "+ 384 $body.css("backgroundAttachment")+" "+$body.css("backgroundPosition")+" / "+$body.css("backgroundSize") 385 }; 386 387 this.$cont = $body.addClass("sm-container"); 388 this.$pusher = $(".sm-pusher"); 389 if (!this.$pusher.length) { 390 var $cnt = $body.children(':not(nav.sm-menu)'); 391 this.$pusher = $('<div class="sm-pusher"><div class="sm-content"><div class="sm-content-inner">').appendTo($body); 392 } 393 this.$content = this.$pusher.children(); 394 this.$inner = this.$content.children(".sm-content-inner").append($cnt); 395 396 $html.css('overflow-y', 'auto'); 397 }, 398 399 initSidebar: function() { 400 if (this.sidebar) { 401 this.$button.css("display", ""); 402 this.$node.appendTo(this.$cont); 403 } 404 this.$cont.on("click.sm touchstart.sm", function(e) { this.effect < 0 || this.closeMenu(e) }.bind(this)); 405 // disable page scrolling when sidebar is open 406 this.$lvls.on("touchstart.sm", function(e) { this.effect < 0 || this.scrollFixStart(e) }.bind(this)); 407 this.$cont.on("touchmove.sm", function(e) { this.effect < 0 || this.scrollFixMove(e) }.bind(this)); 408 409 // TransitionEnd fix 410 this.$node.on(smTransitionEnd, Hlpr.cancelTransitionEnd); 411 this.$inner.on(smTransitionEnd, Hlpr.cancelTransitionEnd); 412 413 if (this.menuIconCorner) { 414 this.$button.appendTo(this.$inner); 415 } else { 416 this.$button.appendTo(this.$parent); 417 this.$button.push(this.$button.clone().css("opacity", 0).appendTo(this.$node)[0]); 418 } 419 if (!this.sidebar) this.$button.css("display", "none"); 420 }, 421 422 initOverlay: function() {
423 var $overlay = $('<div>').addClass("sm-overlay-"+this.id).appendTo($body); 424 this.$overlay = $('<div>').addClass("sm-overlay-win").appendTo($overlay) 425 .on("click.sm "+smTransitionEnd, Hlpr.stopPropagation) // don't close overlay on click & TransitionEnd fix 426 this.$node.appendTo(this.$overlay); 427 this.$cont.on("click.sm touchstart.sm", $.proxy(this, "closeMenu")); 428 // disable touch-scrolling when sidebar is open 429 this.$lvls.on("touchstart.sm", $.proxy(this, "scrollFixStart")); 430 this.$cont.on("touchmove.sm", $.proxy(this, "scrollFixMove")); 431 432 if (this.menuIconCorner) { 433 this.$button.appendTo($body); 434 } else { 435 this.$button.appendTo(this.$parent); 436 this.$button.push(this.$button.clone().css("opacity", 0).insertBefore(this.$node)[0]); 437 } 438 }, 439 440 scrollFixStart: function(e) { 441 this.touchstartY = e.originalEvent.touches[0].clientY; 442 }, 443 444 scrollFixMove: function(e) { 445 if (!this.$cont.hasClass(this.openClass)) return; 446 else if (!$(e.target).closest('.sm-levels').length) return e.preventDefault(); 447 448 var node = this.opened.children[0]; 449 if (this.touchstartY < e.originalEvent.touches[0].clientY) { // on scroll up 450 if (node.scrollTop == 0) e.preventDefault(); 451 } else { // on scroll down 452 if (node.scrollTop == node.scrollHeight - node.offsetHeight) e.preventDefault(); 453 } 454 }, 455 456 onMouseDown: function(e) { 457 if (e.button == 0) { 458 if (e.target.tagName == "A") e.preventDefault(); 459 $body 460 .on("mousemove.sm", $.proxy(this, "onTouchMove")) 461 .on("mouseup.sm", $.proxy(this, "onMouseUp")); 462 } 463 }, 464 465 onMouseUp: function(e) { 466 if (e.button == 0) { 467 $body.off("mousemove.sm mouseup.sm"); 468 this.onTouchEnd(e); 469 } 470 }, 471 472 onTouchMove: function(e) { 473 if (this.touchEvent == "scroll") return; 474 if (smMobile && smMobile[0] == "Windows Phone") e.preventDefault(); // disable scrolling or swipe back 475 var x = 'pageX' in e ? e.pageX : e.originalEvent.touches[0].pageX, 476 y = 'pageY' in e ? e.pageY : e.originalEvent.touches[0].pageY; 477 if (this.touchStartX === undefined) { 478 // touchstart 479 this.touchTarget = e.target; 480 this.touchStartX = this.touchPrevX = x; 481 this.touchStartY = this.touchPrevY = y; 482 if (!this.opened.parent) this.touchEvent = "scroll"; 483 return; 484 } 485 var diffX = x - this.touchStartX, 486 diffY = y - this.touchStartY; 487 if (this.touchEvent === undefined) { 488 if (Math.abs(diffY) > this.minSwipe) { // vertical swipe 489 this.touchEvent = "scroll"; 490 $body.addClass("sm-scroll"); 491 } else if (diffX > this.minSwipe) { // horizontal swipe 492 if (this.openTL && this.openTL.isActive()) { 493 if (this.openTL.time() < this.dur) return; 494 else this.openTL.pause(); 495 } 496 this.touchEvent = "back"; 497 if (!smMobile) $(this.opened.children).perfectScrollbar("destroy"); 498 this.opened.parent.style.display = "block"; 499 this.initBackTimeline(); 500 TweenLite.set(this.$lvls[0], {perspective: this.perspective}); // blur fix for retina 501 this.nodeW = this.$lvls.outerWidth(); 502 } 503 } 504 if (this.touchEvent == "back") { 505 e.preventDefault(); // disable scrolling 506 diffX -= this.minSwipe; 507 508 if (diffX <= 1) diffX = 0.1; 509 if (diffX >= this.nodeW) diffX = this.nodeW - 0.1; 510 this.backTL.seek(this.dur * diffX / this.nodeW); 511 512 this.touchDirLeft = this.touchPrevX < x; 513 this.touchDirTop = this.touchPrevY < y; 514 if (this.touchPrevX != x) this.touchPrevX = x; 515 if (this.touchPrevY != y) this.touchPrevY = y; 516 } 517 }, 518 519 onTouchEnd: function(e) { 520 var touchEvent = this.touchEvent; 521 delete this.touchEvent; 522 delete this.touchStartX; 523 524 if (!touchEvent) return; 525 e.preventDefault(); 526 e.stopPropagation(); 527 528 if (touchEvent == "scroll") { 529 $body.removeClass("sm-scroll"); 530 } else if (touchEvent == "back") { 531 // disable click when swipe finished on the same menu-item where it started 532 if (this.touchTarget == e.target) this.disableClick = true; 533 if (this.touchDirLeft) { 534 this.back(); 535 } else { 536 if (!smMobile) $(this.opened.children).perfectScrollbar(); 537 this.backTL.reverse(); 538 } 539 } 540 }, 541 542 onEsc: function(e) { 543 if (e.keyCode == 27 && !this.$button.eq(1).hasClass("sm-hide") && this.$button.css('display') != 'none') { 544 if (!this.popup) 545 e.stopPropagation(), this.closeMenu(); 546 else if (this.$node.css("visibility") == "visible") 547 e.stopPropagation(), this.closePopup(); 548 } 549 }, 550 551 onClickButton: function(e) { 552 e.stopPropagation(); 553 e.preventDefault(); 554 if (this.$button.hasClass("sm-hide")) { 555 this.$button[0]._gsTransform.x = this.menuIconX; 556 this.$button.css(smTransform, '').removeClass("sm-hide"); 557 return; 558 } 559 if (this.popup) { // POPUP 560 if (this.$node.css("visibility") == "hidden") { 561 this.openPopup(); 562 } else { 563 if (e.currentTarget == this.$button[0]) return; // don't close menu for any click 564 this.closePopup(); 565 } 566 } else { // SIDEBAR || OVERLAY 567 if ($(e.currentTarget).hasClass(this.closeClass)) this.closeMenu(); 568 else this.openMenu(); 569 } 570 }, 571 572 openPopup: function() { 573 var bw = this.$button.width(), 574 bh = this.$button.height(),
575 w = this.$node.width(), 576 h = this.$node.height(); 577 this.$node.css("visibility", "visible"); 578 if (this.menuIconCorner) { // fixed position 579 TweenLite.set(this.$node[0], {transformOrigin: "0% 0% 0"}); 580 } else { // module position 581 this.onResize(); 582 } 583 var tl = new TimelineLite({ paused: true, autoRemoveChildren: true, onComplete: this.$noTrans }); 584 tl.add(TweenLite.fromTo(this.$node[0], 1, {scaleX: bw/w, scaleY: bh/h}, {css: {scaleX: 1, scaleY: 1}, ease: Back.easeOut}), 0); 585 tl.add(TweenLite.to(this.$node[0], 1, {css: {opacity: 1}, onComplete: $.proxy(this.$button.eq(1), "addClass", this.closeClass)}), 0); 586 tl.add(TweenLite.fromTo(this.$button[1], 0.75, {x: -bw, opacity: 1}, {css: {x: 0}}), -0.5); 587 tl.duration(this.$noTrans ? 0.001 : this.popupDur); 588 tl.play(); 589 this.$node.trigger("openMenu", this); 590 }, 591 592 closePopup: function() { 593 var bw = this.$button.width(), 594 bh = this.$button.height(), 595 w = this.$node.width(), 596 h = this.$node.height(); 597 this.$button.removeClass(this.closeClass); 598 var tl = new TimelineLite({paused: true, autoRemoveChildren: true}); 599 tl.add(TweenLite.to(this.$button[1], 0.3, {css: {x: -bw}}), -0.15); 600 tl.add(TweenLite.to(this.$node[0], 0.3, {css: {opacity: 0}, ease: Quad.easeIn}), 0.3); 601 tl.add(TweenLite.to(this.$node[0], 0.3, {css: {scaleX: bw/w, scaleY: bh/h}, onComplete: $.proxy(this.$node, "css", "visibility", "hidden")}), 0.3); 602 tl.play(); 603 this.$node.trigger("closeMenu", this); 604 }, 605 606 openMenu: function(e, effect) { 607 if (this.$cont.hasClass(this.openClass)) return; 608 var otherOpen = this.$cont[0].className.match(/sm-open-(\d+)/); 609 if (otherOpen) { // if another menu is already open 610 window['sm'+otherOpen[1]].closeMenu(); 611 return setTimeout($.proxy(this, 'openMenu'), 550); 612 } 613 if (e && e.stopPropagation) e.stopPropagation(); 614 $body.off(smTransitionEnd+".tr").one(smTransitionEnd+".tr", this.overlay ? ".sm-overlay-"+this.id : "", $.proxy(this, "onEndOpenMenu")); 615 616 this.effect = effect || this.effect; 617 if (this.effect < 0) { 618 $html.addClass('sm-reduce-width'); 619 hackMediaWidths(this.width); 620 $.fn.width = Hlpr.hackWidth(this.width); 621 } 622 this.$cont.addClass("sm-effect-" + Math.abs(this.effect)); 623 624 var btn = this.$button.length && (!this.menuIconCorner || this.overlay || this.effectEx[this.effect]); 625 if (btn && this.menuIconCorner) this.$button.appendTo(this.overlay ? this.$overlay : this.$node); 626 627 this.scroll = $win.scrollTop(); 628 if (smMobile) { 629 this.effect < 0 ? $win.off("resize.sm") : $win.off("resize.sm").scrollTop(0); // don't resize during animation on mobile 630 } 631 632 this.$cont.css({ position: 'fixed', top: 0, bottom: 0 }); 633 $html.addClass(this.fullClass); 634 this.$inner.css(this.bodyCSS); 635 this.$content.css(this.htmlCSS); 636 637 if (!smMobile) { 638 if (btn && !this.menuIconCorner) { 639 if (!this.overlay) this.$button.eq(1).appendTo(this.effectEx[this.effect] ? this.$node : this.$inner); 640 this.$button[1].style.display = "inline-block"; 641 } 642 } else { // mobile 643 if (this.$button[1]) this.$button[1].style.display = "block"; 644 } 645 646 if (this.overlay) { 647 this.$content.css('maxWidth', '100vw'); // Firefox bugfix (#18) 648 this.$lvls.css('maxHeight', ''); 649 } else if (this.sidebar || this.winWidth < this.sidebarUnder) { 650 if (this.effect > 0) this.$content.css('maxWidth', '100vw'); // Firefox bugfix (#18) 651 this.$lvls.css('maxHeight', this.effect == 8 ? window.innerHeight : window.innerHeight - this.$lvls.position().top); // fix for sidebar effect 8 652 } 653 654 this.$content.scrollTop(this.scroll); 655 this.$cont.css("background", this.siteBg).addClass(this.openClass); 656 this.$node.trigger("openMenu", this); 657 if (oldIE) this.onEndOpenMenu(); 658 }, 659 660 onEndOpenMenu: function(e) { 661 if (smMobile) { 662 $win.on("resize.sm", $.proxy(this, "onResize")); // allow resize after animation on mobile 663 if (this.sidebar || this.winWidth < this.sidebarUnder) // fix for sidebar bottom can't be see 664 this.$lvls.css('maxHeight', window.innerHeight - this.$lvls.position().top); 665 } 666 if (this.effect < 0 && this.winWidth > 767) $win.resize(); 667 if (this.menuIconCorner) 668 setTimeout($.proxy(this.$button, "addClass", this.closeClass), 1); 669 else { 670 this.$button[0].style.opacity = 0; 671 this.$button[1].style.opacity = 1; 672 this.$button.eq(1).addClass(this.closeClass); 673 } 674 if (this.overlay) { // calculate overlay max-height after transition 675 var topHeight = 0; 676 this.$lvls.prevAll().each(function() { topHeight += $(this).outerHeight() }); 677 this.$lvls.css("maxHeight", this.$overlay.outerHeight() - topHeight); 678 } else if (this.effect == 8) { // fix for sidebar effect 8 679 this.$lvls.css('maxHeight', this.$cont.outerHeight() - this.$lvls.position().top); 680 } 681 this.$node.css("zIndex", 99); 682 if (this.$noTrans) { 683 this.$button.addClass(this.closeClass).show(); 684 this.$noTrans.css(smTransition+'Duration', ''); 685 delete this.$noTrans; 686 } 687 this.updateScrollbar(); 688 }, 689 690 closeMenu: function(e) { 691 if (e && $(e.target).closest(".sm-menu").length) return; 692 if (!this.$cont) return; 693 if (!this.$cont.hasClass(this.openClass)) return; 694 $body.off(smTransitionEnd+".tr").one(smTransitionEnd+".tr", this.overlay ? ".sm-overlay-"+this.id : "", $.proxy(this, "onEndCloseMenu")); 695 if (!this.menuIconCorner) { 696 this.$button[1].style.display = "none"; 697 this.$button[1].style.opacity = 0; 698 } 699 if (smMobile) this.$filter.blur(); 700 this.$cont.removeClass(this.openClass); 701 this.$node.css("zIndex", "").trigger("closeMenu", this); 702 if (oldIE) this.onEndCloseMenu(); 703 }, 704 705 onEndCloseMenu: function(e) { 706 if (this.effect < 0) { 707 $.fn.width = Hlpr.width; 708 hackMediaWidths(0); 709 this.scroll = $win.scrollTop(); 710 $html.removeClass('sm-reduce-width'); 711 if (this.winWidth >= 768) $win.resize(); 712 } 713 var s = this.$inner[0].style; 714 s.position = s.background = s.border = s.padding = s.margin = ""; 715 $body[0].style.background = $body[0].style.position = $body[0].style.top = $body[0].style.bottom = ""; 716 this.$content.css({height: '', background: ''}); 717 $html.removeClass(this.fullClass); 718 //$html.css("overflowY", "");
719 if (smMobile) this.$node.css({top: "", position: ""}); 720 $win.scrollTop(this.scroll); 721 this.$cont.removeClass("sm-effect-" + Math.abs(this.effect)); 722 723 this.$content.css('maxWidth', ''); // Firefox bugfix (#18) 724 if (this.$button.length) { 725 if (!this.menuIconCorner || this.overlay || this.effectEx[this.effect]) { 726 if (this.menuIconCorner) this.$button.appendTo(this.$inner); 727 else this.$button[0].style.opacity = 1; 728 setTimeout($.proxy(this.$button, "removeClass", this.closeClass), 1); 729 } 730 else this.$button.removeClass(this.closeClass); 731 } 732 }, 733 734 onResize: function(e) { 735 var isInCont = this.$node[0].parentNode != this.$parent[0], 736 $title = this.$title.last(); 737 this.prevWinWidth = this.winWidth || $win.outerWidth(); 738 this.winWidth = $win.outerWidth(); 739 this.winHeight = $win.outerHeight(); 740 // update button 741 if (!this.sidebar && this.winWidth < this.sidebarUnder && !isInCont) { 742 this.$button.css("display", ""); 743 this.$node 744 .appendTo(this.$cont) 745 .trigger("moveToSidebar", this); 746 } 747 748 // update title position (don't update on init) 749 if (e && $title[0]) TweenLite.set($title[0], {x: $title._center(this.$back.length)}); 750 751 // update dropmenu 752 var drop = this.drop; 753 this.drop = this.dropmenu && !smMobile && this.winWidth >= this.sidebarUnder; 754 if (drop != this.drop) { 755 if (this.drop) { 756 if (this.$head.length) { 757 this.$title.filter(":not(:first)").remove(); 758 this.$title.length = 1; 759 TweenLite.set(this.$title[0], {css: {scale:1, x:this.$title.attr("class", "sm-title")._center(this.$back.length)}}); 760 } 761 this.$lvls.children().attr("style", "display: none;"); 762 this.opened = this.$lvls.children(":first").attr("style", "position: static;")[0]; 763 this.prev = undefined; 764 this.$node 765 .on(this.dropEvent+".dm", "dt.parent", $.proxy(this, "onOpenDrop")) 766 .on(this.dropEvent+".dm", ">.sm-level", $.proxy(this, "onMouseEnterDrop")); 767 this.$drop 768 .on(this.dropEvent+".dm", "dt.parent", $.proxy(this, "onOpenDrop")) 769 .on(this.dropEvent+".dm", ".sm-level", $.proxy(this, "onMouseEnterDrop")); 770 if (this.dropEvent == "click") { 771 $body.on("click.dm", $.proxy(this, "closeAllDrops")); 772 } else { 773 this.$node 774 .on("mouseleave.dm", "dt.parent", $.proxy(this, "onCloseDrop")) 775 .on("mouseleave.dm", ">.sm-level", $.proxy(this, "onMouseLeaveDrop")); 776 this.$drop 777 .on("mouseleave.dm", "dt.parent", $.proxy(this, "onCloseDrop")) 778 .on("mouseleave.dm", ".sm-level", $.proxy(this, "onMouseLeaveDrop")); 779 } 780 } else { 781 this.$node.off(".dm"); 782 this.$drop.off(".dm"); 783 $body.off("click.dm"); 784 } 785 } 786 // update background img pos 787 if (this.bg && this.bgX) { 788 var level = this.opened.children[0].attributes['class'].value.match(/level(\d)/)[1]; 789 this.$node[0].backgroundPosition = this.bgX * (level - 1) + "% 0"; 790 } 791 792 if (this.popup) { 793 var maxH, mb = navigator.userAgent.match(/iPad/i) ? 25 : 5; 794 if (this.menuIconCorner) { // fixed position 795 var off = this.$lvls.offset(); 796 maxH = (this.winHeight - (off.top - $win.scrollTop()) - mb); 797 this.opened.children[0].style.maxHeight = maxH - 2 * this.menuPadding + "px"; 798 this.$lvls.css("maxHeight", maxH); 799 this.$node.css("maxWidth", this.winWidth - off.left - this.$button.width()); 800 } else if (this.$node.css("visibility") != "hidden") { // module position 801 var btn = this.$button.offset(), 802 top = $win.scrollTop(), 803 originX = "0%"; 804 if (this.winWidth/2 > btn.left || this.popup == 2) { // left 805 this.$node.css({ 806 maxWidth: this.winWidth - btn.left - this.$button.width(), 807 left: btn.left, 808 right: "" 809 }); 810 } else { // right 811 originX = "100%"; 812 this.$node.css({ 813 maxWidth: btn.left, 814 left: "", 815 right: this.winWidth - btn.left - this.$button.width() 816 }); 817 } 818 if (top + this.winHeight/2 > btn.top) { // top 819 TweenLite.set(this.$node[0], {transformOrigin: originX + " 0% 0", scaleX: 1, scaleY: 1}); 820 maxH = this.winHeight - (btn.top - top) - this.$lvls.position().top - mb; 821 this.$node.css({top: btn.top, bottom: ""}); 822 } else { // bottom 823 TweenLite.set(this.$node[0], {transformOrigin: originX + " 100% 0", scaleX: 1, scaleY: 1}); 824 maxH = btn.top - top + this.$button.height() - this.$lvls.position().top; 825 this.$node.css({top: "", bottom: this.winHeight - btn.top - this.$button.height()}); 826 }
827 this.opened.children[0].style.maxHeight = maxH - 2 * this.menuPadding + "px"; 828 this.$lvls.css({maxHeight: maxH, height: $(this.opened.children).height() + 2 * this.menuPadding}); 829 } 830 } else if (this.sidebar || this.sidebarUnder) { 831 // update button & sidebar 832 if (!this.sidebar && this.winWidth >= this.sidebarUnder && isInCont) { 833 this.$button.css("display", "none"); 834 this.$node 835 .css({top: "", position: ""}) // mobile fix 836 .appendTo(this.$parent); 837 if (this.$cont.hasClass(this.openClass)) { 838 this.closeMenu(); 839 this.onEndCloseMenu(); 840 } 841 this.$node.trigger("moveToModulepos", this); 842 } 843 if (this.$node.css("display") == "block") { // if sidebar is open 844 this.$pusher.addClass("no-trans"); // disable transitions during resize 845 if (this.$pusher[0]) this.$pusher[0].offsetHeight; // trigger a reflow, flushing the CSS changes 846 this.$pusher.removeClass("no-trans"); 847 // update menu height 848 if (this.sidebar || this.winWidth < this.sidebarUnder) 849 this.$lvls.css('maxHeight', window.innerHeight - this.$lvls.position().top); 850 else if (!this.treemenu) 851 this.$lvls.height($(this.opened.children).outerHeight() + 2 * this.menuPadding); 852 else 853 this.$lvls[0].style.height = ""; 854 } else { // if sidebar is close 855 if (this.hideBurger && this.autoOpen == 2 && this.prevWinWidth < 768 && this.winWidth >= 768) this.openMenu(); 856 } 857 } else if (this.overlay && $body.hasClass(this.openClass)) { // OVERLAY 858 var topHeight = 0; 859 this.$lvls.prevAll().each(function() { topHeight += $(this).outerHeight() }); 860 this.$lvls.css('maxHeight', this.$overlay.outerHeight() - topHeight); 861 } 862 863 this.updateScrollbar(); 864 }, 865 866 onFilter: function(e) { 867 this.$filter.attr('value', this.$filter.val()); 868 if (!e.target.value.length && $(this.opened.children).hasClass("sm-result")) this.onBack(); 869 if (this.filterTimeout) this.filterTimeout = clearTimeout(this.filterTimeout); 870 if (e.target.value.length < this.filterMinChar) return; 871 this.filterTimeout = setTimeout($.proxy(this, "filter", e.target.value), this.filterDelay); 872 }, 873 874 filter: function(keyword) { 875 keyword = keyword.trim().replace(/\s+/g, " ").replace(/([.?*+^$|{}()\\[\]])/g, "\\$1"); 876 if (this.keyword == keyword) return; 877 if (!this.keyword) this.filterParent = this.opened; 878 this.keyword = keyword; 879 this.$filter.trigger("filter", [this, keyword]); 880 var i, $dt, 881 $result = this.$result.clone().appendTo(this.$lvls).children(), 882 submenu = $result[0].parentNode; 883 for (i = 0; i < this.$dt.length; i++) { 884 $dt = $(this.$dt[i]); 885 if ($dt.text().match( new RegExp(this.keyword, "i") )) { 886 var $clone = $dt.clone().removeClass("parent").addClass("notparent"); 887 $clone[0].innerHTML = $clone[0].innerHTML.replace(new RegExp(">([^<]*)("+this.keyword+")([^>]*)<", "ig"), ">$1<strong>$2</strong>$3<"); 888 $clone.appendTo($result); 889 } 890 } 891 var res = $result[0].children.length; 892 if (this.backItem && res == 1 || !res) { 893 var $no = $(this.opened).find("dt:first").clone() 894 .removeClass("parent opened").addClass("notparent").css("pointerEvents", "none"); 895 $no.find("a").removeAttr("href").html(this.noResult); 896 $no.find(".desc, .sm-icon, .productnum").remove(); 897 $no.appendTo($result); 898 } 899 submenu.parent = this.filterParent; 900 this.open(this.result, submenu); 901 }, 902 903 onRedirect: function(e) { 904 e.stopPropagation(); 905 if (this.disableClick) return e.preventDefault(); // disable click during swipe 906 var $a = e.currentTarget.tagName == "A" ? $(e.currentTarget) : $("a", e.currentTarget), 907 a = $a[0], event = $.Event("openMenuItem"); 908 $a.trigger(event, this); 909 if (event.isDefaultPrevented()) return e.preventDefault(); 910 var $scrollTo = $(), hash = a.href && a.href.match(/#([\w-]+)$/); 911 if (hash) $scrollTo = hash[0] == '#top' ? $body : $(hash[0]+', a[name="'+hash[1]+'"]'); 912 if ($scrollTo.length) { // scroll 913 e.preventDefault(); 914 var $cont, cont, t, b; 915 if (this.$cont && this.$cont.hasClass(this.openClass) && this.effect > 0) { // sidebar 916 $cont = this.$content; 917 cont = {scroll: $cont.scrollTop()}; 918 t = $scrollTo.offset().top + cont.scroll - $cont.offset().top; 919 b = this.$inner.outerHeight() - this.$content.height(); 920 } else { // not sidebar 921 $cont = $win; 922 cont = {scroll: $cont.scrollTop()}; 923 t = $scrollTo.offset().top; 924 b = $body.outerHeight() - this.winHeight; 925 } 926 this.scroll = t < b ? t : b; 927 var dur = 0.4 + Math.abs(cont.scroll - this.scroll) / 5000; 928 TweenLite.to(cont, dur, { 929 scroll: this.scroll, 930 onUpdate: function onUpdateScroll() { $cont.scrollTop(cont.scroll) }, 931 onComplete: this.popup && this.menuIconCorner && this.winWidth < this.hidePopupUnder ? function onEndScroll() { 932 if (!this.$button.eq(1).hasClass(this.closeClass)) return; 933 TweenLite.set(this.$button[0], {
934 x: this.menuIconX - this.$node.width(), 935 y: this.menuIconY 936 }); 937 this.$button.eq(1).addClass("sm-hide"); 938 if (!smMobile) this.$node.one("mouseenter", $.proxy(this, "onClickButton")); 939 }.bind(this) : function() { $a.closest('dt').addClass('active').siblings('.active').removeClass('active') } 940 }); 941 } else { // open url 942 if (!(smMobile && this.popup)) // fix for mobile popup menu-item opening 943 if (a == e.target.parentNode || a == e.target) return; 944 if (!a.click) { 945 var event = document.createEvent("HTMLEvents"); 946 event.initEvent("click", false, true); 947 a.dispatchEvent(event); 948 } else a.click(); 949 } 950 }, 951 952 onOpenDrop: function(e) { 953 if (this.sidebar && !$body.hasClass(this.openClass)) return; 954 var item = e.currentTarget, 955 openTween = item.parentNode.parentNode.openTween, 956 closeTween = item.parentNode.parentNode.closeTween, 957 items = item.parentNode.children, i; 958 for (i = 0; i < items.length; i++) 959 if (items[i] != item && items[i].menu && items[i].menu.style.display == "block") 960 { this.closeDrop(items[i].menu); break; } 961 item.menu.closeTimeout = clearTimeout(item.menu.closeTimeout); 962 if (openTween && openTween.isActive()) 963 openTween.vars.onComplete = $.proxy(this, "openDrop", item); 964 else if (closeTween && closeTween.isActive()) 965 closeTween.vars.onReverseComplete = $.proxy(this, "openDrop", item); 966 else 967 this.openDrop(item); 968 }, 969 970 onCloseDrop: function(e) { 971 var item = e.currentTarget, 972 openTween = item.parentNode.parentNode.openTween, 973 closeTween = item.parentNode.parentNode.closeTween; 974 if (openTween && openTween.vars.onComplete) 975 delete openTween.vars.onComplete; 976 else if (closeTween && closeTween.vars.onReverseComplete) 977 delete closeTween.vars.onReverseComplete; 978 else 979 item.menu.closeTimeout = setTimeout($.proxy(this, "closeDrop", item.menu), this.anim.outDur * 500 || 200); 980 }, 981 982 onMouseEnterDrop: function(e) { 983 if (this.sidebar && !$body.hasClass(this.openClass)) return; 984 var menu = e.currentTarget, 985 item = menu.parentItem; 986 menu.style.zIndex = 99; 987 do { 988 if (menu.closeTween && menu.closeTween.isActive()) menu.closeTween.reverse(); 989 menu.closeTimeout = clearTimeout(menu.closeTimeout); 990 menu = menu.parent; 991 $(item).addClass("hover"); 992 item = menu.parentItem; 993 } while ("closeTimeout" in menu); 994 }, 995 996 onMouseLeaveDrop: function(e) { 997 var menu = e.currentTarget, 998 item = menu.parentItem, 999 items = menu.children[0].children, 1000 i = items.length, t = 1; 1001 while (i--) 1002 if (items[i].menu && items[i].menu.closeTimeout) {t++; break} 1003 do { 1004 menu.closeTimeout = setTimeout($.proxy(this, "closeDrop", menu), (this.anim.outDur * 500 || 200) * t++); 1005 menu = menu.parent; 1006 $(item).removeClass("hover"); 1007 item = menu.parentItem; 1008 } while ("closeTimeout" in menu); 1009 }, 1010 1011 closeAllDrops: function() { 1012 var $menu = this[this.sidebar ? "$node" : "$drop"].children(".sm-level[style*=block]:last"); 1013 if ($menu.length) this.onMouseLeaveDrop({currentTarget: $menu[0]}); 1014 }, 1015 1016 openDrop: function(item) { 1017 var submenu = item.menu, 1018 openTween = item.parentNode.parentNode.openTween, 1019 closeTween = item.parentNode.parentNode.closeTween; 1020 if (openTween) delete openTween.vars.onComplete; 1021 if (closeTween) delete closeTween.vars.onReverseComplete; 1022 // replace nodes to be on top (zIndex) 1023 if (this.sidebar && submenu.parentNode != this.$node[0]) 1024 $(submenu).appendTo(this.$node); 1025 if (!this.sidebar && submenu.parentNode != this.$drop[0]) 1026 $(submenu).appendTo(this.$drop); 1027 1028 var p = $(item).offset(), 1029 w = $(item).outerWidth(), 1030 h = $(submenu).outerHeight(), 1031 t = $win.scrollTop(), 1032 m = t + this.winHeight - p.top - h; 1033 if (submenu.parent.parentNode == this.$lvls[0]) 1034 this.dropdir = p.left + w/2 - this.winWidth/2 < 0 ? 1 : -1; 1035 1036 if (this.dropdir < 0) { 1037 p.right = $win.outerWidth() - p.left; // don't use this.winWidth 1038 if (this.sidebar && p.right < this.width) p.right = this.width - this.menuPadding; 1039 submenu.style.right = p.right + this.menuPadding + this.dropspace + "px"; 1040 submenu.style.left = ""; 1041 } else { 1042 if (p.left < 0) p.left = 0; 1043 submenu.style.left = w + p.left + this.menuPadding + this.dropspace + "px"; 1044 submenu.style.right = ""; 1045 } 1046 1047 if (this.dropFullHeight) { 1048 p.top = t; 1049 submenu.style.height = "100vh"; 1050 } else if (m < 0) { // out of screen 1051 var ih = $(item).outerHeight(), y = p.top; 1052 p.top += Math.floor(m / ih) * ih; 1053 if (p.top + h <= y) p.top += ih; 1054 if (p.top < t) p.top = t; 1055 submenu.children[0].style.height = h >= this.winHeight ? "100vh" : ""; 1056 } 1057 if (this.effect < 0) p.top -= $win.scrollTop(); // reduce_width bugfix (#21) 1058 submenu.style.top = p.top - (this.dropFullHeight ? 0 : this.menuPadding) + "px"; 1059 submenu.style.zIndex = 99; 1060 1061 this.anim.inCSS.x = this.anim.inUnitX == "%" ? this.anim.inX * this.dropwidth / 100 : this.anim.inX; 1062 this.anim.inCSS.x *= this.dropdir; 1063 this.anim.inCSS.rotationY = this.dropdir * this.anim.inRotationY; 1064 TweenLite.set(submenu, { 1065 transformPerspective: this.anim.perspective, 1066 transformOrigin: Hlpr.calcOrigin(this.anim.inOrigin, this.dropwidth, this.dropdir) 1067 }); 1068 var animTo = {
1069 overwrite: 1, 1070 css: this.baseCSS, 1071 ease: this.anim.inEase 1072 }; 1073 if (submenu.style.display == "none") { 1074 submenu.openTween = TweenLite.fromTo(submenu, this.anim.inDur, {css: this.anim.inCSS}, animTo); 1075 // menu-item anim 1076 if (this.miAnim) { 1077 this.miCSS.x = this.miUnitX == "%" ? this.miX * w / 100 : this.miX; 1078 this.miCSS.x *= this.dropdir; 1079 this.miCSS.rotationY = this.miRotationY * this.dropdir; 1080 if (this.miShift) 1081 TweenMax.staggerFromTo($(">dl>dt", submenu), this.miDur, {css: this.miCSS}, {overwrite: 1, css: this.baseCSS, ease: this.miEase}, this.miShift); 1082 else 1083 TweenLite.fromTo(submenu.children[0], this.miDur, {css: this.miCSS}, {overwrite: 1, css: this.baseCSS, ease: this.miEase}); 1084 } 1085 // icons anim 1086 if (this.iconAnim && !smMobile) 1087 TweenLite.fromTo($(".sm-icon img", submenu), 0.5, {scale: 0, opacity: 0}, {css: {scale: 1, opacity: 1}, ease: Back.easeOut, delay: 0.66*this.dur}); 1088 } else { 1089 submenu.openTween = TweenLite.to(submenu, this.anim.inDur, animTo); 1090 } 1091 1092 submenu.style.display = "block"; 1093 this.updateScrollbar(submenu); 1094 $(item).trigger("openParentItem", this); 1095 }, 1096 1097 closeDrop: function(submenu) { 1098 if (submenu.style.display == 'none') return; 1099 submenu.style.zIndex = ""; 1100 this.anim.outCSS.x = this.anim.outUnitX == "%" ? this.anim.outX * this.dropwidth / 100 : this.anim.outX; 1101 this.anim.outCSS.rotationY = this.dropdir * this.anim.outRotationY; 1102 TweenLite.set(submenu, {transformOrigin: Hlpr.calcOrigin(this.anim.outOrigin, this.dropwidth, this.dropdir)}); 1103 submenu.closeTween = TweenLite.to(submenu, this.anim.outDur, { 1104 overwrite: 1, 1105 css: this.anim.outCSS, 1106 ease: this.anim.outEase, 1107 onComplete: Target.hide 1108 }); 1109 }, 1110 1111 onClickTree: function(e) { 1112 e.stopPropagation(); 1113 e.preventDefault(); 1114 //if (smMobile && e.type == 'click') return; 1115 var $item = $(e.currentTarget); 1116 this[$item.hasClass("opened") ? "closeTree" : "openTree"]($item); 1117 }, 1118 1119 openTree: function($item) { 1120 var dur = this.dur; 1121 var $dd = $item.addClass("opened").next(); 1122 if (this.popup) this.$lvls.height("auto"); 1123 if (this.accordion) { 1124 $item.siblings("dt.opened").removeClass("opened"); 1125 $dd.siblings("dd.opened").removeClass("opened").slideUp({ easing: this.outEase, duration: dur * 1000 }); 1126 } 1127 $dd.slideDown({ 1128 queue: false, 1129 easing: this.inEase, 1130 duration: dur * 1000, 1131 progress: this.bindUpdateScrollbar, 1132 complete: function() { $dd.attr('style', 'display: block;') } 1133 }).addClass('opened'); 1134 1135 if (this.miAnim) { 1136 this.miCSS.x = this.miUnitX == "%" ? this.miX * this.$lvls.outerWidth() / 100 : this.miX; 1137 if (this.miShift) 1138 dur = new TimelineLite() 1139 .staggerFromTo($dd.find("dt").not("dd:not(.opened) dt"), this.miDur, {css: this.miCSS}, {overwrite: 1, css: this.baseCSS, ease: this.miEase}, this.miShift) 1140 .totalDuration(); 1141 else 1142 TweenLite.fromTo($dd.find("dl").not("dd:not(.opened) dl"), this.miDur, {css: this.miCSS}, {overwrite: 1, css: this.baseCSS, ease: this.miEase}); 1143 } 1144 1145 // icons anim 1146 if (this.iconAnim && !smMobile) 1147 TweenLite.fromTo($dd.find(".sm-icon img"), 0.5, {scale: 0, opacity: 0}, {css: {scale: 1, opacity: 1}, ease: Back.easeOut, delay: 0.66*this.dur}); 1148 1149 $item.trigger("openParentItem", this); 1150 }, 1151 1152 closeTree: function($item) { 1153 var $dd = $item.removeClass("opened").next(); 1154 $dd.removeClass('opened').slideUp({ 1155 queue: false, 1156 easing: this.outEase, 1157 duration: this.dur * 1000, 1158 progress: this.bindUpdateScrollbar, 1159 complete: function() { $dd.attr('style', '') } 1160 }); 1161 }, 1162 1163 onOpen: function(e) { 1164 if (this.drop) return; 1165 if (e.type == "touchend") e.preventDefault(); 1166 if (e.currentTarget.parentNode.parentNode == this.prev) return; 1167 if (this.disableClick) return; // disable click during swipe 1168 var title = $(e.currentTarget).find("a").html().replace(/<.*>/, ""); 1169 this.open(title, e.currentTarget.menu); 1170 }, 1171 1172 open: function(title, submenu) { 1173 if (submenu.parentNode != this.$lvls[0]) 1174 $(submenu).css({top:'', left:'', right:''}).appendTo(this.$lvls); 1175 var w = this.$lvls.outerWidth(), 1176 tl = new TimelineLite({paused: true, autoRemoveChildren: true, onComplete: $.proxy(this, "onEndSlide")}); 1177 TweenLite.set(this.opened, {transformOrigin: Hlpr.calcOrigin(this.outOrigin, w)}); 1178 TweenLite.set(submenu, {transformOrigin: Hlpr.calcOrigin(this.inOrigin, w)}); 1179 1180 this.inCSS.x = this.inUnitX == "%" ? this.inX * w / 100 : this.inX; 1181 this.outCSS.x = this.outUnitX == "%" ? this.outX * w / 100 : this.outX; 1182 1183 // submenu anims 1184 tl.add(TweenLite.to(this.opened, this.dur, {css: this.outCSS, ease: this.outEase, onComplete: Target.scrollUp}), 0); 1185 tl.add(TweenLite.fromTo(submenu, this.dur, {css: this.inCSS}, {css: this.baseCSS, ease: this.inEase}), 0); 1186 1187 this.opened.style.zIndex = ""; 1188 submenu.style.zIndex = 99; 1189 submenu.style.display = "block"; 1190 if (!this.sidebar && this.winWidth >= this.sidebarUnder) { 1191 if (this.popup) submenu.children[0].style.maxHeight = this.$lvls[0].style.maxHeight; 1192 var h = $(submenu.children[0]).outerHeight() + 2 * this.menuPadding; 1193 tl.add(TweenLite.to(this.$lvls[0], this.dur, {css: {height: h}}), 0); 1194 } 1195
1196 if (!$(this.opened.children).hasClass("sm-result")) { // if filtering was started at search result, don't run it 1197 // header anims 1198 if (this.$head.length) { 1199 var $title = $('<span class="sm-title" title="'+title+'">'+title+'</span>').appendTo(this.$head), 1200 i = this.$title.length; 1201 if (!this.$title[0].style.position) // init title position 1202 TweenLite.set(this.$title[0], {css: {position: "absolute", x: this.$title._center(this.$back.length)}}); 1203 if (this.$back.length) { // clean theme 1204 if (i == 1) 1205 tl.add(TweenLite.to(this.$back[0], this.dur, {css: {opacity: 1, display: 'block'}}), 0); 1206 if (this.$title[--i]) this.$title[i].style.position = "absolute", 1207 tl.add(TweenLite.to(this.$title[i], 2*this.dur, {css: {x: -w*0.6, opacity: -1, scale: 0}}), 0); 1208 } else { // flat theme 1209 this.$title.attr("class", "sm-back"); 1210 if (this.$title[--i]) this.$title[i].style.position = "absolute", 1211 tl.add(TweenLite.to(this.$title[i], this.dur, {css: {x: 0, scale: backScale}}), 0); 1212 if (this.$title[--i]) 1213 tl.add(TweenLite.to(this.$title[i], this.dur, {css: {x: -w*0.6}, ease: Linear.easeNone}), 0); 1214 } 1215 tl.add(TweenLite.fromTo($title, this.dur, {x: w}, {css: {x: $title._center(this.$back.length)}}), 0); 1216 this.$title.push($title[0]); 1217 } 1218 1219 // bg anim 1220 if (this.bg && this.bgX) { 1221 var level = this.opened.children[0].attributes['class'].value.match(/level(\d)/)[1]; 1222 tl.add(TweenLite.to(this.$node[0], this.dur, {css: {backgroundPosition: this.bgX * level + "% 0"}}), 0); 1223 } 1224 } 1225 // menu-item anim 1226 if (this.miAnim) { 1227 this.miCSS.x = this.miUnitX == "%" ? this.miX * w / 100 : this.miX; 1228 if (this.miShift) 1229 tl.staggerFromTo($(">dl>dt", submenu), this.miDur, {css: this.miCSS}, {css: this.baseCSS, ease: this.miEase}, this.miShift, 0); 1230 else 1231 tl.fromTo(submenu.children[0], this.miDur, {css: this.miCSS}, {css: this.baseCSS, ease: this.miEase}, 0); 1232 } 1233 // icons anim 1234 if (this.iconAnim && !smMobile) 1235 tl.add(TweenLite.fromTo($(".sm-icon img", submenu), 0.5, {scale: 0, opacity: 0}, {css: {scale: 1, opacity: 1}, ease: Back.easeOut}), 0.66*this.dur); 1236 this.openTL = tl; 1237 1238 if (this.backTL && this.backTL._first) delete this.backTL._first.vars.onComplete; // don't run Target.scrollUp 1239 TweenLite.set(this.$lvls[0], {perspective: this.perspective}); // blur fix for retina 1240 this.openTL.play(); 1241 this.prev = this.opened; 1242 this.opened = submenu; 1243 this.updateScrollbar(); 1244 1245 // don't trigger event when submenu is search result 1246 if (!$(submenu.children[0]).hasClass("sm-result")) $(submenu.parentItem).trigger("openParentItem", [this, title]); 1247 }, 1248 1249 onResetFilter: function() { 1250 this.$filter.attr("value", ""); 1251 if ($(this.opened.children).hasClass("sm-result")) this.onBack(); 1252 this.$filter[0].focus(); 1253 }, 1254 1255 onBack: function(e) { 1256 if (e && e.type == "touchend") e.preventDefault(); 1257 if (!this.opened.parent) return; 1258 this.initBackTimeline(); 1259 this.back(); 1260 }, 1261 1262 back: function() { 1263 if (this.openTL && this.openTL._first) delete this.openTL._first.vars.onComplete; // don't run Target.scrollUp 1264 TweenLite.set(this.$lvls[0], {perspective: this.perspective}); // blur fix for retina 1265 this.backTL.resume(); 1266 this.prev = this.opened; 1267 this.opened = this.opened.parent; 1268 this.updateScrollbar(); 1269 1270 this.$title.length--; 1271 this.$filter.attr("value", ""); 1272 this.keyword = ""; 1273 $(this.opened).trigger("back", this); 1274 }, 1275 1276 initBackTimeline: function() { 1277 var w = this.$lvls.addClass("sm-swipe").outerWidth(), 1278 tl = new TimelineLite({ 1279 paused: true, 1280 autoRemoveChildren: true, 1281 onComplete: $.proxy(this, "onEndSlide"), 1282 onReverseComplete: function() { this.onEndSlide(), this.opened.parent.style.display = "none" }.bind(this) 1283 }); 1284 1285 this.inCSS.x = this.inUnitX == "%" ? this.inX * w / 100 : this.inX; 1286 1287 TweenLite.set(this.opened, {transformOrigin: Hlpr.calcOrigin(this.inOrigin, w)}); 1288 TweenLite.set(this.opened.parent, {transformOrigin: Hlpr.calcOrigin(this.outOrigin, w)}); 1289 1290 // submenu anims 1291 tl.add(TweenLite.to(this.opened, this.dur, {css: this.inCSS, onComplete: Target.scrollUp}), 0); 1292 tl.add(TweenLite.to(this.opened.parent, this.dur, {css: this.baseCSS, ease: this.inEase}), 0); 1293 1294 this.opened.parent.style.display = "block"; 1295 if (!this.sidebar && this.winWidth >= this.sidebarUnder) { 1296 if (this.popup) this.opened.parent.children[0].style.maxHeight = this.$lvls[0].style.maxHeight; 1297 tl.add(TweenLite.to(this.$lvls[0], this.dur, { 1298 css: {height: $(this.opened.parent.children[0]).outerHeight() + 2 * this.menuPadding}, 1299 onComplete: this.prev.parentNode.children[0] == this.prev ? Target.autoHeight : undefined // auto height first level 1300 }), 0); 1301 } 1302 1303 // header anims 1304 if (this.$head.length) { 1305 var i = this.$title.length; 1306 tl.add(TweenLite.to(this.$title[--i], this.dur, {css: {x: w, opacity: 0}, onComplete: Target.remove}), 0); 1307 if (this.$back.length) { // clean theme 1308 if (i == 1) tl.add(TweenLite.to(this.$back[0], this.dur, {css: {opacity: 0, display: 'none'}}
1308), 0); 1309 tl.add(TweenLite.to(this.$title[--i], this.dur, {css: {x: $(this.$title[i])._center(true), opacity: 1, scale: 1}}), 0); 1310 } else { // flat theme 1311 tl.add(TweenLite.to(this.$title[--i], this.dur, { 1312 css: {x: $(this.$title[i])._center(), scale: 1, maxWidth: i ? this.titleWidth : "100%"}, 1313 onComplete: Target.autoMaxWidth 1314 }), 0); 1315 if (this.$title[--i]) tl.add(TweenLite.to(this.$title[i], this.dur, {css: {x: 0}}), 0); 1316 } 1317 } 1318 1319 // bg anim 1320 if (this.bg && this.bgX) { 1321 var level = this.opened.children[0].attributes['class'].value.match(/level(\d)/); 1322 level = level ? level[1] - 2 : 0; 1323 tl.add(TweenLite.to(this.$node[0], this.dur, {css: {backgroundPosition: this.bgX * level + "% 0"}}), 0); 1324 } 1325 1326 this.backTL = tl; 1327 }, 1328 1329 onEndSlide: function() { 1330 // blur fix for retina 1331 $(this.opened).css({WebkitTransform: "", MozTransform: "", msTransform: "", transform: ""}); 1332 this.$lvls.css({WebkitPerspective: "", MozPerspective: "", perspective: ""}).removeClass("sm-swipe"); 1333 this.disableClick = false; // enable click after swipe 1334 }, 1335 1336 updateScrollbar: function(menu) { 1337 if (smMobile) return; 1338 var $dl = $( (menu || this.opened).children[0] ); 1339 $dl.perfectScrollbar($dl.data("perfectScrollbar") ? "update" : undefined); 1340 } 1341 1342}; 1343 1344// depreciated functions 1345VerticalSlideMenu.prototype.openSidebar = VerticalSlideMenu.prototype.openMenu; 1346VerticalSlideMenu.prototype.closeSidebar = VerticalSlideMenu.prototype.closeMenu; 1347 1348(function initMenuSpy() { 1349 1350 $elems = $(); 1351 var $cont = $(window) 1352 .on("resize.menuspy", onResize) 1353 .on("scroll.menuspy load.menuspy", onScroll); 1354 1355 function onScroll() { 1356 if (!$elems.length) return; 1357 var y = $cont.scrollTop(); 1358 $elems.each(function(i) { 1359 var $elem = $(this); 1360 var o = $elem.data('menuspy'); 1361 if (y >= o.max || y < o.min) { 1362 if (o.inside) { 1363 o.inside = false; 1364 $elem.trigger("scrollLeave.menuspy", {scrollTop: y, enters: o.enters, leaves: ++o.leaves}); 1365 } 1366 } else { 1367 if (!o.inside) { 1368 o.inside = true; 1369 $elem.trigger("scrollEnter.menuspy", {scrollTop: y, enters: ++o.enters, leaves: o.leaves}); 1370 } 1371 } 1372 }); 1373 } 1374 1375 function onResize() { 1376 $elems.each(function() { 1377 var $elem = $(this); 1378 var o = $elem.data("menuspy"); 1379 o.min = $elem.offset().top; 1380 o.max = $elem.outerHeight() + o.min; 1381 }); 1382 } 1383 1384 $.fn.menuspy = function(options) { 1385 var defaults = { 1386 offset: 0, 1387 enters: 0, 1388 leaves: 0, 1389 inside: false 1390 }; 1391 return this.each(function() { 1392 var $elem = $(this); 1393 var top = $elem.offset().top; 1394 $elem.data("menuspy", $.extend({ 1395 min: top, 1396 max: top + $elem.outerHeight(), 1397 }, defaults, options)); 1398 $elems.push(this); 1399 }); 1400 }; 1401 1402})(); 1403 1404})(window.jq183||jQuery);
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.