Changeset 1429
- Timestamp:
- 03/19/2015 10:36:17 PM (9 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/handbooks.php
r954 r1429 45 45 add_action( 'wporg_action_links', array( 'WPorg_Handbook_Watchlist', 'display_action_link' ) ); 46 46 } 47 48 // Modify SyntaxHighlighter Evolved code output to facilitate code collapse/expand. 49 add_filter( 'syntaxhighlighter_htmlresult', array( __CLASS__, 'syntaxhighlighter_htmlresult' ) ); 50 } 51 52 /** 53 * Is the current (or specified) post_type one of the DevHub handbook post types? 54 * 55 * TOOD: The handbook plugin should probably have this. 56 * 57 * @param string $post_type Optional. The post_type to check for being a handbook post type. Default '' (the current post type). 58 * @return bool 59 */ 60 public static function is_handbook_post_type( $post_type = '' ) { 61 if ( ! $post_type ) { 62 $post_type = get_post_type(); 63 } 64 65 return in_array( str_replace( '-handbook', '', $post_type ), self::$post_types ); 66 } 67 68 /** 69 * If a syntax highlighted code block exceeds a given number of lines, wrap the 70 * markup with other markup to trigger the code expansion/collapse JS handling 71 * already implemented for the code reference. 72 * 73 * @param string $text The pending result of the syntax highlighting. 74 * @return string 75 */ 76 public static function syntaxhighlighter_htmlresult( $text ) { 77 $new_text = ''; 78 // Collapse is handled for >10 lines. But just go ahead and show the full 79 // code if that is just barely being exceeded (no one wants to expand to 80 // see one or two more lines). 81 $lines_to_show = 12; 82 $do_collapse = ( substr_count( $text, "\n" ) - 1 ) > $lines_to_show; 83 84 if ( $do_collapse ) { 85 $new_text .= '<section class="source-content">'; 86 $new_text .= '<div class="source-code-container">'; 87 } 88 89 $new_text .= $text; 90 91 if ( $do_collapse ) { 92 $new_text .= '</div>'; 93 $new_text .= '<p class="source-code-links"><span>'; 94 $new_text .= '<a href="#" class="show-complete-source">' . __( 'Expand full source code', 'wporg' ) . '</a>'; 95 $new_text .= '<a href="#" class="less-complete-source">' . __( 'Collapse full source code', 'wporg' ) . '</a>'; 96 $new_text .= '</span></p>'; 97 $new_text .= '</section>'; 98 } 99 100 return $new_text; 47 101 } 48 102 -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/user-content.php
r1198 r1429 66 66 public static function scripts_and_styles() { 67 67 if ( is_singular() ) { 68 if ( '0' != get_comments_number() || \DevHub\post_type_has_source_code() ) {68 if ( '0' != get_comments_number() || \DevHub\post_type_has_source_code() || Devhub_Handbooks::is_handbook_post_type() ) { 69 69 wp_enqueue_script( 'wporg-developer-function-reference', get_template_directory_uri() . '/js/function-reference.js', array( 'jquery', 'syntaxhighlighter-core', 'syntaxhighlighter-brush-php' ), '20150126', true ); 70 70 wp_enqueue_style( 'syntaxhighlighter-core' ); -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/js/function-reference.js
r1196 r1429 7 7 'use strict'; 8 8 9 var $sourceCo ntent, $sourceCodeContainer, $sourceCodeTable, $showCompleteSource, $lessCompleteSource, sourceCollapsedHeight;9 var $sourceCollapsedHeight; 10 10 11 11 var $usesList, $usedByList, $showMoreUses, $hideMoreUses, $showMoreUsedBy, $hideMoreUsedBy; … … 24 24 } 25 25 26 // We only expect one source-content per document27 $sourceContent = $( '.source-content' );28 $sourceCodeContainer = $( '.source-code-container' );29 30 26 SyntaxHighlighter.highlight(); 31 32 $sourceCodeTable = $sourceContent.find( 'table' );33 27 34 28 // 1em (margin) + 10 * 17px + 10. Lines are 1.1em which rounds to 17px: calc( 1em + 17px * 10 + 10 ). 35 29 // Extra 10px added to partially show next line so it's clear there is more. 36 sourceCollapsedHeight = 196;30 $sourceCollapsedHeight = 196; 37 31 38 if ( ( sourceCollapsedHeight - 12 ) < $sourceCodeTable.height() ) { 32 $( '.source-content' ).find( 'table' ).each( function( t ) { 33 if ( ( $sourceCollapsedHeight - 12 ) < $( this ).height() ) { 39 34 40 // Do this with javascript so javascript-less can enjoy the total sourcecode 41 $( '.source-code-container' ).css( { height: sourceCollapsedHeight + 'px' } ); 35 var sourceContent = $( this ).closest( '.source-content' ); 42 36 43 $showCompleteSource = $( '.show-complete-source' );44 $lessCompleteSource = $( '.less-complete-source');37 // Do this with javascript so javascript-less can enjoy the total sourcecode 38 sourceContent.find( '.source-code-container' ).css( { height: $sourceCollapsedHeight + 'px' } ); 45 39 46 $( '.source-code-links span:first' ).show(); 47 $showCompleteSource.show(); 48 $showCompleteSource.on( 'click', toggleCompleteSource ); 49 $lessCompleteSource.on( 'click', toggleCompleteSource ); 50 } 40 sourceContent.find( '.source-code-links').find('span:first' ).show(); 41 sourceContent.find( '.show-complete-source' ).show(); 42 sourceContent.find( '.show-complete-source' ).on( 'click', toggleCompleteSource ); 43 sourceContent.find( '.less-complete-source' ).on( 'click', toggleCompleteSource ); 44 } 45 } ); 51 46 } 52 47 … … 54 49 e.preventDefault(); 55 50 56 if ( $showCompleteSource.is(':visible') ) { 57 var heightGoal = $sourceCodeTable.height() + 45; // takes into consideration potential x-scrollbar 51 var sourceContent = $( this ).closest( '.source-content' ); 52 53 if ( $( this ).parent().find( '.show-complete-source' ).is( ':visible' ) ) { 54 var heightGoal = sourceContent.find( 'table' ).height() + 45; // takes into consideration potential x-scrollbar 58 55 } else { 59 var heightGoal = sourceCollapsedHeight;56 var heightGoal = $sourceCollapsedHeight; 60 57 } 61 58 62 $sourceCodeContainer.animate( { height: heightGoal + 'px' } );59 sourceContent.find( '.source-code-container:first' ).animate( { height: heightGoal + 'px' } ); 63 60 64 $showCompleteSource.toggle(); 65 $lessCompleteSource.toggle(); 66 61 $( this ).parent().find( 'a' ).toggle(); 67 62 } 68 63 -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/scss/main.scss
r1380 r1429 1063 1063 } 1064 1064 1065 .source-code-links span { 1066 border-left: 1px solid #999; 1067 margin-left: 1em; 1068 padding-left: 1em; 1069 } 1070 1065 1071 .source-code-links span:first-child { 1066 1072 display: none; 1067 border- right: 1px solid #999;1068 margin- right: 1em;1069 padding- right: 1em;1073 border-left: 0; 1074 margin-left: 1em; 1075 padding-left: 0; 1070 1076 } 1071 1077 -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/stylesheets/main.css
r1380 r1429 1242 1242 margin-top: 1em; 1243 1243 } 1244 .devhub-wrap .source-code-links span { 1245 border-left: 1px solid #999; 1246 margin-left: 1em; 1247 padding-left: 1em; 1248 } 1244 1249 .devhub-wrap .source-code-links span:first-child { 1245 1250 display: none; 1246 border- right: 1px solid #999;1247 margin- right: 1em;1248 padding- right: 1em;1251 border-left: 0; 1252 margin-left: 1em; 1253 padding-left: 0; 1249 1254 } 1250 1255 .devhub-wrap .source-code-container {
Note: See TracChangeset
for help on using the changeset viewer.