diff --git a/functions.php b/functions.php index dcb71ca..85e7419 100644 --- a/functions.php +++ b/functions.php @@ -87,6 +87,19 @@ if ( ! function_exists( 'blogrow_setup' ) ) { add_action( 'after_setup_theme', 'blogrow_setup' ); +/* Custom navigation +/* ------------------------------------ */ +require_once 'functions/nav.php'; +$nav = new \AlxMedia\Nav(); +$nav->enqueue( + [ + 'script' => 'js/nav.js', + 'inline' => false, + ] +); +$nav->init(); + + /* Custom logo /* ------------------------------------ */ if ( ! function_exists( 'blogrow_custom_logo' ) ) { diff --git a/functions/nav.php b/functions/nav.php new file mode 100644 index 0000000..360f779 --- /dev/null +++ b/functions/nav.php @@ -0,0 +1,305 @@ +URL,style=>URL,inline=>true|false]. + * + * @return void + */ + public function enqueue( $args = false ) { + if ( ! $args ) { + return; + } + + // Early exit if we've already enqueued our assets. + if ( self::$enqueued ) { + return; + } + + $args = wp_parse_args( + $args, + [ + 'script' => false, + 'style' => false, + 'inline' => false, + ] + ); + + $this->assets['script'] = $args['script']; + $this->assets['style'] = $args['style']; + $this->inline = $args['inline']; + + if ( $this->inline ) { + add_action( 'wp_footer', [ $this, 'inline_assets' ] ); + } else { + add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_assets' ] ); + } + self::$enqueued = true; + } + + /** + * Inline assets. + * + * @access public + * + * @return void + */ + public function inline_assets() { + if ( $this->assets['script'] ) { + echo ''; + } + + if ( $this->assets['style'] ) { + echo ''; + } + } + + /** + * Enqueue assets. + * + * @access public + * + * @return void + */ + public function enqueue_assets() { + if ( $this->assets['style'] ) { + wp_enqueue_style( + $this->handle_prefix . '-style', + get_theme_file_uri( $this->assets['style'] ), + [], + filemtime( get_theme_file_path( $this->assets['style'] ) ) + ); + } + + if ( $this->assets['script'] ) { + wp_enqueue_script( + $this->handle_prefix . '-script', + get_theme_file_uri( $this->assets['script'] ), + [], + filemtime( get_theme_file_path( $this->assets['script'] ) ), + true + ); + } + } + + /** + * A wrapper for the wp_nav_menu function, adding our custom HTML for the expand/collapse button. + * + * @static + * + * @access public + * + * @param array $args The arguments to pass to wp_nav_menu(). + * @param string|false $toggle_label The label for our toggle button. + * @param string $nav_classes CSS classes to add to the