WordPress.org

Making WordPress.org

Changeset 6285


Ignore:
Timestamp:
12/18/2017 06:36:37 PM (3 years ago)
Author:
obenland
Message:

Plugins: Make FAQ topics linkable.

Allows for faq topics to be linked to directly, and show up expanded and scrolled to.

Props joostdevalk for initial patch.
Fixes #3319.

Location:
sites/trunk/wordpress.org/public_html/wp-content
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/readme/class-parser.php

    r5841 r6285  
    401401                $this->sections['faq'] .= "\n<dl>\n";
    402402                foreach ( $this->faq as $question => $answer ) {
    403                     $this->sections['faq'] .= "<dt>{$question}</dt>\n<dd>{$answer}</dd>\n";
     403                    $question_slug = sanitize_title_with_dashes( $question );
     404                    $this->sections['faq'] .= "<dt id='{$question_slug}'>{$question}</dt>\n<dd>{$answer}</dd>\n";
    404405                }
    405406                $this->sections['faq'] .= "\n</dl>\n";
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/js/section-faq.js

    r5244 r6285  
    11( function( $ ) {
    2     $( 'dt', '#faq' )
     2    var questions = $( 'dt', '#faq' );
     3    var hash      = window.location.hash.replace( /[^a-z0-9-#]/gi, '' );
     4
     5    questions
    36        .each( function( index, question ) {
    47            var $question = $( question ),
    5                 $button   = $( '<button type="button" class="button-link" aria-expanded="false" />' );
     8                $button   = $( '<a href="#" />' ),
     9                id        = $question.attr( 'id' );
     10
     11            // If there is no ID, create our own.
     12            if ( ! id ) {
     13                id = '#' + $question.text().toLowerCase().replace( /[^\w\s]/gi, '' ).replace( /\s/gi, '-' );
     14                $question.attr( 'id', id );
     15            }
     16
     17            $button.attr( 'href', id ).on( 'click', function( event ) {
     18                event.preventDefault();
     19            } );
    620
    721            $question.html( $button.text( $question.text() ) );
     
    2135                return 'true' !== attribute;
    2236            } ).next( 'dd' ).slideToggle( 200 );
     37
     38            if ( hash ) {
     39                window.scrollTo( 0, $question.offset().top );
     40            }
    2341        } );
     42
     43    if ( hash ) {
     44        questions.find( '[href="' + hash + '"]' ).trigger( 'click' );
     45    }
    2446} )( jQuery );
Note: See TracChangeset for help on using the changeset viewer.