Ticket #323: 323.2.diff
| File 323.2.diff, 15.2 KB (added by , 12 years ago) |
|---|
-
content-reference-archive.php
diff --git a/content-reference-archive.php b/content-reference-archive.php index 345fa49..825c27e 100644
a b 17 17 <p>Source: <?php echo get_source_file(); ?>:<?php echo get_line_number(); ?></p> 18 18 </div> 19 19 20 <?php 21 $used_by = get_used_by()->post_count; 22 $uses = get_uses()->post_count; 23 ?> 24 <div class="meta"> 25 Used by <a href="<?php the_permalink(); ?>#usage"><?php printf( _n( '1 function', '%d functions', $used_by ), $used_by ); ?></a> 26 | 27 Uses <a href="<?php the_permalink(); ?>#usage"><?php printf( _n( '1 function', '%d functions', $uses ), $uses ); ?></a> 28 <?php /* 29 | 30 <a href="<?php the_permalink(); ?>#examples">2 examples</a> 31 */ ?> 32 </div> 20 33 </article> 34 No newline at end of file -
content-reference.php
diff --git a/content-reference.php b/content-reference.php index 6b0030c..cb93b23 100644
a b 44 44 </section> 45 45 <?php endif; ?> 46 46 47 <?php /* 48 <?php if ( is_archive() ) : ?> 49 <section class="meta">Used by TODO | Uses TODO | TODO Examples</section> 47 <?php if ( show_usage_info() ) : ?> 48 <hr id="usage" /> 49 <section class="usage"> 50 <article class="used-by"> 51 <h2><?php _e( 'Used by', 'wporg' ); ?></h2> 52 <ul> 53 <?php 54 $used_by = get_used_by(); 55 while ( $used_by->have_posts() ) : $used_by->the_post(); 56 ?> 57 <li> 58 <strong><?php echo esc_attr( get_source_file() ); ?>:</strong> 59 <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> 60 </li> 61 <?php endwhile; wp_reset_postdata(); ?> 62 <?php if ( $used_by->post_count > 5 ) : ?> 63 <a href="#" class="show-more"><?php printf( _n( 'Show 1 more used by', 'Show %d more used by', $used_by->post_count, 'wporg' ), $used_by->post_count ); ?></a> 64 <a href="#" class="hide-more"><?php _e( 'Hide more used by', 'wporg' ); ?></a> 65 <?php endif; ?> 66 </ul> 67 </article> 68 <?php if ( post_type_has_uses_info() ) : ?> 69 <article class="uses"> 70 <h2><?php _e( 'Uses', 'wporg' ); ?></h2> 71 <ul> 72 <?php 73 $uses = get_uses(); 74 while ( $uses->have_posts() ) : $uses->the_post() 75 ?> 76 <li> 77 <strong><?php echo esc_attr( get_source_file() ); ?>:</strong> 78 <a href="<?php the_permalink(); ?>"><?php the_title(); ?> 79 <?php if ( 'wp-parser-hook' !== get_post_type() ) : ?>()<?php endif; ?></a> 80 </li> 81 <?php endwhile; wp_reset_postdata(); ?> 82 <?php if ( $uses->post_count > 5 ) : ?> 83 <a href="#" class="show-more"><?php printf( _n( 'Show 1 more use', 'Show %d more uses', $uses->post_count, 'wporg' ), $uses->post_count ); ?></a> 84 <a href="#" class="hide-more"><?php _e( 'Hide more uses', 'wporg' ); ?></a> 85 <?php endif; ?> 86 </ul> 87 </article> 88 <?php endif; ?> 89 </section> 50 90 <?php endif; ?> 51 */ ?>52 91 53 92 <?php 54 93 ob_start(); -
inc/template-tags.php
diff --git a/inc/.DS_Store b/inc/.DS_Store deleted file mode 100644 index 5008ddf..0000000 Binary files a/inc/.DS_Store and /dev/null differ diff --git a/inc/template-tags.php b/inc/template-tags.php index 1212318..5c7f0f5 100755
a b function compare_objects_by_name( $a, $b ) { 700 700 return strcmp( $a->post_name, $b->post_name ); 701 701 } 702 702 703 function show_usage_info() { 704 $p2p_enabled = function_exists( 'p2p_register_connection_type' ); 705 706 return $p2p_enabled && post_type_has_usage_info( get_post_type() ); 707 } 708 709 /** 710 * Does the post type support usage information? 711 * 712 * @param string $post_type Optional. The post type name. If blank, assumes current post type. 713 * 714 * @return boolean 715 */ 716 function post_type_has_usage_info( $post_type = null ) { 717 $post_type = $post_type ? $post_type : get_post_type(); 718 $post_types_with_usage = array( 'wp-parser-function', 'wp-parser-method', 'wp-parser-hook' ); 719 720 return in_array( $post_type, $post_types_with_usage ); 721 } 722 723 /** 724 * Does the post type support uses information? 725 * 726 * @param string $post_type Optional. The post type name. If blank, assumes current post type. 727 * 728 * @return boolean 729 */ 730 function post_type_has_uses_info( $post_type = null ) { 731 $post_type = $post_type ? $post_type : get_post_type(); 732 $post_types_with_uses = array( 'wp-parser-function', 'wp-parser-method' ); 733 734 return in_array( $post_type, $post_types_with_uses ); 735 } 736 737 /** 738 * Retrieve a WP_Query object for the posts that the current post uses 739 * 740 * @return WP_Query A WP_Query object for the posts the current post uses 741 */ 742 function get_uses() { 743 744 if ( 'wp-parser-function' === get_post_type() ) { 745 $connection_types = array( 'functions_to_functions', 'functions_to_methods', 'functions_to_hooks' ); 746 } else { 747 $connection_types = array( 'methods_to_functions', 'methods_to_methods', 'methods_to_hooks' ); 748 } 749 750 $connected = new \WP_Query( array( 751 'post_type' => array( 'wp-parser-function', 'wp-parser-method', 'wp-parser-hook' ), 752 'connected_type' => $connection_types, 753 'connected_direction' => array( 'from', 'from', 'from' ), 754 'connected_items' => get_the_ID(), 755 'nopaging' => true, 756 ) ); 757 758 return $connected; 759 } 760 761 function get_used_by( $post_id = null ) { 762 763 if ( empty( $post_id ) ) { 764 $post_id = get_the_ID(); 765 } 766 767 switch ( get_post_type() ) { 768 769 case 'wp-parser-function': 770 $connection_types = array( 'functions_to_functions', 'methods_to_functions' ); 771 break; 772 773 case 'wp-parser-method': 774 $connection_types = array( 'functions_to_methods', 'methods_to_methods', ); 775 break; 776 777 case 'wp-parser-hook': 778 $connection_types = array( 'functions_to_hooks', 'methods_to_hooks' ); 779 break; 780 } 781 782 $connected = new \WP_Query( array( 783 'post_type' => array( 'wp-parser-function', 'wp-parser-method' ), 784 'connected_type' => $connection_types, 785 'connected_direction' => array( 'to', 'to' ), 786 'connected_items' => $post_id, 787 'nopaging' => true, 788 ) ); 789 790 return $connected; 791 } 792 703 793 /** 704 794 * Does the post type have source code? 705 795 * -
inc/user-content.php
diff --git a/inc/user-content.php b/inc/user-content.php index e85cf3e..c7dbca6 100644
a b public static function do_init() { 61 61 * Enqueues scripts and styles. 62 62 */ 63 63 public static function scripts_and_styles() { 64 if ( is_singular() && ( '0' != get_comments_number() || \DevHub\post_type_has_source_code() ) ) { 65 wp_enqueue_script( 'wporg-developer-function-reference', get_template_directory_uri() . '/js/function-reference.js', array( 'jquery', 'syntaxhighlighter-core', 'syntaxhighlighter-brush-php' ), '20140515', true ); 66 wp_enqueue_style( 'syntaxhighlighter-core' ); 67 wp_enqueue_style( 'syntaxhighlighter-theme-default' ); 68 69 wp_enqueue_script( 'wporg-developer-user-notes', get_template_directory_uri() . '/js/user-notes.js', array(), '20140912', true ); 70 if ( get_option( 'thread_comments' ) ) { 71 wp_enqueue_script( 'comment-reply' ); 64 if ( is_singular() ) { 65 wp_enqueue_script( 'wporg-developer-function-reference', get_template_directory_uri() . '/js/function-reference.js', array( 'jquery' ), '20140515', true ); 66 67 if ( \DevHub\post_type_has_source_code() ) { 68 wp_enqueue_script( 'syntaxhighlighter-core' ); 69 wp_enqueue_script( 'syntaxhighlighter-brush-php' ); 70 71 wp_enqueue_style( 'syntaxhighlighter-core' ); 72 wp_enqueue_style( 'syntaxhighlighter-theme-default' ); 73 } 74 75 if ( '0' != get_comments_number() ) { 76 wp_enqueue_script( 'wporg-developer-user-notes', get_template_directory_uri() . '/js/user-notes.js', array(), '20140912', true ); 77 78 if ( get_option( 'thread_comments' ) ) { 79 wp_enqueue_script( 'comment-reply' ); 80 } 72 81 } 73 82 } 74 83 } -
js/function-reference.js
diff --git a/js/function-reference.js b/js/function-reference.js index ee80690..99c177b 100644
a b 4 4 * Handles all interactivity on the single function page 5 5 */ 6 6 ( function( $ ) { 7 var $sourceContent, $sourceCodeContainer, $sourceCodeTable, $showCompleteSource, $lessCompleteSource, sourceCollapsedHeight; 8 9 function toggleCompleteSource( e ) { 10 e.preventDefault(); 7 'use strict'; 11 8 12 if ( $showCompleteSource.is(':visible') ) { 13 var heightGoal = $sourceCodeTable.height() + 45; // takes into consideration potential x-scrollbar 14 } else { 15 var heightGoal = sourceCollapsedHeight; 16 } 9 var $sourceContent, $sourceCodeContainer, $sourceCodeTable, $showCompleteSource, $lessCompleteSource, sourceCollapsedHeight; 17 10 18 $sourceCodeContainer.animate( { height: heightGoal + 'px' } );11 var $usesList, $usedByList, $showMoreUses, $hideMoreUses, $showMoreUsedBy, $hideMoreUsedBy; 19 12 20 $showCompleteSource.toggle();21 $lessCompleteSource.toggle();13 function onLoad() { 14 sourceCodeHighlightInit(); 22 15 16 toggleUsageListInit(); 23 17 } 24 18 25 function onLoad() { 19 function sourceCodeHighlightInit() { 20 21 // We require the SyntaxHighlighter javascript library 22 if ( undefined === window.SyntaxHighlighter ) { 23 return; 24 } 26 25 27 26 // We only expect one source-content per document 28 27 $sourceContent = $( '.source-content' ); … … 49 48 $showCompleteSource.on( 'click', toggleCompleteSource ); 50 49 $lessCompleteSource.on( 'click', toggleCompleteSource ); 51 50 } 51 } 52 53 function toggleCompleteSource( e ) { 54 e.preventDefault(); 55 56 if ( $showCompleteSource.is(':visible') ) { 57 var heightGoal = $sourceCodeTable.height() + 45; // takes into consideration potential x-scrollbar 58 } else { 59 var heightGoal = sourceCollapsedHeight; 60 } 61 62 $sourceCodeContainer.animate( { height: heightGoal + 'px' } ); 63 64 $showCompleteSource.toggle(); 65 $lessCompleteSource.toggle(); 66 67 } 68 69 function toggleUsageListInit() { 70 71 // We only expect one used_by and uses per document 72 $usedByList = $( '.used-by' ).find( 'li' ); 73 $usesList = $( '.uses' ).find( 'li' ); 74 75 if ( $usedByList.length > 5 ) { 76 $usedByList = $usedByList.slice( 5 ).hide(); 77 78 $showMoreUsedBy = $( '.used-by .show-more' ).show().on( 'click', toggleMoreUsedBy ); 79 $hideMoreUsedBy = $( '.used-by .hide-more' ).on( 'click', toggleMoreUsedBy ); 80 } 81 82 if ( $usesList.length > 5 ) { 83 $usesList = $usesList.slice( 5 ).hide(); 84 85 $showMoreUses = $( '.uses .show-more' ).show().on( 'click', toggleMoreUses ); 86 $hideMoreUses = $( '.uses .hide-more' ).on( 'click', toggleMoreUses ); 87 } 88 } 89 90 function toggleMoreUses( e ) { 91 e.preventDefault(); 92 93 $usesList.toggle(); 94 95 $showMoreUses.toggle(); 96 $hideMoreUses.toggle(); 97 } 98 99 function toggleMoreUsedBy( e ) { 100 e.preventDefault(); 101 102 $usedByList.toggle(); 52 103 104 $showMoreUsedBy.toggle(); 105 $hideMoreUsedBy.toggle(); 53 106 } 54 107 55 108 $( onLoad ); -
new file scss/_mixins.scss
diff --git a/scss/_mixins.scss b/scss/_mixins.scss new file mode 100644 index 0000000..62aae3c
- + 1 @mixin clearfix { 2 &:before, 3 &:after { 4 content: " "; 5 display: table; 6 } 7 8 &:after { 9 clear: both; 10 } 11 } 12 No newline at end of file -
scss/main.scss
diff --git a/scss/main.scss b/scss/main.scss index 897267b..67a0ab5 100644
a b 1 1 @import "reset"; 2 2 @import "global"; 3 3 4 @import "mixins"; 5 4 6 .home .devhub-wrap { 5 7 #content { 6 8 padding: 0; … … 886 888 } 887 889 .wp-parser-class, .wp-parser-function, .wp-parser-hook, .wp-parser-method { 888 890 border-bottom: 1px solid #dfdfdf; 891 892 @include clearfix(); 889 893 h1 { 890 894 margin: 24px 0; 891 895 padding-left: 100px; … … 966 970 } 967 971 } 968 972 973 /* = Usage 974 ----------------------------------------------- */ 975 .usage { 976 @include clearfix; 977 978 article { 979 float: left; 980 width: 50%; 981 } 982 983 .used-by { 984 padding-right: 30px; 985 } 986 987 .uses { 988 padding-left: 30px; 989 } 990 991 ul { 992 line-height: 1.7; // Slightly increase the line height for more readability 993 list-style-type: none; 994 margin: 0; 995 } 996 997 .show-more, .hide-more { 998 display: none; 999 } 1000 } 1001 1002 969 1003 .source-content { 970 1004 overflow: auto; 971 1005 } … … 1203 1237 } 1204 1238 } 1205 1239 } 1240 1241 &.archive, &.search { 1242 .meta { 1243 font-size: 100%; 1244 margin-bottom: 1.5em; 1245 1246 a { 1247 color: #21759b; 1248 } 1249 } 1250 } 1206 1251 } 1207 1252 1208 1253 @media ( max-width: 59.999999em ) { … … 1229 1274 } 1230 1275 } 1231 1276 1277 @media ( min-width: 43em ) { 1278 .devhub-wrap { 1279 &.archive, &.search { 1280 .meta { 1281 float: right; 1282 } 1283 1284 .sourcefile { 1285 float: left; 1286 } 1287 } 1288 } 1289 } 1290 1232 1291 @media ( max-width: 43em ) { 1233 1292 1234 1293 #content-area.has-sidebar { … … 1313 1372 .two-columns .box { 1314 1373 width: 99%; 1315 1374 } 1375 1376 .usage { 1377 article { 1378 width: 100%; 1379 } 1380 } 1316 1381 } 1317 1382 } 1383 No newline at end of file -
stylesheets/main.css
diff --git a/stylesheets/main.css b/stylesheets/main.css index db6736e..8cf0cb0 100644
a b input { 298 298 /* 299 299 * section styles 300 300 */ 301 /* = Usage 302 ----------------------------------------------- */ 301 303 /* Comments */ 302 304 /* 303 305 * Content … … input { 1097 1099 .devhub-wrap .wp-parser-class, .devhub-wrap .wp-parser-function, .devhub-wrap .wp-parser-hook, .devhub-wrap .wp-parser-method { 1098 1100 border-bottom: 1px solid #dfdfdf; 1099 1101 } 1102 .devhub-wrap .wp-parser-class:before, .devhub-wrap .wp-parser-class:after, .devhub-wrap .wp-parser-function:before, .devhub-wrap .wp-parser-function:after, .devhub-wrap .wp-parser-hook:before, .devhub-wrap .wp-parser-hook:after, .devhub-wrap .wp-parser-method:before, .devhub-wrap .wp-parser-method:after { 1103 content: " "; 1104 display: table; 1105 } 1106 .devhub-wrap .wp-parser-class:after, .devhub-wrap .wp-parser-function:after, .devhub-wrap .wp-parser-hook:after, .devhub-wrap .wp-parser-method:after { 1107 clear: both; 1108 } 1100 1109 .devhub-wrap .wp-parser-class h1, .devhub-wrap .wp-parser-function h1, .devhub-wrap .wp-parser-hook h1, .devhub-wrap .wp-parser-method h1 { 1101 1110 margin: 24px 0; 1102 1111 padding-left: 100px; … … input { 1157 1166 .devhub-wrap .single .wp-parser-class, .devhub-wrap .single .wp-parser-function, .devhub-wrap .single .wp-parser-hook, .devhub-wrap .single .wp-parser-method { 1158 1167 border-bottom-style: none; 1159 1168 } 1169 .devhub-wrap .usage:before, .devhub-wrap .usage:after { 1170 content: " "; 1171 display: table; 1172 } 1173 .devhub-wrap .usage:after { 1174 clear: both; 1175 } 1176 .devhub-wrap .usage article { 1177 float: left; 1178 width: 50%; 1179 } 1180 .devhub-wrap .usage .used-by { 1181 padding-right: 30px; 1182 } 1183 .devhub-wrap .usage .uses { 1184 padding-left: 30px; 1185 } 1186 .devhub-wrap .usage ul { 1187 line-height: 1.7; 1188 list-style-type: none; 1189 margin: 0; 1190 } 1191 .devhub-wrap .usage .show-more, .devhub-wrap .usage .hide-more { 1192 display: none; 1193 } 1160 1194 .devhub-wrap .source-content { 1161 1195 overflow: auto; 1162 1196 } … … input { 1331 1365 .devhub-wrap ul.items li a { 1332 1366 color: #555 !important; 1333 1367 } 1368 .devhub-wrap.archive .meta, .devhub-wrap.search .meta { 1369 font-size: 100%; 1370 margin-bottom: 1.5em; 1371 } 1372 .devhub-wrap.archive .meta a, .devhub-wrap.search .meta a { 1373 color: #21759b; 1374 } 1334 1375 1335 1376 @media (max-width: 60em) { 1336 1377 .devhub-wrap { … … input { 1351 1392 padding-left: 0; 1352 1393 } 1353 1394 } 1395 @media (min-width: 43em) { 1396 .devhub-wrap.archive .meta, .devhub-wrap.search .meta { 1397 float: right; 1398 } 1399 .devhub-wrap.archive .sourcefile, .devhub-wrap.search .sourcefile { 1400 float: left; 1401 } 1402 } 1354 1403 @media (max-width: 43em) { 1355 1404 #content-area.has-sidebar main { 1356 1405 float: right; … … input { 1423 1472 .devhub-wrap .two-columns .box { 1424 1473 width: 99%; 1425 1474 } 1475 .devhub-wrap .usage article { 1476 width: 100%; 1477 } 1426 1478 }