ru-se.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

nav-bar.php (13540B)


      1 <?php
      2 
      3 function materialis_customize_register_options_navigation_general_options()
      4 {
      5     materialis_navigation_general_options(false);
      6     materialis_navigation_general_options(true);
      7 }
      8 
      9 add_action("materialis_customize_register_options", 'materialis_customize_register_options_navigation_general_options');
     10 
     11 
     12 function materialis_navigation_general_options($inner = false)
     13 {
     14     $priority = 1;
     15     $section  = $inner ? "inner_page_navigation" : "front_page_navigation";
     16     $prefix   = $inner ? "inner_header" : "header";
     17 
     18     materialis_add_kirki_field(array(
     19         'type'     => 'sectionseparator',
     20         'label'    => $inner ? esc_html__('Inner Pages Navigation options', 'materialis') : esc_html__('Front Page Navigation options', 'materialis'),
     21         'settings' => "{$prefix}_nav_separator",
     22         'section'  => $section,
     23         'priority' => $priority,
     24     ));
     25 
     26     do_action('materialis_after_navigation_separator_option', $inner, $section, $prefix);
     27 
     28 
     29     materialis_add_kirki_field(array(
     30         'type'      => 'checkbox',
     31         'label'     => esc_html__('Stick to top', 'materialis'),
     32         'section'   => $section,
     33         'priority'  => $priority,
     34         'settings'  => "{$prefix}_nav_sticked",
     35         'default'   => true,
     36         'transport' => 'postMessage',
     37     ));
     38 
     39     materialis_add_kirki_field(array(
     40         'type'      => 'checkbox',
     41         'label'     => esc_html__('Boxed Navigation', 'materialis'),
     42         'section'   => $section,
     43         'priority'  => $priority,
     44         'settings'  => "{$prefix}_nav_boxed",
     45         'default'   => false,
     46         'transport' => 'refresh',
     47     ));
     48 
     49 
     50     materialis_add_kirki_field(array(
     51         'type'      => 'checkbox',
     52         'label'     => esc_html__('Show Navigation Bottom Border', 'materialis'),
     53         'section'   => $section,
     54         'priority'  => $priority,
     55         'settings'  => "{$prefix}_nav_border",
     56         'default'   => materialis_mod_default("{$prefix}_nav_border", "#ffffff"),
     57         'transport' => 'postMessage',
     58     ));
     59 
     60 
     61     $group = $prefix . '_nav_border_group_button';
     62 
     63     materialis_add_kirki_field(array(
     64         'type'            => 'sectionseparator',
     65         'label'           => esc_html__('Bottom Border Options', 'materialis'),
     66         'section'         => $section,
     67         'settings'        => $prefix . '_nav_border_color_options_separator',
     68         'priority'        => $priority,
     69         'group'           => $group,
     70         'active_callback' => array(
     71             array(
     72                 'setting'  => "{$prefix}_nav_border",
     73                 'operator' => '==',
     74                 'value'    => true,
     75             ),
     76         ),
     77     ));
     78 
     79     $selector_start = $inner ? ".materialis-inner-page" : ".materialis-front-page";
     80 
     81     materialis_add_kirki_field(array(
     82         'type'            => 'color',
     83         'label'           => esc_html__('Bottom Border Color', 'materialis'),
     84         'section'         => $section,
     85         'settings'        => $prefix . '_nav_border_color',
     86         'priority'        => $priority,
     87         'choices'         => array(
     88             'alpha' => true,
     89         ),
     90         'default'         => materialis_mod_default("{$prefix}_nav_border_color", "#ffffff"),
     91         'transport'       => 'postMessage',
     92         "output"          => array(
     93             array(
     94                 'element'  => "{$selector_start} .navigation-bar.bordered",
     95                 'property' => 'border-bottom-color',
     96             ),
     97         ),
     98         'js_vars'         => array(
     99             array(
    100                 'element'  => "{$selector_start} .navigation-bar.bordered",
    101                 'property' => 'border-bottom-color',
    102                 'function' => 'style',
    103             ),
    104         ),
    105         'group'           => $group,
    106         'active_callback' => array(
    107             array(
    108                 'setting'  => "{$prefix}_nav_border",
    109                 'operator' => '==',
    110                 'value'    => true,
    111             ),
    112         ),
    113     ));
    114 
    115     materialis_add_kirki_field(array(
    116         'type'            => 'number',
    117         'label'           => esc_html__('Bottom Border Thickness', 'materialis'),
    118         'section'         => $section,
    119         'settings'        => $prefix . '_nav_border_thickness',
    120         'choices'         => array(
    121             'min'  => 1,
    122             'max'  => 50,
    123             'step' => 1,
    124         ),
    125         'default'         => materialis_mod_default("header_nav_border_thickness", "2"),
    126         'priority'        => $priority,
    127         'transport'       => 'postMessage',
    128         "output"          => array(
    129             array(
    130                 'element'  => "{$selector_start} .navigation-bar.bordered:not(.fixto-fixed)",
    131                 'property' => 'border-bottom-width',
    132                 'suffix'   => 'px',
    133             ),
    134             array(
    135                 'element'       => "{$selector_start} .navigation-bar.bordered",
    136                 'property'      => 'border-bottom-style',
    137                 'value_pattern' => 'solid',
    138             ),
    139         ),
    140         'js_vars'         => array(
    141             array(
    142                 'element'  => "{$selector_start} .navigation-bar.bordered:not(.fixto-fixed)",
    143                 'property' => 'border-bottom-width',
    144                 'suffix'   => 'px',
    145                 'function' => 'css',
    146             ),
    147             array(
    148                 'element'       => "{$selector_start} .navigation-bar.bordered",
    149                 'property'      => 'border-bottom-style',
    150                 'function'      => 'css',
    151                 'value_pattern' => 'solid',
    152             ),
    153         ),
    154         'group'           => $group,
    155         'active_callback' => array(
    156             array(
    157                 'setting'  => "{$prefix}_nav_border",
    158                 'operator' => '==',
    159                 'value'    => true,
    160             ),
    161         ),
    162 
    163     ));
    164 
    165     materialis_add_kirki_field(array(
    166         'type'            => 'sidebar-button-group',
    167         'settings'        => $prefix . '_nav_border_group_button',
    168         'label'           => esc_html__('Border Options', 'materialis'),
    169         'section'         => $section,
    170         'priority'        => $priority,
    171         'active_callback' => array(
    172             array(
    173                 'setting'  => "{$prefix}_nav_border",
    174                 'operator' => '==',
    175                 'value'    => true,
    176             ),
    177         ),
    178     ));
    179 
    180     materialis_add_kirki_field(array(
    181         'type'      => 'checkbox',
    182         'label'     => esc_html__('Transparent Nav Bar', 'materialis'),
    183         'section'   => $section,
    184         'priority'  => $priority,
    185         'settings'  => "{$prefix}_nav_transparent",
    186         'default'   => materialis_mod_default("{$prefix}_nav_transparent"),
    187         'transport' => 'postMessage',
    188         'update'    => apply_filters('materialis_transparent_navigation_settings_partial_update', array(), $prefix),
    189     ));
    190 
    191     materialis_add_kirki_field(array(
    192         'type'      => 'ope-info-pro',
    193         'label'     => esc_html__('More colors and typography options available in PRO. @BTN@', 'materialis'),
    194         'section'   => $section,
    195         'priority'  => $priority,
    196         'settings'  => "{$prefix}_nav_pro_info",
    197         'default'   => true,
    198         'transport' => 'postMessage',
    199     ));
    200 
    201     materialis_add_kirki_field(array(
    202         'type'     => 'select',
    203         'settings' => "{$prefix}_nav_bar_type",
    204         'label'    => esc_html__('Navigation bar type', 'materialis'),
    205         'section'  => $section,
    206         'default'  => 'default',
    207         'choices'  => apply_filters('materialis_navigation_types', array(
    208             'default'         => esc_html__('Logo on left, Navigation on right', 'materialis'),
    209             'logo-above-menu' => esc_html__('Logo on center, Navigation below', 'materialis'),
    210 
    211         )),
    212         'update'   => apply_filters('materialis_nav_bar_menu_settings_partial_update', array(
    213             array(
    214                 "value"  => "default",
    215                 "fields" => array(
    216                     "{$prefix}_nav_menu_items_align"   => 'flex-end',
    217                     "{$prefix}_fixed_menu_items_align" => 'flex-end',
    218                 ),
    219             ),
    220             array(
    221                 "value"  => "logo-above-menu",
    222                 "fields" => array(
    223                     "{$prefix}_nav_menu_items_align"   => 'center',
    224                     "{$prefix}_fixed_menu_items_align" => 'flex-end',
    225                 ),
    226             ),
    227 
    228         ), $prefix),
    229         'priority' => $priority,
    230     ));
    231 
    232     materialis_add_kirki_field(array(
    233         'type'     => 'select',
    234         'settings' => "{$prefix}_nav_style",
    235         'label'    => esc_html__('Navigation style', 'materialis'),
    236         'section'  => $section,
    237         'default'  => 'material-buttons',
    238         'choices'  => apply_filters('materialis_navigation_styles', array(
    239             'simple-text-buttons' => esc_html__('Simple text menu', 'materialis'),
    240             'material-buttons'    => esc_html__('Material Buttons', 'materialis'),
    241         )),
    242         'priority' => $priority,
    243 
    244         'transport' => apply_filters('materialis_nav_style_transport', 'refresh'),
    245     ));
    246 
    247 
    248     do_action('materialis_after_navigation_options_area', $inner, $section, $prefix, $priority);
    249 }
    250 
    251 
    252 /*
    253     template functions
    254 */
    255 
    256 function materialis_get_offcanvas_primary_menu()
    257 {
    258     ?>
    259     <a href="#" data-component="offcanvas" data-target="#offcanvas-wrapper" data-direction="right" data-width="300px" data-push="false">
    260         <div class="bubble"></div>
    261         <i class="mdi mdi-view-sequential"></i>
    262     </a>
    263     <div id="offcanvas-wrapper" class="hide force-hide offcanvas-right">
    264         <div class="offcanvas-top">
    265             <div class="logo-holder">
    266                 <?php materialis_print_logo(); ?>
    267             </div>
    268         </div>
    269         <?php
    270         wp_nav_menu(array(
    271             'theme_location' => 'primary',
    272             'menu_id'        => 'offcanvas_menu',
    273             'menu_class'     => 'offcanvas_menu',
    274             'container_id'   => 'offcanvas-menu',
    275             'fallback_cb'    => 'materialis_no_hamburger_menu_cb',
    276         ));
    277         ?>
    278 
    279         <?php do_action("materialis_offcanvas_primary_menu_footer"); ?>
    280     </div>
    281     <?php
    282 }
    283 
    284 
    285 function materialis_print_primary_menu($walker = '', $fallback = 'materialis_nomenu_cb')
    286 {
    287 
    288     $drop_down_menu_classes = apply_filters('materialis_primary_drop_menu_classes', array('default'));
    289     $drop_down_menu_classes = array_merge($drop_down_menu_classes, array('main-menu', 'dropdown-menu'));
    290 
    291     wp_nav_menu(array(
    292         'theme_location'  => 'primary',
    293         'menu_id'         => 'main_menu',
    294         'menu_class'      => esc_attr(implode(" ", $drop_down_menu_classes)),
    295         'container_id'    => 'mainmenu_container',
    296         'container_class' => 'row',
    297         'fallback_cb'     => $fallback,
    298         'walker'          => $walker,
    299     ));
    300 
    301     materialis_get_offcanvas_primary_menu();
    302 }
    303 
    304 function materialis_print_footer_menu()
    305 {
    306     wp_nav_menu(array(
    307         'theme_location'  => 'footer_menu',
    308         'menu_id'         => 'materialis-footer-menu',
    309         'menu_class'      => 'materialis-footer-menu',
    310         'container_class' => 'materialis-footer-menu',
    311         'fallback_cb'     => 'materialis_footer_nomenu_cb',
    312         'depth'           => 1,
    313     ));
    314 }
    315 
    316 
    317 // sticky navigation
    318 function materialis_navigation_sticky_attrs()
    319 {
    320     $inner = materialis_is_inner(true);
    321     $atts  = array(
    322         "data-sticky"        => 0,
    323         "data-sticky-mobile" => 1,
    324         "data-sticky-to"     => "top",
    325     );
    326 
    327     $atts   = apply_filters("materialis_navigation_sticky_attrs", $atts);
    328     $prefix = $inner ? "inner_header" : "header";
    329 
    330     $result = "";
    331     if (get_theme_mod("{$prefix}_nav_sticked", true)) {
    332         foreach ($atts as $key => $value) {
    333             $result .= " " . esc_attr($key) . "='" . esc_attr($value) . "' ";
    334         }
    335     }
    336 
    337     echo $result;
    338 }
    339 
    340 function materialis_navigation_wrapper_class($mainClass = array())
    341 {
    342     $inner   = materialis_is_inner(true);
    343     $classes = array();
    344 
    345     $prefix  = $inner ? "inner_header" : "header";
    346     $isBoxed = materialis_get_theme_mod("{$prefix}_nav_boxed", false);
    347 
    348     if ($isBoxed) {
    349         $classes[] = "gridContainer";
    350     }
    351 
    352     $classes = apply_filters("materialis_navigation_wrapper_class", $classes, $inner);
    353 
    354     if ( ! is_array($mainClass)) {
    355         if (is_string($mainClass)) {
    356             $mainClass = array($mainClass);
    357         } else {
    358             $mainClass = array();
    359         }
    360     }
    361 
    362     $classes = array_merge($classes, $mainClass);
    363 
    364     return implode(" ", $classes);
    365 }
    366 
    367 add_filter('materialis_navigation', 'materialis_navigation_bar_type');
    368 
    369 function materialis_navigation_bar_type($template)
    370 {
    371 
    372     if ( ! $template) {
    373         $setting         = materialis_is_front_page(true) ? "header_nav_bar_type" : "inner_header_nav_bar_type";
    374         $settingTemplate = materialis_get_theme_mod($setting, 'default');
    375 
    376         if ($settingTemplate !== 'default') {
    377             $template = $settingTemplate;
    378         }
    379 
    380     }
    381 
    382     return $template;
    383 }
    384 
    385 
    386 function materialis_primary_drop_menu_classes($classes)
    387 {
    388     $prefix          = materialis_is_front_page(true) ? "header" : "inner_header";
    389     $variation_class = materialis_get_theme_mod("{$prefix}_nav_style", "material-buttons");
    390     $result          = array();
    391 
    392     foreach ($classes as $class) {
    393         if ($class !== "default") {
    394             $result[] = $class;
    395         }
    396     }
    397 
    398     $result[] = $variation_class;
    399 
    400     return $result;
    401 }
    402 
    403 add_filter('materialis_primary_drop_menu_classes', 'materialis_primary_drop_menu_classes');