Making WordPress.org

Changeset 8154


Ignore:
Timestamp:
01/28/2019 08:15:10 AM (6 years ago)
Author:
ocean90
Message:

wp4: Query menu list and toggle button by IDs.

Makes the script more robust by not relying on a specific order of elements.

See #4098.

Location:
sites/trunk/wordpress.org/public_html/style/js
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/style/js/navigation.js

    r8147 r8154  
    1111    }
    1212
    13     button = container.getElementsByTagName( 'button' )[1];
     13    button = document.getElementById( 'mobile-menu-button' );
    1414    if ( 'undefined' === typeof button ) {
    1515        return;
    1616    }
    1717
    18     menu = container.getElementsByTagName( 'ul' )[0];
     18    menu = document.getElementById( 'wporg-header-menu' );
    1919
    2020    // Hide menu toggle button if menu is empty and return early.
  • sites/trunk/wordpress.org/public_html/style/js/navigation.min.js

    r8147 r8154  
    1 !function(e){var n,a,t,s,l,c;if((n=document.getElementById("wporg-header"))&&void 0!==(a=n.getElementsByTagName("button")[1]))if(void 0!==(t=n.getElementsByTagName("ul")[0])){for(-1===t.className.indexOf("nav-menu")&&(t.className+=" nav-menu"),a.onclick=function(){-1!==t.className.indexOf("toggled")?(t.className=t.className.replace(" toggled",""),a.setAttribute("aria-expanded","false")):(t.className+=" toggled",a.setAttribute("aria-expanded","true"))},l=0,c=(s=t.getElementsByTagName("a")).length;l<c;l++)s[l].addEventListener("focus",i,!0),s[l].addEventListener("blur",i,!0);!function(e){var a,t,s=n.querySelectorAll(".menu-item-has-children > a, .page_item_has_children > a");if("ontouchstart"in window)for(a=function(e){var a,t=this.parentNode;if(t.classList.contains("focus"))t.classList.remove("focus");else{for(e.preventDefault(),a=0;a<t.parentNode.children.length;++a)t!==t.parentNode.children[a]&&t.parentNode.children[a].classList.remove("focus");t.classList.add("focus")}},t=0;t<s.length;++t)s[t].addEventListener("touchstart",a,!1)}()}else a.style.display="none";function i(){for(var e=this;-1===e.className.indexOf("nav-menu");)"li"===e.tagName.toLowerCase()&&(-1!==e.className.indexOf("focus")?e.className=e.className.replace(" focus",""):e.className+=" focus"),e=e.parentElement}}();
     1!function(e){var s,a,t,n,l,o;if((s=document.getElementById("wporg-header"))&&void 0!==(a=document.getElementById("mobile-menu-button")))if(void 0!==(t=document.getElementById("wporg-header-menu"))){for(-1===t.className.indexOf("nav-menu")&&(t.className+=" nav-menu"),a.onclick=function(){-1!==t.className.indexOf("toggled")?(t.className=t.className.replace(" toggled",""),a.setAttribute("aria-expanded","false")):(t.className+=" toggled",a.setAttribute("aria-expanded","true"))},l=0,o=(n=t.getElementsByTagName("a")).length;l<o;l++)n[l].addEventListener("focus",c,!0),n[l].addEventListener("blur",c,!0);!function(e){var a,t,n=s.querySelectorAll(".menu-item-has-children > a, .page_item_has_children > a");if("ontouchstart"in window)for(a=function(e){var a,t=this.parentNode;if(t.classList.contains("focus"))t.classList.remove("focus");else{for(e.preventDefault(),a=0;a<t.parentNode.children.length;++a)t!==t.parentNode.children[a]&&t.parentNode.children[a].classList.remove("focus");t.classList.add("focus")}},t=0;t<n.length;++t)n[t].addEventListener("touchstart",a,!1)}()}else a.style.display="none";function c(){for(var e=this;-1===e.className.indexOf("nav-menu");)"li"===e.tagName.toLowerCase()&&(-1!==e.className.indexOf("focus")?e.className=e.className.replace(" focus",""):e.className+=" focus"),e=e.parentElement}}();
Note: See TracChangeset for help on using the changeset viewer.