WordPress.org

Making WordPress.org

Ticket #467: handbook.diff

File handbook.diff, 2.3 KB (added by morganestes, 4 years ago)

Handbook plugin patch with new JS file enqueued

  • wp-content/plugins/handbook/handbook.php

     
    3030                }
    3131
    3232                add_action( 'wp_enqueue_scripts', array( __CLASS__, 'enqueue_styles' ) );
     33                add_action( 'wp_enqueue_scripts', array( __CLASS__, 'enqueue_scripts' ) );
    3334        }
    3435
    3536        static public function enqueue_styles() {
     
    3637                wp_enqueue_style( 'wporg-handbook-css', plugins_url( '/stylesheets/callout-boxes.css', __FILE__ ), array(), '20150507' );
    3738        }
    3839
     40        static public function enqueue_scripts() {
     41                wp_enqueue_script( 'wporg-handbook', plugins_url( '/scripts/handbook.js', __FILE__ ), array( 'jquery' ), '20150930' );
     42        }
     43
    3944}
    4045
    4146add_action( 'after_setup_theme', array( 'WPorg_Handbook_Init', 'init' ) );
     
    235240                }
    236241        }
    237242
    238 }
    239  No newline at end of file
     243}
  • wp-content/plugins/handbook/scripts/handbook.js

     
     1/**
     2 * Enables toggling visibility of all the chapters in the Handbook Chapter widget.
     3 *
     4 * @since ???
     5 */
     6var toggleChapters = function () {
     7        /**
     8         * The Handbook Chapter widget title element.
     9         *
     10         * @type {NodeList}
     11         */
     12        var chapterWidgetHeading = document.querySelectorAll( '.widget_wporg_handbook_pages .widgettitle' );
     13
     14        /*
     15         * Bind to the touch and click events to make it useful on both mobile and desktop.
     16         * Since 'click' is the last event in the chain, we use preventDefault() to stop the
     17         * touch event from continuing and triggering a "ghost click".
     18         *
     19         * @link http://www.html5rocks.com/en/mobile/touchandmouse/
     20         */
     21        jQuery( chapterWidgetHeading ).bind( 'touchstart click', function ( e ) {
     22                e.preventDefault();
     23                jQuery( this ).next( '.menu-table-of-contents-container' ).toggle();
     24        } );
     25};
     26
     27// Layout changes the widget at 700px, so we don't want to enable toggling above that.
     28// @todo Check on window resize, rather than just on page loading
     29jQuery( document ).ready( function() {
     30        if ( 700 >= parseInt( jQuery( window ).width(), 10 ) ) {
     31                toggleChapters();
     32        }
     33});
     34