承接 blackbird/hyva-photo-swipe 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

blackbird/hyva-photo-swipe

Composer 安装命令:

composer require blackbird/hyva-photo-swipe

包简介

An implementation of PhotoSwipe library in Hyvä Theme for Magento 2

README 文档

README

hyva-photo-swipe

Latest Stable Version SplideJS Version License: MIT

An implementation of PhotoSwipe library in Hyvä Theme for Magento 2

You no longer need to worry about how to implement PhotoSwipe in your Magento 2 Hyvä Theme projects.
No manipulations required, instant use after installation.

PhotoSwipe allows you to create full-screen sliders, zoomable, and fully customizable.

The librairy is lazily loaded and does not affect performances accoding to Hyvä documentation.

How It WorksInstallationUsageMore modules

How It Works

The module simply loads PhotoSwipe on all pages that use the PhotoSwipeLightbox class in the DOM
(the class provied by PhotoSwipe).

When the library has been loaded on the page, a state stored in the Alpine.store is updated, indicating that PhotoSwipe is ready for use.

The state can also be used to force the library to be loaded at any time, here is an example using forceLoad()

Installation

Requirements

composer require blackbird/hyva-photo-swipe
php bin/magento setup:upgrade

In production mode, do not forget to recompile and redeploy the static resources.

Usage

Once the module has been installed, simply add the HTML code required to create a slider, don't forget to specify for each child the data-pswp-width and data-pswp-height.

<div id="my-gallery">
  <a href="https://cdn.photoswipe.com/photoswipe-demo-images/photos/2/img-2500.jpg" 
    data-pswp-width="1669" 
    data-pswp-height="2500" 
    target="_blank">
    <img src="https://cdn.photoswipe.com/photoswipe-demo-images/photos/2/img-200.jpg" alt="" />
  </a>
  <a href="https://cdn.photoswipe.com/photoswipe-demo-images/photos/7/img-2500.jpg" 
    data-pswp-width="1875" 
    data-pswp-height="2500" 
    target="_blank">
    <img src="https://cdn.photoswipe.com/photoswipe-demo-images/photos/7/img-200.jpg" alt="" />
  </a>
  <a href="https://unsplash.com" 
    data-pswp-src="https://cdn.photoswipe.com/photoswipe-demo-images/photos/3/img-2500.jpg"
    data-pswp-width="2500" 
    data-pswp-height="1666" 
    target="_blank">
    <img src="https://cdn.photoswipe.com/photoswipe-demo-images/photos/3/img-200.jpg" alt="" />
  </a>
</div>

Next, create a function to listen the Alpine.store state is_loading indicating that PhotoSwipe has been loaded, and apply PhotoSwipe to the HTML elements, as described in the PhotoSwipe documentation.

Don't forget to fill in the important options :

  • gallery: query selection of your parent gallery node
  • children: query selection of your children repetiting nodes
  • pswpModule: just give it PhotoSwipe
<?php
use \Blackbird\HyvaPhotoSwipe\Api\HyvaPhotoSwipeInterface;
?>
<script>
    function myXData () {
        return {
            initPhotoSwipe() {
                if (Alpine.store('<?= HyvaPhotoSwipeInterface::HYVA_PHOTO_SWIPE ?>').is_loaded) {
                    new PhotoSwipeLightbox({
                        gallery: '#my-gallery',
                        children: 'a',
                        pswpModule: PhotoSwipe,
                        ...options
                    }).init();
                }
            }
        }
     }
</script>

You can specify any of the PhotoSwipe options as shown here

Finally, set up the x-data directive and do not forget to call the previous function in an x-effect, to prevent PhotoSwipe being applied until the library is loaded, and to allow it to be automatically applied when the library is loaded.

<div id="my-gallery" x-data="myXData()" x-effect="initPhotoSwipe">
  ...
</div>

Full example

<?php
use \Blackbird\HyvaPhotoSwipe\Api\HyvaPhotoSwipeInterface;
?>
<div id="my-gallery" x-data="myXData()" x-effect="initPhotoSwipe">
  <a href="https://cdn.photoswipe.com/photoswipe-demo-images/photos/2/img-2500.jpg" 
    data-pswp-width="1669" 
    data-pswp-height="2500" 
    target="_blank">
    <img src="https://cdn.photoswipe.com/photoswipe-demo-images/photos/2/img-200.jpg" alt="" />
  </a>
  <a href="https://cdn.photoswipe.com/photoswipe-demo-images/photos/7/img-2500.jpg" 
    data-pswp-width="1875" 
    data-pswp-height="2500" 
    target="_blank">
    <img src="https://cdn.photoswipe.com/photoswipe-demo-images/photos/7/img-200.jpg" alt="" />
  </a>
  <a href="https://unsplash.com" 
    data-pswp-src="https://cdn.photoswipe.com/photoswipe-demo-images/photos/3/img-2500.jpg"
    data-pswp-width="2500" 
    data-pswp-height="1666" 
    target="_blank">
    <img src="https://cdn.photoswipe.com/photoswipe-demo-images/photos/3/img-200.jpg" alt="" />
  </a>
</div>
<script>
    function myXData () {
        return {
            initPhotoSwipe() {
                if (Alpine.store('<?= HyvaPhotoSwipeInterface::HYVA_PHOTO_SWIPE ?>').is_loaded) {
                    new PhotoSwipeLightbox({
                        gallery: '#my-gallery',
                        children: 'a',
                        pswpModule: PhotoSwipe,
                        ...options
                    }).init();
                }
            }
        }
     }
</script>

You can specify any of the PhotoSwipe options as shown here

Example : usage of forceLoad()

Imagine the following case: you do not have the script calling the PhotoSwipeLightbox class provided by the librairy in your DOM, and you want to add it when a user's action is triggered.

In this case, PhotoSwipe won't be loaded by default on the page, you will have to explicitly request that PhotoSwipe be loaded.

Alpine.store('<?= HyvaPhotoSwipeInterface::HYVA_PHOTO_SWIPE ?>').forceLoad()

or

$store.<?= HyvaPhotoSwipeInterface::HYVA_PHOTO_SWIPE ?>.forceLoad()

To find out exactly which one to use, please see the official Alpine documentation for $store or for Alpine.store.

This will force the library to load on the page, even if no script call the PhotoSwipeLightbox class. You can then follow the classic Usage procedure to apply PhotoSwipe.

More modules

hyva-splide-js : An implementation of SplideJS library in Hyvä Theme for Magento 2, highly optimized and customizable sliders.

blackbird/hyva-photo-swipe 适用场景与选型建议

blackbird/hyva-photo-swipe 是一款 基于 HTML 开发的 Composer 扩展包,目前已累计 7.24k 次下载、GitHub Stars 达 9, 最近一次更新时间为 2023 年 09 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 blackbird/hyva-photo-swipe 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 blackbird/hyva-photo-swipe 我们能提供哪些服务?
定制开发 / 二次开发

基于 blackbird/hyva-photo-swipe 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 7.24k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 9
  • 点击次数: 7
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 9
  • Watchers: 2
  • Forks: 1
  • 开发语言: HTML

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-09-26