Skip to content

Commit a365467

Browse files
committed
One Page links. #229
1 parent ae1de8e commit a365467

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

assets/js/shapely-scripts.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,38 @@
1212
});
1313

1414
// Smooth scroll to inner links
15-
1615
jQuery( '.inner-link' ).each(function() {
1716
var href = jQuery( this ).attr( 'href' );
1817
if ( '#' !== href.charAt( 0 ) ) {
1918
jQuery( this ).removeClass( 'inner-link' );
2019
}
2120
});
2221

22+
// Smooth scroll
23+
if ( '' !== window.location.hash ) {
24+
var element = $( '#site-navigation #menu a[href=' + window.location.hash + ']' ),
25+
scrollToID,
26+
newURL;
27+
if ( element ) {
28+
scrollToID = '#' + element.data( 'scroll' );
29+
$('html,body').animate({
30+
scrollTop: $( scrollToID ).offset().top
31+
}, 2000);
32+
33+
newURL = window.location.href.replace( window.location.hash, '' );
34+
window.history.replaceState( {}, document.title, newURL );
35+
36+
}
37+
}
38+
39+
$( '#site-navigation #menu a[href^=#]:not([href=#])' ).click(function( evt ) {
40+
var scrollToID = '#' + $(this).data( 'scroll' );
41+
evt.preventDefault();
42+
$('html,body').animate({
43+
scrollTop: $( scrollToID ).offset().top
44+
}, 2000);
45+
});
46+
2347
jQuery( '.inner-link' ).click(function() {
2448
jQuery( 'html, body' ).animate({
2549
scrollTop: 0
@@ -474,6 +498,8 @@
474498
jQuery( window ).trigger( 'resize' ).trigger( 'scroll' );
475499
});
476500

501+
502+
477503
})( jQuery );
478504

479505
/*

inc/class-wp-bootstrap-navwalker.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public function start_lvl( &$output, $depth = 0, $args = array() ) {
2626
*/
2727
public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
2828
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
29+
$extra = get_post_meta( $item->ID, '_menu_item_extra', true );
30+
$widget = get_post_meta( $item->ID, '_menu_item_widget', true );
2931

3032
/**
3133
* Dividers, Headers or Disabled
@@ -82,6 +84,16 @@ public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0
8284
$atts['href'] = ! empty( $item->url ) ? $item->url : '';
8385
}
8486

87+
if ( 'shapely-section' == $extra ) {
88+
if ( ! is_front_page() ) {
89+
$atts['href'] = site_url() . esc_attr( $item->url );
90+
}
91+
92+
if ( '' != $widget ) {
93+
$atts['data-scroll'] = $widget;
94+
}
95+
}
96+
8597
$atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args );
8698

8799
$attributes = '';

0 commit comments

Comments
 (0)