';
+ } else {
+ $output = '';
+ }
+
+ //Return Output.
+ return $output;
+}
diff --git a/index.php b/index.php
new file mode 100644
index 0000000..49d255d
--- /dev/null
+++ b/index.php
@@ -0,0 +1 @@
+ objectPositionTop && eventFired === false){
- numAnim.start();
- }
- });
- });
-});
\ No newline at end of file
+jQuery( document ).ready( function( $ ){
+ var eventFired = false;
+ var options = {};
+ var counterObjects = {};
+
+ function wpcjs_get_counter() {
+ //Loop to class counter which contains all data provided into the shortcode.
+ $.each( $( '.counter' ), function( index, value ) {
+ $( this ).attr( 'id', 'counter-' + index ); //Add an id to each counter.
+
+ // If you want to put the end counter number dynamically,
+ // get it from an AJAX request or something, change the number
+ // inside of the counter id, in case of "Use the end number inside the shortcode?"
+ // option is checked and use the following shortcode structure
+ // [countup start="20"]55[/countup]:
+ //
+ // $('#counter-1').html('100');
+ //
+ // or, you could use:
+ // $('#counter-1').data('count', 20);
+ //
+ // In case of, "Use the end number inside the shortcode?" is unchecked and use
+ // the following shortcode structure: [countup start="0" end="55"].
+ //
+ // Be sure that the previous code run before the next code.
+ var count = wp_cup_settings.end_inside_shortcode ? $( this ).html() : $( this ).data( 'count' );
+ var start = $( this ).data( 'start' );
+ var decimals = $( this ).data( 'decimals' );
+ var duration = $( this ).data( 'duration' );
+ var onScroll = $( this ).data( 'scroll' );
+ var easing = $( this ).data( 'easing' );
+ var grouping = $( this ).data( 'grouping' );
+ var separator = $( this ).data( 'separator' );
+ var decimal = $( this ).data( 'decimal' );
+ var prefix = $( this ).data( 'prefix' );
+ var suffix = $( this ).data( 'suffix' );
+
+ //Options Variables
+ var options_in_shortcode = {
+ useEasing: easing,
+ useGrouping: grouping,
+ separator: separator,
+ decimal: decimal,
+ prefix: prefix,
+ suffix: suffix
+ };
+
+ //Loop to options_in_shortcode, this means if one option value inside of shortcode is empty, the default value is pull from the options page.
+ $.each( options_in_shortcode, function( key, value ){
+ if( value == " " ){
+ options[ key ] = wp_cup_settings.settings[ key ];
+ } else {
+ options[ key ] = value;
+ }
+ });
+
+ //Get counter id.
+ var counterId = $( this ).attr( 'id' );
+
+ //Object Instance.
+ var numAnim = new CountUp( counterId, start, count, decimals, duration, options );
+
+ //Get the counter id position.
+ objectPositionTop = $( '#' + counterId ).offset().top - window.innerHeight;
+
+ if( onScroll === false && eventFired === false ){
+ numAnim.start();
+ } else {
+ counterObjects[ 'counterObj' + index ] = {
+ 'counterId' : '#' + counterId,
+ 'objectPositionTop' : objectPositionTop,
+ 'numAnimObject' : numAnim
+ };
+ }
+ });
+ }
+
+ // Logic got it from: http://stackoverflow.com/a/488073/2644250
+ function wpcjs_check_visibility() {
+ var docViewTop = $( window ).scrollTop();
+ var docViewBottom = docViewTop + $( window ).height();
+
+ for ( var i in counterObjects ) {
+ var elemTop = $( counterObjects[i].counterId ).offset().top;
+ var elemBottom = elemTop + $( counterObjects[i].counterId ).height();
+
+ if ( ( elemBottom <= docViewBottom ) && ( elemTop >= docViewTop ) ) {
+ counterObjects[i].numAnimObject.start();
+ }
+ }
+ }
+
+ wpcjs_get_counter();
+ wpcjs_check_visibility();
+ $( window ).on( 'scroll', wpcjs_check_visibility );
+});
diff --git a/readme.txt b/readme.txt
index 3ab0feb..92645b5 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1,9 +1,9 @@
=== Plugin Name ===
-Contributors: Roel Magdaleno
+Contributors: rokumetal
Tags: wordpress, plugin, counter, countup, countupjs, animated
Requires at least: 3.5
-Tested up to: 4.5.2
-Stable tag: 2.1
+Tested up to: 4.7.2
+Stable tag: 3.1
License: GPLv2
License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -43,16 +43,59 @@ All counters started their animation before to reach the target counter. Now, wh
** END VERSION 2.1 **
+** VERSION 2.2 **
+
+Now you can add an option if you wanna start the counter when the page is loaded or when scroll it.
+
+Value = true or false.
+
+** END VERSION 2.2 **
+
+** VERSION 2.3 **
+
+Bug fixed where counter at the top starts counters at bottom. Now, every counter works independently.
+
+** END VERSION 2.3 **
+
+** VERSION 3.0 **
+
+Now, you could choose how to use the shortcode:
+
+NEW: [countup start="0" more_options_here]55[/countup] or the old one:
+[countup start="0" end="55"]
+
+If you want to use the first one, you should activate the "Use the end number inside the shortcode?"
+option.
+
+** END VERSION 3.0 **
+
The shortcode accepts those arguments, as you can see previously:
+Normal Arguments:
+
[countup
start="your-value" //This use a number to begin the counter.
end="your-value" //This use a number to end the counter at.
decimals="your-value" //This use a number to put decimals to your counter.
duration="your-value" //This use a number (seconds) as duration of the counter.
+ scroll="your-value" //Load counter when the page is loaded. Default Value: True.
]
-Example: [countup start="0" end="55" decimals="0" duration="5" prefix="my_prefix"]
+Normal Example:
+
+[countup start="0" end="55" decimals="0" duration="5" prefix="my_prefix" scroll="false"]
+
+Inside Shortcode Arguments:
+
+[countup
+ start="your-value" //This use a number to begin the counter.
+ decimals="your-value" //This use a number to put decimals to your counter.
+ duration="your-value" //This use a number (seconds) as duration of the counter.
+ scroll="your-value" //Load counter when the page is loaded. Default Value: True.
+]your-end-number[/countup]
+
+Example Inside Shortcode:
+[countup start="0" decimals="0" duration="5"]55[/countup]
Now you know how to use this plugin, but you can edit some options if you required (Go to "Settings"->"CountUP.js").
@@ -85,4 +128,16 @@ Now you know how to use this plugin, but you can edit some options if you requir
= 2.1 =
* All counters started their animation before to reach the target counter. Now, when you scrolled to the target counter, the counter will start their animation.
+= 2.2 =
+* Now you can add an option if you wanna start the counter when the page is loaded or when scroll it.
+
+= 2.3 =
+* Bug fixed where counter at the top starts counters at bottom. Now, every counter works independently.
+
+= 3.0 =
+* Bug fixed where some counters didn't start after scroll into it. And it was implemented two ways to use the shortcode.
+
+= 3.1 =
+* Bug fixed where the plugin was initializing at the same time of the other plugins, breaking them.
+
== Upgrade Notice ==