Make WordPress Core

Ticket #29979: 29979.6.diff

File 29979.6.diff, 1.9 KB (added by MikeHansenMe, 10 years ago)

patch instead of plugin and reuse of variables

  • src/wp-content/themes/twentyfifteen/functions.php

     
    209209
    210210        wp_enqueue_script( 'twentyfifteen-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20141010', true );
    211211
     212        wp_enqueue_script( 'twentyfifteen-scroll', get_template_directory_uri() . '/js/scroll.js', array( 'jquery' ), '20141010', true );
     213
    212214        if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
    213215                wp_enqueue_script( 'comment-reply' );
    214216        }
  • src/wp-content/themes/twentyfifteen/js/scroll.js

     
     1jQuery( document ).ready( function ( $ ) {
     2               
     3        var window_height = $( window ).height();
     4        var sidebar_scrollheight = $( '#sidebar' )[0].scrollHeight;
     5
     6        if( $( '#content' ).height() < window_height && sidebar_scrollheight > window_height ) {
     7                $( '#content' ).height( $( '#sidebar' ).height() );
     8        }
     9
     10        var content_scrollheight = $( '#content' )[0].scrollHeight;
     11        var ratio = sidebar_scrollheight / content_scrollheight;
     12        var offset = content_scrollheight - window_height;
     13        var multiplier = content_scrollheight / offset;
     14
     15        if( $( window ).width() > 967 ) {
     16                $( '#sidebar' ).css( 'overflow', 'hidden' );
     17                if( sidebar_scrollheight > window_height ) {
     18                        $( window ).scroll( function() {
     19                                var content_position = $( window ).scrollTop();
     20                                var sidebar_position = ( content_position >= 0 ? Math.round( content_position * ratio * multiplier ) : 0 );
     21                                $( '#sidebar' ).scrollTop( Math.abs( sidebar_position ) );
     22                        } );
     23                }
     24        }
     25} );
     26 No newline at end of file