Featherlight Image Count Index/Total [Indexing Error]

84 Views Asked by At

I am trying to add Image count in a Featherlight Gallery. Example : Image 1 of 6 (somewhere beside/below an image)

$.featherlightGallery.prototype.afterContent = function(){
    var object = this.$instance,
        target = this.$currentTarget,
        parent = target.parent(),
        caption = parent.find('.wp-caption-text'),
        galParent = target.parents('.gallery-item'),
        jetParent = target.parents('.tiled-gallery-item');

    $('<div class="count">Image ' + (currentNavigation() + 1)+' of ' + slides().length + '</div>').html(object.find('.featherlight-content'));

    if (0 !== galParent.length) {
        caption = galParent.find('.wp-caption-text');
    } else if (0 !== jetParent.length) {
        caption = jetParent.find('.tiled-gallery-caption');
    }
    object.find('.caption').remove();
    if (0 !== caption.length) {
        $('<div class="caption">').text(caption.text()).appendTo(object.find('.featherlight-content'));
    }
}

It throws me back with the error : currentNavigation is not defined

2

There are 2 best solutions below

0
On BEST ANSWER

Omg! I got it! I guess it was a fluke! After trying a few probabilities, this is the final answer. I hope someone may find this useful ;D

$.featherlightGallery.prototype.afterContent = function(){
    var object = this.$instance,
        target = this.$currentTarget,
        parent = target.parent(),
        caption = parent.find('.wp-caption-text'),
        galParent = target.parents('.gallery-item'),
        jetParent = target.parents('.tiled-gallery-item');

    var sc = $('<div class="count">Image ' + (this.currentNavigation() + 1) + ' of ' + this.slides().length + '</div>');
    sc.appendTo(object.find('.featherlight-content'));

    object.find('.count').remove();
    if (0 !== sc.length) {
        sc.appendTo(object.find('.featherlight-content'));
    }
    if (0 !== galParent.length) {
        caption = galParent.find('.wp-caption-text');
    } else if (0 !== jetParent.length) {
        caption = jetParent.find('.tiled-gallery-caption');
    }
    object.find('.caption').remove();
    if (0 !== caption.length) {
        $('<div class="caption">').text(caption.text()).appendTo(object.find('.featherlight-content'));
    }
}
4
On

You need to call this.currentNavigation()