script.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  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. hamburger_click = 1;
  63. hamburgerButton = $('.hamburger-button');
  64. hamburgerMenuWrap = $('.menu-wrap');
  65. hamburgerMenuItem = $('.menu-nav');
  66. hamburgerMenuWrap.addClass('menu-active');
  67. hamburgerMenuItem.addClass('menu-item-active');
  68. menuOverlay = $('.menu-overlay');
  69. if ( window.innerWidth <= 768) {
  70. $(".content").css("padding-left","257px");
  71. } else {
  72. $(".content").css("padding-left","307px");
  73. }
  74. });
  75. /*
  76. $('.menu-close__wrap').on('mouseup', function(e) {
  77. e.preventDefault();
  78. menuClose = $('.menu-close');
  79. hamburgerMenuWrap = $('.menu-wrap');
  80. hamburgerMenuItem = $('.menu-nav');
  81. menuOverlay = $('.menu-overlay');
  82. if (!hamburgerMenuWrap.is(e.target) && hamburgerMenuWrap.has(e.target).length === 0) {
  83. hamburgerMenuWrap.removeClass('menu-active');
  84. hamburgerMenuItem.removeClass('menu-item-active');
  85. menuOverlay.removeClass('menu-overlay__active');
  86. }
  87. menuClose.on('mousedown', function() {
  88. hamburgerMenuWrap.removeClass('menu-active');
  89. hamburgerMenuItem.removeClass('menu-item-active');
  90. menuOverlay.removeClass('menu-overlay__active');
  91. });
  92. $(".content").css("padding-left","80px");
  93. });
  94. */
  95. $('.menu-close__wrap').on('click', function(e) {
  96. e.preventDefault();
  97. menuClose = $('.menu-close');
  98. hamburgerMenuWrap = $('.menu-wrap');
  99. hamburgerMenuItem = $('.menu-nav');
  100. menuOverlay = $('.menu-overlay');
  101. hamburgerMenuWrap.removeClass('menu-active');
  102. hamburgerMenuItem.removeClass('menu-item-active');
  103. menuOverlay.removeClass('menu-overlay__active');
  104. $(".content").css("padding-left","80px");
  105. });
  106. // Menu END
  107. // Contact START
  108. $('.input-field input, textarea').on('input', function() {
  109. var inputValue = $(this).val();
  110. var inputpParent = $(this).parent('.input-field');
  111. if (inputValue.length > 0) {
  112. inputpParent.addClass('is-active');
  113. } else {
  114. inputpParent.removeClass('is-active');
  115. }
  116. });
  117. // Contact END
  118. // Gallery Single page START
  119. $('.grid-single .grid-item img').parazoom({
  120. customCursorIcon: 'images/magnify.svg',
  121. customCursorSize: '30px',
  122. transitionTime: '1s',
  123. transitionTimeLeave: '1s'
  124. });
  125. var $grid = $('.grid-single').masonry({
  126. itemSelector: '.grid-single .grid-item',
  127. percentPosition: true,
  128. columnWidth: '.grid-single .grid-sizer'
  129. });
  130. $grid.imagesLoaded().progress( function() {
  131. $grid.masonry({
  132. gutter: 15
  133. });
  134. });
  135. $('.grid-single .grid-item a').magnificPopup({
  136. type:'image',
  137. removalDelay: 500,
  138. gallery: {
  139. enabled: true
  140. },
  141. callbacks: {
  142. beforeOpen: function() {
  143. this.st.image.markup = this.st.image.markup.replace('mfp-figure', 'mfp-figure mfp-with-anim');
  144. this.st.mainClass = this.st.el.attr('data-effect');
  145. }
  146. },
  147. });
  148. // Gallery Single page END
  149. // Album page START
  150. function albumMasonry() {
  151. var $gridAlbum = $('.grid-album').masonry({
  152. itemSelector: '.grid-album .grid-item',
  153. percentPosition: true,
  154. columnWidth: '.grid-album .grid-sizer'
  155. });
  156. $gridAlbum.imagesLoaded().progress( function() {
  157. $gridAlbum.masonry({
  158. gutter: 20
  159. });
  160. });
  161. }
  162. albumMasonry();
  163. var bLazy = new Blazy();
  164. $('.album-tab a').on('click', function(e) {
  165. e.preventDefault();
  166. var href = $(this).attr('href');
  167. $('.album-tab a').removeClass('is-active');
  168. $(this).addClass('is-active');
  169. $('.grid-album').removeClass('is-active');
  170. $(href).addClass('is-active');
  171. $(href).addClass('animate__animated animate__slideInUp');
  172. $('.grid-album.is-active:not(' + href + ')').removeClass('animate__animated animate__slideInUp');
  173. albumMasonry();
  174. let column = $(this).attr('column');
  175. if (column == 'pdf' || column == 'video') {
  176. $(".download-all").hide();
  177. } else {
  178. $(".download-all").show();
  179. }
  180. });
  181. // Album page END
  182. // Settings START
  183. $('.settings-btn').on('click', function() {
  184. var settings = $('.settings-wrap');
  185. settings.toggleClass('is-active');
  186. });
  187. var savedColor = localStorage.getItem('boxColor');
  188. if (savedColor) {
  189. $(':root').css('--color-def', savedColor);
  190. }
  191. $('.settings-color-item').on('click', function() {
  192. var color = $(this).css('background-color');
  193. $('.settings-color-item').css('border-color', '#fff');
  194. $(this).css('border-color', color);
  195. $(':root').css('--color-def', color);
  196. localStorage.setItem('boxColor', color);
  197. });
  198. // Settings END
  199. $('.menu-nav-item a').first().click(function () {
  200. $(this).parent().find('.menu-nav-son').stop(true, true).slideToggle(200);
  201. });
  202. $('.menu-nav-son-li').hover(
  203. function () {
  204. // 显示当前 li 的子菜单
  205. $(this).find('.menu-nav-son2').stop(true, true).slideDown(200);
  206. }
  207. );
  208. // 当鼠标离开 .menu-nav ul 时
  209. $('.menu-nav-son-li').mouseleave(function () {
  210. // 隐藏所有子菜单
  211. $('.menu-nav-son2').stop(true, true).slideUp(0);
  212. });
  213. // 创建全屏遮罩层
  214. $('.album-thumb-detail').on('click', function (event) {
  215. // 如果点击的是 download-icon,阻止后续代码执行
  216. if ($(event.target).closest('.download-icon').length) {
  217. return;
  218. }
  219. // 获取当前点击的 .album-thumb-detail 的父级 .grid-album 元素
  220. var $parentAlbum = $(this).closest('.grid-album');
  221. // 获取当前父级下所有 .album-thumb-detail img 的 src
  222. var imageSrcArray = [];
  223. $parentAlbum.find('.album-thumb-detail img').each(function () {
  224. src = $(this).attr('data-src')
  225. // newSrc = src.split('?')[0];
  226. imageSrcArray.push(src);
  227. });
  228. // 获取当前点击图片在数组中的索引
  229. var $albumThumbs = $parentAlbum.find('.album-thumb-detail');
  230. var currentImageIndex = $albumThumbs.index(this);
  231. // console.log(currentImageIndex);
  232. const $fullscreenMask = $('<div>').addClass('fullscreen-mask');
  233. const $fullscreenImg = $('<img>').attr('src', imageSrcArray[currentImageIndex]);
  234. const $btnLeft = $('<div>').addClass('fullscreen-btn fullscreen-btn-left').html('&lt;');
  235. const $btnRight = $('<div>').addClass('fullscreen-btn fullscreen-btn-right').html('&gt;');
  236. $fullscreenMask.append($fullscreenImg, $btnLeft, $btnRight);
  237. // 将遮罩层添加到 body
  238. $('body').append($fullscreenMask);
  239. setTimeout(function () {
  240. $fullscreenMask.addClass('active');
  241. }, 10);
  242. // 点击遮罩层时关闭
  243. $fullscreenMask.on('click', function (e) {
  244. if (!$(e.target).is($btnLeft) && !$(e.target).is($btnRight)) {
  245. $fullscreenMask.removeClass('active');
  246. setTimeout(function () {
  247. $fullscreenMask.remove();
  248. }, 300);
  249. }
  250. });
  251. // 点击左按钮显示上一张图片
  252. $btnLeft.on('click', function () {
  253. currentImageIndex--;
  254. if (currentImageIndex < 0) {
  255. currentImageIndex = imageSrcArray.length - 1;
  256. }
  257. $fullscreenImg.attr('src', imageSrcArray[currentImageIndex]);
  258. });
  259. // 点击右按钮显示下一张图片
  260. $btnRight.on('click', function () {
  261. currentImageIndex++;
  262. if (currentImageIndex >= imageSrcArray.length) {
  263. currentImageIndex = 0;
  264. }
  265. $fullscreenImg.attr('src', imageSrcArray[currentImageIndex]);
  266. });
  267. });
  268. const $overlay = $('#overlay');
  269. const $videoPlayer = $('#videoPlayer');
  270. const $closeBtn = $('#closeBtn');
  271. const $videoBtns = $('.video-btn');
  272. // 点击播放按钮
  273. $videoBtns.on('click', function() {
  274. const videoSrc = $(this).data('src'); // 获取 data-src 属性
  275. $videoPlayer.attr('src', videoSrc); // 设置视频源
  276. $videoPlayer[0].autoplay = true; // 设置自动播放
  277. $overlay.css('display', 'flex'); // 显示遮罩层
  278. });
  279. // 点击关闭按钮
  280. $closeBtn.on('click', function() {
  281. $videoPlayer[0].pause(); // 暂停视频
  282. $videoPlayer.attr('src', ''); // 清空视频源
  283. $overlay.hide(); // 隐藏遮罩层
  284. });
  285. // 点击遮罩层关闭
  286. $overlay.on('click', function(event) {
  287. if (event.target === $overlay[0]) { // 判断是否点击的是遮罩层本身
  288. $videoPlayer[0].pause(); // 暂停视频
  289. $videoPlayer.attr('src', ''); // 清空视频源
  290. $overlay.hide(); // 隐藏遮罩层
  291. }
  292. });
  293. // 为 .log-date 绑定点击事件
  294. $('.log-date').on('click', function() {
  295. // 找到当前 .log-date 的同级 .log-line 元素
  296. $(this).siblings('.log-line').toggleClass('active');
  297. });
  298. //日志
  299. // 检查 update-log 是否存在
  300. if ($('.update-log').length > 0) {
  301. // 定义一个函数来执行 AJAX 请求
  302. function fetchUpdate() {
  303. $.ajax({
  304. url: '/next-log', // 替换为你的 API 端点
  305. method: 'GET', // 根据你的需求选择 GET 或 POST
  306. dataType: 'json', // 根据你的 API 返回的数据类型选择
  307. success: function(response) {
  308. // 假设 response 包含 timestamp 和 message
  309. var created_at = response.data.created_at;
  310. var action = response.data.action;
  311. if (action == 'aa') {
  312. action = '新增了';
  313. } else {
  314. action = '更新了';
  315. }
  316. var model = response.data.model + ' 的';
  317. var content = response.data.content;
  318. var user_name = response.data.user_name;
  319. // 更新 timestamp 和 message
  320. $('.update-log .update-time').text(created_at);
  321. $('.update-log .user_name').text(user_name);
  322. $('.update-log .action').text(action);
  323. $('.update-log .model').text(model);
  324. $('.update-log .log-content').text(content);
  325. },
  326. error: function(xhr, status, error) {
  327. console.error('AJAX 请求失败:', status, error);
  328. }
  329. });
  330. }
  331. // 立即执行一次
  332. fetchUpdate();
  333. // 每 10 秒执行一次
  334. setInterval(fetchUpdate, 20000); // 10000 毫秒 = 10 秒
  335. }
  336. var loadIndex = null;
  337. var downdHref = function() {
  338. // 查找 .album-tab 中带有 is-active 类的 <a> 标签
  339. let activeTab = $('.album-tab a.is-active').attr('href');
  340. // 将 #album- 替换为空,得到 tab 变量
  341. let tab = activeTab.replace('#album-', '');
  342. // 获取当前 URL 中的 id 参数
  343. let currentUrl = window.location.href;
  344. let urlParams = new URLSearchParams(currentUrl.split('?')[1]);
  345. let id = urlParams.get('id');
  346. // 拼接新的 URL
  347. let newUrl = `/download-all?id=${id}&tab=${tab}&refresh=true`;
  348. // 跳转到新 URL
  349. window.location.href = newUrl;
  350. }
  351. //ajax 定时请求 /download-status,直到返回状态为 0 时
  352. var checkDownloadStatus = function() {
  353. var intervalId = setInterval(function() {
  354. $.ajax({
  355. url: '/download-status',
  356. method: 'GET',
  357. dataType: 'json',
  358. success: function(response) {
  359. if (response.status == 0) {
  360. clearInterval(intervalId);
  361. layer.close(loadIndex); // 关闭加载层
  362. }
  363. }
  364. });
  365. }, 1000); // 每秒请求一次
  366. }
  367. // 监听 .download-all 的点击事件
  368. $('.download-all').on('click', function() {
  369. loadIndex = layer.load(2, { shade: [0.8, '#000'] }); // 参数1表示加载样式,shade
  370. //jquery 请求 /download-status
  371. $.ajax({
  372. url: '/download-status',
  373. method: 'GET',
  374. dataType: 'json',
  375. success: function(response) {
  376. if (response.status == 0) {
  377. downdHref();
  378. checkDownloadStatus();
  379. }
  380. }
  381. });
  382. });
  383. if ( window.innerWidth <= 768) {
  384. hamburgerMenuWrap = $('.menu-wrap');
  385. hamburgerMenuWrap.removeClass('menu-active');
  386. $(".content").css("padding-left","80px");
  387. }
  388. });
  389. function changeIframeSrc(url) {
  390. // 获取 iframe 元素
  391. const iframe = document.getElementById('myFrame');
  392. // 改变 iframe 的 src 属性
  393. iframe.src = url;
  394. if ( window.innerWidth <= 768) {
  395. hamburgerMenuWrap = $('.menu-wrap');
  396. hamburgerMenuWrap.removeClass('menu-active');
  397. $(".content").css("padding-left","80px");
  398. }
  399. }