Counter-Up icon indicating copy to clipboard operation
Counter-Up copied to clipboard

Uncaught TypeError: Cannot read property 'shift' of null

Open trewknowledge opened this issue 10 years ago • 14 comments

I am receiving this error when using jquery.counterup.js 1.0 and Waypoints - 3.1.1

trewknowledge avatar Feb 11 '15 18:02 trewknowledge

This is on line 62 of the counterup plugin

trewknowledge avatar Feb 11 '15 18:02 trewknowledge

I was getting this error as well. The root of the error was because Counter Up wants to use the 2.x version of Waypoints. I just added a pull request that fixes Counter Up to work with 3.x version of Waypoints. Hope this helps!

ravenroc avatar Mar 24 '15 13:03 ravenroc

digsite's PR seemed to have fixed the problem for me. Thanks!

cvongrim avatar Apr 06 '15 19:04 cvongrim

No problem @cvongrim! Happy to help.

ravenroc avatar Apr 06 '15 20:04 ravenroc

Thanks for the PR. I had the same issue. It would be nice if @bfintal reviewed and approved the PRs. No code updates in 2 years. :-(

cowgill avatar May 19 '15 07:05 cowgill

To solve it just add the following code in line 62:

                    if (!$this.data('counterup-nums')) {
                        return;
                    }

After

var f = function () {

the code will be after update:

                // Updates the number until we're done
                var f = function () {
                    if (!$this.data('counterup-nums')) {
                        return;
                    }
                    $this.text($this.data('counterup-nums').shift());
                    if ($this.data('counterup-nums').length) {
                        setTimeout($this.data('counterup-func'), $settings.delay);
                    } else {
                        delete $this.data('counterup-nums');
                        $this.data('counterup-nums', null);
                        $this.data('counterup-func', null);
                    }
                };

ebda3is avatar Feb 02 '16 21:02 ebda3is

In my fork I merged a bunch of PRs - it's already on bower and NPM. Waypoint 4.0.0-ready ;)

ciromattia avatar Mar 24 '16 11:03 ciromattia

@ebda3is 👍

visoor avatar Jun 16 '16 22:06 visoor

fix issue with replacing lines 67 - 79 with :

// Updates the number until we're done var f = function() { if ($this.data('counterup-nums', nums).length) { $this.text($this.data('counterup-nums').shift()); } if ($this.data('counterup-nums').length) { setTimeout($this.data('counterup-func'),delay); } else { delete $this.data('counterup-nums'); $this.data('counterup-nums', null); $this.data('counterup-func', null); } };

orbitfum avatar Mar 28 '18 18:03 orbitfum

I have solved the issue checked once and now it is counting properly

var c = function() { if (!$(t.data('counterup-nums'))) { return; } $(t.text(t.data("counterup-nums").shift())); if (t.data("counterup-nums").length) setTimeout(t.data("counterup-func"), r.delay); else { delete t.data("counterup-nums"); t.data("counterup-nums", null); t.data("counterup-func", null) } };

vishalsankpal avatar Jan 28 '19 09:01 vishalsankpal

I am using Waypoints - 4.0.1 I am facing the same issue. the counter is not working. Will I need to use lower version waypoints? http://prntscr.com/n4mpgd

devenamulhaque avatar Mar 29 '19 12:03 devenamulhaque

Tried all these solutions.

It counted up first time fine.

The second time it failed with same error as mentioned.

None of the solutions solved the problem - if they did not throw an error then they did not count up to the total number I was after.

adampblack avatar Apr 10 '19 10:04 adampblack

I found 1 answer, and it works I fixed this by: var $settings = settings; var $originalText = $this.text(); // added this line Changed: var num = $this.text(); to var num = $originalText;

tungpksa avatar Jul 06 '19 09:07 tungpksa

waypoint 4 changed and removed some options, one of them is "triggerOnce" option that has been removed and "waypoint.destroy()" was replaced. So Changed this line: $this.waypoint(counterUpper, { offset: '100%', triggerOnce: true }); to $this.waypoint(counterUpper, { offset: '100%' }); AND add this line this.destroy() after setTimeout($this.data('counterup-func'), $settings.delay);

bahram-css avatar Dec 11 '19 08:12 bahram-css