From aeb6b758285743f8fc2eb689cad697a011bf151b Mon Sep 17 00:00:00 2001 From: Ian Weller Date: Mon, 19 Oct 2015 15:29:06 -0400 Subject: [PATCH] functions and js update --- root/footer.php | 4 +- root/functions.php | 79 +++++++++++++++++++++++++++++++++++++ root/js/custom/pageSetup.js | 8 ++++ 3 files changed, 89 insertions(+), 2 deletions(-) diff --git a/root/footer.php b/root/footer.php index e4855e2..a4ca64a 100644 --- a/root/footer.php +++ b/root/footer.php @@ -7,7 +7,7 @@ - + - + diff --git a/root/functions.php b/root/functions.php index 8edc962..4868803 100644 --- a/root/functions.php +++ b/root/functions.php @@ -78,6 +78,85 @@ function glm_page_menu($parent = 0, $class = '') echo ''."\n"; } +register_nav_menus(array( + 'top-bar' => 'Site Navigation', + //'mobile-off-canvas' => 'Mobile', +// 'footer' => 'Footer' +)); + +if ( ! function_exists( 'feature_top_bar' ) ) { + function feature_top_bar() { + wp_nav_menu(array( + 'container' => false, // remove nav container + 'container_class' => '', // class of container + 'menu' => '', // menu name + 'menu_class' => '', // adding custom nav class + 'theme_location' => 'top-bar', // where it's located in the theme + 'before' => '', // before each link + 'after' => '', // after each link + 'link_before' => '', // before each link text + 'link_after' => '', // after each link text + 'depth' => 3, // limit the depth of the nav + 'fallback_cb' => false, // fallback function (see below) + 'walker' => new Feature_Top_Bar_Walker() + )); + } +} +if ( ! class_exists( 'Feature_Top_Bar_Walker' ) ) : +class Feature_Top_Bar_Walker extends Walker_Nav_Menu { + + function display_element( $element, &$children_elements, $max_depth, $depth = 0, $args, &$output ) { + static $mainLevelCounter; + if ($depth == 0) { + ++$mainLevelCounter; + } + $element->has_children = ! empty( $children_elements[ $element->ID ] ); + $element->classes[] = ( $element->current || $element->current_item_ancestor ) ? 'active' : ''; + $element->classes[] = ( $element->has_children && 1 !== $max_depth ) ? 'has-dropdown' : ''; + $element->classes[] = ( $element->post_parent == 0 && $mainLevelCounter < 6 ) ? '' : 'drop-left'; + parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output ); + } + + function start_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) { + $item_html = ''; + parent::start_el( $item_html, $object, $depth, $args ); + + // Insert style to display page's thumbnail + $item_style = ''; + if ($depth == 0 && has_post_thumbnail((int)$object->object_id)) { + $thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id((int)$object->object_id), 'bpla-drop-down'); + //$item_style .= ""; + } + //$output .= ( 0 == $depth ) ? '
  • ' : ''; + $classes = empty( $object->classes ) ? array() : (array) $object->classes; + if ( in_array( 'label', $classes ) ) { + //$output .= '
  • '; + $item_html = preg_replace( '/]*>(.*)<\/a>/iU', '', $item_html ); + } + if ( in_array( 'divider', $classes ) ) { + $item_html = preg_replace( '/]*>( .* )<\/a>/iU', '', $item_html ); + } + if ($item_style) { + $output .= $item_style; + } + if ($depth == 0 && has_post_thumbnail((int)$object->object_id) && $object->has_children) { + $thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id((int)$object->object_id), 'bpla-drop-down'); + $item_html .= ''; + //$item_html .= '
    ' . print_r($object, true) . '
    '; + } + $output .= $item_html; + } + + function start_lvl( &$output, $depth = 0, $args = array() ) { + if ($depth == 0) { + $output .= "\n
      \n"; + $output .= "\n
    • "; + $output .= "
    • \n"; + } + } + +} +endif; /** * Return the client info option for the given key * diff --git a/root/js/custom/pageSetup.js b/root/js/custom/pageSetup.js index 741d565..dde383c 100644 --- a/root/js/custom/pageSetup.js +++ b/root/js/custom/pageSetup.js @@ -8,4 +8,12 @@ $(document).ready(function () { $(this).toggleClass('open'); $(this).siblings('ul').toggleClass('open'); }); + $('.top-bar-section').find('ul.sub-menu.dropdown').each(function (){ + var menuImg = $(this).parent('li').prop('id'); + var menuNum = menuImg.match(/\d+/)[0]; + var menuImgSrc = 'img_for_menu_' + menuNum; + $(this).find('li.image-placeholder').html(''); + console.log('ul = ' + menuImg); + console.log('menu-id = ' + menuNum); + }); }); -- 2.17.1