diff --git a/content-reference.php b/content-reference.php
index 02cb0b5..fdd1619 100644
a
|
b
|
if ( ! empty( $since ) ) : ?> |
114 | 114 | <?php endif; |
115 | 115 | endif; ?> |
116 | 116 | |
| 117 | <?php if ( 'wp-parser-function' === get_post_type() ) : ?> |
| 118 | <hr /> |
| 119 | <section class="source-content"> |
| 120 | <h2><?php _e( 'Source', 'wporg' ); ?></h2> |
| 121 | <div class="source-code-container" style="height: 200px; overflow: hidden;"> |
| 122 | <pre class="brush: php;"><?php echo esc_html( get_source_code() ); ?></pre> |
| 123 | </div> |
| 124 | <p><a href="#" class="show-complete-source"><?php _e( 'Show complete source code.', 'wporg-developer' ); ?></a></p> |
| 125 | </section> |
| 126 | <?php endif; ?> |
| 127 | |
117 | 128 | <?php endif; ?> |
118 | 129 | |
119 | 130 | </article> |
diff --git a/functions.php b/functions.php
index c0deeac..bc57a6d 100644
a
|
b
|
function theme_scripts_styles() { |
342 | 342 | wp_enqueue_style( 'wp-dev-sass-compiled', get_template_directory_uri() . '/stylesheets/main.css', array( 'wporg-developer-style' ), '20140425' ); |
343 | 343 | wp_enqueue_script( 'wporg-developer-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20120206', true ); |
344 | 344 | wp_enqueue_script( 'wporg-developer-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20130115', true ); |
| 345 | wp_enqueue_script( 'wporg-developer-function-reference', get_template_directory_uri() . '/js/function-reference.js', array( 'jquery' ), '20140514', true ); |
345 | 346 | if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { |
346 | 347 | wp_enqueue_script( 'comment-reply' ); |
347 | 348 | } |
diff --git a/inc/template-tags.php b/inc/template-tags.php
index 28f3199..a0bc383 100755
a
|
b
|
namespace DevHub { |
564 | 564 | return strcmp( $a->post_name, $b->post_name ); |
565 | 565 | } |
566 | 566 | |
| 567 | /** |
| 568 | * Retrieve source code for a function |
| 569 | * |
| 570 | * @param int $post_id |
| 571 | * |
| 572 | * @return string The sourc |
| 573 | */ |
| 574 | function get_source_code( $post_id = null ) { |
| 575 | |
| 576 | if ( empty( $post_id ) ) { |
| 577 | $post_id = get_the_ID(); |
| 578 | } |
| 579 | |
| 580 | // Get the total file sourcecode. |
| 581 | $source_file = get_source_file( $post_id ); |
| 582 | |
| 583 | // Put the total source code in an array. |
| 584 | $total_source_code = file_get_contents( ABSPATH . $source_file ); |
| 585 | $total_source_code = explode( "\n", $total_source_code ); |
| 586 | |
| 587 | // Get the start and end lines. |
| 588 | $start_line = get_post_meta( $post_id, '_wp-parser_line_num', true ) - 1; |
| 589 | $end_line = get_post_meta( $post_id, '_wp-parser_end_line_num', true ); |
| 590 | |
| 591 | // Get the correct source code. |
| 592 | $source_code = array_slice( $total_source_code, $start_line, $end_line - $start_line ); |
| 593 | |
| 594 | return implode( "\n", $source_code ); |
| 595 | } |
| 596 | |
567 | 597 | } |
| 598 | No newline at end of file |
diff --git a/js/function-reference.js b/js/function-reference.js
new file mode 100644
index 0000000..798d451
-
|
+
|
|
| 1 | /** |
| 2 | * function-reference.js |
| 3 | * |
| 4 | * Handles all interactivity on the single function page |
| 5 | */ |
| 6 | ( function( $ ) { |
| 7 | $( '.show-complete-source' ).on( 'click', function( e ) { |
| 8 | e.preventDefault(); |
| 9 | |
| 10 | var $this = $( this ), |
| 11 | source_content = $this.closest( '.source-content' ); |
| 12 | |
| 13 | source_content.children( '.source-code-container' ).animate( { height: source_content.find( 'table' ).height() + 'px' } ); |
| 14 | |
| 15 | $this.remove(); |
| 16 | } ); |
| 17 | } )( jQuery ); |