Cleans a bit of the js code for the media component

This commit is contained in:
mateuswetah 2021-03-10 14:15:01 -03:00
parent b48f0ff0c9
commit a06fff3fb6
2 changed files with 80 additions and 92 deletions

View File

@ -382,8 +382,7 @@ function tainacan_get_the_media_component(
* @type string before_slide_metadata String to be added before the slide-metadata div
* @type string after_slide_metadata String to be added after the slide-metadata div
* @type string class_slide_metadata Class to be added to the slide-metadata div
* @type mixed media_content The content of the slide itself, such as an image, audio, video or iframe tag
* @type string media_full_link A link to wrap the content, possibly to show a full version in the main modal. If this is passed, the slide-content div is rendered as an a tag
* @type mixed media_content The content of the slide itself, such as an image, audio, video or iframe tag. It may be wrapped by a link to the full content
* @type string media_title The media title, if available
* @type string media_description The media description, if available
* @type string media_caption The media caption, if available
@ -401,7 +400,6 @@ function tainacan_get_the_media_component_slide( $args = array() ) {
'after_slide_metadata' => '',
'class_slide_metadata' => '',
'media_content' => '',
'media_full_link' => '',
'media_title' => '',
'media_description' => '',
'media_caption' => '',
@ -412,11 +410,8 @@ function tainacan_get_the_media_component_slide( $args = array() ) {
if ( !empty($args['media_content']) ) : ?>
<?php echo $args['before_slide_content'] ?>
<?php if ($args['media_full_link']) : ?>
<a class="swiper-slide-content <?php echo $args['class_slide_content'] ?>" href="<?php echo $args['media_full_link'] ?>">
<?php else: ?>
<div class="swiper-slide-content <?php echo $args['class_slide_content'] ?>">
<?php endif; ?>
<?php echo $args['media_content'] ?>
<?php echo $args['before_slide_metadata'] ?>
@ -436,11 +431,7 @@ function tainacan_get_the_media_component_slide( $args = array() ) {
<?php endif; ?>
<?php echo $args['after_slide_metadata'] ?>
<?php if ($args['media_full_link']) : ?>
</a>
<?php else: ?>
</div>
<?php endif; ?>
<?php echo $args['after_slide_content'] ?>
<?php endif;

View File

@ -106,9 +106,8 @@ class TainacanMediaGallery {
// Parse URL and open gallery if it contains #&pid=3&gid=1
var hashData = this.photoswipeParseHash();
if (hashData.pid && hashData.gid) {
if (hashData.pid && hashData.gid)
this.openPhotoSwipe(hashData.pid, galleryElements[hashData.gid - 1], true, true);
}
}
@ -128,12 +127,15 @@ class TainacanMediaGallery {
figureEl = thumbElements[i]; // <figure> element
// include only element nodes
if (figureEl.nodeType !== 1) {
if (figureEl.nodeType !== 1)
continue;
}
linkEl = figureEl.children[0]; // <a> element
// There may be a wrapper div before the a tag
if (linkEl.nodeName !== 'A')
linkEl = linkEl.children[0];
if (linkEl.classList.contains('attachment-without-image')) {
item = {
html: '<div class="attachment-without-image"><iframe id="tainacan-attachment-iframe" src="' + linkEl.href + '"></iframe></div>'
@ -149,15 +151,15 @@ class TainacanMediaGallery {
h: parseInt(imgHeight, 10)
};
if (linkEl.children[1] && linkEl.children[1].classList.contains('swiper-slide-name')) {
if (linkEl.children[1] && linkEl.children[1].classList.contains('swiper-slide-metadata__name'))
item.title = linkEl.children[1].innerText;
}
}
item.el = figureEl; // save link to element for getThumbBoundsFn
items.push(item);
}
console.log(items);
return items;
};
@ -171,7 +173,7 @@ class TainacanMediaGallery {
gallery,
options,
items;
console.log(galleryElement);
items = this.parseThumbnailElements(galleryElement);
// Photoswipe options
@ -222,13 +224,11 @@ class TainacanMediaGallery {
}
// exit if index not found
if (isNaN(options.index)) {
if (isNaN(options.index))
return;
}
if (disableAnimation) {
if (disableAnimation)
options.showAnimationDuration = 0;
}
// Pass data to PhotoSwipe and initialize it
gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, options);
@ -248,9 +248,8 @@ class TainacanMediaGallery {
// Swiper autoplay stop when image zoom */
gallery.listen('initialZoomIn', function() {
if( swiperInstance.autoplay.running){
if (swiperInstance.autoplay.running)
swiperInstance.autoplay.stop();
}
});
};
@ -270,9 +269,8 @@ class TainacanMediaGallery {
return el.tagName && el.tagName.toUpperCase() === "LI";
});
if (!clickedListItem) {
if (!clickedListItem)
return;
}
// find index of clicked item by looping through all child nodes
// alternatively, you may define index via data- attribute
@ -283,9 +281,8 @@ class TainacanMediaGallery {
index;
for (var i = 0; i < numChildNodes; i++) {
if (childNodes[i].nodeType !== 1) {
if (childNodes[i].nodeType !== 1)
continue;
}
if (childNodes[i] === clickedListItem) {
index = nodeIndex;
@ -294,10 +291,10 @@ class TainacanMediaGallery {
nodeIndex++;
}
if (index >= 0) {
// open PhotoSwipe if valid index found
if (index >= 0)
self.openPhotoSwipe(index, clickedGallery);
}
return false;
}