Last active
December 20, 2015 17:51
-
-
Save samikeijonen/e5dc51eb477e584761fa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Enqueue scripts. | |
*/ | |
function prefix_scripts() { | |
// Enqueue responsive navigation. | |
wp_enqueue_script( 'prefix-navigation', get_template_directory_uri() . '/js/responsive-nav.js', array(), '1.38', true ); | |
// Enqueue JS functions. | |
wp_enqueue_script( 'prefix-script', get_template_directory_uri() . '/js/functions.js', array( 'prefix-navigation' ), '1.38', true ); | |
wp_localize_script( 'prefix-script', 'navSettings', array( | |
'expand' => '<span class="screen-reader-text">' . esc_html__( 'Expand child menu', 'textdomain' ) . '</span>', | |
'collapse' => '<span class="screen-reader-text">' . esc_html__( 'Collapse child menu', 'textdomain' ) . '</span>', | |
'closeMenu' => esc_html__( 'Close menu', 'textdomain' ), | |
'openMenu' => esc_html__( 'Open menu', 'textdomain' ), | |
'dropdown' => get_theme_mod( 'disable_dropdown' ) ? false : true, | |
) ); | |
} | |
add_action( 'wp_enqueue_scripts', 'prefix_scripts' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* == Navigation section == */ | |
// Add the navigation section. | |
$wp_customize->add_section( | |
'prefix-navigation', | |
array( | |
'title' => esc_html__( 'Navigation settings', 'textdomain' ), | |
'priority' => 10, | |
'panel' => 'theme' | |
) | |
); | |
$wp_customize->add_setting( | |
'disable_dropdown', | |
array( | |
'default' => '', | |
'sanitize_callback' => 'prefix_sanitize_checkbox' | |
) | |
); | |
$wp_customize->add_control( | |
'disable_dropdown', | |
array( | |
'label' => esc_html__( 'Disable multi-level menu', 'textdomain' ), | |
'description' => esc_html__( 'Check this if you want to disable multi-level dropdown in Primary menu.', 'textdomain' ), | |
'section' => 'prefix-navigation', | |
'priority' => 10, | |
'type' => 'checkbox' | |
) | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Enable responsive nav for dropdown menus. | |
*/ | |
( function() { | |
var container; | |
// Primary menu | |
container = document.getElementById( 'menu-primary' ); | |
/** | |
* Enable dropdown menu. | |
*/ | |
if ( container ) { | |
var buttonMain = document.getElementById( 'nav-toggle' ); | |
var navMain = responsiveNav(".main-navigation", { // Selector | |
transition: 350, // Integer: Speed of the transition, in milliseconds | |
customToggle: "#nav-toggle", // Selector: Specify the ID of a custom toggle | |
enableFocus: true, // Boolean: Do we use use 'focus' class in our nav | |
enableDropdown: navSettings.dropdown, // Boolean: Do we use multi level dropdown | |
openDropdown: navSettings.expand, // String: Label for opening sub menu | |
closeDropdown: navSettings.collapse, // String: Label for closing sub menu | |
resizeMobile: function () { // Set ARIA for menu toggle button | |
buttonMain.setAttribute( 'aria-controls', 'menu-primary' ); | |
}, | |
resizeDesktop: function () { // Remove ARIA from menu toggle button | |
buttonMain.removeAttribute( 'aria-controls' ); | |
}, | |
}); | |
} | |
} )(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Enable responsive nav for dropdown menus. | |
*/ | |
( function() { | |
var container; | |
// Primary menu | |
container = document.getElementById( 'menu-primary' ); | |
/** | |
* Enable dropdown menu. | |
*/ | |
if ( container ) { | |
var buttonMain = document.getElementById( 'nav-toggle' ); | |
var navMain = responsiveNav(".main-navigation", { // Selector | |
transition: 350, // Integer: Speed of the transition, in milliseconds | |
customToggle: "#nav-toggle", // Selector: Specify the ID of a custom toggle | |
enableFocus: true, // Boolean: Do we use use 'focus' class in our nav | |
enableDropdown: true, // Boolean: Do we use multi level dropdown | |
openDropdown: navSettings.expand, // String: Label for opening sub menu | |
closeDropdown: navSettings.collapse, // String: Label for closing sub menu | |
resizeMobile: function () { // Set ARIA for menu toggle button | |
buttonMain.setAttribute( 'aria-controls', 'menu-primary' ); | |
}, | |
resizeDesktop: function () { // Remove ARIA from menu toggle button | |
buttonMain.removeAttribute( 'aria-controls' ); | |
}, | |
}); | |
} | |
} )(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Enqueue scripts. | |
*/ | |
function prefix_scripts() { | |
// Enqueue responsive navigation. | |
wp_enqueue_script( 'prefix-navigation', get_template_directory_uri() . '/js/responsive-nav.js', array(), '1.38', true ); | |
// Enqueue JS functions. | |
wp_enqueue_script( 'prefix-script', get_template_directory_uri() . '/js/functions.js', array( 'prefix-navigation' ), '1.38', true ); | |
wp_localize_script( 'prefix-script', 'navSettings', array( | |
'expand' => '<span class="screen-reader-text">' . esc_html__( 'Expand child menu', 'textdomain' ) . '</span>', | |
'collapse' => '<span class="screen-reader-text">' . esc_html__( 'Collapse child menu', 'textdomain' ) . '</span>', | |
'closeMenu' => esc_html__( 'Close menu', 'textdomain' ), | |
'openMenu' => esc_html__( 'Open menu', 'textdomain' ), | |
) ); | |
} | |
add_action( 'wp_enqueue_scripts', 'prefix_scripts' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment