/*jslint browser: true, unparam: true, sloppy: true, nomen: true, indent: 2 */ /*global YAHOO,recursiveGetOffsetTop,unescape */ YAHOO.namespace("azcat"); YAHOO.azcat.topNav = (function () { return { init: function () { // Animation object var oAnim, // Admin Menu object oMenu = new YAHOO.widget.MenuBar("navigation", { autosubmenudisplay: true, hidedelay: 375, lazyload: true, iframe: !!YAHOO.env.ua.ie}); // Custom onClick for dealing with javascript: function onMenuItemClick(p_sType, p_aArgs, p_oMenu) { var oEvent = p_aArgs[0], oItem = this, oTarget = YAHOO.util.Event.getTarget(oEvent), oItemCfg, sURL, fOnclick; if (oItem && !oItem.cfg.getProperty("disabled")) { oItemCfg = oItem.cfg; sURL = oItemCfg.getProperty("url"); if (sURL.search(/^javascript:/) === 0) { fOnclick = new Function("event", unescape(sURL)); fOnclick.call(this, oEvent); YAHOO.util.Event.preventDefault(oEvent); } } } // Utility function used to setup animation for submenus function setupMenuAnimation(p_oMenu) { var aItems, i, oSubitem, oSubmenu; if (!p_oMenu.animationSetup) { aItems = p_oMenu.getItemGroups(); if (aItems && aItems[0]) { i = aItems[0].length - 1; do { oSubitem = p_oMenu.getItem(i); oSubitem.clickEvent.subscribe(onMenuItemClick, oSubitem, true); //This will run before the standard onClick. The standard onClick will not run after the preventDefault. oSubmenu = oSubitem.cfg.getProperty("submenu"); if (oSubmenu) { // do the onShow animation oSubmenu.beforeShowEvent.subscribe(onMenuBeforeShow, oSubmenu, true); oSubmenu.showEvent.subscribe(onMenuShow, oSubmenu, true); // This runs AFTER the onShow method subscribe above. } } while (i -= 1); } p_oMenu.animationSetup = true; } } // "beforeshow" event handler for each submenu of the menu bar function onMenuBeforeShow(p_sType, p_sArgs, p_oMenu) { var topPadding, moveIt; if (oAnim && oAnim.isAnimated()) { oAnim.stop(); oAnim = null; } if (this.parent.parent.parent && this instanceof YAHOO.widget.Menu) { if (YAHOO.env.ua.ie) { topPadding = 3; } else { topPadding = 1; } moveIt = recursiveGetOffsetTop(this.element) - recursiveGetOffsetTop(this._getFirstEnabledItem().element) - topPadding; YAHOO.util.Dom.setStyle(this.element, "top", parseInt(YAHOO.util.Dom.getStyle(this.element, 'top'), 10) + moveIt + "px"); if (this.iframe) { // Move the Iframe as well. YAHOO.util.Dom.setStyle(this.iframe, "top", parseInt(YAHOO.util.Dom.getStyle(this.iframe, 'top'), 10) + moveIt + "px"); } } YAHOO.util.Dom.setStyle(this.element, "overflow", "hidden"); YAHOO.util.Dom.setStyle(this.body, "marginTop", ("-" + this.body.offsetHeight + "px")); } // "show" event handler for each submenu of the menu bar function onMenuShow(p_sType, p_sArgs, p_oMenu) { oAnim = new YAHOO.util.Anim( this.body, { marginTop: { to: 0 } }, 0.1, YAHOO.util.Easing.easeOut ); oAnim.animate(); var me = this; function onTween() { me.cfg.refireEvent("iframe"); } function onAnimationComplete() { YAHOO.util.Dom.setStyle(me.body, "marginTop", ("0px")); YAHOO.util.Dom.setStyle(me.element, "overflow", "visible"); setupMenuAnimation(me); } /* Refire the event handler for the "iframe" configuration property with each tween so that the size and position of the iframe shim remain in sync with the menu. */ if (this.cfg.getProperty("iframe") === true) { oAnim.onTween.subscribe(onTween); } oAnim.onComplete.subscribe(onAnimationComplete); } function onMenuBeforeRender(p_sType, p_sArgs, p_oMenu) { var menu = {"bottom_menu": [], "main_menu": [{"url": "/index_html", "text": "Home"}, {"url": "/resources", "text": "Resources"}, {"url": "/municipal_services", "text": "Municipal Services", "submenu": {"id": "/municipal_services", "itemdata": [{"url": "/municipal_services/blue_bag", "text": "Blue Bag"}, {"url": "/municipal_services/organic_collection", "text": "Organic Collection"}, {"url": "/municipal_services/waste_collection", "text": "Waste Collection"}]}}, {"url": "/in_the_news", "text": "In the News", "submenu": {"id": "/in_the_news", "itemdata": [{"url": "/in_the_news/i~m_dreaming_of_a...green_christmas~", "text": "Green Christmas"}, {"url": "/in_the_news/environmentally_conscious_trio_launches_business_curb-side_recycling_for_households", "text": "Launch"}]}}, {"url": "/advocacy", "text": "Advocacy", "submenu": {"id": "/advocacy", "itemdata": [{"url": "/advocacy/doing_your_part", "text": "Doing Your Part"}, {"url": "/advocacy/where_do_recyclables_go", "text": "Where do recyclables go?"}, {"url": "/advocacy/current_info_~_stats", "text": "Current Info & Stats"}]}}, {"url": "/why_diversion_works", "text": "Why Diversion Works"}, {"url": "/careers", "text": "Careers"}], "utility_menu": [{"url": "/contact", "text": "Contact"}, {"url": "/about_us", "text": "About"}, {"url": "/sitemap", "text": "Sitemap"}]}; menu = menu.main_menu; this.addItems(menu); setupMenuAnimation(this); } // Subscribe to the "render" event oMenu.beforeRenderEvent.subscribe(onMenuBeforeRender, oMenu, true); // render the menu bar oMenu.render(); oMenu.show(); } }; }()); // Initialize and render the menu when it is available in the DOM YAHOO.util.Event.onAvailable("navigation", YAHOO.azcat.topNav.init);