Browse Source

add lazyload for images

master
filesite 3 years ago
parent
commit
934cdf0391
  1. 3
      themes/googleimage/controller/ListController.php
  2. 4
      themes/googleimage/controller/SiteController.php
  3. 1
      themes/googleimage/views/layout/main.php
  4. 6
      themes/googleimage/views/site/index.php
  5. 3
      www/js/lazysizes.min.js

3
themes/googleimage/controller/ListController.php

@ -35,6 +35,9 @@ Class ListController extends Controller {
$breadcrumbs = $this->getBreadcrumbs($menus, $subcate); $breadcrumbs = $this->getBreadcrumbs($menus, $subcate);
$pageTitle = !empty($titles) ? $titles[0]['name'] : "FileSite.io - 无数据库、基于文件和目录的Markdown文档、网址导航、图书、图片、视频网站PHP开源系统"; $pageTitle = !empty($titles) ? $titles[0]['name'] : "FileSite.io - 无数据库、基于文件和目录的Markdown文档、网址导航、图书、图片、视频网站PHP开源系统";
if (!empty($subcate)) {
$pageTitle = "{$subcate['directory']}的照片,来自{$pageTitle}";
}
$viewName = '//site/index'; //共享视图 $viewName = '//site/index'; //共享视图
$params = compact('cateId', 'dirTree', 'scanResults', 'menus', 'html', 'breadcrumbs'); $params = compact('cateId', 'dirTree', 'scanResults', 'menus', 'html', 'breadcrumbs');
return $this->render($viewName, $params, $pageTitle); return $this->render($viewName, $params, $pageTitle);

4
themes/googleimage/controller/SiteController.php

@ -30,7 +30,11 @@ Class SiteController extends Controller {
$html = $scanner->fixMDUrls($readmeFile['realpath'], $html); $html = $scanner->fixMDUrls($readmeFile['realpath'], $html);
} }
$subcate = $scanResults[$cateId];
$pageTitle = !empty($titles) ? $titles[0]['name'] : "FileSite.io - 无数据库、基于文件和目录的Markdown文档、网址导航、图书、图片、视频网站PHP开源系统"; $pageTitle = !empty($titles) ? $titles[0]['name'] : "FileSite.io - 无数据库、基于文件和目录的Markdown文档、网址导航、图书、图片、视频网站PHP开源系统";
if (!empty($subcate)) {
$pageTitle = "{$subcate['directory']}的照片,来自{$pageTitle}";
}
$viewName = 'index'; $viewName = 'index';
$params = compact('cateId', 'dirTree', 'scanResults', 'menus', 'html'); $params = compact('cateId', 'dirTree', 'scanResults', 'menus', 'html');
return $this->render($viewName, $params, $pageTitle); return $this->render($viewName, $params, $pageTitle);

1
themes/googleimage/views/layout/main.php

@ -96,6 +96,7 @@ eof;
<script src="/js/js.cookie.min.js"></script> <script src="/js/js.cookie.min.js"></script>
<script src="/js/main.js?v.1.0"></script> <script src="/js/main.js?v.1.0"></script>
<!--for theme googleimage--> <!--for theme googleimage-->
<script src="/js/lazysizes.min.js"></script>
<script src="/js/blueimp-gallery.min.js"></script> <script src="/js/blueimp-gallery.min.js"></script>
<script src="/js/googleimage.js?v<?=Html::getStaticFileVersion('googleimage.js', 'js')?>"></script> <script src="/js/googleimage.js?v<?=Html::getStaticFileVersion('googleimage.js', 'js')?>"></script>
</body> </body>

6
themes/googleimage/views/site/index.php

@ -53,7 +53,7 @@ eof;
if (!empty($dir['snapshot'])) { if (!empty($dir['snapshot'])) {
echo <<<eof echo <<<eof
<img src="{$dir['snapshot']}" alt="{$dir['directory']}"> <img data-src="{$dir['snapshot']}" class="lazyload" alt="{$dir['directory']}">
eof; eof;
}else if (!empty($dir['files'])) { }else if (!empty($dir['files'])) {
$first_img = array_shift($dir['files']); $first_img = array_shift($dir['files']);
@ -68,7 +68,7 @@ eof;
if (in_array($first_img['extension'], $imgExts)) { if (in_array($first_img['extension'], $imgExts)) {
echo <<<eof echo <<<eof
<img src="{$first_img['path']}" alt="{$first_img['filename']}"> <img data-src="{$first_img['path']}" class="lazyload" alt="{$first_img['filename']}">
eof; eof;
} }
} }
@ -83,7 +83,7 @@ eof;
if (!in_array($file['extension'], $imgExts)) {continue;} if (!in_array($file['extension'], $imgExts)) {continue;}
echo <<<eof echo <<<eof
<a href="{$file['path']}" class="img-item img-preview" target="_blank"> <a href="{$file['path']}" class="img-item img-preview" target="_blank">
<img src="{$file['path']}" alt="{$file['filename']}"> <img data-src="{$file['path']}" class="lazyload" alt="{$file['filename']}">
<strong>{$file['filename']}</strong> <strong>{$file['filename']}</strong>
</a> </a>
eof; eof;

3
www/js/lazysizes.min.js vendored

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save