From fbad35e7a1df590e00b8d1806d6b3b17e60372af Mon Sep 17 00:00:00 2001 From: filesite Date: Sun, 29 Sep 2024 08:26:29 +0800 Subject: [PATCH] add custom button to show 1to1 image --- themes/beauty/views/site/index.php | 6 ++++- www/js/beauty.js | 41 +++++++++++++++++++++++------- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/themes/beauty/views/site/index.php b/themes/beauty/views/site/index.php index 3814ef0..39857a9 100644 --- a/themes/beauty/views/site/index.php +++ b/themes/beauty/views/site/index.php @@ -457,4 +457,8 @@ if ($total > $viewData['pageSize']) { poster="" id="pr-player"> - \ No newline at end of file + + + \ No newline at end of file diff --git a/www/js/beauty.js b/www/js/beauty.js index 6264a4e..78390cb 100644 --- a/www/js/beauty.js +++ b/www/js/beauty.js @@ -1,9 +1,7 @@ /* -******The author - -******Tan + * The author + * Tan */ - //关闭videojs的ga统计 window.HELP_IMPROVE_VIDEOJS = false; @@ -46,9 +44,11 @@ if ($('#image_site').get(0)) { _slidesOfNextPage = data.imgs; }else if (typeof(data.videos) != 'undefined' && data.videos.length > 0) { _slidesOfNextPage = data.videos; - }else { + }else if (typeof(data.msg) != 'undefined' && data.msg) { _noMoreData = true; console.warn('获取下一页json数据出错啦', data.msg); + }else { + _noMoreData = true; } }).fail(function(jqXHR, textStatus, errorThrown) { console.error('获取下一页json数据失败,错误信息:' + errorThrown); @@ -85,29 +85,52 @@ if ($('#image_site').get(0)) { }, 1000); }; + //自定义显示原图按钮 + var customToolbar_show1to1 = { + tpl: $('#btn_show1to1_tmp').html(), + click: function() { + var btn = this, fancybox = this.instance; + var slide = fancybox.getSlide(); + fancybox.showLoading(slide); + $(slide.imageEl).one('load', function() { + console.log('image loaded'); + fancybox.hideLoading(slide); + slide.panzoom.toggleZoom(); + }); + + slide.src = slide.downloadSrc; + slide.imageEl.src = slide.downloadSrc; + } + }; + // 图片浏览 var fancyboxToolbar = { + items: {'show1to1': customToolbar_show1to1}, display: { left: ["infobar"], middle: [ "zoomIn", "zoomOut", - "toggle1to1", + "show1to1", "rotateCCW", "rotateCW", "flipX", - "flipY" + "flipY", + "fitX", + "fitY", + "reset" ], right: ["slideshow", "fullscreen", "thumbs", "download", "close"], }, }; if ($(window).width() < 640) { //小屏幕只显示部分按钮 fancyboxToolbar = { + items: {'show1to1': customToolbar_show1to1}, display: { left: ["infobar"], middle: [ - "zoomIn", - "zoomOut", + "toggleZoom", + "show1to1", "rotateCCW", "rotateCW" ],