script.js 15 KB

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