Ticket #176: 176.4.diff
File 176.4.diff, 5.0 KB (added by , 10 years ago) |
---|
-
content-reference.php
diff --git content-reference.php content-reference.php index 02cb0b5..ec2bd95 100644
if ( ! empty( $since ) ) : ?> 114 114 <?php endif; 115 115 endif; ?> 116 116 117 <?php if ( 'wp-parser-function' === get_post_type() || 'wp-parser-method' === 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( 'View full source code…', 'wporg-developer' ); ?></a></p> 125 </section> 126 <?php endif; ?> 127 117 128 <?php endif; ?> 118 129 119 130 </article> -
functions.php
diff --git functions.php functions.php index 289f45d..38abd10 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() || 'wp-parser-method' === 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 } -
inc/template-tags.php
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 -
new file js/function-reference.js
diff --git js/function-reference.js js/function-reference.js new file mode 100644 index 0000000..01e7542
- + 1 /** 2 * function-reference.js 3 * 4 * Handles all interactivity on the single function page 5 */ 6 ( function( $ ) { 7 var $sourceContent, $sourceCodeContainer, $sourceCodeTable, $showCompleteSource; 8 9 function showCompleteSource( e ) { 10 e.preventDefault(); 11 12 var heightGoal = $sourceCodeTable.height() + 17; 13 14 $sourceCodeContainer.animate( { height: heightGoal + 'px' } ); 15 16 $showCompleteSource.hide(); 17 18 } 19 20 function onLoad() { 21 22 // We only expect one source-content per document 23 $sourceContent = $( '.source-content' ); 24 $sourceCodeContainer = $( '.source-code-container' ); 25 26 SyntaxHighlighter.highlight(); 27 28 $sourceCodeTable = $sourceContent.find( 'table' ); 29 30 if ( 186 < $sourceCodeTable.height() ) { 31 32 // Do this with javascript so javascript-less can enjoy the total sourcecode 33 // 1em (margin) + 10 * 17px. Lines are 1.1em which rounds to 17px: calc( 1em + 17px * 10 ). 34 $sourceCodeContainer.css( { height: '186px' } ); 35 36 $showCompleteSource = $( '.show-complete-source' ); 37 38 $showCompleteSource.show(); 39 $showCompleteSource.on( 'click', showCompleteSource ); 40 } 41 } 42 43 $( onLoad ); 44 } )( jQuery ); -
scss/main.scss
diff --git scss/main.scss scss/main.scss index 585d30c..0627bf0 100644
792 792 padding: 20px; 793 793 } 794 794 } 795 796 .source-code-container { 797 overflow: hidden; 798 } 799 800 .show-complete-source { 801 display: none; 802 } 803 795 804 .loop-pagination { 796 805 text-align: center; 797 806 font-size: 18px; -
stylesheets/main.css
diff --git stylesheets/main.css stylesheets/main.css index 3d9eae4..29b6822 100644
input { 1015 1015 border-radius: 5px; 1016 1016 padding: 20px; 1017 1017 } 1018 .devhub-wrap .source-code-container { 1019 overflow: hidden; 1020 } 1021 .devhub-wrap .show-complete-source { 1022 display: none; 1023 } 1018 1024 .devhub-wrap .loop-pagination { 1019 1025 text-align: center; 1020 1026 font-size: 18px;