PageSourceSearch

https://d-image.i4.cn/i4web/static2025/js/common.js

js i4.cn collected 2026-10-03 21:25:37 UTC 5,954 bytes, 215 lines download raw bytes

1$(document).ready(function() {
2  var $searchPlaceholder = $("#searchPlaceholder");
3  var $searchContent = $(".search-content");
4  var $searchInput = $("#headSearchInput");
5  var $searchDel = $(".search-content .search-del");
6
7  $(".js-open-download-modal").on("click", function (event) {
8    event.preventDefault();
9    var $trigger = $(this);
10    var modalTarget = $trigger.attr("data-download-modal");
11    var handlerName = $trigger.attr("data-download-handler") || "openDownloadModal";
12    var handler = window[handlerName];
13    var tabIndex = $trigger.attr("data-download-tab-index");
14
15    if (typeof handler !== "function") {
16      return;
17    }
18    if (typeof tabIndex !== "undefined" && tabIndex !== "") {
19      handler(modalTarget, parseInt(tabIndex, 10));
20    } else {
21      handler(modalTarget);
22    }
23  });
24
25  // ********** 关键词列表 **********
26  var keywords = ["搜索"];
27  var sIndex = 0;
28  var timer = null;
29
30  // 加载热搜
31  $.getJSON("/index_hotSearch.action", function (res) {
32    keywords = res.data ? res.data.split(";") : ["搜索"];
33    for (var index = 0; index < keywords.length; index++) {
34      var element = keywords[index];
35      // type 3 教程 type 4 资讯
36      $(".search-quick-list").append(
37        '<a href="/index_search.action?type=3&model=1&k=' +
38          element +
39          '">' +
40          element +
41          "</a>"
42      );
43    }
44    $searchInput.attr("placeholder", keywords[sIndex]);
45    $searchPlaceholder.text(keywords[sIndex]);
46  });
47
48  $(document).on("click.module1", function(e) {
49    // Head 处理搜索框外部点击关闭
50    if (
51      !$searchContent.is(e.target) &&
52      !$searchPlaceholder.is(e.target) &&
53      !$searchContent.has(e.target).length
54    ) {
55      $searchContent.removeClass("show");
56      $searchInput.val("");
57    }
58  });
59
60  /**
61   * Header Search
62   */
63  if ($searchPlaceholder.length && $searchContent.length) {
64    $searchPlaceholder.on("click", function(e) {
65      e.stopPropagation();
66      $searchContent.toggleClass("show");
67      setTimeout(function() {
68        $searchInput.focus();
69      }, 300);
70    });
71    // 关闭搜索框
72    $searchDel.on("click", function() {
73      $searchContent.removeClass("show");
74      $searchInput.val("");
75    });
76    // 阻止组件内部事件冒泡
77    $searchContent.on("click", function(e) {
78      e.stopPropagation();
79    });
80
81    // 启动轮播
82    function startCarousel() {
83      stopCarousel(); // 防止重复开
84      timer = setInterval(function () {
85        // 只有在输入框为空时才轮播
86        if ($searchInput.val().trim() === "") {
87          sIndex = (sIndex + 1) % keywords.length;
88          $searchInput.attr("placeholder", keywords[sIndex]);
89          $searchPlaceholder.text(keywords[sIndex]);
90        }
91      }, 3000);
92    }
93    // 停止轮播
94    function stopCarousel() {
95      if (timer) {
96        clearInterval(timer);
97        timer = null;
98      }
99    }
100    // 初始 placeholder
101    $searchInput.attr("placeholder", keywords[sIndex]);
102    $searchPlaceholder.text(keywords[sIndex]);
103    startCarousel();
104    // 输入监听
105    $searchInput.on("input", function () {
106      if ($searchInput.val().trim() !== "") {
107        stopCarousel(); // 有输入 → 停止轮播
108      }
109    });
110    // 回车搜索
111    $searchInput.on("keydown", function (e) {
112      if (e.keyCode == 13) {
113        toSearch();
114      }
115    });
116    // 聚焦时/停止轮播
117    $searchInput.on("focus", function () {
118      stopCarousel();
119    });
120    // 失焦时/如果输入为空,恢复轮播
121    $searchInput.on("blur", function () {
122      if ($searchInput.val().trim() === "") {
123        $searchPlaceholder.text(keywords[sIndex]);
124        startCarousel();
125      }
126    });
127
128    function toSearch() {
129      var val = $searchInput.val().trim();
130      var keyword = val || $searchInput.attr("placeholder");
131      var type = $("#search-tabs").attr("attr_value");
132      window.location.href =
133        "/index_search.action?type=" + type + "&model=1&k=" + keyword;
134      //alert("正在搜索: " + keyword);
135    }
136    // 搜索按钮
137    $("#headSearchBtn").on("click", toSearch);
138  }
139});
140
141// 下载
142function openDownloadModal(ele) {
143  $(ele).addClass("show");
144  // $('body').css('overflow', 'hidden');
145}
146
147// 打开PC端
148function openPcClient() {
149  if (navigator.userAgent.toLocaleLowerCase().indexOf("mac") > -1) {
150    var oFrm = document.createElement("iframe");
151    oFrm.style.height = "0px";
152    oFrm.src = "PCi4Tools://1";
153    document.body.appendChild(oFrm);
154    setTimeout(function () {
155      oFrm.remove();
156    }, 5000);
157    return;
158  } else {
159    //pc
160    window.location = "PCi4Tools://";
161  }
162}
163
164/**
165 * 防抖函数
166 * @param {*} func 需要防抖的函数
167 * @param {*} delay 延迟时间(毫秒)
168 * @param {*} immediate 是否立即执行一次
169 * @returns
170 */
171function debounce(func, delay, immediate) {
172  if (typeof delay === "undefined") {
173    delay = 100;
174  }
175  if (typeof immediate === "undefined") {
176    immediate = false;
177  }
178  var timer = null;
179
180  return function () {
181    var args = arguments;
182    var context = this;
183
184    if (timer) {
185      clearTimeout(timer);
186    }
187
188    if (immediate && !timer) {
189      func.apply(context, args);
190    }
191
192    timer = setTimeout(function() {
193      if (!immediate) {
194        func.apply(context, args);
195      }
196      timer = null;
197    }, delay);
198  };
199}
200
201var Dialog = {
202  show: function (msg) {
203    $("body").append(
204      '<div id="dialogWrapper">' +
205        '<div class="dialog-content">' +
206          '<p class="dialog-desc">' + msg + '</p>' +
207          '<a href="javascript:;" class="dialog-btn" onclick="Dialog.hide()">确定</a>' +
208        '</div>' +
209      '</div>'
210    );
211  },
212  hide: function () {
213    $("#dialogWrapper").remove();
214  }
215};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.