(shift)
| 87 | } |
| 88 | |
| 89 | async update(shift) { |
| 90 | if (shift < 0 && this.index <= 0) { |
| 91 | return; |
| 92 | } |
| 93 | if (shift > 0 && this.index >= this.images.length - 1) { |
| 94 | return; |
| 95 | } |
| 96 | this.index += shift; |
| 97 | |
| 98 | this.prev.style.visibility = this.index ? "unset" : "hidden"; |
| 99 | this.next.style.visibility = this.index === this.images.length - 1 ? "hidden" : "unset"; |
| 100 | |
| 101 | const img = this.images[this.index]; |
| 102 | this.el.style.display = "flex"; |
| 103 | this.el.clientWidth; // Force a reflow |
| 104 | this.el.style.opacity = 1; |
| 105 | this.img.style.opacity = 0; |
| 106 | this.spinner.style.display = "inline-block"; |
| 107 | try { |
| 108 | await loadImage(img); |
| 109 | } catch (err) { |
| 110 | console.error('failed to load image', img, err); |
| 111 | } |
| 112 | this.spinner.style.display = "none"; |
| 113 | this.link.href = img; |
| 114 | this.img.src = img; |
| 115 | this.img.style.opacity = 1; |
| 116 | } |
| 117 | |
| 118 | async updateWithNewImage(img, feedDirection) { |
| 119 | // No-op if lightbox is not open |
no test coverage detected