Changeset 747009
- Timestamp:
- 07/27/2013 08:20:25 AM (13 years ago)
- Location:
- jellyfish-counter-widget/trunk
- Files:
-
- 3 edited
-
jellyfish-counter-widget.php (modified) (5 diffs)
-
js/odometer.js (modified) (1 diff)
-
readme.txt (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
jellyfish-counter-widget/trunk/jellyfish-counter-widget.php
r651892 r747009 1 <?php 1 <?php 2 2 /* 3 3 Plugin Name: Jellyfish Counter Widget … … 5 5 Description: Creates a widget with an odometer style counter that displays either a static number or animates up to a predefined value. 6 6 Author: Rob Miller 7 Version: 0. 67 Version: 0.8 8 8 Author URI: http://strawberryjellyfish.com/ 9 */ 10 11 /* 12 This program is free software; you can redistribute it and/or modify 13 it under the terms of the GNU General Public License as published by 14 the Free Software Foundation; either version 2 of the License, or 15 (at your option) any later version. 16 17 This program is distributed in the hope that it will be useful, 18 but WITHOUT ANY WARRANTY; without even the implied warranty of 19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 GNU General Public License for more details. 21 22 You should have received a copy of the GNU General Public License 23 along with this program; if not, write to the Free Software 24 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 25 Online: http://www.gnu.org/licenses/gpl.txt 9 26 */ 10 27 ?> 11 28 <?php 12 // Register function to be called when widget initialization occurs 13 14 add_action( 'widgets_init', 'jellyfish_cw_create_widgets' ); 15 16 // Create new widget 29 add_action('widgets_init', 'jellyfish_cw_create_widgets'); 30 17 31 function jellyfish_cw_create_widgets() { 18 register_widget( 'Jellyfish_Counter_Widget');32 register_widget('Jellyfish_Counter_Widget'); 19 33 } 20 34 21 // Widget implementationclass35 // Counter Widget class 22 36 class Jellyfish_Counter_Widget extends WP_Widget { 23 24 // Constructor function 37 25 38 function __construct() { 26 // Widget creation function 27 parent::__construct( 28 'counter_widget', 29 'Counter Widget', 30 array( 'description' => 'Show an odometer style counter' ) 39 parent::__construct( 40 'counter_widget', 'Counter Widget', array('description' => 'Show an odometer style counter') 31 41 ); 32 42 } 33 43 34 // Code to render options form 35 function form( $instance ) { 36 37 // Retrieve previous values from instance 44 // options form 45 function form($instance) { 46 // Retrieve previous values from instance 38 47 // or set default values if not present 39 $show_title = ( !empty( $instance['show_title'] ) ? 40 $instance['show_title'] : 'true' ); 41 42 $widget_title = ( !empty( $instance['widget_title'] ) ? 43 esc_attr( $instance['widget_title'] ) : 44 'Counter' ); 45 46 $display_tenths = ( !empty( $instance['display_tenths'] ) ? 47 $instance['display_tenths'] : 'true' ); 48 49 $number_of_digits = ( !empty( $instance['number_of_digits'] ) ? 50 esc_attr( $instance['number_of_digits'] ) : 51 '6' ); 52 53 $digit_height = ( !empty( $instance['digit_height'] ) ? 54 esc_attr( $instance['digit_height'] ) : 55 '40' ); 56 57 $digit_width = ( !empty( $instance['digit_width'] ) ? 58 esc_attr( $instance['digit_width'] ) : 59 '30' ); 60 61 $digit_padding = ( !empty( $instance['digit_padding'] ) ? 62 esc_attr( $instance['digit_padding'] ) : 63 '0' ); 64 65 $digit_bustedness = ( !empty( $instance['digit_bustedness'] ) ? 66 esc_attr( $instance['digit_bustedness'] ) : 67 '2' ); 68 69 $digit_style = ( !empty( $instance['digit_style'] ) ? 70 esc_attr( $instance['digit_style'] ) : 71 'font-family: Courier New, Courier, monospace; font-weight: 900;' ); 72 73 $start_value = ( !empty( $instance['start_value'] ) ? 74 esc_attr( $instance['start_value'] ) : 75 '0' ); 76 77 $end_value = ( !empty( $instance['end_value'] ) ? 78 esc_attr( $instance['end_value'] ) : 79 '100' ); 80 $animate_speed = ( !empty( $instance['animate_speed'] ) ? 81 esc_attr( $instance['animate_speed'] ) : 82 '50' ); 83 84 ?> 85 <p> 86 <label for="<?php echo 87 $this->get_field_id( 'widget_title' ); ?>"> 88 <?php echo 'Title:'; ?> 89 <input type="text" 90 id="<?php echo $this->get_field_id( 'widget_title' ); ?>" 91 name="<?php echo $this->get_field_name( 'widget_title' ); ?>" 92 value="<?php echo $widget_title; ?>" /> 93 </label> 94 </p> 95 <p> 96 <label for="<?php echo 97 $this->get_field_id( 'show_title' ); ?>"> 98 <?php echo 'Show Title'; ?> 99 <select id="<?php echo $this->get_field_id( 'show_title' ); ?>" 100 name="<?php echo $this->get_field_name( 'show_title' ); ?>"> 101 <option value="true" 102 <?php selected( $show_title, 'true' ); ?>> 103 Yes</option> 104 <option value="false" 105 <?php selected( $show_title, 'false' ); ?>> 106 No</option> 107 </select> 108 </label> 109 </p> 110 <p> 111 <label for="<?php echo 112 $this->get_field_id( 'number_of_digits' ); ?>"> 113 <?php echo 'Number of Digits:'; ?> 114 <input type="text" 115 id="<?php echo $this->get_field_id( 'number_of_digits' ); ?>" 116 name="<?php echo $this->get_field_name( 'number_of_digits' ); ?>" 117 value="<?php echo $number_of_digits; ?>" /> 118 </label> 119 </p> 120 <p> 121 <label for="<?php echo 122 $this->get_field_id( 'display_tenths' ); ?>"> 123 <?php echo 'Display Tenths'; ?> 124 <select id="<?php echo $this->get_field_id( 'display_tenths' ); ?>" 125 name="<?php echo $this->get_field_name( 'display_tenths' ); ?>"> 126 <option value="true" 127 <?php selected( $display_tenths, 'true' ); ?>> 128 Yes</option> 129 <option value="false" 130 <?php selected( $display_tenths, 'false' ); ?>> 131 No</option> 132 </select> 133 </label> 134 </p> 135 <p> 136 <label for="<?php echo 137 $this->get_field_id( 'start_value' ); ?>"> 138 <?php echo 'Start Value:'; ?> 139 <input type="text" 140 id="<?php echo $this->get_field_id( 'start_value' ); ?>" 141 name="<?php echo $this->get_field_name( 'start_value' ); ?>" 142 value="<?php echo $start_value; ?>" /> 143 </label> 144 </p> 145 <p> 146 <label for="<?php echo 147 $this->get_field_id( 'end_value' ); ?>"> 148 <?php echo 'End Value:'; ?> 149 <input type="text" 150 id="<?php echo $this->get_field_id( 'end_value' ); ?>" 151 name="<?php echo $this->get_field_name( 'end_value' ); ?>" 152 value="<?php echo $end_value; ?>" /> 153 </label> 154 </p> 155 <p> 156 <label for="<?php echo 157 $this->get_field_id( 'animate_speed' ); ?>"> 158 <?php echo 'Animation Speed (1-100):'; ?> 159 <input type="text" 160 id="<?php echo $this->get_field_id( 'animate_speed' ); ?>" 161 name="<?php echo $this->get_field_name( 'animate_speed' ); ?>" 162 value="<?php echo $animate_speed; ?>" /> 163 </label> 164 </p> 165 <p> 166 <label for="<?php echo 167 $this->get_field_id( 'digit_height' ); ?>"> 168 <?php echo 'Digit Height:'; ?> 169 <input type="text" 170 id="<?php echo $this->get_field_id( 'digit_height' ); ?>" 171 name="<?php echo $this->get_field_name( 'digit_height' ); ?>" 172 value="<?php echo $digit_height; ?>" /> 173 </label> 174 </p> 175 <p> 176 <label for="<?php echo 177 $this->get_field_id( 'digit_width' ); ?>"> 178 <?php echo 'Digit Width:'; ?> 179 <input type="text" 180 id="<?php echo $this->get_field_id( 'digit_width' ); ?>" 181 name="<?php echo $this->get_field_name( 'digit_width' ); ?>" 182 value="<?php echo $digit_width; ?>" /> 183 </label> 184 </p> 185 <p> 186 <label for="<?php echo 187 $this->get_field_id( 'digit_padding' ); ?>"> 188 <?php echo 'Padding:'; ?> 189 <input type="text" 190 id="<?php echo $this->get_field_id( 'digit_padding' ); ?>" 191 name="<?php echo $this->get_field_name( 'digit_padding' ); ?>" 192 value="<?php echo $digit_padding; ?>" /> 193 </label> 194 </p> 195 <p> 196 <label for="<?php echo 197 $this->get_field_id( 'digit_bustedness' ); ?>"> 198 <?php echo 'Bustedness:'; ?> 199 <input type="text" 200 id="<?php echo $this->get_field_id( 'digit_bustedness' ); ?>" 201 name="<?php echo $this->get_field_name( 'digit_bustedness' ); ?>" 202 value="<?php echo $digit_bustedness; ?>" /> 203 </label> 204 </p> 205 <p> 206 <label for="<?php echo 207 $this->get_field_id( 'digit_style' ); ?>"> 208 <?php echo 'Digit Style:'; ?> 209 <input type="text" 210 id="<?php echo $this->get_field_id( 'digit_style' ); ?>" 211 name="<?php echo $this->get_field_name( 'digit_style' ); ?>" 212 value="<?php echo $digit_style; ?>" /> 213 </label> 214 </p> 215 <?php 216 48 $show_title = (!empty($instance['show_title']) ? $instance['show_title'] : 'true' ); 49 $widget_title = (!empty($instance['widget_title']) ? esc_attr($instance['widget_title']) : 'Counter' ); 50 $display_tenths = (!empty($instance['display_tenths']) ? $instance['display_tenths'] : 'true' ); 51 $number_of_digits = (!empty($instance['number_of_digits']) ? esc_attr($instance['number_of_digits']) : '6' ); 52 $digit_height = (!empty($instance['digit_height']) ? esc_attr($instance['digit_height']) : '40' ); 53 $digit_width = (!empty($instance['digit_width']) ? esc_attr($instance['digit_width']) : '30' ); 54 $digit_padding = (!empty($instance['digit_padding']) ? esc_attr($instance['digit_padding']) : '0' ); 55 $digit_bustedness = (!empty($instance['digit_bustedness']) ? esc_attr($instance['digit_bustedness']) : '2' ); 56 $digit_style = (!empty($instance['digit_style']) ? esc_attr($instance['digit_style']) : 'font-family: Courier New, Courier, monospace; font-weight: 900;' ); 57 $start_value = (!empty($instance['start_value']) ? esc_attr($instance['start_value']) : '0' ); 58 $end_value = (!empty($instance['end_value']) ? esc_attr($instance['end_value']) : '100' ); 59 $animate_speed = (!empty($instance['animate_speed']) ? esc_attr($instance['animate_speed']) : '50' ); 60 $persist = (!empty($instance['persist']) ? esc_attr($instance['persist']) : 'false' ); 61 $persist_interval = (!empty($instance['persist_interval']) ? esc_attr($instance['persist_interval']) : '1' ); 62 $init_timestamp = (!empty($instance['init_timestamp']) ? esc_attr($instance['init_timestamp']) : time() ); 63 ?> 64 <p> 65 <label for="<?php echo $this->get_field_id('widget_title'); ?>"> 66 <?php echo 'Title:'; ?> 67 <input type="text" 68 id="<?php echo $this->get_field_id('widget_title'); ?>" 69 name="<?php echo $this->get_field_name('widget_title'); ?>" 70 value="<?php echo $widget_title; ?>" /> 71 </label> 72 </p> 73 <p> 74 <label for="<?php echo $this->get_field_id('show_title'); ?>"> 75 <?php echo 'Show Title'; ?> 76 <select id="<?php echo $this->get_field_id('show_title'); ?>" 77 name="<?php echo $this->get_field_name('show_title'); ?>"> 78 <option value="true" 79 <?php selected($show_title, 'true'); ?>> 80 Yes</option> 81 <option value="false" 82 <?php selected($show_title, 'false'); ?>> 83 No</option> 84 </select> 85 </label> 86 </p> 87 <p> 88 <label for="<?php echo $this->get_field_id('start_value'); ?>"> 89 <?php echo 'Start Value:'; ?> 90 <input type="text" 91 id="<?php echo $this->get_field_id('start_value'); ?>" 92 name="<?php echo $this->get_field_name('start_value'); ?>" 93 value="<?php echo $start_value; ?>" /> 94 </label> 95 </p> 96 <p> 97 <label for="<?php echo $this->get_field_id('end_value'); ?>"> 98 <?php echo 'End Value:'; ?> 99 <input type="text" 100 id="<?php echo $this->get_field_id('end_value'); ?>" 101 name="<?php echo $this->get_field_name('end_value'); ?>" 102 value="<?php echo $end_value; ?>" /> 103 </label> 104 </p> 105 <p> 106 <label for="<?php echo $this->get_field_id('persist'); ?>"> 107 <?php echo 'Continuous Counter'; ?> 108 <select id="<?php echo $this->get_field_id('persist'); ?>" 109 name="<?php echo $this->get_field_name('persist'); ?>"> 110 <option value="true" 111 <?php selected($persist, 'true'); ?>> 112 Yes</option> 113 <option value="false" 114 <?php selected($persist, 'false'); ?>> 115 No</option> 116 </select> 117 </label> 118 </p> 119 <p> 120 <label for="<?php echo $this->get_field_id('persist_interval'); ?>"> 121 <?php echo 'Continuous Interval (seconds):'; ?> 122 <input type="text" 123 id="<?php echo $this->get_field_id('persist_interval'); ?>" 124 name="<?php echo $this->get_field_name('persist_interval'); ?>" 125 value="<?php echo $persist_interval; ?>" /> 126 </label> 127 </p> 128 <p> 129 <label for="<?php echo $this->get_field_id('number_of_digits'); ?>"> 130 <?php echo 'Number of Digits:'; ?> 131 <input type="text" 132 id="<?php echo $this->get_field_id('number_of_digits'); ?>" 133 name="<?php echo $this->get_field_name('number_of_digits'); ?>" 134 value="<?php echo $number_of_digits; ?>" /> 135 </label> 136 </p> 137 <p> 138 <label for="<?php echo $this->get_field_id('display_tenths'); ?>"> 139 <?php echo 'Display Tenths'; ?> 140 <select id="<?php echo $this->get_field_id('display_tenths'); ?>" 141 name="<?php echo $this->get_field_name('display_tenths'); ?>"> 142 <option value="true" 143 <?php selected($display_tenths, 'true'); ?>> 144 Yes</option> 145 <option value="false" 146 <?php selected($display_tenths, 'false'); ?>> 147 No</option> 148 </select> 149 </label> 150 </p> 151 <p> 152 <label for="<?php echo $this->get_field_id('animate_speed'); ?>"> 153 <?php echo 'Animation Speed (1-100):'; ?> 154 <input type="text" 155 id="<?php echo $this->get_field_id('animate_speed'); ?>" 156 name="<?php echo $this->get_field_name('animate_speed'); ?>" 157 value="<?php echo $animate_speed; ?>" /> 158 </label> 159 </p> 160 <p> 161 <label for="<?php echo $this->get_field_id('digit_height'); ?>"> 162 <?php echo 'Digit Height:'; ?> 163 <input type="text" 164 id="<?php echo $this->get_field_id('digit_height'); ?>" 165 name="<?php echo $this->get_field_name('digit_height'); ?>" 166 value="<?php echo $digit_height; ?>" /> 167 </label> 168 </p> 169 <p> 170 <label for="<?php echo $this->get_field_id('digit_width'); ?>"> 171 <?php echo 'Digit Width:'; ?> 172 <input type="text" 173 id="<?php echo $this->get_field_id('digit_width'); ?>" 174 name="<?php echo $this->get_field_name('digit_width'); ?>" 175 value="<?php echo $digit_width; ?>" /> 176 </label> 177 </p> 178 <p> 179 <label for="<?php echo $this->get_field_id('digit_padding'); ?>"> 180 <?php echo 'Padding:'; ?> 181 <input type="text" 182 id="<?php echo $this->get_field_id('digit_padding'); ?>" 183 name="<?php echo $this->get_field_name('digit_padding'); ?>" 184 value="<?php echo $digit_padding; ?>" /> 185 </label> 186 </p> 187 <p> 188 <label for="<?php echo $this->get_field_id('digit_bustedness'); ?>"> 189 <?php echo 'Bustedness:'; ?> 190 <input type="text" 191 id="<?php echo $this->get_field_id('digit_bustedness'); ?>" 192 name="<?php echo $this->get_field_name('digit_bustedness'); ?>" 193 value="<?php echo $digit_bustedness; ?>" /> 194 </label> 195 </p> 196 <p> 197 <label for="<?php echo $this->get_field_id('digit_style'); ?>"> 198 <?php echo 'Digit Style:'; ?> 199 <input type="text" 200 id="<?php echo $this->get_field_id('digit_style'); ?>" 201 name="<?php echo $this->get_field_name('digit_style'); ?>" 202 value="<?php echo $digit_style; ?>" /> 203 </label> 204 </p> 205 <?php 217 206 } 218 207 219 220 function update( $new_instance, $old_instance ) { 221 $instance = $old_instance; 222 // validate inputs 223 224 // Only numeric values 225 if ( is_numeric ( $new_instance['number_of_digits'] ) ) { 226 $instance['number_of_digits'] = intval( $new_instance['number_of_digits'] ); 227 } else { 228 $instance['number_of_digits'] = $instance['number_of_digits']; 229 } 230 231 if ( is_numeric ( $new_instance['digit_height'] ) ) { 232 $instance['digit_height'] = intval( $new_instance['digit_height'] ); 233 } else { 234 $instance['digit_height'] = $instance['digit_height']; 235 } 236 237 if ( is_numeric ( $new_instance['digit_width'] ) ) { 238 $instance['digit_width'] = intval( $new_instance['digit_width'] ); 239 } else { 240 $instance['digit_width'] = $instance['digit_width']; 241 } 242 243 if ( is_numeric ( $new_instance['digit_padding'] ) ) { 244 $instance['digit_padding'] = intval( $new_instance['digit_padding'] ); 245 } else { 246 $instance['digit_padding'] = $instance['digit_padding']; 247 } 248 249 if ( is_numeric ( $new_instance['digit_bustedness'] ) ) { 250 $instance['digit_bustedness'] = intval( $new_instance['digit_bustedness'] ); 251 } else { 252 $instance['digit_bustedness'] = $instance['digit_bustedness']; 253 } 254 255 if ( is_numeric ( $new_instance['start_value'] ) ) { 256 $instance['start_value'] = floatval( $new_instance['start_value'] ); 257 } else { 258 $instance['start_value'] = $instance['start_value']; 259 } 260 261 if ( is_numeric ( $new_instance['end_value'] ) ) { 262 $instance['end_value'] = floatval( $new_instance['end_value'] ); 263 } else { 264 $instance['end_value'] = $instance['end_value']; 265 } 266 if ( is_numeric ( $new_instance['animate_speed'] ) ) { 267 $instance['animate_speed'] = intval( $new_instance['animate_speed'] ); 268 if ($instance['animate_speed'] >100) { 269 $instance['animate_speed']=100; 270 } 271 } else { 272 $instance['end_value'] = $instance['end_value']; 273 } 274 // string values 275 $instance['digit_style'] = 276 strip_tags( $new_instance['digit_style'] ); 277 278 $instance['widget_title'] = 279 strip_tags( $new_instance['widget_title'] ); 280 // boolean values 281 $instance['show_title'] = 282 strip_tags( $new_instance['show_title'] ); 283 284 $instance['display_tenths'] = 285 strip_tags( $new_instance['display_tenths'] ); 286 287 return $instance; 208 function update($new_instance, $old_instance) { 209 $instance = $old_instance; 210 // validate inputs 211 // Only numeric values 212 if (is_numeric($new_instance['number_of_digits'])) { 213 $instance['number_of_digits'] = intval($new_instance['number_of_digits']); 214 } else { 215 $instance['number_of_digits'] = $instance['number_of_digits']; 216 } 217 218 if (is_numeric($new_instance['digit_height'])) { 219 $instance['digit_height'] = intval($new_instance['digit_height']); 220 } else { 221 $instance['digit_height'] = $instance['digit_height']; 222 } 223 224 if (is_numeric($new_instance['digit_width'])) { 225 $instance['digit_width'] = intval($new_instance['digit_width']); 226 } else { 227 $instance['digit_width'] = $instance['digit_width']; 228 } 229 230 if (is_numeric($new_instance['digit_padding'])) { 231 $instance['digit_padding'] = intval($new_instance['digit_padding']); 232 } else { 233 $instance['digit_padding'] = $instance['digit_padding']; 234 } 235 236 if (is_numeric($new_instance['digit_bustedness'])) { 237 $instance['digit_bustedness'] = intval($new_instance['digit_bustedness']); 238 } else { 239 $instance['digit_bustedness'] = $instance['digit_bustedness']; 240 } 241 242 if (is_numeric($new_instance['start_value'])) { 243 $instance['start_value'] = floatval($new_instance['start_value']); 244 } else { 245 $instance['start_value'] = $instance['start_value']; 246 } 247 248 if (is_numeric($new_instance['end_value'])) { 249 $instance['end_value'] = floatval($new_instance['end_value']); 250 } else { 251 $instance['end_value'] = $instance['end_value']; 252 } 253 if (is_numeric($new_instance['animate_speed'])) { 254 $instance['animate_speed'] = intval($new_instance['animate_speed']); 255 if ($instance['animate_speed'] > 100) { 256 $instance['animate_speed'] = 100; 257 } 258 } 259 if (is_numeric($new_instance['persist_interval'])) { 260 $instance['persist_interval'] = intval($new_instance['persist_interval']); 261 } 262 // string values 263 $instance['digit_style'] = 264 strip_tags($new_instance['digit_style']); 265 266 $instance['widget_title'] = 267 strip_tags($new_instance['widget_title']); 268 // boolean values 269 $instance['show_title'] = 270 strip_tags($new_instance['show_title']); 271 272 $instance['persist'] = 273 strip_tags($new_instance['persist']); 274 275 $instance['display_tenths'] = 276 strip_tags($new_instance['display_tenths']); 277 $instance['init_timestamp'] = time(); 278 279 return $instance; 288 280 } 289 281 290 function widget( $args, $instance) {291 // queue javascript if widget is used292 if ( is_active_widget(false, false, $this->id_base))293 wp_enqueue_script('odometer', plugins_url( 'js/odometer.js', __FILE__ ), array('jquery'), '', true);282 function widget($args, $instance) { 283 // queue javascript if widget is used 284 if (is_active_widget(false, false, $this->id_base)) 285 wp_enqueue_script('odometer', plugins_url('js/odometer.js', __FILE__), array('jquery'), '', true); 294 286 295 287 // Extract members of args array as individual variables 296 extract( $args);288 extract($args); 297 289 $widget_title = $instance['widget_title']; 298 290 $show_title = $instance['show_title']; … … 307 299 $digit_bustedness = $instance['digit_bustedness']; 308 300 $digit_style = $instance['digit_style']; 301 302 //these were added at v0.7 and may not have defaults for existing widgets 303 //so we'll add some defaults here to avoid any undefined indexes 304 305 $persist = (!empty($instance['persist']) ? 306 esc_attr($instance['persist']) : 307 'false' ); 308 309 $persist_interval = (!empty($instance['persist_interval']) ? 310 esc_attr($instance['persist_interval']) : 311 '1' ); 312 313 $init_timestamp = (!empty($instance['init_timestamp']) ? 314 esc_attr($instance['init_timestamp']) : 315 time() ); 316 317 if ($persist == 'true') { 318 $start_value = $start_value + round((time() - $init_timestamp) / $persist_interval); 319 if ($start_value > $end_value) { 320 $start_value = $end_value; 321 } 322 $animate_speed = 100; 323 $display_tenths = 0; 324 } else { 325 $persist_interval = 1; 326 } 309 327 // Display widget title 310 328 echo $before_widget; 311 329 if ($show_title == 'true') { 312 330 echo $before_title; 313 echo apply_filters( 'widget_title', $widget_title);331 echo apply_filters('widget_title', $widget_title); 314 332 echo $after_title; 315 333 } 316 334 317 335 // output counter div 318 echo '<div id="odometer-' .$args['widget_id'] .'" class="odometer"></div>';336 echo '<div id="odometer-' . $args['widget_id'] . '" class="odometer-widget"></div>'; 319 337 // output javascript 320 338 echo "<script type='text/javascript'> 321 339 jQuery(document).ready(function() { 322 var waitTime = 100 - $animate_speed;340 var waitTime = (100 - $animate_speed); 323 341 var counterStartValue = $start_value; 324 342 var counterEndValue = $end_value; 325 343 var counterNow = $start_value; 326 var div = document.getElementById('odometer-".$args['widget_id'] ."'); 344 var wholeNumber = 0; 345 var persist = $persist; 346 var div = document.getElementById('odometer-" . $args['widget_id'] . "'); 327 347 var myOdometer = new Odometer(div, { 328 348 digits: $number_of_digits, … … 335 355 }); 336 356 357 337 358 function updateOdometer() { 338 counterNow=counterNow+0.005; 359 if (persist == true) { 360 counterNow=counterNow+0.15; 361 wholeNumber=wholeNumber+0.15; 362 if (wholeNumber >= 1) { 363 wholeNumber = 0; 364 waitTime = ($persist_interval * 1000); 365 } else { 366 waitTime = 1; 367 } 368 } else { 369 counterNow=counterNow+0.01; 370 waitTime = (100 - $animate_speed); 371 } 339 372 if (counterNow < counterEndValue) { 340 373 myOdometer.set(counterNow); … … 354 387 ); 355 388 </script>"; 356 389 357 390 // finish off widget 358 391 echo $after_widget; 359 } 392 } 393 360 394 } 361 395 ?> -
jellyfish-counter-widget/trunk/js/odometer.js
r651892 r747009 98 98 99 99 var odometerDiv = document.createElement("div") 100 odometerDiv.setAttribute("id","odometer");100 //odometerDiv.setAttribute("id","odometer"); 101 101 // set container height and width based on the digit size so we can style 102 102 // the container for borders etc. -
jellyfish-counter-widget/trunk/readme.txt
r651894 r747009 7 7 Requires at least: 3.0 8 8 Tested up to: 3.5 9 Stable tag: 0. 69 Stable tag: 0.8 10 10 License: GPLv2 or later 11 11 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 17 17 This plugin adds a widget to your WordPress web site that displays a static or 18 18 animated odometer style counter that can display a set value or can animate 19 between a starting and ending value. 19 between a starting and ending value. The counter can now have a continuous and 20 non resetting operation where it increments over time in the background until 21 the goal is reached. 20 22 21 23 A great visual effect for travel blogs or any website that wants to display a … … 25 27 totals and appearance. 26 28 27 The counters are created via css and require no external graphics files. 29 The counters are created via css and javascript and require no external graphics 30 files. 28 31 29 32 … … 44 47 45 48 Add a counter widget to your sidebar and adjust the settings to suit your 46 requirements. If you specify different start and end values the counter will 47 count upwards when the page loads until it reaches the ending value. 49 requirements. 48 50 49 If you just want a static counter make the start and end the same value or make 50 the end value lower than the starting value. 51 There are three basic modes of operation: 51 52 52 You can configure the digit height, width and font as well as animation 53 speed and "bustedness" (misalignment of the digits). 53 * Static - If you only give a Start Value and no End Value the counter will display 54 a static number (useful if you just want to show a total and update it manually 55 as necessary) 56 57 * Animated – If you supply both start value and end value in the widget, when it 58 is displayed the counter will increment upwards until it reaches the end value. 59 Speed of the count is controlled by the Animation Speed option. Note, this counter 60 has no memory, it will reset when a page is reloaded or changed. Good for visual 61 effect where start and end values are very close together. 62 63 * Continuous – If you want to count over a long period of time and need your 64 counter to continue to count irrespective of page loads then just select the 65 continuous option in the widget. Then select the interval between the counter 66 increments, in seconds. As soon as you save the widget the counter will “start” 67 and will continue to tick away even if nobody is viewing your blog. You can of 68 course still use the start values and end values in this mode however animation 69 speed and display tenths have no effect. 70 71 You can also configure the digit height, width and font as well as animation 72 speed (animated mode only) and "bustedness" (misalignment of the digits). 54 73 55 74 In the "Digit Style" setting you can specify a font or font style, this must be … … 68 87 == Frequently Asked Questions == 69 88 70 None yet71 72 89 == Changelog == 73 90 =0.6= 74 91 * initial release 75 92 93 =0.8= 94 * by request, added a non resetting continuous counter feature that can increment 95 every set number of seconds until it reaches its goal 96 76 97 == Upgrade Notice == 77 98 99 Existing counter widgets may need the animation speed adjusting as the timing 100 method has changed slightly making the counter animate slightly faster on 101 some browsers. 102 78 103 == Screenshots ==
Note: See TracChangeset
for help on using the changeset viewer.