You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

search.js 49 kB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724
  1. var token;
  2. if (isEmpty(token)) {
  3. var meta = $("meta[name=_uid]");
  4. if (!isEmpty(meta)) {
  5. token = meta.attr("content");
  6. }
  7. }
  8. var html = document.documentElement;
  9. var lang = html.attributes["lang"];
  10. var isZh = true;
  11. if (lang != null && lang.nodeValue == "en-US") {
  12. isZh = false;
  13. } else {
  14. }
  15. function isEmpty(str) {
  16. if (typeof str == "undefined" || str == null || str == "") {
  17. return true;
  18. }
  19. return false;
  20. }
  21. var itemType = {
  22. 1: "repository",
  23. 2: "issue",
  24. 3: "user",
  25. 4: "org",
  26. 5: "dataset",
  27. 6: "pr",
  28. };
  29. var sortBy = {
  30. 10: "default",
  31. 11: "updated_unix.keyword",
  32. 12: "num_watches",
  33. 13: "num_stars",
  34. 14: "num_forks",
  35. 20: "default",
  36. 21: "updated_unix.keyword",
  37. 30: "default",
  38. 31: "name.keyword",
  39. 32: "name.keyword",
  40. 33: "created_unix.keyword",
  41. 34: "created_unix.keyword",
  42. 40: "default",
  43. 41: "name.keyword",
  44. 42: "name.keyword",
  45. 43: "created_unix.keyword",
  46. 44: "created_unix.keyword",
  47. 50: "default",
  48. 51: "download_times",
  49. 60: "default",
  50. 61: "updated_unix.keyword",
  51. };
  52. var sortAscending = {
  53. 10: "false",
  54. 11: "false",
  55. 12: "false",
  56. 13: "false",
  57. 14: "false",
  58. 20: "false",
  59. 21: "false",
  60. 30: "false",
  61. 31: "true",
  62. 32: "false",
  63. 33: "false",
  64. 34: "true",
  65. 40: "false",
  66. 41: "true",
  67. 42: "false",
  68. 43: "false",
  69. 44: "true",
  70. 50: "false",
  71. 51: "false",
  72. 60: "false",
  73. 61: "false",
  74. };
  75. var currentPage = 1;
  76. var pageSize = 15;
  77. var currentSearchTableName = "repository";
  78. var currentSearchKeyword = "";
  79. var currentSearchSortBy = "";
  80. var currentSearchAscending = "false";
  81. var OnlySearchLabel = false;
  82. var startIndex = 1;
  83. var endIndex = 5;
  84. var totalPage = 1;
  85. var totalNum = 0;
  86. var privateTotal = 0;
  87. function initPageInfo() {
  88. currentPage = 1;
  89. startIndex = 1;
  90. endIndex = 5;
  91. }
  92. function searchItem(type, sortType) {
  93. if (OnlySearchLabel) {
  94. doSearchLabel(
  95. currentSearchTableName,
  96. currentSearchKeyword,
  97. sortBy[sortType],
  98. sortAscending[sortType]
  99. );
  100. } else {
  101. currentSearchKeyword = document.getElementById("keyword_input").value;
  102. if (!isEmpty(currentSearchKeyword)) {
  103. initPageInfo();
  104. currentSearchTableName = itemType[type];
  105. currentSearchSortBy = sortBy[sortType];
  106. currentSearchAscending = sortAscending[sortType];
  107. OnlySearchLabel = false;
  108. page(currentPage);
  109. } else {
  110. emptySearch();
  111. }
  112. }
  113. }
  114. function search() {
  115. currentSearchKeyword = document.getElementById("keyword_input").value;
  116. if (!isEmpty(currentSearchKeyword)) {
  117. currentSearchKeyword = currentSearchKeyword.trim();
  118. }
  119. if (!isEmpty(currentSearchKeyword)) {
  120. doSpcifySearch(
  121. currentSearchTableName,
  122. currentSearchKeyword,
  123. sortBy[10],
  124. "false"
  125. );
  126. } else {
  127. emptySearch();
  128. }
  129. }
  130. function emptySearch() {
  131. initDiv(false);
  132. initPageInfo();
  133. $("#searchForm").addClass("hiddenSearch");
  134. document.getElementById("find_id").innerHTML = getLabel(isZh, "search_empty");
  135. $("#find_title").html("");
  136. document.getElementById("sort_type").innerHTML = "";
  137. document.getElementById("child_search_item").innerHTML = "";
  138. document.getElementById("page_menu").innerHTML = "";
  139. $("#repo_total").text("");
  140. $("#pr_total").text("");
  141. $("#issue_total").text("");
  142. $("#dataset_total").text("");
  143. $("#user_total").text("");
  144. $("#org_total").text("");
  145. setActivate(null);
  146. }
  147. function initDiv(isSearchLabel = false) {
  148. if (isSearchLabel) {
  149. document.getElementById("search_div").style.display = "none";
  150. document.getElementById("search_label_div").style.display = "block";
  151. document.getElementById("dataset_item").style.display = "none";
  152. document.getElementById("issue_item").style.display = "none";
  153. document.getElementById("pr_item").style.display = "none";
  154. document.getElementById("user_item").style.display = "none";
  155. document.getElementById("org_item").style.display = "none";
  156. document.getElementById("find_id").innerHTML = "";
  157. } else {
  158. document.getElementById("search_div").style.display = "block";
  159. document.getElementById("search_label_div").style.display = "none";
  160. document.getElementById("dataset_item").style.display = "block";
  161. document.getElementById("issue_item").style.display = "block";
  162. document.getElementById("pr_item").style.display = "block";
  163. document.getElementById("user_item").style.display = "block";
  164. document.getElementById("org_item").style.display = "block";
  165. document.getElementById("find_id").innerHTML = getLabel(
  166. isZh,
  167. "search_finded"
  168. );
  169. }
  170. }
  171. function doSpcifySearch(tableName, keyword, sortBy = "", ascending = "false") {
  172. initDiv(false);
  173. $("#searchForm").addClass("hiddenSearch");
  174. document.getElementById("find_id").innerHTML = getLabel(
  175. isZh,
  176. "search_finded"
  177. );
  178. currentSearchKeyword = keyword;
  179. initPageInfo();
  180. currentSearchTableName = tableName;
  181. currentSearchSortBy = sortBy;
  182. currentSearchAscending = ascending;
  183. OnlySearchLabel = false;
  184. page(currentPage);
  185. if (currentSearchTableName != "repository") {
  186. doSearch("repository", currentSearchKeyword, 1, pageSize, true, "", false);
  187. }
  188. if (currentSearchTableName != "issue") {
  189. doSearch("issue", currentSearchKeyword, 1, pageSize, true, "", false);
  190. }
  191. if (currentSearchTableName != "user") {
  192. doSearch("user", currentSearchKeyword, 1, pageSize, true, "", false);
  193. }
  194. if (currentSearchTableName != "org") {
  195. doSearch("org", currentSearchKeyword, 1, pageSize, true, "", false);
  196. }
  197. if (currentSearchTableName != "dataset") {
  198. doSearch("dataset", currentSearchKeyword, 1, pageSize, true, "", false);
  199. }
  200. if (currentSearchTableName != "pr") {
  201. doSearch("pr", currentSearchKeyword, 1, pageSize, true, "", false);
  202. }
  203. }
  204. function doSearchLabel(tableName, keyword, sortBy = "", ascending = "false") {
  205. initDiv(true);
  206. //document.getElementById("search_div").style.display="none";
  207. //document.getElementById("search_label_div").style.display="block";
  208. document.getElementById("search_label_div").innerHTML =
  209. '<p class="searchlabel">#' + keyword + "</p>";
  210. currentSearchKeyword = keyword;
  211. initPageInfo();
  212. currentSearchTableName = tableName;
  213. currentSearchSortBy = sortBy;
  214. currentSearchAscending = ascending;
  215. OnlySearchLabel = true;
  216. page(currentPage);
  217. }
  218. function searchLabel(tableName, keyword, sortBy = "", ascending = "false") {
  219. sessionStorage.setItem("keyword", keyword);
  220. sessionStorage.setItem("tableName", tableName);
  221. sessionStorage.setItem("searchLabel", true);
  222. sessionStorage.setItem("sortBy", sortBy);
  223. sessionStorage.setItem("ascending", ascending);
  224. window.open("/all/search/");
  225. }
  226. function doSearch(
  227. tableName,
  228. keyword,
  229. page,
  230. pageSize = 15,
  231. onlyReturnNum = true,
  232. sortBy = "",
  233. OnlySearchLabel = false
  234. ) {
  235. var language = "zh-CN";
  236. if (!isZh) {
  237. language = "en-US";
  238. }
  239. $.ajax({
  240. type: "GET",
  241. url: "/all/dosearch/",
  242. headers: {
  243. authorization: token,
  244. },
  245. dataType: "json",
  246. data: {
  247. TableName: tableName,
  248. Key: keyword,
  249. Page: page,
  250. PageSize: pageSize,
  251. OnlyReturnNum: onlyReturnNum,
  252. SortBy: sortBy,
  253. OnlySearchLabel: OnlySearchLabel,
  254. Ascending: currentSearchAscending,
  255. WebTotal: totalNum,
  256. PrivateTotal: privateTotal,
  257. language: language,
  258. },
  259. async: true,
  260. success: function (json) {
  261. displayResult(tableName, page, json, onlyReturnNum, keyword);
  262. },
  263. error: function (response) {},
  264. });
  265. }
  266. function displayResult(tableName, page, jsonResult, onlyReturnNum, keyword) {
  267. if (tableName == "repository") {
  268. displayRepoResult(page, jsonResult, onlyReturnNum, keyword);
  269. } else if (tableName == "issue") {
  270. displayIssueResult(page, jsonResult, onlyReturnNum, keyword);
  271. } else if (tableName == "user") {
  272. displayUserResult(page, jsonResult, onlyReturnNum, keyword);
  273. } else if (tableName == "org") {
  274. displayOrgResult(page, jsonResult, onlyReturnNum, keyword);
  275. } else if (tableName == "dataset") {
  276. displayDataSetResult(page, jsonResult, onlyReturnNum, keyword);
  277. } else if (tableName == "pr") {
  278. displayPrResult(page, jsonResult, onlyReturnNum, keyword);
  279. }
  280. if (!onlyReturnNum) {
  281. totalPage = Math.ceil(jsonResult.Total / pageSize);
  282. totalNum = jsonResult.Total;
  283. privateTotal = jsonResult.PrivateTotal;
  284. setPage(page);
  285. }
  286. }
  287. function displayPrResult(page, jsonResult, onlyReturnNum, keyword) {
  288. var data = jsonResult.Result;
  289. var total = jsonResult.Total;
  290. $("#pr_total").text(total);
  291. if (!onlyReturnNum) {
  292. setActivate("pr_item");
  293. //$('#keyword_desc').text(keyword);
  294. //$('#obj_desc').text(getLabel(isZh,"search_pr"));
  295. //$('#child_total').text(total);
  296. $("#find_title").html(
  297. getLabel(isZh, "find_title")
  298. .replace("{keyword}", keyword)
  299. .replace("{tablename}", getLabel(isZh, "search_pr"))
  300. .replace("{total}", total)
  301. );
  302. setIssueOrPrInnerHtml(data, "pulls");
  303. }
  304. }
  305. var categoryDesc = {
  306. computer_vision: "计算机视觉",
  307. natural_language_processing: "自然语言处理",
  308. speech_processing: "语音处理",
  309. computer_vision_natural_language_processing: "计算机视觉、自然语言处理",
  310. };
  311. var categoryENDesc = {
  312. computer_vision: "computer vision",
  313. natural_language_processing: "natural language processing",
  314. speech_processing: "speech processing",
  315. computer_vision_natural_language_processing:
  316. "computer vision and natural language processing",
  317. };
  318. var taskDesc = {
  319. machine_translation: "机器翻译",
  320. question_answering_system: "问答系统",
  321. information_retrieval: "信息检索",
  322. knowledge_graph: "知识图谱",
  323. text_annotation: "文本标注",
  324. text_categorization: "文本分类",
  325. emotion_analysis: "情感分析",
  326. language_modeling: "语言建模",
  327. speech_recognition: "语音识别",
  328. automatic_digest: "自动文摘",
  329. information_extraction: "信息抽取",
  330. description_generation: "说明生成",
  331. image_classification: "图像分类",
  332. face_recognition: "人脸识别",
  333. image_search: "图像搜索",
  334. target_detection: "目标检测",
  335. image_description_generation: "图像描述生成",
  336. vehicle_license_plate_recognition: "车辆车牌识别",
  337. medical_image_analysis: "医学图像分析",
  338. unmanned: "无人驾驶",
  339. unmanned_security: "无人安防",
  340. drone: "无人机",
  341. vr_ar: "VR/AR",
  342. "2_d_vision": "2-D视觉",
  343. "2_5_d_vision": "2.5-D视觉",
  344. "3_d_reconstruction": "3D重构",
  345. image_processing: "图像处理",
  346. video_processing: "视频处理",
  347. visual_input_system: "视觉输入系统",
  348. speech_coding: "语音编码",
  349. speech_enhancement: "语音增强",
  350. speech_recognition: "语音识别",
  351. speech_synthesis: "语音合成",
  352. };
  353. var taskENDesc = {
  354. machine_translation: "machine translation",
  355. question_answering_system: "question answering system",
  356. information_retrieval: "information retrieval",
  357. knowledge_graph: "knowledge graph",
  358. text_annotation: "text annotation",
  359. text_categorization: "text categorization",
  360. emotion_analysis: "emotion analysis",
  361. language_modeling: "language modeling",
  362. speech_recognition: "speech recognition",
  363. automatic_digest: "automatic digest",
  364. information_extraction: "information extraction",
  365. description_generation: "description generation",
  366. image_classification: "image classification",
  367. face_recognition: "face recognition",
  368. image_search: "image search",
  369. target_detection: "target detection",
  370. image_description_generation: "image description generation",
  371. vehicle_license_plate_recognition: "vehicle license plate recognition",
  372. medical_image_analysis: "medical image analysis",
  373. unmanned: "unmanned",
  374. unmanned_security: "unmanned security",
  375. drone: "drone",
  376. vr_ar: "VR/AR",
  377. "2_d_vision": "2.D vision",
  378. "2.5_d_vision": "2.5D vision",
  379. "3_d_reconstruction": "3Dreconstruction",
  380. image_processing: "image processing",
  381. video_processing: "video processing",
  382. visual_input_system: "visual input system",
  383. speech_coding: "speech coding",
  384. speech_enhancement: "speech enhancement",
  385. speech_recognition: "speech recognition",
  386. speech_synthesis: "speech synthesis",
  387. };
  388. function getCategoryDesc(isZh, key) {
  389. var re = key;
  390. if (isZh) {
  391. re = categoryDesc[key];
  392. } else {
  393. re = categoryENDesc[key];
  394. }
  395. if (isEmpty(re)) {
  396. return key;
  397. }
  398. return re;
  399. }
  400. function getTaskDesc(isZh, key) {
  401. var re = key;
  402. if (isZh) {
  403. re = taskDesc[key];
  404. } else {
  405. re = taskENDesc[key];
  406. }
  407. if (isEmpty(re)) {
  408. return key;
  409. }
  410. return re;
  411. }
  412. function getActiveItem(sort_type) {
  413. if (
  414. currentSearchSortBy == sortBy[sort_type] &&
  415. currentSearchAscending == sortAscending[sort_type]
  416. ) {
  417. return "active ";
  418. } else {
  419. return "";
  420. }
  421. }
  422. function displayDataSetResult(page, jsonResult, onlyReturnNum, keyword) {
  423. var data = jsonResult.Result;
  424. var total = jsonResult.Total;
  425. $("#dataset_total").text(total);
  426. if (!onlyReturnNum) {
  427. setActivate("dataset_item");
  428. //$('#keyword_desc').text(keyword);
  429. //$('#obj_desc').text(getLabel(isZh,"search_dataset"));
  430. //$('#child_total').text(total);
  431. $("#find_title").html(
  432. getLabel(isZh, "find_title")
  433. .replace("{keyword}", keyword)
  434. .replace("{tablename}", getLabel(isZh, "search_dataset"))
  435. .replace("{total}", total)
  436. );
  437. var sortHtml = "";
  438. sortHtml +=
  439. '<a class="' +
  440. getActiveItem(50) +
  441. 'item" href="javascript:searchItem(5,50);" tabindex="-1" role="menuitem" id="menuitem_1">' +
  442. getLabel(isZh, "search_matched") +
  443. "</a>";
  444. sortHtml +=
  445. '<a class="' +
  446. getActiveItem(51) +
  447. 'item" href="javascript:searchItem(5,51);" tabindex="-1" role="menuitem" id="menuitem_1">' +
  448. getLabel(isZh, "search_matched_download") +
  449. "</a>";
  450. document.getElementById("sort_type").innerHTML = sortHtml;
  451. var html = "";
  452. var currentTime = new Date().getTime();
  453. for (var i = 0; i < data.length; i++) {
  454. var recordMap = data[i];
  455. html += '<div class="item">';
  456. html += ' <div class="content">';
  457. html += ' <div class="ui right metas">';
  458. if (!isEmpty(recordMap["category"])) {
  459. html +=
  460. ' <span class="text grey"><svg class="svg octicon-tasklist" width="16" height="16" aria-hidden="true"><use xlink:href="#octicon-tasklist" /></svg> ' +
  461. getCategoryDesc(isZh, recordMap["category"]) +
  462. "</span>";
  463. }
  464. if (!isEmpty(recordMap["task"])) {
  465. html +=
  466. ' <span class="text grey"><svg class="svg octicon-tag" width="16" height="16" aria-hidden="true"><use xlink:href="#octicon-tag" /></svg>' +
  467. getTaskDesc(isZh, recordMap["task"]) +
  468. "</span>";
  469. }
  470. html +=
  471. ' <span class="text grey"><i class="ri-fire-line"></i> ' +
  472. recordMap["download_times"] +
  473. "</span> ";
  474. html += " </div>";
  475. html += ' <div class="ui header">';
  476. html +=
  477. ' <a class="name" href="/' +
  478. recordMap["repoUrl"] +
  479. '/datasets" target="_blank">' +
  480. recordMap["title"] +
  481. "</a>";
  482. html +=
  483. ' <span class="middle"><svg class="svg octicon-repo-clone" width="16" height="16" aria-hidden="true"><use xlink:href="#octicon-repo-clone"></use></svg></span>';
  484. html += " </div>";
  485. html += ' <div class="description">';
  486. html +=
  487. ' <p class="has-emoji"> ' + recordMap["description"] + "</p>";
  488. if (!isEmpty(recordMap["file_name"])) {
  489. html +=
  490. ' <p class="has-emoji"> ' + recordMap["file_name"] + "</p>";
  491. }
  492. html += ' <p class="time">';
  493. html +=
  494. ' <span class="am-ml-10"></span> ' +
  495. getLabel(isZh, "search_lasted_update") +
  496. " " +
  497. recordMap["updated_html"];
  498. html += " </p>";
  499. html += " </div>";
  500. html += " </div>";
  501. html += "</div>";
  502. }
  503. document.getElementById("child_search_item").innerHTML = html;
  504. }
  505. }
  506. function displayOrgResult(page, jsonResult, onlyReturnNum, keyword) {
  507. var data = jsonResult.Result;
  508. var total = jsonResult.Total;
  509. $("#org_total").text(total);
  510. if (!onlyReturnNum) {
  511. setActivate("org_item");
  512. //$('#keyword_desc').text(keyword);
  513. //$('#obj_desc').text(getLabel(isZh,"search_org"));
  514. //$('#child_total').text(total);
  515. $("#find_title").html(
  516. getLabel(isZh, "find_title")
  517. .replace("{keyword}", keyword)
  518. .replace("{tablename}", getLabel(isZh, "search_org"))
  519. .replace("{total}", total)
  520. );
  521. var sortHtml = "";
  522. sortHtml +=
  523. '<a class="' +
  524. getActiveItem(40) +
  525. 'item" href="javascript:searchItem(4,40);" tabindex="-1" role="menuitem" id="menuitem_1">' +
  526. getLabel(isZh, "search_matched") +
  527. "</a>";
  528. sortHtml +=
  529. '<a class="' +
  530. getActiveItem(41) +
  531. 'item" href="javascript:searchItem(4,41);" tabindex="-1" role="menuitem" id="menuitem_1">' +
  532. getLabel(isZh, "search_letter_asc") +
  533. "</a>";
  534. sortHtml +=
  535. '<a class="' +
  536. getActiveItem(42) +
  537. 'item" href="javascript:searchItem(4,42);" tabindex="-1" role="menuitem" id="menuitem_2">' +
  538. getLabel(isZh, "search_letter_desc") +
  539. "</a>";
  540. sortHtml +=
  541. '<a class="' +
  542. getActiveItem(43) +
  543. 'item" href="javascript:searchItem(4,43);" tabindex="-1" role="menuitem" id="menuitem_2">' +
  544. getLabel(isZh, "search_lasted_create") +
  545. "</a>";
  546. sortHtml +=
  547. '<a class="' +
  548. getActiveItem(44) +
  549. 'item" href="javascript:searchItem(4,44);" tabindex="-1" role="menuitem" id="menuitem_2">' +
  550. getLabel(isZh, "search_early_create") +
  551. "</a>";
  552. document.getElementById("sort_type").innerHTML = sortHtml;
  553. var html = "";
  554. var currentTime = new Date().getTime();
  555. for (var i = 0; i < data.length; i++) {
  556. var recordMap = data[i];
  557. html += '<div class="item members">';
  558. html +=
  559. '<img class="ui avatar image" src="' + recordMap["avatar"] + '"></img>';
  560. html += ' <div class="content">';
  561. html += ' <div class="ui header">';
  562. html +=
  563. ' <a class="name" href="/' +
  564. recordMap["real_name"] +
  565. '" target="_blank">' +
  566. recordMap["name"] +
  567. "&nbsp;&nbsp;" +
  568. recordMap["full_name"] +
  569. "</a>";
  570. html += " </div>";
  571. html += ' <div class="description">';
  572. html +=
  573. ' <p class="has-emoji"> ' + recordMap["description"] + "</p>";
  574. html += ' <p class="has-emoji">';
  575. if (!isEmpty(recordMap["location"]) && recordMap["location"] != "null") {
  576. html +=
  577. ' <i class="ri-map-pin-2-line"></i> ' +
  578. recordMap["location"];
  579. }
  580. html += ' <span class="am-ml-10"></span>';
  581. if (!isEmpty(recordMap["website"]) && recordMap["website"] != "null") {
  582. html +=
  583. ' <i class="ri-links-line"></i>' +
  584. '<a href="' +
  585. recordMap["website"] +
  586. '" target="_blank">' +
  587. recordMap["website"] +
  588. "</a>";
  589. }
  590. html +=
  591. ' <i class="ri-time-line am-ml-10"></i> ' +
  592. getLabel(isZh, "search_add_by") +
  593. " ";
  594. html += recordMap["add_time"];
  595. html += " </p>";
  596. html += " </div>";
  597. html += " </div>";
  598. html += "</div>";
  599. }
  600. document.getElementById("child_search_item").innerHTML = html;
  601. }
  602. }
  603. var monthDisplay = new Array(
  604. "Jan",
  605. "Feb",
  606. "Mar",
  607. "Apr",
  608. "May",
  609. "Jun",
  610. "Jul",
  611. "Aug",
  612. "Spt",
  613. "Oct",
  614. "Nov",
  615. "Dec"
  616. );
  617. function displayUserResult(page, jsonResult, onlyReturnNum, keyword) {
  618. var data = jsonResult.Result;
  619. var total = jsonResult.Total;
  620. $("#user_total").text(total);
  621. if (!onlyReturnNum) {
  622. setActivate("user_item");
  623. //$('#keyword_desc').text(keyword);
  624. //$('#obj_desc').text(getLabel(isZh,"search_user"));
  625. //$('#child_total').text(total);
  626. $("#find_title").html(
  627. getLabel(isZh, "find_title")
  628. .replace("{keyword}", keyword)
  629. .replace("{tablename}", getLabel(isZh, "search_user"))
  630. .replace("{total}", total)
  631. );
  632. var sortHtml = ""; //equal user sort by
  633. sortHtml +=
  634. '<a class="' +
  635. getActiveItem(30) +
  636. 'item" href="javascript:searchItem(3,30);" tabindex="-1" role="menuitem" id="menuitem_1">' +
  637. getLabel(isZh, "search_matched") +
  638. "</a>";
  639. sortHtml +=
  640. '<a class="' +
  641. getActiveItem(31) +
  642. 'item" href="javascript:searchItem(3,31);" tabindex="-1" role="menuitem" id="menuitem_1">' +
  643. getLabel(isZh, "search_letter_asc") +
  644. "</a>";
  645. sortHtml +=
  646. '<a class="' +
  647. getActiveItem(32) +
  648. 'item" href="javascript:searchItem(3,32);" tabindex="-1" role="menuitem" id="menuitem_2">' +
  649. getLabel(isZh, "search_letter_desc") +
  650. "</a>";
  651. sortHtml +=
  652. '<a class="' +
  653. getActiveItem(33) +
  654. 'item" href="javascript:searchItem(3,33);" tabindex="-1" role="menuitem" id="menuitem_2">' +
  655. getLabel(isZh, "search_lasted_create") +
  656. "</a>";
  657. sortHtml +=
  658. '<a class="' +
  659. getActiveItem(34) +
  660. 'item" href="javascript:searchItem(3,34);" tabindex="-1" role="menuitem" id="menuitem_2">' +
  661. getLabel(isZh, "search_early_create") +
  662. "</a>";
  663. document.getElementById("sort_type").innerHTML = sortHtml;
  664. var html = "";
  665. var currentTime = new Date().getTime();
  666. for (var i = 0; i < data.length; i++) {
  667. var recordMap = data[i];
  668. html += '<div class="item members">';
  669. html +=
  670. '<img class="ui avatar image" src="' + recordMap["avatar"] + '"></img>';
  671. html += ' <div class="content">';
  672. html += ' <div class="ui header">';
  673. html +=
  674. ' <a class="name" href="/' +
  675. recordMap["real_name"] +
  676. '" target="_blank">' +
  677. recordMap["name"] +
  678. "&nbsp;&nbsp;" +
  679. recordMap["full_name"] +
  680. "</a>";
  681. html += " </div>";
  682. html += ' <div class="description">';
  683. html +=
  684. ' <p class="has-emoji"> ' + recordMap["description"] + "</p>";
  685. html += ' <p class="has-emoji">';
  686. if (!isEmpty(recordMap["email"]) && recordMap["email"] != "null") {
  687. html +=
  688. ' <i class="ri-mail-line"></i>&nbsp;<a href="mailto:' +
  689. recordMap["email"] +
  690. '" rel="nofollow">' +
  691. recordMap["email"] +
  692. "</a>";
  693. }
  694. html +=
  695. ' <i class="ri-time-line am-ml-10"></i> ' +
  696. getLabel(isZh, "search_add_by") +
  697. " ";
  698. html += recordMap["add_time"];
  699. html += " </p>";
  700. html += " </div>";
  701. html += " </div>";
  702. html += "</div>";
  703. }
  704. document.getElementById("child_search_item").innerHTML = html;
  705. }
  706. }
  707. function setIssueOrPrInnerHtml(data, path) {
  708. var sortHtml = "";
  709. if (path == "issues") {
  710. sortHtml +=
  711. '<a class="' +
  712. getActiveItem(20) +
  713. 'item" href="javascript:searchItem(2,20);" tabindex="-1" role="menuitem" id="menuitem_1">' +
  714. getLabel(isZh, "search_matched") +
  715. "</a>";
  716. sortHtml +=
  717. '<a class="' +
  718. getActiveItem(21) +
  719. 'item" href="javascript:searchItem(2,21);" tabindex="-1" role="menuitem" id="menuitem_1">' +
  720. getLabel(isZh, "search_lasted") +
  721. "</a>";
  722. } else {
  723. sortHtml +=
  724. '<a class="' +
  725. getActiveItem(60) +
  726. 'item" href="javascript:searchItem(6,60);" tabindex="-1" role="menuitem" id="menuitem_1">' +
  727. getLabel(isZh, "search_matched") +
  728. "</a>";
  729. sortHtml +=
  730. '<a class="' +
  731. getActiveItem(61) +
  732. 'item" href="javascript:searchItem(6,61);" tabindex="-1" role="menuitem" id="menuitem_1">' +
  733. getLabel(isZh, "search_lasted") +
  734. "</a>";
  735. }
  736. document.getElementById("sort_type").innerHTML = sortHtml;
  737. var html = "";
  738. var currentTime = new Date().getTime();
  739. for (var i = 0; i < data.length; i++) {
  740. var recordMap = data[i];
  741. html += '<div class="item">';
  742. html += ' <div class="content">';
  743. html += ' <div class="ui header">';
  744. html +=
  745. ' <a class="name" href="/' +
  746. recordMap["repoUrl"] +
  747. "/" +
  748. path +
  749. "/" +
  750. recordMap["index"] +
  751. '" target="_blank">' +
  752. recordMap["name"] +
  753. "</a>";
  754. html += " </div>";
  755. html += ' <div class="description">';
  756. html += ' <p class="has-emoji"> ' + recordMap["content"] + "</p>";
  757. html += ' <p class="time">';
  758. html += ' <i class="ri-code-box-line"></i>';
  759. html +=
  760. ' <a class="am-text grey" href="/' +
  761. recordMap["repoUrl"] +
  762. "/" +
  763. path +
  764. "/" +
  765. recordMap["index"] +
  766. '" target="_blank"> ' +
  767. addBlank(recordMap["repoUrl"]) +
  768. " #" +
  769. recordMap["index"] +
  770. "</a>&nbsp;&nbsp;&nbsp;&nbsp;";
  771. html += ' <i class="ri-information-line am-ml-10"></i>&nbsp;';
  772. if (
  773. recordMap["is_closed"] != null &&
  774. (!recordMap["is_closed"] || recordMap["is_closed"] == "f")
  775. ) {
  776. html += getLabel(isZh, "search_open");
  777. } else {
  778. html += getLabel(isZh, "search_closed");
  779. }
  780. html +=
  781. ' &nbsp;&nbsp;&nbsp;&nbsp;<i class="ri-message-2-line am-ml-10"></i>&nbsp;' +
  782. recordMap["num_comments"];
  783. html +=
  784. ' <span class="am-ml-10">&nbsp;&nbsp;</span>&nbsp;&nbsp;' +
  785. getLabel(isZh, "search_lasted_update") +
  786. " " +
  787. recordMap["updated_html"];
  788. html += " </p>";
  789. html += " </div>";
  790. html += " </div>";
  791. html += "</div>";
  792. }
  793. document.getElementById("child_search_item").innerHTML = html;
  794. }
  795. function addBlank(url) {
  796. if (url == null) {
  797. return url;
  798. }
  799. var tmps = url.split("/");
  800. if (tmps.length == 2) {
  801. return tmps[0] + " / " + tmps[1];
  802. }
  803. return url;
  804. }
  805. function displayIssueResult(page, jsonResult, onlyReturnNum, keyword) {
  806. var data = jsonResult.Result;
  807. var total = jsonResult.Total;
  808. $("#issue_total").text(total);
  809. if (!onlyReturnNum) {
  810. setActivate("issue_item");
  811. //$('#keyword_desc').text(keyword);
  812. //$('#obj_desc').text(getLabel(isZh,"search_issue"));
  813. //$('#child_total').text(total);
  814. $("#find_title").html(
  815. getLabel(isZh, "find_title")
  816. .replace("{keyword}", keyword)
  817. .replace("{tablename}", getLabel(isZh, "search_issue"))
  818. .replace("{total}", total)
  819. );
  820. setIssueOrPrInnerHtml(data, "issues");
  821. }
  822. }
  823. function setActivate(name) {
  824. $("#repo_item").removeClass("active");
  825. $("#user_item").removeClass("active");
  826. $("#issue_item").removeClass("active");
  827. $("#dataset_item").removeClass("active");
  828. $("#org_item").removeClass("active");
  829. $("#pr_item").removeClass("active");
  830. if (name == null) {
  831. return;
  832. }
  833. var tmp = "#" + name;
  834. $(tmp).addClass("active");
  835. }
  836. function LetterAvatar(name, size, color) {
  837. name = name || "";
  838. size = size || 60;
  839. var colours = [
  840. "#1abc9c",
  841. "#2ecc71",
  842. "#3498db",
  843. "#9b59b6",
  844. "#34495e",
  845. "#16a085",
  846. "#27ae60",
  847. "#2980b9",
  848. "#8e44ad",
  849. "#2c3e50",
  850. "#f1c40f",
  851. "#e67e22",
  852. "#e74c3c",
  853. "#00bcd4",
  854. "#95a5a6",
  855. "#f39c12",
  856. "#d35400",
  857. "#c0392b",
  858. "#bdc3c7",
  859. "#7f8c8d",
  860. ],
  861. nameSplit = String(name).split(" "),
  862. initials,
  863. charIndex,
  864. colourIndex,
  865. canvas,
  866. context,
  867. dataURI;
  868. if (nameSplit.length == 1) {
  869. initials = nameSplit[0] ? nameSplit[0].charAt(0) : "?";
  870. } else {
  871. initials = nameSplit[0].charAt(0) + nameSplit[1].charAt(0);
  872. }
  873. let initials1 = initials.toUpperCase();
  874. initials.toUpperCase();
  875. if (w.devicePixelRatio) {
  876. size = size * w.devicePixelRatio;
  877. }
  878. charIndex = (initials == "?" ? 72 : initials.charCodeAt(0)) - 64;
  879. colourIndex = charIndex % 20;
  880. canvas = d.createElement("canvas");
  881. canvas.width = size;
  882. canvas.height = size;
  883. context = canvas.getContext("2d");
  884. context.fillStyle = color ? color : colours[colourIndex - 1];
  885. context.fillRect(0, 0, canvas.width, canvas.height);
  886. context.font = Math.round(canvas.width / 2) + "px 'Microsoft Yahei'";
  887. context.textAlign = "center";
  888. context.fillStyle = "#FFF";
  889. context.fillText(initials1, size / 2, size / 1.5);
  890. dataURI = canvas.toDataURL();
  891. canvas = null;
  892. return dataURI;
  893. }
  894. LetterAvatar.transform = function () {
  895. Array.prototype.forEach.call(
  896. d.querySelectorAll("img[avatar]"),
  897. function (img, name, color) {
  898. name = img.getAttribute("avatar");
  899. color = img.getAttribute("color");
  900. img.src = LetterAvatar(name, img.getAttribute("width"), color);
  901. img.removeAttribute("avatar");
  902. img.setAttribute("alt", name);
  903. }
  904. );
  905. };
  906. function displayRepoResult(page, jsonResult, onlyReturnNum, keyword) {
  907. var data = jsonResult.Result;
  908. var total = jsonResult.Total;
  909. $("#repo_total").text(total);
  910. if (!onlyReturnNum) {
  911. setActivate("repo_item");
  912. // $('#keyword_desc').text(keyword);
  913. //$('#obj_desc').text(getLabel(isZh,"search_repo"));
  914. //$('#child_total').text(total);
  915. $("#find_title").html(
  916. getLabel(isZh, "find_title")
  917. .replace("{keyword}", keyword)
  918. .replace("{tablename}", getLabel(isZh, "search_repo"))
  919. .replace("{total}", total)
  920. );
  921. var sortHtml = "";
  922. sortHtml +=
  923. '<a class="' +
  924. getActiveItem(10) +
  925. 'item" href="javascript:searchItem(1,10);" tabindex="-1" role="menuitem" id="menuitem_1">' +
  926. getLabel(isZh, "search_matched") +
  927. "</a>";
  928. sortHtml +=
  929. '<a class="' +
  930. getActiveItem(11) +
  931. 'item" href="javascript:searchItem(1,11);" tabindex="-1" role="menuitem" id="menuitem_1">' +
  932. getLabel(isZh, "search_lasted") +
  933. "</a>";
  934. sortHtml +=
  935. '<a class="' +
  936. getActiveItem(12) +
  937. 'item" href="javascript:searchItem(1,12);" tabindex="-1" role="menuitem" id="menuitem_1">' +
  938. getLabel(isZh, "search_watched") +
  939. "</a>";
  940. sortHtml +=
  941. '<a class="' +
  942. getActiveItem(13) +
  943. 'item" href="javascript:searchItem(1,13);" tabindex="-1" role="menuitem" id="menuitem_1">' +
  944. getLabel(isZh, "search_star") +
  945. "</a>";
  946. sortHtml +=
  947. '<a class="' +
  948. getActiveItem(14) +
  949. 'item" href="javascript:searchItem(1,14);" tabindex="-1" role="menuitem" id="menuitem_1">' +
  950. getLabel(isZh, "search_fork") +
  951. "</a>";
  952. document.getElementById("sort_type").innerHTML = sortHtml;
  953. var html = "";
  954. var currentTime = new Date().getTime();
  955. for (var i = 0; i < data.length; i++) {
  956. var recordMap = data[i];
  957. html += '<div class="item">';
  958. if (recordMap["avatar"]) {
  959. html += `<img class="ui avatar image" src="${recordMap["avatar"]}">`;
  960. } else {
  961. html += `<img class="ui avatar image" avatar="${recordMap["owner_name"]}">`;
  962. }
  963. html += ' <div class="content">';
  964. html += ' <div class="ui header">';
  965. html +=
  966. ' <a class="name" href="/' +
  967. recordMap["owner_name"] +
  968. "/" +
  969. recordMap["real_name"] +
  970. '" target="_blank"> <span>' +
  971. recordMap["owner_name"] +
  972. "</span> <span>/</span> <strong>" +
  973. recordMap["alias"] +
  974. "</strong></a>";
  975. if (recordMap["is_private"]) {
  976. html +=
  977. ' <span class="middle text gold"><svg class="svg octicon-lock" width="16" height="16" aria-hidden="true"><use xlink:href="#octicon-lock" /></svg></span>';
  978. }
  979. html += " </div>";
  980. html += ' <div class="description">';
  981. html +=
  982. ' <p class="has-emoji"> ' + recordMap["description"] + "</p>";
  983. html += ' <div class="ui tags">';
  984. if (!isEmpty(recordMap["topics"]) && recordMap["topics"] != "null") {
  985. for (var j = 0; j < recordMap["topics"].length; j++) {
  986. //function searchLabel(tableName,keyword,sortBy="",ascending=false)
  987. html +=
  988. " <a href=\"javascript:searchLabel('repository','" +
  989. recordMap["topics"][j] +
  990. "','updated_unix.keyword',false);\" ><div class=\"ui small label topic\">" +
  991. recordMap["hightTopics"][j] +
  992. "</div></a>";
  993. }
  994. }
  995. html += " </div>";
  996. html += ' <p class="time">';
  997. html +=
  998. ' <i class="icon fa-eye outline"></i>&nbsp;' +
  999. recordMap["num_watches"] +
  1000. '&nbsp;&nbsp;<i class="icon star outline"></i>&nbsp;' +
  1001. recordMap["num_stars"] +
  1002. '&nbsp;&nbsp;<i class="icon code branch"></i>&nbsp;' +
  1003. recordMap["num_forks"] +
  1004. "&nbsp;&nbsp;";
  1005. html +=
  1006. "&nbsp;&nbsp;&nbsp;&nbsp;" +
  1007. getLabel(isZh, "search_lasted_update") +
  1008. " " +
  1009. recordMap["updated_html"];
  1010. if (!isEmpty(recordMap["lang"])) {
  1011. var lang = recordMap["lang"];
  1012. var tmpLang = recordMap["lang"].split(",");
  1013. if (tmpLang.length > 0) {
  1014. lang = tmpLang[0];
  1015. }
  1016. var backColor = "#3572A5";
  1017. if (LanguagesColor[lang] != null) {
  1018. backColor = LanguagesColor[lang];
  1019. }
  1020. html +=
  1021. ' <span class="text grey am-ml-10"><i class="color-icon" style="background-color: ' +
  1022. backColor +
  1023. '"></i>&nbsp;' +
  1024. lang +
  1025. "</span>";
  1026. }
  1027. html += " </p>";
  1028. html += " </div>";
  1029. html += " </div>";
  1030. html += "</div>";
  1031. }
  1032. document.getElementById("child_search_item").innerHTML = html;
  1033. LetterAvatar.transform();
  1034. }
  1035. }
  1036. function getTime(UpdatedUnix, currentTime) {
  1037. UpdatedUnix = UpdatedUnix;
  1038. currentTime = currentTime / 1000;
  1039. var timeEscSecond = currentTime - UpdatedUnix;
  1040. if (timeEscSecond < 0) {
  1041. timeEscSecond = 1;
  1042. }
  1043. var hours = Math.floor(timeEscSecond / 3600);
  1044. //计算相差分钟数
  1045. var leave2 = Math.floor(timeEscSecond % 3600); //计算小时数后剩余的秒数
  1046. var minutes = Math.floor(leave2 / 60); //计算相差分钟数
  1047. var leave3 = Math.floor(leave2 % 60); //计算分钟数后剩余的秒数
  1048. var seconds = leave3;
  1049. if (hours == 0 && minutes == 0) {
  1050. return seconds + getRepoOrOrg(6, isZh);
  1051. } else {
  1052. if (hours > 0) {
  1053. if (hours >= 24) {
  1054. var days = Math.ceil(hours / 24);
  1055. if (days >= 30 && days < 365) {
  1056. return Math.ceil(days / 30) + getRepoOrOrg(8, isZh);
  1057. } else if (days >= 365) {
  1058. return Math.ceil(days / 365) + getRepoOrOrg(9, isZh);
  1059. }
  1060. return Math.ceil(hours / 24) + getRepoOrOrg(7, isZh);
  1061. } else {
  1062. return hours + getRepoOrOrg(4, isZh);
  1063. }
  1064. } else {
  1065. return minutes + getRepoOrOrg(5, isZh);
  1066. }
  1067. }
  1068. }
  1069. function getRepoOrOrg(key, isZhLang) {
  1070. if (isZhLang) {
  1071. return repoAndOrgZH[key];
  1072. } else {
  1073. return repoAndOrgEN[key];
  1074. }
  1075. }
  1076. var repoAndOrgZH = {
  1077. 1: "项目",
  1078. 2: "成员",
  1079. 3: "团队",
  1080. 4: "小时前",
  1081. 5: "分钟前",
  1082. 6: "秒前",
  1083. 7: "天前",
  1084. 8: "个月前",
  1085. 9: "年前",
  1086. };
  1087. var repoAndOrgEN = {
  1088. 1: "repository",
  1089. 2: "Members ",
  1090. 3: "Teams",
  1091. 4: " hours ago",
  1092. 5: " minutes ago",
  1093. 6: " seconds ago",
  1094. 7: " day ago",
  1095. 8: " month ago",
  1096. 9: " year ago",
  1097. };
  1098. function page(current) {
  1099. currentPage = current;
  1100. doSearch(
  1101. currentSearchTableName,
  1102. currentSearchKeyword,
  1103. current,
  1104. pageSize,
  1105. false,
  1106. currentSearchSortBy,
  1107. OnlySearchLabel
  1108. );
  1109. }
  1110. function nextPage() {
  1111. currentPage = currentPage + 1;
  1112. page(currentPage);
  1113. }
  1114. function prePage() {
  1115. if (currentPage > 1) {
  1116. currentPage = currentPage - 1;
  1117. page(currentPage);
  1118. }
  1119. }
  1120. function getXPosition(e) {
  1121. var x = e.offsetLeft;
  1122. while ((e = e.offsetParent)) {
  1123. x += e.offsetLeft;
  1124. }
  1125. return x + 20; //-260防止屏幕超出
  1126. }
  1127. //获取y坐标
  1128. function getYPosition(e) {
  1129. var y = e.offsetTop;
  1130. while ((e = e.offsetParent)) {
  1131. y += e.offsetTop;
  1132. }
  1133. return y + 20; //80为input高度
  1134. }
  1135. function goPage(event) {
  1136. var inputpage = document.getElementById("inputpage_div");
  1137. var left = getXPosition(event.target);
  1138. var top = getYPosition(event.target);
  1139. var goNum = $("#inputpage").val();
  1140. if (goNum <= 0) {
  1141. showTip(getLabel(isZh, "search_input_large_0"), "warning", left + 5, top);
  1142. } else if (goNum <= totalPage) {
  1143. page(parseInt(goNum, 10));
  1144. } else {
  1145. showTip(getLabel(isZh, "search_input_maxed"), "warning", left + 5, top);
  1146. }
  1147. }
  1148. function showTip(tip, type, left, top) {
  1149. var $tip = $("#tipmsg");
  1150. var tipmsg = document.getElementById("tipmsg");
  1151. var style =
  1152. "z-index:10024;top:" +
  1153. top +
  1154. "px;left:" +
  1155. left +
  1156. "px;position:absolute;width:200px;height:60px;vertical-align:middle;";
  1157. tipmsg.style = style;
  1158. var html = "<p>" + tip + "</p>";
  1159. $tip
  1160. .stop(true)
  1161. .prop("class", "alert alert-" + type)
  1162. .html(html)
  1163. .fadeIn(500)
  1164. .delay(2000)
  1165. .fadeOut(500);
  1166. }
  1167. function setPage(currentPage) {
  1168. var html = "";
  1169. startIndex = currentPage - 1;
  1170. if (startIndex < 1) {
  1171. startIndex = 1;
  1172. }
  1173. endIndex = currentPage + 2;
  1174. if (endIndex >= totalPage) {
  1175. endIndex = totalPage;
  1176. }
  1177. html +=
  1178. '<span class="item">' +
  1179. getLabel(isZh, "search_input_total") +
  1180. " " +
  1181. totalNum +
  1182. " " +
  1183. getLabel(isZh, "search_srtip") +
  1184. "</span>";
  1185. if (currentPage > 1) {
  1186. html +=
  1187. '<a class="item navigation" href="javascript:page(1)"><span class="navigation_label">' +
  1188. getLabel(isZh, "search_home_page") +
  1189. "</span></a>";
  1190. html +=
  1191. '<a class="item navigation" href="javascript:prePage()"><i class="left arrow icon"></i></a>';
  1192. } else {
  1193. html +=
  1194. '<a class="disabled item navigation" href="javascript:page(1)"><span class="navigation_label">' +
  1195. getLabel(isZh, "search_home_page") +
  1196. "</span></a>";
  1197. html +=
  1198. '<a class="disabled item navigation" href="javascript:prePage()"><i class="left arrow icon"></i></a>';
  1199. }
  1200. for (var i = startIndex; i <= endIndex; i++) {
  1201. var page_i = i;
  1202. if (page_i > totalPage) {
  1203. break;
  1204. }
  1205. if (page_i == currentPage) {
  1206. html +=
  1207. '<a id="page_' +
  1208. page_i +
  1209. '" class="active item" href="javascript:page(' +
  1210. page_i +
  1211. ')">' +
  1212. page_i +
  1213. "</a>";
  1214. } else {
  1215. html +=
  1216. '<a id="page_' +
  1217. page_i +
  1218. '" class="item" href="javascript:page(' +
  1219. page_i +
  1220. ')">' +
  1221. page_i +
  1222. "</a>";
  1223. }
  1224. }
  1225. if (endIndex < totalPage - 1) {
  1226. html += "...";
  1227. html +=
  1228. '<a id="page_' +
  1229. totalPage +
  1230. '" class="item" href="javascript:page(' +
  1231. totalPage +
  1232. ')">' +
  1233. totalPage +
  1234. "</a>";
  1235. }
  1236. if (currentPage >= totalPage) {
  1237. html +=
  1238. '<a class="disabled item navigation" href="javascript:nextPage()"><i class="icon right arrow"></i></a>';
  1239. html +=
  1240. '<a class="disabled item navigation" href="javascript:page(' +
  1241. totalPage +
  1242. ')"><span class="navigation_label">' +
  1243. getLabel(isZh, "search_last_page") +
  1244. "</span></a>";
  1245. } else {
  1246. html +=
  1247. '<a class="item navigation" href="javascript:nextPage()"><i class="icon right arrow"></i></a>';
  1248. html +=
  1249. '<a class="item navigation" href="javascript:page(' +
  1250. totalPage +
  1251. ')"><span class="navigation_label">' +
  1252. getLabel(isZh, "search_last_page") +
  1253. "</span></a>";
  1254. }
  1255. html +=
  1256. '<div class="item"> ' +
  1257. getLabel(isZh, "search_go_to") +
  1258. '<div id="inputpage_div" class="ui input"><input id="inputpage" type="text"></div>' +
  1259. getLabel(isZh, "search_go_page") +
  1260. "</div>";
  1261. document.getElementById("page_menu").innerHTML = html;
  1262. $("#inputpage").on("keypress", function (event) {
  1263. if (event.keyCode == 13) {
  1264. goPage(event);
  1265. }
  1266. });
  1267. }
  1268. $("#keyword_input").on("keypress", function (event) {
  1269. if (event.keyCode == 13) {
  1270. search();
  1271. }
  1272. });
  1273. var LanguagesColor = {
  1274. "1C Enterprise": "#814CCC",
  1275. ABAP: "#E8274B",
  1276. "AGS Script": "#B9D9FF",
  1277. AMPL: "#E6EFBB",
  1278. ANTLR: "#9DC3FF",
  1279. "API Blueprint": "#2ACCA8",
  1280. APL: "#5A8164",
  1281. ASP: "#6a40fd",
  1282. ATS: "#1ac620",
  1283. ActionScript: "#882B0F",
  1284. Ada: "#02f88c",
  1285. Agda: "#315665",
  1286. Alloy: "#64C800",
  1287. AngelScript: "#C7D7DC",
  1288. AppleScript: "#101F1F",
  1289. Arc: "#aa2afe",
  1290. AspectJ: "#a957b0",
  1291. Assembly: "#6E4C13",
  1292. Asymptote: "#4a0c0c",
  1293. AutoHotkey: "#6594b9",
  1294. AutoIt: "#1C3552",
  1295. Ballerina: "#FF5000",
  1296. Batchfile: "#C1F12E",
  1297. BlitzMax: "#cd6400",
  1298. Boo: "#d4bec1",
  1299. Brainfuck: "#2F2530",
  1300. C: "#555555",
  1301. "C#": "#178600",
  1302. "C++": "#f34b7d",
  1303. CSS: "#563d7c",
  1304. Ceylon: "#dfa535",
  1305. Chapel: "#8dc63f",
  1306. Cirru: "#ccccff",
  1307. Clarion: "#db901e",
  1308. Clean: "#3F85AF",
  1309. Click: "#E4E6F3",
  1310. Clojure: "#db5855",
  1311. CoffeeScript: "#244776",
  1312. ColdFusion: "#ed2cd6",
  1313. "Common Lisp": "#3fb68b",
  1314. "Common Workflow Language": "#B5314C",
  1315. "Component Pascal": "#B0CE4E",
  1316. Crystal: "#000100",
  1317. Cuda: "#3A4E3A",
  1318. D: "#ba595e",
  1319. DM: "#447265",
  1320. Dart: "#00B4AB",
  1321. DataWeave: "#003a52",
  1322. Dhall: "#dfafff",
  1323. Dockerfile: "#384d54",
  1324. Dogescript: "#cca760",
  1325. Dylan: "#6c616e",
  1326. E: "#ccce35",
  1327. ECL: "#8a1267",
  1328. EQ: "#a78649",
  1329. Eiffel: "#946d57",
  1330. Elixir: "#6e4a7e",
  1331. Elm: "#60B5CC",
  1332. "Emacs Lisp": "#c065db",
  1333. EmberScript: "#FFF4F3",
  1334. Erlang: "#B83998",
  1335. "F#": "#b845fc",
  1336. "F*": "#572e30",
  1337. FLUX: "#88ccff",
  1338. Factor: "#636746",
  1339. Fancy: "#7b9db4",
  1340. Fantom: "#14253c",
  1341. Faust: "#c37240",
  1342. Forth: "#341708",
  1343. Fortran: "#4d41b1",
  1344. FreeMarker: "#0050b2",
  1345. Frege: "#00cafe",
  1346. "G-code": "#D08CF2",
  1347. GAML: "#FFC766",
  1348. GDScript: "#355570",
  1349. "Game Maker Language": "#71b417",
  1350. Genie: "#fb855d",
  1351. Gherkin: "#5B2063",
  1352. Glyph: "#c1ac7f",
  1353. Gnuplot: "#f0a9f0",
  1354. Go: "#00ADD8",
  1355. Golo: "#88562A",
  1356. Gosu: "#82937f",
  1357. "Grammatical Framework": "#79aa7a",
  1358. Groovy: "#e69f56",
  1359. HTML: "#e34c26",
  1360. Hack: "#878787",
  1361. Harbour: "#0e60e3",
  1362. Haskell: "#5e5086",
  1363. Haxe: "#df7900",
  1364. HiveQL: "#dce200",
  1365. HolyC: "#ffefaf",
  1366. Hy: "#7790B2",
  1367. IDL: "#a3522f",
  1368. "IGOR Pro": "#0000cc",
  1369. Idris: "#b30000",
  1370. Io: "#a9188d",
  1371. Ioke: "#078193",
  1372. Isabelle: "#FEFE00",
  1373. J: "#9EEDFF",
  1374. JSONiq: "#40d47e",
  1375. Java: "#b07219",
  1376. JavaScript: "#f1e05a",
  1377. Jolie: "#843179",
  1378. Jsonnet: "#0064bd",
  1379. Julia: "#a270ba",
  1380. "Jupyter Notebook": "#DA5B0B",
  1381. KRL: "#28430A",
  1382. Kotlin: "#F18E33",
  1383. LFE: "#4C3023",
  1384. LLVM: "#185619",
  1385. LOLCODE: "#cc9900",
  1386. LSL: "#3d9970",
  1387. Lasso: "#999999",
  1388. Lex: "#DBCA00",
  1389. LiveScript: "#499886",
  1390. LookML: "#652B81",
  1391. Lua: "#000080",
  1392. MATLAB: "#e16737",
  1393. MAXScript: "#00a6a6",
  1394. MLIR: "#5EC8DB",
  1395. MQL4: "#62A8D6",
  1396. MQL5: "#4A76B8",
  1397. MTML: "#b7e1f4",
  1398. Makefile: "#427819",
  1399. Mask: "#f97732",
  1400. Max: "#c4a79c",
  1401. Mercury: "#ff2b2b",
  1402. Meson: "#007800",
  1403. Metal: "#8f14e9",
  1404. Mirah: "#c7a938",
  1405. "Modula-3": "#223388",
  1406. NCL: "#28431f",
  1407. Nearley: "#990000",
  1408. Nemerle: "#3d3c6e",
  1409. NetLinx: "#0aa0ff",
  1410. "NetLinx+ERB": "#747faa",
  1411. NetLogo: "#ff6375",
  1412. NewLisp: "#87AED7",
  1413. Nextflow: "#3ac486",
  1414. Nim: "#37775b",
  1415. Nit: "#009917",
  1416. Nix: "#7e7eff",
  1417. Nu: "#c9df40",
  1418. OCaml: "#3be133",
  1419. ObjectScript: "#424893",
  1420. "Objective-C": "#438eff",
  1421. "Objective-C++": "#6866fb",
  1422. "Objective-J": "#ff0c5a",
  1423. Odin: "#60AFFE",
  1424. Omgrofl: "#cabbff",
  1425. Opal: "#f7ede0",
  1426. OpenQASM: "#AA70FF",
  1427. Oxygene: "#cdd0e3",
  1428. Oz: "#fab738",
  1429. P4: "#7055b5",
  1430. PHP: "#4F5D95",
  1431. PLSQL: "#dad8d8",
  1432. Pan: "#cc0000",
  1433. Papyrus: "#6600cc",
  1434. Parrot: "#f3ca0a",
  1435. Pascal: "#E3F171",
  1436. Pawn: "#dbb284",
  1437. Pep8: "#C76F5B",
  1438. Perl: "#0298c3",
  1439. PigLatin: "#fcd7de",
  1440. Pike: "#005390",
  1441. PogoScript: "#d80074",
  1442. PostScript: "#da291c",
  1443. PowerBuilder: "#8f0f8d",
  1444. PowerShell: "#012456",
  1445. Processing: "#0096D8",
  1446. Prolog: "#74283c",
  1447. "Propeller Spin": "#7fa2a7",
  1448. Puppet: "#302B6D",
  1449. PureBasic: "#5a6986",
  1450. PureScript: "#1D222D",
  1451. Python: "#3572A5",
  1452. QML: "#44a51c",
  1453. Quake: "#882233",
  1454. R: "#198CE7",
  1455. RAML: "#77d9fb",
  1456. RUNOFF: "#665a4e",
  1457. Racket: "#3c5caa",
  1458. Ragel: "#9d5200",
  1459. Raku: "#0000fb",
  1460. Rascal: "#fffaa0",
  1461. Reason: "#ff5847",
  1462. Rebol: "#358a5b",
  1463. Red: "#f50000",
  1464. "Ren'Py": "#ff7f7f",
  1465. Ring: "#2D54CB",
  1466. Riot: "#A71E49",
  1467. Roff: "#ecdebe",
  1468. Rouge: "#cc0088",
  1469. Ruby: "#701516",
  1470. Rust: "#dea584",
  1471. SAS: "#B34936",
  1472. SQF: "#3F3F3F",
  1473. "SRecode Template": "#348a34",
  1474. SaltStack: "#646464",
  1475. Scala: "#c22d40",
  1476. Scheme: "#1e4aec",
  1477. Self: "#0579aa",
  1478. Shell: "#89e051",
  1479. Shen: "#120F14",
  1480. Slash: "#007eff",
  1481. Slice: "#003fa2",
  1482. SmPL: "#c94949",
  1483. Smalltalk: "#596706",
  1484. Solidity: "#AA6746",
  1485. SourcePawn: "#5c7611",
  1486. Squirrel: "#800000",
  1487. Stan: "#b2011d",
  1488. "Standard ML": "#dc566d",
  1489. Starlark: "#76d275",
  1490. SuperCollider: "#46390b",
  1491. Swift: "#ffac45",
  1492. SystemVerilog: "#DAE1C2",
  1493. "TI Program": "#A0AA87",
  1494. Tcl: "#e4cc98",
  1495. TeX: "#3D6117",
  1496. Terra: "#00004c",
  1497. Turing: "#cf142b",
  1498. TypeScript: "#2b7489",
  1499. UnrealScript: "#a54c4d",
  1500. V: "#5d87bd",
  1501. VBA: "#867db1",
  1502. VBScript: "#15dcdc",
  1503. VCL: "#148AA8",
  1504. VHDL: "#adb2cb",
  1505. Vala: "#fbe5cd",
  1506. Verilog: "#b2b7f8",
  1507. "Vim script": "#199f4b",
  1508. "Visual Basic .NET": "#945db7",
  1509. Volt: "#1F1F1F",
  1510. Vue: "#2c3e50",
  1511. WebAssembly: "#04133b",
  1512. Wollok: "#a23738",
  1513. X10: "#4B6BEF",
  1514. XC: "#99DA07",
  1515. XQuery: "#5232e7",
  1516. XSLT: "#EB8CEB",
  1517. YARA: "#220000",
  1518. YASnippet: "#32AB90",
  1519. Yacc: "#4B6C4B",
  1520. ZAP: "#0d665e",
  1521. ZIL: "#dc75e5",
  1522. ZenScript: "#00BCD1",
  1523. Zephir: "#118f9e",
  1524. Zig: "#ec915c",
  1525. eC: "#913960",
  1526. "mIRC Script": "#926059",
  1527. mcfunction: "#E22837",
  1528. nesC: "#94B0C7",
  1529. ooc: "#b0b77e",
  1530. q: "#0040cd",
  1531. sed: "#64b970",
  1532. wdl: "#42f1f4",
  1533. wisp: "#7582D1",
  1534. xBase: "#403a40",
  1535. };
  1536. function getLabel(isZh, key) {
  1537. if (isZh) {
  1538. return zhCN[key];
  1539. } else {
  1540. return esUN[key];
  1541. }
  1542. }
  1543. var zhCN = {
  1544. search: "搜索",
  1545. search_repo: "项目",
  1546. search_dataset: "数据集",
  1547. search_issue: "任务",
  1548. search_pr: "合并请求",
  1549. search_user: "用户",
  1550. search_org: "组织",
  1551. search_finded: "找到",
  1552. search_matched: "最佳匹配",
  1553. search_matched_download: "下载次数",
  1554. search_lasted_update: "最后更新于",
  1555. search_letter_asc: "字母顺序排序",
  1556. search_letter_desc: "字母逆序排序",
  1557. search_lasted_create: "最近创建",
  1558. search_early_create: "最早创建",
  1559. search_add_by: "加入于",
  1560. search_lasted: "最近更新",
  1561. search_open: "开启中",
  1562. search_closed: "已关闭",
  1563. search_watched: "关注数",
  1564. search_star: "点赞数",
  1565. search_fork: "Fork数",
  1566. search_input_large_0: "请输入大于0的数值。",
  1567. search_input_maxed: "不能超出总页数。",
  1568. search_input_total: "共",
  1569. search_srtip: "条",
  1570. search_home_page: "首页",
  1571. search_last_page: "末页",
  1572. search_go_to: "前往",
  1573. search_go_page: "页",
  1574. find_title:
  1575. '“<strong class="highlight" id="keyword_desc">{keyword}</strong>”相关{tablename}约为{total}个',
  1576. search_empty: "<strong>请输入任意关键字开始搜索。</strong>",
  1577. };
  1578. var esUN = {
  1579. search: "Search",
  1580. search_repo: "Repository",
  1581. search_dataset: "DataSet",
  1582. search_issue: "Issue",
  1583. search_pr: "Pull Request",
  1584. search_user: "User",
  1585. search_org: "Organization",
  1586. search_finded: "Find",
  1587. search_matched: "Best Match",
  1588. search_matched_download: "Most downloads",
  1589. search_lasted_update: "Updated ",
  1590. search_letter_asc: "Alphabetically",
  1591. search_letter_desc: "Reverse alphabetically",
  1592. search_lasted_create: "Recently created",
  1593. search_early_create: "First created",
  1594. search_add_by: "Joined on",
  1595. search_lasted: "Recently updated",
  1596. search_open: "Open",
  1597. search_closed: "Closed",
  1598. search_watched: "Watches",
  1599. search_star: "Stars",
  1600. search_fork: "Forks",
  1601. search_input_large_0: "Please enter a value greater than 0.",
  1602. search_input_maxed: "Cannot exceed total pages.",
  1603. search_input_total: "Total",
  1604. search_srtip: "",
  1605. search_home_page: "First",
  1606. search_last_page: "Last",
  1607. search_go_to: "Go",
  1608. search_go_page: "Page",
  1609. find_title:
  1610. ' {total} "<strong class="highlight" id="keyword_desc">{keyword}</strong>" related {tablename}',
  1611. search_empty:
  1612. "<strong>Please enter any keyword to start the search.</strong>",
  1613. };
  1614. initDiv(false);
  1615. document.onreadystatechange = function () {
  1616. if (document.readyState === "complete") {
  1617. var tmpSearchLabel = sessionStorage.getItem("searchLabel");
  1618. if (tmpSearchLabel) {
  1619. sessionStorage.removeItem("searchLabel");
  1620. doSearchLabel(
  1621. sessionStorage.getItem("tableName"),
  1622. sessionStorage.getItem("keyword"),
  1623. sessionStorage.getItem("sortBy"),
  1624. sessionStorage.getItem("ascending")
  1625. );
  1626. } else {
  1627. var specifySearch = sessionStorage.getItem("specifySearch");
  1628. if (specifySearch) {
  1629. sessionStorage.removeItem("specifySearch");
  1630. document.getElementById("keyword_input").value =
  1631. sessionStorage.getItem("keyword");
  1632. doSpcifySearch(
  1633. sessionStorage.getItem("tableName"),
  1634. sessionStorage.getItem("keyword"),
  1635. sessionStorage.getItem("sortBy"),
  1636. sessionStorage.getItem("ascending")
  1637. );
  1638. } else {
  1639. search();
  1640. }
  1641. }
  1642. }
  1643. };