Hi,
First of all: great little plugin!
In one of my projects, I have extended the Javascript Array class with some added functionality, for example:
Array.prototype.distinct = function ()
{
let distinctValues = []
this.forEach(function (value)
{
if (distinctValues.includes(value))
{
return
}
distinctValues.push(value)
})
return distinctValues
}
If I include these extensions whilst also using countdownCube, in the above example, I get the error that 'this.forEach is not a function', the reason being that somehow, 'distinct' is tagged on as an entry in 'this.topTags' (although logging 'this.topTags' to the console won't show it), which causes the 'this' context of 'distinct' to be:
cube = element.append('<section></section>')
.children(':last')
.attr('id', tag )
.addClass( "countdownCubeContainer" )
.append('<div></div>')
.children(':last')
.addClass('countdownCubeCube')
.data('side', 'show-front');
I don't know why this happens, probably my own short comings, but it might as well be a bug in the core javascript for all I know.
The fix I implemented is to explicitly define 'this.topTags' as an Array and cycle through it using the 'of' keyword (i.s.o cycling through it with the 'in' keyword) like so:
if( options.showDaysOnly ) {
this.topTags = new Array( 'day','hour', 'minute', 'second' );
this.loadingTags = [ 'LOAD', 'ING.', '....', '....'];
}
else {
this.topTags = new Array( 'year', 'month', 'day','hour', 'minute', 'second' );
this.loadingTags = [ 'LO', 'AD', 'IN', 'G.', '..', '...'];
}
this.transformNames = [ '-webkit-transform', '-moz-transform', '-o-transform', 'transform' ];
//add the figures, etc to the div
let tagIndex = 0;
for( let tag of this.topTags ) {
cube = element.append('<section></section>')
.children(':last')
.attr('id', tag )
.addClass( "countdownCubeContainer" )
.append('<div></div>')
.children(':last')
.addClass('countdownCubeCube')
.data('side', 'show-front');
/*this is horrible, chaining would be much cooler*/
this.addFigures( cube,
this.classes,
this.loadingTags[ tagIndex++ ] );
element.children(':last')
.append('<div></div>')
.children(':last')
.html(options.labelsTranslations[tag])
.addClass('countdownCubeTitleDiv');
}
How to replicate? Simply add the 'Array.prototype.distinct' extension to countdowncube.js
Regards,
Edwin