diff --git content-reference.php content-reference.php
index 02cb0b5..0588196 100644
|
|
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"> |
| 122 | <pre class="brush: php; toolbar: false;"><?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 functions.php functions.php
index 289f45d..734d533 100644
|
|
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 | |
| 346 | if ( 'wp-parser-function' === get_post_type() ) { |
| 347 | wp_enqueue_script( 'wporg-developer-function-reference', get_template_directory_uri() . '/js/function-reference.js', array( 'jquery', 'syntaxhighlighter-core', 'syntaxhighlighter-brush-php' ), '20140515', true ); |
| 348 | wp_enqueue_style( 'syntaxhighlighter-core' ); |
| 349 | wp_enqueue_style( 'syntaxhighlighter-theme-default' ); |
| 350 | } |
| 351 | |
345 | 352 | if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { |
346 | 353 | wp_enqueue_script( 'comment-reply' ); |
347 | 354 | } |
diff --git inc/template-tags.php inc/template-tags.php
index 871d488..4c778c9 100755
|
|
namespace DevHub { |
567 | 567 | return strcmp( $a->post_name, $b->post_name ); |
568 | 568 | } |
569 | 569 | |
| 570 | /** |
| 571 | * Retrieve source code for a function |
| 572 | * |
| 573 | * @param int $post_id |
| 574 | * |
| 575 | * @return string The sourc |
| 576 | */ |
| 577 | function get_source_code( $post_id = null ) { |
| 578 | |
| 579 | if ( empty( $post_id ) ) { |
| 580 | $post_id = get_the_ID(); |
| 581 | } |
| 582 | |
| 583 | // Get the total file sourcecode. |
| 584 | $source_file = get_source_file( $post_id ); |
| 585 | |
| 586 | // Put the total source code in an array. |
| 587 | $total_source_code = file_get_contents( ABSPATH . $source_file ); |
| 588 | $total_source_code = explode( "\n", $total_source_code ); |
| 589 | |
| 590 | // Get the start and end lines. |
| 591 | $start_line = get_post_meta( $post_id, '_wp-parser_line_num', true ) - 1; |
| 592 | $end_line = get_post_meta( $post_id, '_wp-parser_end_line_num', true ); |
| 593 | |
| 594 | // Get the correct source code. |
| 595 | $source_code = array_slice( $total_source_code, $start_line, $end_line - $start_line ); |
| 596 | |
| 597 | return implode( "\n", $source_code ); |
| 598 | } |
| 599 | |
570 | 600 | } |
| 601 | No newline at end of file |
diff --git js/function-reference.js js/function-reference.js
new file mode 100644
index 0000000..c69a782
-
|
+
|
|
| 1 | /** |
| 2 | * function-reference.js |
| 3 | * |
| 4 | * Handles all interactivity on the single function page |
| 5 | */ |
| 6 | ( function( $ ) { |
| 7 | |
| 8 | function onLoad() { |
| 9 | SyntaxHighlighter.all(); |
| 10 | |
| 11 | // Do this with javascript so javascript-less can enjoy the total sourcecode |
| 12 | // 1em (margin) + 10 * 17px. Lines are 1.1em which rounds to 17px: calc( 1em + 17px * 10 ). |
| 13 | $( '.source-code-container' ).css( { height: '186px' } ); |
| 14 | } |
| 15 | |
| 16 | $( '.show-complete-source' ).on( 'click', function( e ) { |
| 17 | e.preventDefault(); |
| 18 | |
| 19 | var $this = $( this ), |
| 20 | source_content = $this.closest( '.source-content' ); |
| 21 | |
| 22 | source_content.children( '.source-code-container' ).animate( { height: source_content.find( 'table' ).height() + 'px' } ); |
| 23 | |
| 24 | $this.remove(); |
| 25 | } ); |
| 26 | |
| 27 | $( onLoad ); |
| 28 | } )( jQuery ); |
diff --git scss/main.scss scss/main.scss
index 585d30c..e1ba440 100644
|
|
|
792 | 792 | padding: 20px; |
793 | 793 | } |
794 | 794 | } |
| 795 | |
| 796 | .source-code-container { |
| 797 | overflow: hidden; |
| 798 | } |
| 799 | |
795 | 800 | .loop-pagination { |
796 | 801 | text-align: center; |
797 | 802 | font-size: 18px; |
diff --git stylesheets/main.css stylesheets/main.css
index 3d9eae4..5b3af2c 100644
|
|
input { |
1015 | 1015 | border-radius: 5px; |
1016 | 1016 | padding: 20px; |
1017 | 1017 | } |
| 1018 | .devhub-wrap .source-code-container { |
| 1019 | overflow: hidden; |
| 1020 | } |
1018 | 1021 | .devhub-wrap .loop-pagination { |
1019 | 1022 | text-align: center; |
1020 | 1023 | font-size: 18px; |