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

[Add] Audio supports and update readme #124

Open
wants to merge 2 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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ export default {
## Docs
You can see the complete documentation with examples here: [https://vue-cool-lightbox.lucaspulliese.com/](https://vue-cool-lightbox.lucaspulliese.com/).

## Supported contents
- Images
- Videos
- Audios (mp3, wav, ogg)
- iFrames

## Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Expand Down
61 changes: 61 additions & 0 deletions src/components/CoolLightBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,19 @@
<source :src="checkIsMp4(getItemSrc(itemIndex))" :type="'video/'+(getVideoExt(getItemSrc(itemIndex)) ? getVideoExt(getItemSrc(itemIndex)) : getExtFromItem(itemIndex))">
Sorry, your browser doesn't support embedded videos
</video>

<audio
v-autoplayObserver
:data-autoplay="setAutoplay(itemIndex)"
class="cool-lightbox-video"
v-if="checkIsAudio(getItemSrc(itemIndex))"
:style="aspectRatioVideo" :key="checkIsAudio(getItemSrc(itemIndex))"
controls=""
controlslist="nodownload">
<source :src="checkIsAudio(getItemSrc(itemIndex))" :type="'audio/'+getAudioExt(getItemSrc(itemIndex))">
Sorry, your browser does not support the audio element
</audio>

</div>
<!--/cool-lightbox__iframe-->
</div>
Expand Down Expand Up @@ -274,6 +287,19 @@
<source :src="checkIsMp4(getItemSrc(imgIndex))" :type="'video/'+(getVideoExt(getItemSrc(imgIndex)) ? getVideoExt(getItemSrc(imgIndex)) : getExtFromItem(imgIndex))">
Sorry, your browser doesn't support embedded videos
</video>

<audio
v-autoplayObserver
:data-autoplay="setAutoplay(itemIndex)"
class="cool-lightbox-video"
v-if="checkIsAudio(getItemSrc(itemIndex))"
:style="aspectRatioVideo" :key="checkIsAudio(getItemSrc(itemIndex))"
controls=""
controlslist="nodownload">
<source :src="checkIsAudio(getItemSrc(itemIndex))" :type="'audio/'+getAudioExt(getItemSrc(itemIndex))">
Sorry, your browser does not support the audio element
</audio>

</transition>
</div>
<!--/cool-lightbox__iframe-->
Expand Down Expand Up @@ -1828,6 +1854,41 @@ export default {
return false
},

checkIsAudio(url) {
if(this.imgIndex === null) {
return false
}

const str = new String(url);
if(
(str.indexOf('.mp3') !== -1) ||
(str.indexOf('.ogg') !== -1) ||
(str.indexOf('.wav') !== -1)
) {
return url
}

return false
},

// if is video get extension
getAudioExt(url) {
if(this.imgIndex === null) {
return false
}

const str = new String(url);
if(str.indexOf('.mp3') !== -1 || str.indexOf('.wav') !== -1){
return 'mpeg'
}

if(str.indexOf('.ogg') !== -1) {
return 'ogg'
}

return false
},

// check if item is object
checkIfIsObject(itemIndex) {
const item = this.items[itemIndex]
Expand Down