1/*------------------------------------------------------------------------- 2# mod_vertical_menu - Vertical Menu 3# ------------------------------------------------------------------------- 4# @ author Balint Polgarfi 5# @ copyright Copyright (C) 2015 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.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 this.$content = this.$pusher.children(); 390 this.$inner = this.$content.children(".sm-content-inner"); 391 392 $html.css('overflow-y', 'auto'); 393 }, 394 395 initSidebar: function() { 396 if (this.sidebar) { 397 this.$button.css("display", ""); 398 this.$node.appendTo(this.$cont); 399 } 400 this.$cont.on("click.sm touchstart.sm", function(e) { this.effect < 0 || this.closeMenu(e) }.bind(this)); 401 // disable page scrolling when sidebar is open 402 this.$lvls.on("touchstart.sm", function(e) { this.effect < 0 || this.scrollFixStart(e) }.bind(this)); 403 this.$cont.on("touchmove.sm", function(e) { this.effect < 0 || this.scrollFixMove(e) }.bind(this)); 404 405 // TransitionEnd fix 406 this.$node.on(smTransitionEnd, Hlpr.cancelTransitionEnd); 407 this.$inner.on(smTransitionEnd, Hlpr.cancelTransitionEnd); 408 409 if (this.menuIconCorner) { 410 this.$button.appendTo(this.$inner); 411 } else { 412 this.$button.appendTo(this.$parent); 413 this.$button.push(this.$button.clone().css("opacity", 0).appendTo(this.$node)[0]); 414 } 415 if (!this.sidebar) this.$button.css("display", "none"); 416 }, 417 418 initOverlay: function() {
419 var $overlay = $('<div>').addClass("sm-overlay-"+this.id).appendTo($body); 420 this.$overlay = $('<div>').addClass("sm-overlay-win").appendTo($overlay) 421 .on("click.sm "+smTransitionEnd, Hlpr.stopPropagation) // don't close overlay on click & TransitionEnd fix 422 this.$node.appendTo(this.$overlay); 423 this.$cont.on("click.sm touchstart.sm", $.proxy(this, "closeMenu")); 424 // disable touch-scrolling when sidebar is open 425 this.$lvls.on("touchstart.sm", $.proxy(this, "scrollFixStart")); 426 this.$cont.on("touchmove.sm", $.proxy(this, "scrollFixMove")); 427 428 if (this.menuIconCorner) { 429 this.$button.appendTo($body); 430 } else { 431 this.$button.appendTo(this.$parent); 432 this.$button.push(this.$button.clone().css("opacity", 0).insertBefore(this.$node)[0]); 433 } 434 }, 435 436 scrollFixStart: function(e) { 437 this.touchstartY = e.originalEvent.touches[0].clientY; 438 }, 439 440 scrollFixMove: function(e) { 441 if (!this.$cont.hasClass(this.openClass)) return; 442 else if (!$(e.target).closest('.sm-levels').length) return e.preventDefault(); 443 444 var node = this.opened.children[0]; 445 if (this.touchstartY < e.originalEvent.touches[0].clientY) { // on scroll up 446 if (node.scrollTop == 0) e.preventDefault(); 447 } else { // on scroll down 448 if (node.scrollTop == node.scrollHeight - node.offsetHeight) e.preventDefault(); 449 } 450 }, 451 452 onMouseDown: function(e) { 453 if (e.button == 0) { 454 if (e.target.tagName == "A") e.preventDefault(); 455 $body 456 .on("mousemove.sm", $.proxy(this, "onTouchMove")) 457 .on("mouseup.sm", $.proxy(this, "onMouseUp")); 458 } 459 }, 460 461 onMouseUp: function(e) { 462 if (e.button == 0) { 463 $body.off("mousemove.sm mouseup.sm"); 464 this.onTouchEnd(e); 465 } 466 }, 467 468 onTouchMove: function(e) { 469 if (this.touchEvent == "scroll") return; 470 if (smMobile && smMobile[0] == "Windows Phone") e.preventDefault(); // disable scrolling or swipe back 471 var x = 'pageX' in e ? e.pageX : e.originalEvent.touches[0].pageX, 472 y = 'pageY' in e ? e.pageY : e.originalEvent.touches[0].pageY; 473 if (this.touchStartX === undefined) { 474 // touchstart 475 this.touchTarget = e.target; 476 this.touchStartX = this.touchPrevX = x; 477 this.touchStartY = this.touchPrevY = y; 478 if (!this.opened.parent) this.touchEvent = "scroll"; 479 return; 480 } 481 var diffX = x - this.touchStartX, 482 diffY = y - this.touchStartY; 483 if (this.touchEvent === undefined) { 484 if (Math.abs(diffY) > this.minSwipe) { // vertical swipe 485 this.touchEvent = "scroll"; 486 $body.addClass("sm-scroll"); 487 } else if (diffX > this.minSwipe) { // horizontal swipe 488 if (this.openTL && this.openTL.isActive()) { 489 if (this.openTL.time() < this.dur) return; 490 else this.openTL.pause(); 491 } 492 this.touchEvent = "back"; 493 if (!smMobile) $(this.opened.children).perfectScrollbar("destroy"); 494 this.opened.parent.style.display = "block"; 495 this.initBackTimeline(); 496 TweenLite.set(this.$lvls[0], {perspective: this.perspective}); // blur fix for retina 497 this.nodeW = this.$lvls.outerWidth(); 498 } 499 } 500 if (this.touchEvent == "back") { 501 e.preventDefault(); // disable scrolling 502 diffX -= this.minSwipe; 503 504 if (diffX <= 1) diffX = 0.1; 505 if (diffX >= this.nodeW) diffX = this.nodeW - 0.1; 506 this.backTL.seek(this.dur * diffX / this.nodeW); 507 508 this.touchDirLeft = this.touchPrevX < x; 509 this.touchDirTop = this.touchPrevY < y; 510 if (this.touchPrevX != x) this.touchPrevX = x; 511 if (this.touchPrevY != y) this.touchPrevY = y; 512 } 513 }, 514 515 onTouchEnd: function(e) { 516 var touchEvent = this.touchEvent; 517 delete this.touchEvent; 518 delete this.touchStartX; 519 520 if (!touchEvent) return; 521 e.preventDefault(); 522 e.stopPropagation(); 523 524 if (touchEvent == "scroll") { 525 $body.removeClass("sm-scroll"); 526 } else if (touchEvent == "back") { 527 // disable click when swipe finished on the same menu-item where it started 528 if (this.touchTarget == e.target) this.disableClick = true; 529 if (this.touchDirLeft) { 530 this.back(); 531 } else { 532 if (!smMobile) $(this.opened.children).perfectScrollbar(); 533 this.backTL.reverse(); 534 } 535 } 536 }, 537 538 onEsc: function(e) { 539 if (e.keyCode == 27 && !this.$button.eq(1).hasClass("sm-hide") && this.$button.css('display') != 'none') { 540 if (!this.popup) 541 e.stopPropagation(), this.closeMenu(); 542 else if (this.$node.css("visibility") == "visible") 543 e.stopPropagation(), this.closePopup(); 544 } 545 }, 546 547 onClickButton: function(e) { 548 e.stopPropagation(); 549 e.preventDefault(); 550 if (this.$button.hasClass("sm-hide")) { 551 this.$button[0]._gsTransform.x = this.menuIconX; 552 this.$button.css(smTransform, '').removeClass("sm-hide"); 553 return; 554 } 555 if (this.popup) { // POPUP 556 if (this.$node.css("visibility") == "hidden") { 557 this.openPopup(); 558 } else { 559 if (e.currentTarget == this.$button[0]) return; // don't close menu for any click 560 this.closePopup(); 561 } 562 } else { // SIDEBAR || OVERLAY 563 if ($(e.currentTarget).hasClass(this.closeClass)) this.closeMenu(); 564 else this.openMenu(); 565 } 566 }, 567 568 openPopup: function() { 569 var bw = this.$button.width(), 570 bh = this.$button.height(),
571 w = this.$node.width(), 572 h = this.$node.height(); 573 this.$node.css("visibility", "visible"); 574 if (this.menuIconCorner) { // fixed position 575 TweenLite.set(this.$node[0], {transformOrigin: "0% 0% 0"}); 576 } else { // module position 577 this.onResize(); 578 } 579 var tl = new TimelineLite({ paused: true, autoRemoveChildren: true, onComplete: this.$noTrans }); 580 tl.add(TweenLite.fromTo(this.$node[0], 1, {scaleX: bw/w, scaleY: bh/h}, {css: {scaleX: 1, scaleY: 1}, ease: Back.easeOut}), 0); 581 tl.add(TweenLite.to(this.$node[0], 1, {css: {opacity: 1}, onComplete: $.proxy(this.$button.eq(1), "addClass", this.closeClass)}), 0); 582 tl.add(TweenLite.fromTo(this.$button[1], 0.75, {x: -bw, opacity: 1}, {css: {x: 0}}), -0.5); 583 tl.duration(this.$noTrans ? 0.001 : this.popupDur); 584 tl.play(); 585 this.$node.trigger("openMenu", this); 586 }, 587 588 closePopup: function() { 589 var bw = this.$button.width(), 590 bh = this.$button.height(), 591 w = this.$node.width(), 592 h = this.$node.height(); 593 this.$button.removeClass(this.closeClass); 594 var tl = new TimelineLite({paused: true, autoRemoveChildren: true}); 595 tl.add(TweenLite.to(this.$button[1], 0.3, {css: {x: -bw}}), -0.15); 596 tl.add(TweenLite.to(this.$node[0], 0.3, {css: {opacity: 0}, ease: Quad.easeIn}), 0.3); 597 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); 598 tl.play(); 599 this.$node.trigger("closeMenu", this); 600 }, 601 602 openMenu: function(e, effect) { 603 if (this.$cont.hasClass(this.openClass)) return; 604 var otherOpen = this.$cont[0].className.match(/sm-open-(\d+)/); 605 if (otherOpen) { // if another menu is already open 606 window['sm'+otherOpen[1]].closeMenu(); 607 return setTimeout($.proxy(this, 'openMenu'), 550); 608 } 609 if (e && e.stopPropagation) e.stopPropagation(); 610 $body.off(smTransitionEnd+".tr").one(smTransitionEnd+".tr", this.overlay ? ".sm-overlay-"+this.id : "", $.proxy(this, "onEndOpenMenu")); 611 612 this.effect = effect || this.effect; 613 if (this.effect < 0) { 614 $html.addClass('sm-reduce-width'); 615 hackMediaWidths(this.width); 616 $.fn.width = Hlpr.hackWidth(this.width); 617 } 618 this.$cont.addClass("sm-effect-" + Math.abs(this.effect)); 619 620 var btn = this.$button.length && (!this.menuIconCorner || this.overlay || this.effectEx[this.effect]); 621 if (btn && this.menuIconCorner) this.$button.appendTo(this.overlay ? this.$overlay : this.$node); 622 623 this.scroll = $win.scrollTop(); 624 if (smMobile) { 625 this.effect < 0 ? $win.off("resize.sm") : $win.off("resize.sm").scrollTop(0); // don't resize during animation on mobile 626 } 627 628 this.$cont.css({ position: 'fixed', top: 0, bottom: 0 }); 629 $html.addClass(this.fullClass); 630 this.$inner.css(this.bodyCSS); 631 this.$content.css(this.htmlCSS).scrollTop(this.scroll); 632 633 if (!smMobile) { 634 if (btn && !this.menuIconCorner) { 635 if (!this.overlay) this.$button.eq(1).appendTo(this.effectEx[this.effect] ? this.$node : this.$inner); 636 this.$button[1].style.display = "inline-block"; 637 } 638 } else { // mobile 639 if (this.$button[1]) this.$button[1].style.display = "block"; 640 } 641 642 if (this.overlay) { 643 this.$content.css('maxWidth', '100vw'); // Firefox bugfix (#18) 644 this.$lvls.css('maxHeight', ''); 645 } else if (this.sidebar || this.winWidth < this.sidebarUnder) { 646 if (this.effect > 0) this.$content.css('maxWidth', '100vw'); // Firefox bugfix (#18) 647 this.$lvls.css('maxHeight', this.effect == 8 ? window.innerHeight : window.innerHeight - this.$lvls.position().top); // fix for sidebar effect 8 648 } 649 this.$cont.css("background", this.siteBg).addClass(this.openClass); 650 this.$node.trigger("openMenu", this); 651 if (oldIE) this.onEndOpenMenu(); 652 }, 653 654 onEndOpenMenu: function(e) { 655 if (smMobile) { 656 $win.on("resize.sm", $.proxy(this, "onResize")); // allow resize after animation on mobile 657 if (this.sidebar || this.winWidth < this.sidebarUnder) // fix for sidebar bottom can't be see 658 this.$lvls.css('maxHeight', window.innerHeight - this.$lvls.position().top); 659 } 660 if (this.effect < 0 && this.winWidth > 767) $win.resize(); 661 if (this.menuIconCorner) 662 setTimeout($.proxy(this.$button, "addClass", this.closeClass), 1); 663 else { 664 this.$button[0].style.opacity = 0; 665 this.$button[1].style.opacity = 1; 666 this.$button.eq(1).addClass(this.closeClass); 667 } 668 if (this.overlay) { // calculate overlay max-height after transition 669 this.$lvls.css("maxHeight", this.$overlay.outerHeight() - this.$lvls.position().top); 670 } else if (this.effect == 8) { // fix for sidebar effect 8 671 this.$lvls.css('maxHeight', this.$cont.outerHeight() - this.$lvls.position().top); 672 } 673 this.$node.css("zIndex", 99); 674 if (this.$noTrans) { 675 this.$button.addClass(this.closeClass).show(); 676 this.$noTrans.css(smTransition+'Duration', ''); 677 delete this.$noTrans; 678 } 679 this.updateScrollbar(); 680 }, 681 682 closeMenu: function(e) { 683 if (e && $(e.target).closest(".sm-menu").length) return; 684 if (!this.$cont) return; 685 if (!this.$cont.hasClass(this.openClass)) return; 686 $body.off(smTransitionEnd+".tr").one(smTransitionEnd+".tr", this.overlay ? ".sm-overlay-"+this.id : "", $.proxy(this, "onEndCloseMenu")); 687 if (!this.menuIconCorner) { 688 this.$button[1].style.display = "none"; 689 this.$button[1].style.opacity = 0; 690 } 691 if (smMobile) this.$filter.blur(); 692 this.$cont.removeClass(this.openClass); 693 this.$node.css("zIndex", "").trigger("closeMenu", this); 694 if (oldIE) this.onEndCloseMenu(); 695 }, 696 697 onEndCloseMenu: function(e) { 698 if (this.effect < 0) { 699 $.fn.width = Hlpr.width; 700 hackMediaWidths(0); 701 this.scroll = $win.scrollTop(); 702 $html.removeClass('sm-reduce-width'); 703 if (this.winWidth >= 768) $win.resize(); 704 } 705 var s = this.$inner[0].style; 706 s.position = s.background = s.border = s.padding = s.margin = ""; 707 $body[0].style.background = $body[0].style.position = $body[0].style.top = $body[0].style.bottom = ""; 708 this.$content.css({height: '', background: ''}); 709 $html.removeClass(this.fullClass); 710 //$html.css("overflowY", "");
711 if (smMobile) this.$node.css({top: "", position: ""}); 712 $win.scrollTop(this.scroll); 713 this.$cont.removeClass("sm-effect-" + Math.abs(this.effect)); 714 715 this.$content.css('maxWidth', ''); // Firefox bugfix (#18) 716 if (this.$button.length) { 717 if (!this.menuIconCorner || this.overlay || this.effectEx[this.effect]) { 718 if (this.menuIconCorner) this.$button.appendTo(this.$inner); 719 else this.$button[0].style.opacity = 1; 720 setTimeout($.proxy(this.$button, "removeClass", this.closeClass), 1); 721 } 722 else this.$button.removeClass(this.closeClass); 723 } 724 }, 725 726 onResize: function(e) { 727 var isInCont = this.$node[0].parentNode != this.$parent[0], 728 $title = this.$title.last(); 729 this.prevWinWidth = this.winWidth || $win.outerWidth(); 730 this.winWidth = $win.outerWidth(); 731 this.winHeight = $win.outerHeight(); 732 // update button 733 if (!this.sidebar && this.winWidth < this.sidebarUnder && !isInCont) { 734 this.$button.css("display", ""); 735 this.$node 736 .appendTo(this.$cont) 737 .trigger("moveToSidebar", this); 738 } 739 740 // update title position (don't update on init) 741 if (e && $title[0]) TweenLite.set($title[0], {x: $title._center(this.$back.length)}); 742 743 // update dropmenu 744 var drop = this.drop; 745 this.drop = this.dropmenu && !smMobile && this.winWidth >= this.sidebarUnder; 746 if (drop != this.drop) { 747 if (this.drop) { 748 if (this.$head.length) { 749 this.$title.filter(":not(:first)").remove(); 750 this.$title.length = 1; 751 TweenLite.set(this.$title[0], {css: {scale:1, x:this.$title.attr("class", "sm-title")._center(this.$back.length)}}); 752 } 753 this.$lvls.children().attr("style", "display: none;"); 754 this.opened = this.$lvls.children(":first").attr("style", "position: static;")[0]; 755 this.prev = undefined; 756 this.$node 757 .on(this.dropEvent+".dm", "dt.parent", $.proxy(this, "onOpenDrop")) 758 .on(this.dropEvent+".dm", ">.sm-level", $.proxy(this, "onMouseEnterDrop")); 759 this.$drop 760 .on(this.dropEvent+".dm", "dt.parent", $.proxy(this, "onOpenDrop")) 761 .on(this.dropEvent+".dm", ".sm-level", $.proxy(this, "onMouseEnterDrop")); 762 if (this.dropEvent == "click") { 763 $body.on("click.dm", $.proxy(this, "closeAllDrops")); 764 } else { 765 this.$node 766 .on("mouseleave.dm", "dt.parent", $.proxy(this, "onCloseDrop")) 767 .on("mouseleave.dm", ">.sm-level", $.proxy(this, "onMouseLeaveDrop")); 768 this.$drop 769 .on("mouseleave.dm", "dt.parent", $.proxy(this, "onCloseDrop")) 770 .on("mouseleave.dm", ".sm-level", $.proxy(this, "onMouseLeaveDrop")); 771 } 772 } else { 773 this.$node.off(".dm"); 774 this.$drop.off(".dm"); 775 $body.off("click.dm"); 776 } 777 } 778 // update background img pos 779 if (this.bg && this.bgX) { 780 var level = this.opened.children[0].attributes['class'].value.match(/level(\d)/)[1]; 781 this.$node[0].backgroundPosition = this.bgX * (level - 1) + "% 0"; 782 } 783 784 if (this.popup) { 785 var maxH, mb = navigator.userAgent.match(/iPad/i) ? 25 : 5; 786 if (this.menuIconCorner) { // fixed position 787 var off = this.$lvls.offset(); 788 maxH = (this.winHeight - (off.top - $win.scrollTop()) - mb); 789 this.opened.children[0].style.maxHeight = maxH - 2 * this.menuPadding + "px"; 790 this.$lvls.css("maxHeight", maxH); 791 this.$node.css("maxWidth", this.winWidth - off.left - this.$button.width()); 792 } else if (this.$node.css("visibility") != "hidden") { // module position 793 var btn = this.$button.offset(), 794 top = $win.scrollTop(), 795 originX = "0%"; 796 if (this.winWidth/2 > btn.left || this.popup == 2) { // left 797 this.$node.css({ 798 maxWidth: this.winWidth - btn.left - this.$button.width(), 799 left: btn.left, 800 right: "" 801 }); 802 } else { // right 803 originX = "100%"; 804 this.$node.css({ 805 maxWidth: btn.left, 806 left: "", 807 right: this.winWidth - btn.left - this.$button.width() 808 }); 809 } 810 if (top + this.winHeight/2 > btn.top) { // top 811 TweenLite.set(this.$node[0], {transformOrigin: originX + " 0% 0", scaleX: 1, scaleY: 1}); 812 maxH = this.winHeight - (btn.top - top) - this.$lvls.position().top - mb; 813 this.$node.css({top: btn.top, bottom: ""}); 814 } else { // bottom 815 TweenLite.set(this.$node[0], {transformOrigin: originX + " 100% 0", scaleX: 1, scaleY: 1}); 816 maxH = btn.top - top + this.$button.height() - this.$lvls.position().top; 817 this.$node.css({top: "", bottom: this.winHeight - btn.top - this.$button.height()}); 818 }
819 this.opened.children[0].style.maxHeight = maxH - 2 * this.menuPadding + "px"; 820 this.$lvls.css({maxHeight: maxH, height: $(this.opened.children).height() + 2 * this.menuPadding}); 821 } 822 } else if (this.sidebar || this.sidebarUnder) { 823 // update button & sidebar 824 if (!this.sidebar && this.winWidth >= this.sidebarUnder && isInCont) { 825 this.$button.css("display", "none"); 826 this.$node 827 .css({top: "", position: ""}) // mobile fix 828 .appendTo(this.$parent); 829 if (this.$cont.hasClass(this.openClass)) { 830 this.closeMenu(); 831 this.onEndCloseMenu(); 832 } 833 this.$node.trigger("moveToModulepos", this); 834 } 835 if (this.$node.css("display") == "block") { // if sidebar is open 836 this.$pusher.addClass("no-trans"); // disable transitions during resize 837 if (this.$pusher[0]) this.$pusher[0].offsetHeight; // trigger a reflow, flushing the CSS changes 838 this.$pusher.removeClass("no-trans"); 839 // update menu height 840 if (this.sidebar || this.winWidth < this.sidebarUnder) 841 this.$lvls.css('maxHeight', window.innerHeight - this.$lvls.position().top); 842 else if (!this.treemenu) 843 this.$lvls.height($(this.opened.children).outerHeight() + 2 * this.menuPadding); 844 else 845 this.$lvls[0].style.height = ""; 846 } else { // if sidebar is close 847 if (this.hideBurger && this.autoOpen == 2 && this.prevWinWidth < 768 && this.winWidth >= 768) this.openMenu(); 848 } 849 } else if (this.overlay && $body.hasClass(this.openClass)) { // OVERLAY 850 this.$lvls.css('maxHeight', '').css('maxHeight', this.$overlay.outerHeight() - this.$lvls.position().top); 851 } 852 853 this.updateScrollbar(); 854 }, 855 856 onFilter: function(e) { 857 this.$filter.attr('value', this.$filter.val()); 858 if (!e.target.value.length && $(this.opened.children).hasClass("sm-result")) this.onBack(); 859 if (this.filterTimeout) this.filterTimeout = clearTimeout(this.filterTimeout); 860 if (e.target.value.length < this.filterMinChar) return; 861 this.filterTimeout = setTimeout($.proxy(this, "filter", e.target.value), this.filterDelay); 862 }, 863 864 filter: function(keyword) { 865 keyword = keyword.trim().replace(/\s+/g, " ").replace(/([.?*+^$|{}()\\[\]])/g, "\\$1"); 866 if (this.keyword == keyword) return; 867 if (!this.keyword) this.filterParent = this.opened; 868 this.keyword = keyword; 869 this.$filter.trigger("filter", [this, keyword]); 870 var i, $dt, 871 $result = this.$result.clone().appendTo(this.$lvls).children(), 872 submenu = $result[0].parentNode; 873 for (i = 0; i < this.$dt.length; i++) { 874 $dt = $(this.$dt[i]); 875 if ($dt.text().match( new RegExp(this.keyword, "i") )) { 876 var $clone = $dt.clone().removeClass("parent").addClass("notparent"); 877 $clone[0].innerHTML = $clone[0].innerHTML.replace(new RegExp(">([^<]*)("+this.keyword+")([^>]*)<", "ig"), ">$1<strong>$2</strong>$3<"); 878 $clone.appendTo($result); 879 } 880 } 881 var res = $result[0].children.length; 882 if (this.backItem && res == 1 || !res) { 883 var $no = $(this.opened).find("dt:first").clone() 884 .removeClass("parent opened").addClass("notparent").css("pointerEvents", "none"); 885 $no.find("a").removeAttr("href").html(this.noResult); 886 $no.find(".desc, .sm-icon").remove(); 887 $no.appendTo($result); 888 } 889 submenu.parent = this.filterParent; 890 this.open(this.result, submenu); 891 }, 892 893 onRedirect: function(e) { 894 e.stopPropagation(); 895 if (this.disableClick) return e.preventDefault(); // disable click during swipe 896 var $a = e.currentTarget.tagName == "A" ? $(e.currentTarget) : $("a", e.currentTarget), 897 a = $a[0], event = $.Event("openMenuItem"); 898 $a.trigger(event, this); 899 if (event.isDefaultPrevented()) return e.preventDefault(); 900 var hash = $a.attr('href').match(/#([\w-]+)$/); 901 if(hash) var $node = hash[0] == '#top' ? $body : $(hash[0]+', a[name="'+hash[1]+'"]'); 902 if ($node && $node.length) { // scroll 903 e.preventDefault(); 904 var $cont, cont, t, b; 905 if (this.$cont && this.$cont.hasClass(this.openClass) && this.effect > 0) { // sidebar 906 $cont = this.$content; 907 cont = {scroll: $cont.scrollTop()}; 908 t = $node.offset().top + cont.scroll - $cont.offset().top; 909 b = this.$inner.outerHeight() - this.$content.height(); 910 } else { // not sidebar 911 $cont = $win; 912 cont = {scroll: $cont.scrollTop()}; 913 t = $node.offset().top; 914 b = $body.outerHeight() - this.winHeight; 915 } 916 this.scroll = t < b ? t : b; 917 var dur = 0.4 + Math.abs(cont.scroll - this.scroll) / 5000; 918 TweenLite.to(cont, dur, { 919 scroll: this.scroll, 920 onUpdate: function onUpdateScroll() { $cont.scrollTop(cont.scroll) }, 921 onComplete: this.popup && this.menuIconCorner && this.winWidth < this.hidePopupUnder ? function onEndScroll() { 922 if (!this.$button.eq(1).hasClass(this.closeClass)) return; 923 TweenLite.set(this.$button[0], {
924 x: this.menuIconX - this.$node.width(), 925 y: this.menuIconY 926 }); 927 this.$button.eq(1).addClass("sm-hide"); 928 if (!smMobile) this.$node.one("mouseenter", $.proxy(this, "onClickButton")); 929 }.bind(this) : function() { $a.closest('dt').addClass('active').siblings('.active').removeClass('active') } 930 }); 931 } else { // open url 932 if (!(smMobile && this.popup)) // fix for mobile popup menu-item opening 933 if (a == e.target.parentNode || a == e.target) return; 934 if (!a.click) { 935 var event = document.createEvent("HTMLEvents"); 936 event.initEvent("click", false, true); 937 a.dispatchEvent(event); 938 } else a.click(); 939 } 940 }, 941 942 onOpenDrop: function(e) { 943 if (this.sidebar && !$body.hasClass(this.openClass)) return; 944 var item = e.currentTarget, 945 openTween = item.parentNode.parentNode.openTween, 946 closeTween = item.parentNode.parentNode.closeTween, 947 items = item.parentNode.children, i; 948 for (i = 0; i < items.length; i++) 949 if (items[i] != item && items[i].menu && items[i].menu.style.display == "block") 950 { this.closeDrop(items[i].menu); break; } 951 item.menu.closeTimeout = clearTimeout(item.menu.closeTimeout); 952 if (openTween && openTween.isActive()) 953 openTween.vars.onComplete = $.proxy(this, "openDrop", item); 954 else if (closeTween && closeTween.isActive()) 955 closeTween.vars.onReverseComplete = $.proxy(this, "openDrop", item); 956 else 957 this.openDrop(item); 958 }, 959 960 onCloseDrop: function(e) { 961 var item = e.currentTarget, 962 openTween = item.parentNode.parentNode.openTween, 963 closeTween = item.parentNode.parentNode.closeTween; 964 if (openTween && openTween.vars.onComplete) 965 delete openTween.vars.onComplete; 966 else if (closeTween && closeTween.vars.onReverseComplete) 967 delete closeTween.vars.onReverseComplete; 968 else 969 item.menu.closeTimeout = setTimeout($.proxy(this, "closeDrop", item.menu), this.anim.outDur * 500 || 200); 970 }, 971 972 onMouseEnterDrop: function(e) { 973 if (this.sidebar && !$body.hasClass(this.openClass)) return; 974 var menu = e.currentTarget, 975 item = menu.parentItem; 976 menu.style.zIndex = 99; 977 do { 978 if (menu.closeTween && menu.closeTween.isActive()) menu.closeTween.reverse(); 979 menu.closeTimeout = clearTimeout(menu.closeTimeout); 980 menu = menu.parent; 981 $(item).addClass("hover"); 982 item = menu.parentItem; 983 } while ("closeTimeout" in menu); 984 }, 985 986 onMouseLeaveDrop: function(e) { 987 var menu = e.currentTarget, 988 item = menu.parentItem, 989 items = menu.children[0].children, 990 i = items.length, t = 1; 991 while (i--) 992 if (items[i].menu && items[i].menu.closeTimeout) {t++; break} 993 do { 994 menu.closeTimeout = setTimeout($.proxy(this, "closeDrop", menu), (this.anim.outDur * 500 || 200) * t++); 995 menu = menu.parent; 996 $(item).removeClass("hover"); 997 item = menu.parentItem; 998 } while ("closeTimeout" in menu); 999 }, 1000 1001 closeAllDrops: function() { 1002 var $menu = this[this.sidebar ? "$node" : "$drop"].children(".sm-level[style*=block]:last"); 1003 if ($menu.length) this.onMouseLeaveDrop({currentTarget: $menu[0]}); 1004 }, 1005 1006 openDrop: function(item) { 1007 var submenu = item.menu, 1008 openTween = item.parentNode.parentNode.openTween, 1009 closeTween = item.parentNode.parentNode.closeTween; 1010 if (openTween) delete openTween.vars.onComplete; 1011 if (closeTween) delete closeTween.vars.onReverseComplete; 1012 // replace nodes to be on top (zIndex) 1013 if (this.sidebar && submenu.parentNode != this.$node[0]) 1014 $(submenu).appendTo(this.$node); 1015 if (!this.sidebar && submenu.parentNode != this.$drop[0]) 1016 $(submenu).appendTo(this.$drop); 1017 1018 var p = $(item).offset(), 1019 w = $(item).outerWidth(), 1020 h = $(submenu).outerHeight(), 1021 t = $win.scrollTop(), 1022 m = t + this.winHeight - p.top - h; 1023 if (submenu.parent.parentNode == this.$lvls[0]) 1024 this.dropdir = p.left + w/2 - this.winWidth/2 < 0 ? 1 : -1; 1025 1026 if (this.dropdir < 0) { 1027 p.right = $win.outerWidth() - p.left; // don't use this.winWidth 1028 if (this.sidebar && p.right < this.width) p.right = this.width - this.menuPadding; 1029 submenu.style.right = p.right + this.menuPadding + this.dropspace + "px"; 1030 submenu.style.left = ""; 1031 } else { 1032 if (p.left < 0) p.left = 0; 1033 submenu.style.left = w + p.left + this.menuPadding + this.dropspace + "px"; 1034 submenu.style.right = ""; 1035 } 1036 1037 if (this.dropFullHeight) { 1038 p.top = t; 1039 submenu.style.height = "100vh"; 1040 } else if (m < 0) { // out of screen 1041 var ih = $(item).outerHeight(), y = p.top; 1042 p.top += Math.floor(m / ih) * ih; 1043 if (p.top + h <= y) p.top += ih; 1044 if (p.top < t) p.top = t; 1045 if (h >= this.winHeight) 1046 submenu.children[0].style.height = "100vh"; 1047 else 1048 submenu.children[0].style.height = ""; 1049 } 1050 if (this.effect < 0) p.top -= $win.scrollTop(); // reduce_width bugfix (#21) 1051 submenu.style.top = p.top - (this.dropFullHeight ? 0 : this.menuPadding) + "px"; 1052 submenu.style.zIndex = 99; 1053 1054 this.anim.inCSS.x = this.anim.inUnitX == "%" ? this.anim.inX * this.dropwidth / 100 : this.anim.inX; 1055 this.anim.inCSS.x *= this.dropdir; 1056 this.anim.inCSS.rotationY = this.dropdir * this.anim.inRotationY; 1057 TweenLite.set(submenu, { 1058 transformPerspective: this.anim.perspective, 1059 transformOrigin: Hlpr.calcOrigin(this.anim.inOrigin, this.dropwidth, this.dropdir) 1060 }); 1061 var animTo = {
1062 overwrite: 1, 1063 css: this.baseCSS, 1064 ease: this.anim.inEase 1065 }; 1066 if (submenu.style.display == "none") { 1067 submenu.openTween = TweenLite.fromTo(submenu, this.anim.inDur, {css: this.anim.inCSS}, animTo); 1068 // menu-item anim 1069 if (this.miAnim) { 1070 this.miCSS.x = this.miUnitX == "%" ? this.miX * w / 100 : this.miX; 1071 this.miCSS.x *= this.dropdir; 1072 this.miCSS.rotationY = this.miRotationY * this.dropdir; 1073 if (this.miShift) 1074 TweenMax.staggerFromTo($(">dl>dt", submenu), this.miDur, {css: this.miCSS}, {overwrite: 1, css: this.baseCSS, ease: this.miEase}, this.miShift); 1075 else 1076 TweenLite.fromTo(submenu.children[0], this.miDur, {css: this.miCSS}, {overwrite: 1, css: this.baseCSS, ease: this.miEase}); 1077 } 1078 // icons anim 1079 if (this.iconAnim && !smMobile) 1080 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}); 1081 } else { 1082 submenu.openTween = TweenLite.to(submenu, this.anim.inDur, animTo); 1083 } 1084 1085 submenu.style.display = "block"; 1086 this.updateScrollbar(submenu); 1087 $(item).trigger("openParentItem", this); 1088 }, 1089 1090 closeDrop: function(submenu) { 1091 if (submenu.style.display == 'none') return; 1092 submenu.style.zIndex = ""; 1093 this.anim.outCSS.x = this.anim.outUnitX == "%" ? this.anim.outX * this.dropwidth / 100 : this.anim.outX; 1094 this.anim.outCSS.rotationY = this.dropdir * this.anim.outRotationY; 1095 TweenLite.set(submenu, {transformOrigin: Hlpr.calcOrigin(this.anim.outOrigin, this.dropwidth, this.dropdir)}); 1096 submenu.closeTween = TweenLite.to(submenu, this.anim.outDur, { 1097 overwrite: 1, 1098 css: this.anim.outCSS, 1099 ease: this.anim.outEase, 1100 onComplete: Target.hide 1101 }); 1102 }, 1103 1104 onClickTree: function(e) { 1105 e.stopPropagation(); 1106 e.preventDefault(); 1107 //if (smMobile && e.type == 'click') return; 1108 var $item = $(e.currentTarget); 1109 this[$item.hasClass("opened") ? "closeTree" : "openTree"]($item); 1110 }, 1111 1112 openTree: function($item) { 1113 var dur = this.dur; 1114 var $dd = $item.addClass("opened").next(); 1115 if (this.popup) this.$lvls.height("auto"); 1116 if (this.accordion) { 1117 $item.siblings("dt.opened").removeClass("opened"); 1118 $dd.siblings("dd.opened").removeClass("opened").slideUp({ easing: this.outEase, duration: dur * 1000 }); 1119 } 1120 $dd.slideDown({ 1121 queue: false, 1122 easing: this.inEase, 1123 duration: dur * 1000, 1124 progress: this.bindUpdateScrollbar, 1125 complete: function() { $dd.attr('style', 'display: block;') } 1126 }).addClass('opened'); 1127 1128 if (this.miAnim) { 1129 this.miCSS.x = this.miUnitX == "%" ? this.miX * this.$lvls.outerWidth() / 100 : this.miX; 1130 if (this.miShift) 1131 dur = new TimelineLite() 1132 .staggerFromTo($dd.find("dt").not("dd:not(.opened) dt"), this.miDur, {css: this.miCSS}, {overwrite: 1, css: this.baseCSS, ease: this.miEase}, this.miShift) 1133 .totalDuration(); 1134 else 1135 TweenLite.fromTo($dd.find("dl").not("dd:not(.opened) dl"), this.miDur, {css: this.miCSS}, {overwrite: 1, css: this.baseCSS, ease: this.miEase}); 1136 } 1137 $item.trigger("openParentItem", this); 1138 }, 1139 1140 closeTree: function($item) { 1141 var $dd = $item.removeClass("opened").next(); 1142 $dd.removeClass('opened').slideUp({ 1143 queue: false, 1144 easing: this.outEase, 1145 duration: this.dur * 1000, 1146 progress: this.bindUpdateScrollbar, 1147 complete: function() { $dd.attr('style', '') } 1148 }); 1149 }, 1150 1151 onOpen: function(e) { 1152 if (this.drop) return; 1153 if (e.type == "touchend") e.preventDefault(); 1154 if (e.currentTarget.parentNode.parentNode == this.prev) return; 1155 if (this.disableClick) return; // disable click during swipe 1156 var title = $(e.currentTarget).find("a").html().replace(/<.*>/, ""); 1157 this.open(title, e.currentTarget.menu); 1158 }, 1159 1160 open: function(title, submenu) { 1161 if (submenu.parentNode != this.$lvls[0]) 1162 $(submenu).css({top:'', left:'', right:''}).appendTo(this.$lvls); 1163 var w = this.$lvls.outerWidth(), 1164 tl = new TimelineLite({paused: true, autoRemoveChildren: true, onComplete: $.proxy(this, "onEndSlide")}); 1165 TweenLite.set(this.opened, {transformOrigin: Hlpr.calcOrigin(this.outOrigin, w)}); 1166 TweenLite.set(submenu, {transformOrigin: Hlpr.calcOrigin(this.inOrigin, w)}); 1167 1168 this.inCSS.x = this.inUnitX == "%" ? this.inX * w / 100 : this.inX; 1169 this.outCSS.x = this.outUnitX == "%" ? this.outX * w / 100 : this.outX; 1170 1171 // submenu anims 1172 tl.add(TweenLite.to(this.opened, this.dur, {css: this.outCSS, ease: this.outEase, onComplete: Target.scrollUp}), 0); 1173 tl.add(TweenLite.fromTo(submenu, this.dur, {css: this.inCSS}, {css: this.baseCSS, ease: this.inEase}), 0); 1174 1175 this.opened.style.zIndex = ""; 1176 submenu.style.zIndex = 99; 1177 submenu.style.display = "block"; 1178 if (!this.sidebar && this.winWidth >= this.sidebarUnder) { 1179 if (this.popup) submenu.children[0].style.maxHeight = this.$lvls[0].style.maxHeight; 1180 var h = $(submenu.children[0]).outerHeight() + 2 * this.menuPadding; 1181 tl.add(TweenLite.to(this.$lvls[0], this.dur, {css: {height: h}}), 0); 1182 } 1183
1184 if (!$(this.opened.children).hasClass("sm-result")) { // if filtering was started at search result, don't run it 1185 // header anims 1186 if (this.$head.length) { 1187 var $title = $('<span class="sm-title" title="'+title+'">'+title+'</span>').appendTo(this.$head), 1188 i = this.$title.length; 1189 if (!this.$title[0].style.position) // init title position 1190 TweenLite.set(this.$title[0], {css: {position: "absolute", x: this.$title._center(this.$back.length)}}); 1191 if (this.$back.length) { // clean theme 1192 if (i == 1) 1193 tl.add(TweenLite.to(this.$back[0], this.dur, {css: {opacity: 1, display: 'block'}}), 0); 1194 if (this.$title[--i]) this.$title[i].style.position = "absolute", 1195 tl.add(TweenLite.to(this.$title[i], 2*this.dur, {css: {x: -w*0.6, opacity: -1, scale: 0}}), 0); 1196 } else { // flat theme 1197 this.$title.attr("class", "sm-back"); 1198 if (this.$title[--i]) this.$title[i].style.position = "absolute", 1199 tl.add(TweenLite.to(this.$title[i], this.dur, {css: {x: 0, scale: backScale}}), 0); 1200 if (this.$title[--i]) 1201 tl.add(TweenLite.to(this.$title[i], this.dur, {css: {x: -w*0.6}, ease: Linear.easeNone}), 0); 1202 } 1203 tl.add(TweenLite.fromTo($title, this.dur, {x: w}, {css: {x: $title._center(this.$back.length)}}), 0); 1204 this.$title.push($title[0]); 1205 } 1206 1207 // bg anim 1208 if (this.bg && this.bgX) { 1209 var level = this.opened.children[0].attributes['class'].value.match(/level(\d)/)[1]; 1210 tl.add(TweenLite.to(this.$node[0], this.dur, {css: {backgroundPosition: this.bgX * level + "% 0"}}), 0); 1211 } 1212 } 1213 // menu-item anim 1214 if (this.miAnim) { 1215 this.miCSS.x = this.miUnitX == "%" ? this.miX * w / 100 : this.miX; 1216 if (this.miShift) 1217 tl.staggerFromTo($(">dl>dt", submenu), this.miDur, {css: this.miCSS}, {css: this.baseCSS, ease: this.miEase}, this.miShift, 0); 1218 else 1219 tl.fromTo(submenu.children[0], this.miDur, {css: this.miCSS}, {css: this.baseCSS, ease: this.miEase}, 0); 1220 } 1221 // icons anim 1222 if (this.iconAnim && !smMobile) 1223 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); 1224 this.openTL = tl; 1225 1226 if (this.backTL && this.backTL._first) delete this.backTL._first.vars.onComplete; // don't run Target.scrollUp 1227 TweenLite.set(this.$lvls[0], {perspective: this.perspective}); // blur fix for retina 1228 this.openTL.play(); 1229 this.prev = this.opened; 1230 this.opened = submenu; 1231 this.updateScrollbar(); 1232 1233 // don't trigger event when submenu is search result 1234 if (!$(submenu.children[0]).hasClass("sm-result")) $(submenu.parentItem).trigger("openParentItem", [this, title]); 1235 }, 1236 1237 onResetFilter: function() { 1238 this.$filter.attr("value", ""); 1239 if ($(this.opened.children).hasClass("sm-result")) this.onBack(); 1240 this.$filter[0].focus(); 1241 }, 1242 1243 onBack: function(e) { 1244 if (e && e.type == "touchend") e.preventDefault(); 1245 if (!this.opened.parent) return; 1246 this.initBackTimeline(); 1247 this.back(); 1248 }, 1249 1250 back: function() { 1251 if (this.openTL && this.openTL._first) delete this.openTL._first.vars.onComplete; // don't run Target.scrollUp 1252 TweenLite.set(this.$lvls[0], {perspective: this.perspective}); // blur fix for retina 1253 this.backTL.resume(); 1254 this.prev = this.opened; 1255 this.opened = this.opened.parent; 1256 this.updateScrollbar(); 1257 1258 this.$title.length--; 1259 this.$filter.attr("value", ""); 1260 this.keyword = ""; 1261 $(this.opened).trigger("back", this); 1262 }, 1263 1264 initBackTimeline: function() { 1265 var w = this.$lvls.addClass("sm-swipe").outerWidth(), 1266 tl = new TimelineLite({ 1267 paused: true, 1268 autoRemoveChildren: true, 1269 onComplete: $.proxy(this, "onEndSlide"), 1270 onReverseComplete: function() { this.onEndSlide(), this.opened.parent.style.display = "none" }.bind(this) 1271 }); 1272 1273 this.inCSS.x = this.inUnitX == "%" ? this.inX * w / 100 : this.inX; 1274 1275 TweenLite.set(this.opened, {transformOrigin: Hlpr.calcOrigin(this.inOrigin, w)}); 1276 TweenLite.set(this.opened.parent, {transformOrigin: Hlpr.calcOrigin(this.outOrigin, w)}); 1277 1278 // submenu anims 1279 tl.add(TweenLite.to(this.opened, this.dur, {css: this.inCSS, onComplete: Target.scrollUp}), 0); 1280 tl.add(TweenLite.to(this.opened.parent, this.dur, {css: this.baseCSS, ease: this.inEase}), 0); 1281 1282 this.opened.parent.style.display = "block"; 1283 if (!this.sidebar && this.winWidth >= this.sidebarUnder) { 1284 if (this.popup) this.opened.parent.children[0].style.maxHeight = this.$lvls[0].style.maxHeight; 1285 tl.add(TweenLite.to(this.$lvls[0], this.dur, { 1286 css: {height: $(this.opened.parent.children[0]).outerHeight() + 2 * this.menuPadding}, 1287 onComplete: this.prev.parentNode.children[0] == this.prev ? Target.autoHeight : undefined // auto height first level 1288 }), 0); 1289 } 1290 1291 // header anims 1292 if (this.$head.length) { 1293 var i = this.$title.length; 1294 tl.add(TweenLite.to(this.$title[--i], this.dur, {css: {x: w, opacity: 0}, onComplete: Target.remove}), 0); 1295 if (this.$back.length) { // clean theme 1296 if (i == 1) tl.add(TweenLite.to(this.$back[0], this.dur, {css: {opacity: 0, display: 'none'}}
1296), 0); 1297 tl.add(TweenLite.to(this.$title[--i], this.dur, {css: {x: $(this.$title[i])._center(true), opacity: 1, scale: 1}}), 0); 1298 } else { // flat theme 1299 tl.add(TweenLite.to(this.$title[--i], this.dur, { 1300 css: {x: $(this.$title[i])._center(), scale: 1, maxWidth: i ? this.titleWidth : "100%"}, 1301 onComplete: Target.autoMaxWidth 1302 }), 0); 1303 if (this.$title[--i]) tl.add(TweenLite.to(this.$title[i], this.dur, {css: {x: 0}}), 0); 1304 } 1305 } 1306 1307 // bg anim 1308 if (this.bg && this.bgX) { 1309 var level = this.opened.children[0].attributes['class'].value.match(/level(\d)/); 1310 level = level ? level[1] - 2 : 0; 1311 tl.add(TweenLite.to(this.$node[0], this.dur, {css: {backgroundPosition: this.bgX * level + "% 0"}}), 0); 1312 } 1313 1314 this.backTL = tl; 1315 }, 1316 1317 onEndSlide: function() { 1318 // blur fix for retina 1319 $(this.opened).css({WebkitTransform: "", MozTransform: "", msTransform: "", transform: ""}); 1320 this.$lvls.css({WebkitPerspective: "", MozPerspective: "", perspective: ""}).removeClass("sm-swipe"); 1321 this.disableClick = false; // enable click after swipe 1322 }, 1323 1324 updateScrollbar: function(menu) { 1325 if (smMobile) return; 1326 var $dl = $( (menu || this.opened).children[0] ); 1327 $dl.perfectScrollbar($dl.data("perfectScrollbar") ? "update" : undefined); 1328 } 1329 1330}; 1331 1332// depreciated functions 1333VerticalSlideMenu.prototype.openSidebar = VerticalSlideMenu.prototype.openMenu; 1334VerticalSlideMenu.prototype.closeSidebar = VerticalSlideMenu.prototype.closeMenu; 1335 1336(function initMenuSpy() { 1337 1338 $elems = $(); 1339 var $cont = $(window) 1340 .on("resize.menuspy", onResize) 1341 .on("scroll.menuspy load.menuspy", onScroll); 1342 1343 function onScroll() { 1344 if (!$elems.length) return; 1345 var y = $cont.scrollTop(); 1346 $elems.each(function(i) { 1347 var $elem = $(this); 1348 var o = $elem.data('menuspy'); 1349 if (y >= o.max || y < o.min) { 1350 if (o.inside) { 1351 o.inside = false; 1352 $elem.trigger("scrollLeave.menuspy", {scrollTop: y, enters: o.enters, leaves: ++o.leaves}); 1353 } 1354 } else { 1355 if (!o.inside) { 1356 o.inside = true; 1357 $elem.trigger("scrollEnter.menuspy", {scrollTop: y, enters: ++o.enters, leaves: o.leaves}); 1358 } 1359 } 1360 }); 1361 } 1362 1363 function onResize() { 1364 $elems.each(function() { 1365 var $elem = $(this); 1366 var o = $elem.data("menuspy"); 1367 o.min = $elem.offset().top; 1368 o.max = $elem.outerHeight() + o.min; 1369 }); 1370 } 1371 1372 $.fn.menuspy = function(options) { 1373 var defaults = { 1374 offset: 0, 1375 enters: 0, 1376 leaves: 0, 1377 inside: false 1378 }; 1379 return this.each(function() { 1380 var $elem = $(this); 1381 var top = $elem.offset().top; 1382 $elem.data("menuspy", $.extend({ 1383 min: top, 1384 max: top + $elem.outerHeight(), 1385 }, defaults, options)); 1386 $elems.push(this); 1387 }); 1388 }; 1389 1390})(); 1391 1392})(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.