Skip to content
This repository was archived by the owner on Mar 24, 2023. It is now read-only.

(fix) Avoid sometimes throwing the exceptions when the image list is … #141

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
193 changes: 105 additions & 88 deletions dist/vue-cool-lightbox.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,73 +76,73 @@ function findChild(parent, nodeName) {
);
}

var AutoplayObserver = {
inserted: function (el) {
// getYoutube ID
function isYoutubeVideo(url) {
// youtube data
var youtubeRegex = /^(?:https?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})(?:\S+)?$/;
var ytId = (url.match(youtubeRegex)) ? RegExp.$1 : false;
if(ytId) {
return true;
}
return false;
}
function autoplayVideo() {
var tagName = el.tagName;
var autoplay = el.dataset.autoplay;
if(autoplay) {
if(tagName === 'VIDEO') {
el.muted = true;
el.autoplay = true;
return;
}
if(tagName === 'IFRAME') {
var url = new URL(el.src);
var muted = 'muted';
if(isYoutubeVideo(el.src)) {
muted = 'mute';
}
// append autoplay
url.searchParams.append(muted, 1);
url.searchParams.append('autoplay', 1);
el.src = url.href;
}
}
}
function handleIntersect(entries, observer) {
entries.forEach(function (entry) {
if (entry.isIntersecting) {
autoplayVideo();
observer.unobserve(el);
}
});
}
function createObserver() {
var options = {
root: null,
threshold: "0"
};
var observer = new IntersectionObserver(handleIntersect, options);
observer.observe(el);
}
if (window["IntersectionObserver"]) {
createObserver();
} else {
loadImage();
}
}
var AutoplayObserver = {
inserted: function (el) {
// getYoutube ID
function isYoutubeVideo(url) {

// youtube data
var youtubeRegex = /^(?:https?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})(?:\S+)?$/;
var ytId = (url.match(youtubeRegex)) ? RegExp.$1 : false;

if(ytId) {
return true;
}

return false;
}

function autoplayVideo() {
var tagName = el.tagName;
var autoplay = el.dataset.autoplay;
if(autoplay) {
if(tagName === 'VIDEO') {
el.muted = true;
el.autoplay = true;

return;
}

if(tagName === 'IFRAME') {
var url = new URL(el.src);
var muted = 'muted';

if(isYoutubeVideo(el.src)) {
muted = 'mute';
}

// append autoplay
url.searchParams.append(muted, 1);
url.searchParams.append('autoplay', 1);

el.src = url.href;
}
}
}

function handleIntersect(entries, observer) {
entries.forEach(function (entry) {
if (entry.isIntersecting) {
autoplayVideo();
observer.unobserve(el);
}
});
}

function createObserver() {
var options = {
root: null,
threshold: "0"
};
var observer = new IntersectionObserver(handleIntersect, options);
observer.observe(el);
}
if (window["IntersectionObserver"]) {
createObserver();
} else {
loadImage();
}
}
};

//
Expand Down Expand Up @@ -347,6 +347,11 @@ var script = {

watch: {
zoomBar: function zoomBar(newVal, prevVal) {

if (this.$refs.items.length === 0 || this.$refs.items[this.imgIndex].childNodes === 0 ) {
return false
}

var item;
if(this.isZooming) {
if(this.effect == 'swipe') {
Expand Down Expand Up @@ -667,6 +672,10 @@ var script = {

// start swipe event
startSwipe: function startSwipe(event) {
if(this.imgIndex == null) {
return false
}

if(this.isZooming) {
return false
}
Expand Down Expand Up @@ -1171,6 +1180,10 @@ var script = {
return false
}

if (this.$refs.items.length === 0 || this.$refs.items[this.imgIndex].childNodes === 0 ) {
return false
}

// item zoom
var item;
if(this.effect == 'swipe') {
Expand Down Expand Up @@ -1228,6 +1241,10 @@ var script = {

// only if index is not null
if(this.imgIndex != null) {

if (this.$refs.items.length === 0 || this.$refs.items[this.imgIndex].childNodes === 0 ) {
return
}

var item;
if(this.effect == 'swipe') {
Expand Down Expand Up @@ -1847,27 +1864,27 @@ var __vue_staticRenderFns__ = [];
undefined
);

function install(Vue) {
if (install.installed) { return; }
install.installed = true;
Vue.component("CoolLightBox", CoolLightBox);
}
var plugin = {
install: install
};
var GlobalVue = null;
if (typeof window !== "undefined") {
GlobalVue = window.Vue;
} else if (typeof global !== "undefined") {
GlobalVue = global.vue;
}
if (GlobalVue) {
GlobalVue.use(plugin);
}
function install(Vue) {
if (install.installed) { return; }
install.installed = true;
Vue.component("CoolLightBox", CoolLightBox);
}

var plugin = {
install: install
};

var GlobalVue = null;
if (typeof window !== "undefined") {
GlobalVue = window.Vue;
} else if (typeof global !== "undefined") {
GlobalVue = global.vue;
}

if (GlobalVue) {
GlobalVue.use(plugin);
}

CoolLightBox.install = install;

export default CoolLightBox;
2 changes: 1 addition & 1 deletion dist/vue-cool-lightbox.min.js

Large diffs are not rendered by default.

Loading