script.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. $(document).ready(function() {
  2. new WOW({
  3. mobile: false,
  4. animateClass: 'animate__animated',
  5. }).init();
  6. setTimeout(function() {
  7. $('.prelodaer-wrap').fadeOut('slow');
  8. }, 4500);
  9. //Ajax Form Send START
  10. $('#contact-form').on('submit', function() {
  11. var th = $(this);
  12. $.ajax({
  13. type: 'POST',
  14. url: 'mail.php',
  15. data: th.serialize(),
  16. success: function() {
  17. th.trigger('reset');
  18. $('.input-field').removeClass('is-active');
  19. $.magnificPopup.open({
  20. items: {
  21. src: '<div class="form-alert"><p>Your application has been successfully sent. <br> Expect a call!</p></div>',
  22. type: 'inline'
  23. }
  24. });
  25. },
  26. error: function() {
  27. th.trigger('reset');
  28. $('.input-field').removeClass('is-active');
  29. $.magnificPopup.open({
  30. items: {
  31. src: '<div class="form-alert"><p>An error occurred, please try again</p></div>',
  32. type: 'inline'
  33. }
  34. });
  35. }
  36. });
  37. return false;
  38. });
  39. //Ajax Form Send END
  40. // Banner START
  41. const swiperBanner = new Swiper('.swiper-banner', {
  42. speed: 800,
  43. spaceBetween: 100,
  44. effect: 'fade',
  45. fadeEffect: {
  46. crossFade: true
  47. },
  48. navigation: {
  49. nextEl: '.swiper-banner .swiper-button-next',
  50. prevEl: '.swiper-banner .swiper-button-prev',
  51. },
  52. scrollbar: {
  53. el: '.swiper-banner .swiper-scrollbar',
  54. enabled: true,
  55. draggable: true
  56. },
  57. });
  58. // Banner END
  59. // Menu START
  60. $('body').on('click', '.hamburger-button', function(e) {
  61. e.preventDefault();
  62. hamburgerButton = $('.hamburger-button');
  63. hamburgerMenuWrap = $('.menu-wrap');
  64. hamburgerMenuItem = $('.menu-nav');
  65. hamburgerMenuWrap.addClass('menu-active');
  66. hamburgerMenuItem.addClass('menu-item-active');
  67. menuOverlay = $('.menu-overlay');
  68. // menuOverlay.addClass('menu-overlay__active');
  69. });
  70. $('.menu-close__wrap').on('mouseup', function(e) {
  71. e.preventDefault();
  72. menuClose = $('.menu-close');
  73. hamburgerMenuWrap = $('.menu-wrap');
  74. hamburgerMenuItem = $('.menu-nav');
  75. menuOverlay = $('.menu-overlay');
  76. if (!hamburgerMenuWrap.is(e.target) && hamburgerMenuWrap.has(e.target).length === 0) {
  77. hamburgerMenuWrap.removeClass('menu-active');
  78. hamburgerMenuItem.removeClass('menu-item-active');
  79. menuOverlay.removeClass('menu-overlay__active');
  80. }
  81. menuClose.on('mousedown', function() {
  82. hamburgerMenuWrap.removeClass('menu-active');
  83. hamburgerMenuItem.removeClass('menu-item-active');
  84. menuOverlay.removeClass('menu-overlay__active');
  85. });
  86. });
  87. // Menu END
  88. // Contact START
  89. $('.input-field input, textarea').on('input', function() {
  90. var inputValue = $(this).val();
  91. var inputpParent = $(this).parent('.input-field');
  92. if (inputValue.length > 0) {
  93. inputpParent.addClass('is-active');
  94. } else {
  95. inputpParent.removeClass('is-active');
  96. }
  97. });
  98. // Contact END
  99. // Gallery Single page START
  100. $('.grid-single .grid-item img').parazoom({
  101. customCursorIcon: 'images/magnify.svg',
  102. customCursorSize: '30px',
  103. transitionTime: '1s',
  104. transitionTimeLeave: '1s'
  105. });
  106. var $grid = $('.grid-single').masonry({
  107. itemSelector: '.grid-single .grid-item',
  108. percentPosition: true,
  109. columnWidth: '.grid-single .grid-sizer'
  110. });
  111. $grid.imagesLoaded().progress( function() {
  112. $grid.masonry({
  113. gutter: 15
  114. });
  115. });
  116. $('.grid-single .grid-item a').magnificPopup({
  117. type:'image',
  118. removalDelay: 500,
  119. gallery: {
  120. enabled: true
  121. },
  122. callbacks: {
  123. beforeOpen: function() {
  124. this.st.image.markup = this.st.image.markup.replace('mfp-figure', 'mfp-figure mfp-with-anim');
  125. this.st.mainClass = this.st.el.attr('data-effect');
  126. }
  127. },
  128. });
  129. // Gallery Single page END
  130. // Album page START
  131. function albumMasonry() {
  132. var $gridAlbum = $('.grid-album').masonry({
  133. itemSelector: '.grid-album .grid-item',
  134. percentPosition: true,
  135. columnWidth: '.grid-album .grid-sizer'
  136. });
  137. $gridAlbum.imagesLoaded().progress( function() {
  138. $gridAlbum.masonry({
  139. gutter: 20
  140. });
  141. });
  142. }
  143. albumMasonry();
  144. var bLazy = new Blazy();
  145. $('.album-tab a').on('click', function(e) {
  146. e.preventDefault();
  147. var href = $(this).attr('href');
  148. $('.album-tab a').removeClass('is-active');
  149. $(this).addClass('is-active');
  150. $('.grid-album').removeClass('is-active');
  151. $(href).addClass('is-active');
  152. $(href).addClass('animate__animated animate__slideInUp');
  153. $('.grid-album.is-active:not(' + href + ')').removeClass('animate__animated animate__slideInUp');
  154. albumMasonry();
  155. let column = $(this).attr('column');
  156. if (column == 'pdf' || column == 'video') {
  157. $(".download-all").hide();
  158. } else {
  159. $(".download-all").show();
  160. }
  161. });
  162. // Album page END
  163. // Settings START
  164. $('.settings-btn').on('click', function() {
  165. var settings = $('.settings-wrap');
  166. settings.toggleClass('is-active');
  167. });
  168. var savedColor = localStorage.getItem('boxColor');
  169. if (savedColor) {
  170. $(':root').css('--color-def', savedColor);
  171. }
  172. $('.settings-color-item').on('click', function() {
  173. var color = $(this).css('background-color');
  174. $('.settings-color-item').css('border-color', '#fff');
  175. $(this).css('border-color', color);
  176. $(':root').css('--color-def', color);
  177. localStorage.setItem('boxColor', color);
  178. });
  179. // Settings END
  180. $('.menu-nav-item').hover(
  181. function () {
  182. // 显示当前 li 的子菜单
  183. $(this).find('.menu-nav-son').stop(true, true).slideDown(200);
  184. }
  185. );
  186. // 当鼠标离开 .menu-nav ul 时
  187. $('.menu-nav-item').mouseleave(function () {
  188. // 隐藏所有子菜单
  189. $('.menu-nav-son').stop(true, true).slideUp(0);
  190. });
  191. // 创建全屏遮罩层
  192. $('.album-thumb-detail').on('click', function (event) {
  193. // 如果点击的是 download-icon,阻止后续代码执行
  194. if ($(event.target).closest('.download-icon').length) {
  195. return;
  196. }
  197. // 获取当前点击的 .album-thumb-detail 的父级 .grid-album 元素
  198. var $parentAlbum = $(this).closest('.grid-album');
  199. // 获取当前父级下所有 .album-thumb-detail img 的 src
  200. var imageSrcArray = [];
  201. $parentAlbum.find('.album-thumb-detail img').each(function () {
  202. src = $(this).attr('data-src')
  203. // newSrc = src.split('?')[0];
  204. imageSrcArray.push(src);
  205. });
  206. // 获取当前点击图片在数组中的索引
  207. var $albumThumbs = $parentAlbum.find('.album-thumb-detail');
  208. var currentImageIndex = $albumThumbs.index(this);
  209. // console.log(currentImageIndex);
  210. const $fullscreenMask = $('<div>').addClass('fullscreen-mask');
  211. const $fullscreenImg = $('<img>').attr('src', imageSrcArray[currentImageIndex]);
  212. const $btnLeft = $('<div>').addClass('fullscreen-btn fullscreen-btn-left').html('&lt;');
  213. const $btnRight = $('<div>').addClass('fullscreen-btn fullscreen-btn-right').html('&gt;');
  214. $fullscreenMask.append($fullscreenImg, $btnLeft, $btnRight);
  215. // 将遮罩层添加到 body
  216. $('body').append($fullscreenMask);
  217. setTimeout(function () {
  218. $fullscreenMask.addClass('active');
  219. }, 10);
  220. // 点击遮罩层时关闭
  221. $fullscreenMask.on('click', function (e) {
  222. if (!$(e.target).is($btnLeft) && !$(e.target).is($btnRight)) {
  223. $fullscreenMask.removeClass('active');
  224. setTimeout(function () {
  225. $fullscreenMask.remove();
  226. }, 300);
  227. }
  228. });
  229. // 点击左按钮显示上一张图片
  230. $btnLeft.on('click', function () {
  231. currentImageIndex--;
  232. if (currentImageIndex < 0) {
  233. currentImageIndex = imageSrcArray.length - 1;
  234. }
  235. $fullscreenImg.attr('src', imageSrcArray[currentImageIndex]);
  236. });
  237. // 点击右按钮显示下一张图片
  238. $btnRight.on('click', function () {
  239. currentImageIndex++;
  240. if (currentImageIndex >= imageSrcArray.length) {
  241. currentImageIndex = 0;
  242. }
  243. $fullscreenImg.attr('src', imageSrcArray[currentImageIndex]);
  244. });
  245. });
  246. const $overlay = $('#overlay');
  247. const $videoPlayer = $('#videoPlayer');
  248. const $closeBtn = $('#closeBtn');
  249. const $videoBtns = $('.video-btn');
  250. // 点击播放按钮
  251. $videoBtns.on('click', function() {
  252. const videoSrc = $(this).data('src'); // 获取 data-src 属性
  253. $videoPlayer.attr('src', videoSrc); // 设置视频源
  254. $videoPlayer[0].autoplay = true; // 设置自动播放
  255. $overlay.css('display', 'flex'); // 显示遮罩层
  256. });
  257. // 点击关闭按钮
  258. $closeBtn.on('click', function() {
  259. $videoPlayer[0].pause(); // 暂停视频
  260. $videoPlayer.attr('src', ''); // 清空视频源
  261. $overlay.hide(); // 隐藏遮罩层
  262. });
  263. // 点击遮罩层关闭
  264. $overlay.on('click', function(event) {
  265. if (event.target === $overlay[0]) { // 判断是否点击的是遮罩层本身
  266. $videoPlayer[0].pause(); // 暂停视频
  267. $videoPlayer.attr('src', ''); // 清空视频源
  268. $overlay.hide(); // 隐藏遮罩层
  269. }
  270. });
  271. // 为 .log-date 绑定点击事件
  272. $('.log-date').on('click', function() {
  273. // 找到当前 .log-date 的同级 .log-line 元素
  274. $(this).siblings('.log-line').toggleClass('active');
  275. });
  276. //日志
  277. // 检查 update-log 是否存在
  278. if ($('.update-log').length > 0) {
  279. // 定义一个函数来执行 AJAX 请求
  280. function fetchUpdate() {
  281. $.ajax({
  282. url: '/next-log', // 替换为你的 API 端点
  283. method: 'GET', // 根据你的需求选择 GET 或 POST
  284. dataType: 'json', // 根据你的 API 返回的数据类型选择
  285. success: function(response) {
  286. // 假设 response 包含 timestamp 和 message
  287. var created_at = response.data.created_at;
  288. var action = response.data.action;
  289. if (action == 'aa') {
  290. action = '新增了';
  291. } else {
  292. action = '更新了';
  293. }
  294. var model = response.data.model + ' 的';
  295. var content = response.data.content;
  296. // 更新 timestamp 和 message
  297. $('.update-log .update-time').text(created_at);
  298. $('.update-log .action').text(action);
  299. $('.update-log .model').text(model);
  300. $('.update-log .log-content').text(content);
  301. },
  302. error: function(xhr, status, error) {
  303. console.error('AJAX 请求失败:', status, error);
  304. }
  305. });
  306. }
  307. // 立即执行一次
  308. fetchUpdate();
  309. // 每 10 秒执行一次
  310. setInterval(fetchUpdate, 20000); // 10000 毫秒 = 10 秒
  311. }
  312. // 监听 .download-all 的点击事件
  313. $('.download-all').on('click', function() {
  314. // 查找 .album-tab 中带有 is-active 类的 <a> 标签
  315. let activeTab = $('.album-tab a.is-active').attr('href');
  316. // 将 #album- 替换为空,得到 tab 变量
  317. let tab = activeTab.replace('#album-', '');
  318. // 获取当前 URL 中的 id 参数
  319. let currentUrl = window.location.href;
  320. let urlParams = new URLSearchParams(currentUrl.split('?')[1]);
  321. let id = urlParams.get('id');
  322. // 拼接新的 URL
  323. let newUrl = `/download-all?id=${id}&tab=${tab}`;
  324. // 跳转到新 URL
  325. window.location.href = newUrl;
  326. });
  327. });