dist/viewer.common.js
function update() {
    var element = this.element,
        options = this.options,
        isImg = this.isImg;

    // Destroy viewer if the target image was deleted

    if (isImg && !element.parentNode) {
      return this.destroy();
    }

    var images = [];

    forEach(isImg ? [element] : element.querySelectorAll('img'), function (image) {
      if (options.filter) {
        if (options.filter(image)) {
          images.push(image);
        }
      } else {
        images.push(image);
      }
    });

    if (!images.length) {
      return this;
    }

    this.images = images;
    this.length = images.length;

    if (this.ready) {
      var indexes = [];

      forEach(this.items, function (item, i) {
        var img = item.querySelector('img');
        var image = images[i];

        if (image) {
          if (image.src !== img.src) {
            indexes.push(i);
          }
        } else {
          indexes.push(i);
        }
      });

      setStyle(this.list, {
        width: 'auto'
      });

      this.initList();

      if (this.isShown) {
        if (this.length) {
          if (this.viewed) {
            var index = indexes.indexOf(this.index);

            if (index >= 0) {
              this.viewed = false;
              this.view(Math.max(this.index - (index + 1), 0));
            } else {
              addClass(this.items[this.index], CLASS_ACTIVE);
            }
          }
        } else {
          this.image = null;
          this.viewed = false;
          this.index = 0;
          this.imageData = null;
          this.canvas.innerHTML = '';
          this.title.innerHTML = '';
        }
      }
    } else {
      this.build();
    }

    return this;
  }
function update() {
    var element = this.element,
        options = this.options,
        isImg = this.isImg;

    // Destroy viewer if the target image was deleted

    if (isImg && !element.parentNode) {
      return this.destroy();
    }

    var images = [];

    forEach(isImg ? [element] : element.querySelectorAll('img'), function (image) {
      if (options.filter) {
        if (options.filter(image)) {
          images.push(image);
        }
      } else {
        images.push(image);
      }
    });

    if (!images.length) {
      return this;
    }

    this.images = images;
    this.length = images.length;

    if (this.ready) {
      var indexes = [];

      forEach(this.items, function (item, i) {
        var img = item.querySelector('img');
        var image = images[i];

        if (image) {
          if (image.src !== img.src) {
            indexes.push(i);
          }
        } else {
          indexes.push(i);
        }
      });

      setStyle(this.list, {
        width: 'auto'
      });

      this.initList();

      if (this.isShown) {
        if (this.length) {
          if (this.viewed) {
            var index = indexes.indexOf(this.index);

            if (index >= 0) {
              this.viewed = false;
              this.view(Math.max(this.index - (index + 1), 0));
            } else {
              addClass(this.items[this.index], CLASS_ACTIVE);
            }
          }
        } else {
          this.image = null;
          this.viewed = false;
          this.index = 0;
          this.imageData = null;
          this.canvas.innerHTML = '';
          this.title.innerHTML = '';
        }
      }
    } else {
      this.build();
    }

    return this;
  }
function update ( ) { var element = this . element , options = this . options , isImg = this . isImg ; // Destroy viewer if the target image was deleted if ( isImg && ! element . parentNode ) { return this . destroy ( ) ; } var images = [ ] ; forEach ( isImg ? [ element ] : element . querySelectorAll ( 'img' ) , function ( image ) { if ( options . filter ) { if ( options . filter ( image ) ) { images . push ( image ) ; } } else { images . push ( image ) ; } } ) ; if ( ! images . length ) { return this ; } this . images = images ; this . length = images . length ; if ( this . ready ) { var indexes = [ ] ; forEach ( this . items , function ( item , i ) { var img = item . querySelector ( 'img' ) ; var image = images [ i ] ; if ( image ) { if ( image . src !== img . src ) { indexes . push ( i ) ; } } else { indexes . push ( i ) ; } } ) ; setStyle ( this . list , { width : 'auto' } ) ; this . initList ( ) ; if ( this . isShown ) { if ( this . length ) { if ( this . viewed ) { var index = indexes . indexOf ( this . index ) ; if ( index >= 0 ) { this . viewed = false ; this . view ( Math . max ( this . index - ( index + 1 ) , 0 ) ) ; } else { addClass ( this . items [ this . index ] , CLASS_ACTIVE ) ; } } } else { this . image = null ; this . viewed = false ; this . index = 0 ; this . imageData = null ; this . canvas . innerHTML = '' ; this . title . innerHTML = '' ; } } } else { this . build ( ) ; } return this ; }
Update viewer when images changed
Update viewer when images changed