Changeset 466654
- Timestamp:
- 11/23/2011 06:06:12 PM (13 years ago)
- Location:
- tdd-progress-bar/trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
tdd-progress-bar/trunk/css/default.css
r464667 r466654 18 18 19 19 .red { 20 background-position -y:0;20 background-position0; 21 21 } 22 22 23 23 .race .red { 24 background-position -y:-12px;24 background-position-12px; 25 25 } 26 26 27 27 .orange { 28 background-position -y:-50px;28 background-position-50px; 29 29 } 30 30 31 31 .race .orange { 32 background-position -y:-62px;32 background-position-62px; 33 33 } 34 34 35 35 .yellow { 36 background-position -y:-100px;36 background-position-100px; 37 37 } 38 38 39 39 .race .yellow { 40 background-position -y:-112px;40 background-position-112px; 41 41 } 42 42 43 43 .green { 44 background-position -y:-150px;44 background-position-150px; 45 45 } 46 46 47 47 .race .green { 48 background-position -y:-162px;48 background-position-162px; 49 49 } 50 50 51 51 .teal { 52 background-position -y:-200px;52 background-position-200px; 53 53 } 54 54 55 55 .race .teal { 56 background-position -y:-212px;56 background-position-212px; 57 57 } 58 58 59 59 .lightblue { 60 background-position -y:-250px;60 background-position-250px; 61 61 } 62 62 63 63 .race .lightblue { 64 background-position -y:-262px;64 background-position-262px; 65 65 } 66 66 67 67 .blue { 68 background-position -y:-300px;68 background-position-300px; 69 69 } 70 70 71 71 .race .blue { 72 background-position -y:-312px;72 background-position-312px; 73 73 } 74 74 75 75 .purple { 76 background-position -y:-350px;76 background-position-350px; 77 77 } 78 78 79 79 .race .purple { 80 background-position -y:-362px;80 background-position-362px; 81 81 } 82 82 83 83 .fuchsia { 84 background-position -y:-400px;84 background-position-400px; 85 85 } 86 86 87 87 .race .fuchsia { 88 background-position -y:-415px;88 background-position-415px; 89 89 } 90 90 91 91 .strawberry { 92 background-position -y:-450px;92 background-position-450px; 93 93 } 94 94 95 95 .race .strawberry { 96 background-position -y:-415px;96 background-position5px; 97 97 } 98 98 -
tdd-progress-bar/trunk/inc/admin.php
r464689 r466654 1 1 <?php 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 2 19 /* 3 20 * Setup custom meta boxes for the tdd_bp custom post type page 4 21 */ 5 22 function tdd_pb_metabox_create() { 6 add_meta_box( 'tdd_pb_meta', 'Progress Bar Options', 'tdd_pb_metabox_display', 'tdd_pb' );23 add_meta_box( 'tdd_pb_meta', , 'tdd_pb_metabox_display', 'tdd_pb' ); 7 24 } 8 25 add_action( 'add_meta_boxes', 'tdd_pb_metabox_create' ); 9 26 27 28 29 10 30 function tdd_pb_metabox_display($post) { 11 /*12 bar specific options:13 - color/graphic14 - percentage (or API call)15 */16 31 $tdd_pb_color = get_post_meta( $post->ID, '_tdd_pb_color', true ); 17 32 $tdd_pb_percentage = get_post_meta( $post->ID, '_tdd_pb_percentage', true ); 18 19 33 ?> 20 34 … … 23 37 <th scope="row"><label for="td_pb_color">Bar Color</label></th> 24 38 <td><select name="tdd_pb_color"> 25 <option value="strawberry" <?php selected( $tdd_pb_color, 'strawberry' ); ?>>Strawberry</option> 26 <option value="fuchsia" <?php selected( $tdd_pb_color, 'fuchsia' ); ?>>Fuchsia</option> 27 <option value="purple" <?php selected( $tdd_pb_color, 'purple' ); ?>>Purple</option> 28 <option value="blue" <?php selected( $tdd_pb_color, 'blue' ); ?>>Blue</option> 29 <option value="lightblue" <?php selected( $tdd_pb_color, 'lightblue' ); ?>>Light Blue</option> 30 <option value="teal" <?php selected( $tdd_pb_color, 'teal' ); ?>>Teal</option> 31 <option value="green" <?php selected( $tdd_pb_color, 'green' ); ?>>Green</option> 32 <option value="yellow" <?php selected( $tdd_pb_color, 'yellow' ); ?>>Yellow</option> 33 <option value="orange" <?php selected( $tdd_pb_color, 'orange' ); ?>>Orange</option> 34 <option value="red" <?php selected( $tdd_pb_color, 'red' ); ?>>Red</option> 39 <?php global $colors; ?> 40 <?php foreach ($colors as $color=>$label ): ?> 41 <option value="<?php echo $color; ?>" <?php selected( $tdd_pb_color, $color ); ?>"><?php echo $label; ?></option> 42 <?php endforeach; ?> 35 43 </select></td> 36 44 </tr> … … 40 48 </tr> 41 49 </table> 42 43 <p>Example shortcode: <code>[progress id=<?php the_ID(); ?>]</code> </p> 50 <?php $id = get_the_ID(); ?> 51 <p><?php _e( "Example shortcode: <code>[progress id={$id}]</code>", 'tdd_pb'); ?> </p> 52 53 <?php echo tdd_pb_get_bars( array( 54 'ids' => array( get_the_ID() ), 55 'class' => 'race', 56 ) ); 57 ?> 58 44 59 <?php 45 60 } … … 68 83 unset($columns['date']); 69 84 return array_merge($columns, 70 array('percentage' => 'Percentage', 71 'color' => 'Color' , 85 array('progress_bar' => 'Progress Bar', 72 86 'shortcode' => 'Shortcode', 73 87 'date' => __('Date'), … … 84 98 85 99 switch ( $column ){ 86 case 'color': 87 echo get_post_meta( $post->ID, '_tdd_pb_color', true ); 88 break; 89 case 'percentage': 90 echo get_post_meta( $post->ID, '_tdd_pb_percentage', true ) . '% complete'; 100 case 'progress_bar': 101 echo tdd_pb_get_bars( array( 102 'ids' => array( $post->ID ), 103 'class' => 'race', 104 ) ); 105 91 106 break; 92 107 case 'shortcode': 93 echo '<code>[progress id='. $post->ID .'] ';108 echo '<code>[progress id='. $post->ID .']'; 94 109 break; 95 110 } 96 111 } 97 112 add_action( 'manage_posts_custom_column' , 'tdd_pb_custom_columns' ); 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 98 225 99 226 … … 107 234 <div class="wrap"> 108 235 <?php screen_icon( 'plugins' ); ?> 109 <h2> TDD Progress Bars</h2>236 <h2></h2> 110 237 111 238 <form action="options.php" method="post"> 112 239 <?php settings_fields( 'tdd_pb_options' ); ?> 113 240 <?php do_settings_sections( __FILE__ ); ?> 114 <input name="Submit" type="submit" value=" Save Changes" class="button-primary" />241 <input name="Submit" type="submit" value="" class="button-primary" /> 115 242 </form> 116 243 </div> … … 123 250 124 251 //register Scripts and Styles section & controls 125 add_settings_section( 'tdd_pb_sas', 'Scripts and Styles', 'tdd_pb_admin_sasheader', __FILE__ );126 add_settings_field( 'animate', 'Animate Bars', 'tdd_pb_admin_form_animate', __FILE__ , 'tdd_pb_sas' );127 add_settings_field( 'default_css', 'Use Default CSS', 'tdd_pb_admin_form_default_css', __FILE__, 'tdd_pb_sas');252 add_settings_section( 'tdd_pb_sas', , 'tdd_pb_admin_sasheader', __FILE__ ); 253 add_settings_field( 'animate', , 'tdd_pb_admin_form_animate', __FILE__ , 'tdd_pb_sas' ); 254 add_settings_field( 'default_css', , 'tdd_pb_admin_form_default_css', __FILE__, 'tdd_pb_sas'); 128 255 129 256 //register Percent section & controls 130 add_settings_section( 'tdd_pb_percent', 'Percentage Displays', 'tdd_pb_admin_percentheader', __FILE__ );131 add_settings_field( 'display_percentage', 'Display Percent Complete', 'tdd_pb_admin_form_perecent_display', __FILE__, 'tdd_pb_percent' );132 add_settings_field( 'percentage_color', 'Color of Percentage Text', 'tdd_pb_admin_form_percentage_color', __FILE__, 'tdd_pb_percent' );133 add_settings_field( 'bar_background_color', 'Color of Bar Background', 'tdd_pb_admin_form_bar_background_color', __FILE__, 'tdd_pb_percent' );257 add_settings_section( 'tdd_pb_percent', , 'tdd_pb_admin_percentheader', __FILE__ ); 258 add_settings_field( 'display_percentage', , 'tdd_pb_admin_form_perecent_display', __FILE__, 'tdd_pb_percent' ); 259 add_settings_field( 'percentage_color', , 'tdd_pb_admin_form_percentage_color', __FILE__, 'tdd_pb_percent' ); 260 add_settings_field( 'bar_background_color', , 'tdd_pb_admin_form_bar_background_color', __FILE__, 'tdd_pb_percent' ); 134 261 135 262 } … … 138 265 //Scripts & Styles section header 139 266 function tdd_pb_admin_sasheader(){ 140 echo "<p>The following two boxes allow you to stop including the animation javascript and the default CSS on each page load. It's highly suggested that you don't turn off the Default CSS option unless you have a replacement in mind. The Animate Bars option can be turned off freely if you'd prefer the bars didn't have that cool animation (or you want to save HTTP requests).</p>";267 ; 141 268 } 142 269 … … 145 272 $options = get_option('tdd_pb_options'); 146 273 $checked = ($options['animate']) ? ' checked="checked" ' : ''; 147 echo "<input name='tdd_pb_options[animate]' id='animate' type='checkbox' ". $checked ."> <br /> 148 <small>This script depends on jQuery, so it will ensure that is loaded as well</small>";274 echo "<input name='tdd_pb_options[animate]' id='animate' type='checkbox' ". $checked ."> <br /> 275 ; 149 276 } 150 277 … … 159 286 //Percentage displays section header 160 287 function tdd_pb_admin_percentheader(){ 161 echo "<p>By default, the percentage progress is displayed in the bar. This allows you to optionally turn that off and/or set the color of the text</p>";288 ; 162 289 } 163 290 … … 173 300 function tdd_pb_admin_form_percentage_color(){ 174 301 $options = get_option('tdd_pb_options'); 175 echo "#<input name='tdd_pb_options[percentage_color]' id='percentage_color' type='text' value='{$options['percentage_color']}' maxlength='6' size='6' />";302 ; 176 303 } 177 304 -
tdd-progress-bar/trunk/js/animate.js
r464667 r466654 1 1 jQuery(document).ready(function($){ 2 2 3 var i = -700; 3 /* http://keith-wood.name/backgroundPos.html 4 Background position animation for jQuery v1.0.1. 5 Written by Keith Wood (kbwood{at}iinet.com.au) November 2010. 6 Dual licensed under the GPL (http://dev.jquery.com/browser/trunk/jquery/GPL-LICENSE.txt) and 7 MIT (http://dev.jquery.com/browser/trunk/jquery/MIT-LICENSE.txt) licenses. 8 Please attribute the author if you use it. */ 9 (function($){var g='bgPos';$.fx.step['backgroundPosition']=$.fx.step['background-position']=function(a){if(!a.set){var b=$(a.elem);var c=b.data(g);b.css('backgroundPosition',c);a.start=parseBackgroundPosition(c);a.end=parseBackgroundPosition($.fn.jquery>='1.6'?a.end:a.options.curAnim['backgroundPosition']||a.options.curAnim['background-position']);for(var i=0;i<a.end.length;i++){if(a.end[i][0]){a.end[i][1]=a.start[i][1]+(a.end[i][0]=='-='?-1:+1)*a.end[i][1]}}a.set=true}$(a.elem).css('background-position',((a.pos*(a.end[0][1]-a.start[0][1])+a.start[0][1])+a.end[0][2])+' '+((a.pos*(a.end[1][1]-a.start[1][1])+a.start[1][1])+a.end[1][2]))};function parseBackgroundPosition(c){var d={center:'50%',left:'0%',right:'100%',top:'0%',bottom:'100%'};var e=c.split(/ /);var f=function(a){var b=(d[e[a]]||e[a]||'50%').match(/^([+-]=)?([+-]?\d+(\.\d*)?)(.*)$/);e[a]=[b[1],parseFloat(b[2]),b[4]||'px']};if(e.length==1&&$.inArray(e[0],['top','bottom'])>-1){e[1]=e[0];e[0]='50%'}f(0);f(1);return e}$.fn.animate=function(e){return function(a,b,c,d){if(a['backgroundPosition']||a['background-position']){this.data(g,this.css('backgroundPosition')||'center')}return e.apply(this,[a,b,c,d])}}($.fn.animate)})(jQuery); 4 10 5 setInterval(function() {6 7 $('.tdd_pb_bar').animate( {'background-position-x': i}, 18000, 'linear' );8 i = i - 700;9 11 10 } , 1000); 12 //Width of graphic in pixels. Just to keep things logical. 13 //Also the amount that it will move every x seconds... 14 var i = -400; 11 15 12 }); 16 //for each .tdd_pb_bar, set a function that does this thing... 17 $('.tdd_pb_bar').each(function(index,value){ 18 19 //Get the background position (x and y), split into an array 20 var currbackgroundposn = $(value).css('background-position').split(' ', 2 ); 21 var x = Number(currbackgroundposn[0].split('px',1)); 22 var y = currbackgroundposn[1]; 23 24 //Run it once to start us off. 25 $(value).animate( {'background-position': i + 'px ' + y }, 15000, 'linear' ); 26 27 28 setInterval( function(){ 29 30 var currbackgroundposn = $(value).css('background-position').split(' ', 2 ); 31 var x = Number(currbackgroundposn[0].split('px',1)); 32 33 var posn = x+i + 'px ' + y; 34 35 $(value).animate( {'background-position': posn }, 15000, 'linear' ); 36 37 }, 15000 ); 38 39 }); // .each 40 41 42 }); //doc.ready -
tdd-progress-bar/trunk/readme.txt
r464689 r466654 5 5 Requires at least: 3.2.1 6 6 Tested up to: 3.2.1 7 Stable tag: 0.1. 27 Stable tag: 0.1. 8 8 9 9 A progress bar plugin solution. … … 42 42 == Changelog == 43 43 44 = 1.2 = 44 = 0.1.3= 45 * Given the major change to the CSS, the javascript to make things animate also had to change pretty extensively. One side effect is that the animations on a page will eventually slow to a standstill at the rate of about 1-2 pixels every 15 seconds or so. The animation is still a work in progress... 46 * Major bug fixes for the CSS to show up in, well, pretty much everything but Chrome. Didn't realize I was using an unsupported style. 47 * Small CSS fix for the "Strawberry" color - now shows up correctly 48 * Quick Edit mode on the "Manage Progress Bars" page now has the ability to change percentage and bar color. No need to specifically edit the progress bar now. 49 * Added the function tdd_pb_get_bars() function, which could be used in templates, but I'm going to leave undocumented for the moment so If it needs to change, it can. It's mostly designed for internal use. 50 * Added [tdd_pb] as a shortcode alias for [progress]. I think most people will use [progress], but I wanted to use [tdd_pb] since it's all over the code 51 * The Default CSS and Javascript are now added to the progress bar pages in wp-admin. 52 * Progress bars are now displayed in wp-admin on the "Manage Progress Bars" and the "Edit Progress Bar" screens 53 54 = 0.1.2 = 45 55 * Settings page actually works now 46 56 * Settings page now references __FILE__ instead of some arbitrary tag. 47 57 48 = 1.1 =58 = 1.1 = 49 59 * Left some debugging code for the advanced debug bar in the script. Have to remove it to make this thing work. 50 60 … … 54 64 == Upgrade Notice == 55 65 56 = 1.2 = 66 = 0.1.3 = 67 * Major fix for CSS and Javascript. Now works in Firefox (and likely other browsers, but still testing). 68 * Added some features to the "Manage Progress Bars" page 69 * If you use custom CSS (or javascript for that matter), you will need to also include it for use in wp-admin. See admin_enqueue_scripts for examples of how to do this. This is to enable the proper display of progress bars in wp-admin. Alternatively, you could leave the default styles checkbox on (which will enable them for the admin side as well), and remove the action that adds the styles to the public side. 70 71 = 0.1.2 = 57 72 * If you'd like the settings page to work, upgrade. 58 73 59 = 1.1 =74 = 1.1 = 60 75 * Blocking bugfix. Plugin won't work unless you upgrade 61 76 -
tdd-progress-bar/trunk/tdd-progress-bar.php
r464751 r466654 4 4 Plugin URI: http://github.com/tddewey/tdd-progress 5 5 Description: Manage and display progress bars 6 Version: 0.1. 26 Version: 0.1. 7 7 Author: Taylor D. Dewey 8 8 Author URI: http://websitesthatdontsuck.com … … 38 38 39 39 */ 40 41 42 43 44 45 46 47 48 49 50 40 51 $tdd_pb_options = get_option( 'tdd_pb_options'); 52 41 53 42 54 /* load some default settings during plugin activation */ … … 61 73 function tdd_pb_load_styles() { 62 74 wp_enqueue_style( 'tdd_pb_style', plugins_url( 'css/default.css', __FILE__ ), '', '.1' ); 75 63 76 } 64 77 65 78 if ( $tdd_pb_options['default_css'] ){ 66 79 add_action( 'init', 'tdd_pb_load_styles', 99 ); 80 67 81 } 68 82 … … 83 97 if ( $tdd_pb_options['animate'] ){ 84 98 add_action( 'init', 'tdd_pb_load_js', 99 ); 99 85 100 } 86 101 … … 93 108 function tdd_pb_register_post_type(){ 94 109 $labels = array( 95 'name' => 'Progress Bars',96 'singular_name' => 'Progress Bar',97 'add_new' => 'Add New Progress Bar',98 'add_new_item' => 'Add New Progress Bar',99 'edit_item' => 'Edit Progress Bar',100 'new_item' => 'New Progress Bar',101 'view_item' => 'View Progress Bar',102 'search_items' => 'Search Progress Bars',103 'not_found' => 'No Progress Bars Found',104 'not_found_in_trash' => 'No Progress Bars Found in the Trash',110 'name' => , 111 'singular_name' => , 112 'add_new' => , 113 'add_new_item' => , 114 'edit_item' => , 115 'new_item' => , 116 'view_item' => , 117 'search_items' => , 118 'not_found' => , 119 'not_found_in_trash' => , 105 120 ); 106 121 … … 140 155 * [progress ids=1] 141 156 * [progress ids=3,4 width='50px'] 142 */ 143 144 function tdd_pb_shortcode($args){ 145 $tdd_pb_options = get_option( 'tdd_pb_options'); 157 158 * Also any of the above formats using shortcode [tdd_pb] 159 */ 160 161 162 function tdd_pb_shortcode( $args ){ 146 163 147 164 $args = shortcode_atts( array( … … 158 175 $idsarr = array_merge($idarr, $idsarr); 159 176 160 //Filter the array to ensure we're getting things that look like integers. 161 $idsarr = array_filter( $idsarr, 'is_numeric' ); 162 163 //count if this is a race (more than one progress bar being displayed) 177 //Request some bars 178 $return = tdd_pb_get_bars(array( 179 'ids' => $idsarr, 180 'width' => $args['width'], 181 'class' => $args['class'], 182 )); 183 184 //Return them bars 185 return $return; 186 } 187 188 add_shortcode('progress', 'tdd_pb_shortcode' ); 189 add_shortcode('tdd_pb', 'tdd_pb_shortcode' ); 190 191 192 /* 193 * Returns a progress bar container with 1 or more progress bars 194 * 195 * @param array $ids An array of the ids of progress bars to fetch. 196 * @param str $width Width, specified in pixels, percents, em, whatever of the container 197 * @param str $class Any additional CSS classes to add to the global container (can force a race this way) 198 * @param str $default_color If the color of a bar isn't specified, this is the fallback. 199 */ 200 function tdd_pb_get_bars( $args ){ 201 $defaults = array( 202 'ids' => array(), 203 'width' => 'auto', 204 'class' => '', 205 'default_color' => 'red', 206 ); 207 208 $tdd_pb_options = get_option( 'tdd_pb_options'); 209 210 211 //parse incoming arguments against default. 212 $args = wp_parse_args( $args, $defaults ); 213 214 215 //Filter the array to ensure we're getting things that look like integers. Will also filter out blank array items (i.e. '' ) 216 $idsarr = array_filter( $args['ids'], 'is_numeric' ); 217 218 //count if this is a race (more than one progress bar being displayed. The race format can also be forced by passing "race" in the $class argument) 164 219 $race = ( count( $idsarr ) > 1 ) ? 'race' : ''; 165 //Load up the $return var with our progress bar container 166 $return = '<div class="tdd_pb_global_container '. $race .' '.$args["class"].'" style="width:'.strip_tags($args["width"]).'">'; 220 221 //Set up our global container 222 $return = '<div class="tdd_pb_global_container '.$race.' '.$args['class'].'" style="width:'.strip_tags( $args['width'] ).'">'; 223 224 //If there are no ids to display, this is kind of a moot proccess - so let's say so: 225 if ( count( $idsarr ) <= 0 ){ 226 $return .= '<p>' . __( 'No progress bars were set, so there is nothing to display', 'tdd_pb' ). '</p></div>'; 227 return $return; 228 } 167 229 168 230 //Setup a new WP_Query for our progress bars. … … 174 236 'meta_key' => '_tdd_pb_percentage' 175 237 )); 238 239 240 241 242 243 176 244 177 245 while ( $tdd_pb_query->have_posts() ): $tdd_pb_query->the_post(); … … 179 247 $color = strip_tags( get_post_meta( get_the_ID(), '_tdd_pb_color', true ) ); 180 248 //if no color, define a default 181 $color = (!$color) ? 'red': $color;249 $color = (!$color) ? : $color; 182 250 $return .= '<div title="'.get_the_title() .'" class="tdd_pb_bar_container" style="background-color: #'. $tdd_pb_options["bar_background_color"] .'">'; 183 251 if ($tdd_pb_options['display_percentage']){ … … 187 255 188 256 endwhile; 189 257 190 258 //Close the progress bar container, and return everything to screen. 191 259 $return .= '</div>'; 192 260 return $return; 193 261 } 194 add_shortcode('progress', 'tdd_pb_shortcode' );
Note: See TracChangeset
for help on using the changeset viewer.