1// JavaScript Document 2var searchPage = null; 3 4var SearchPage = SearchPage || {}; 5SearchPage = (function () { 6 var objTypeMenus = $("#typemenus"); 7 var objTypeMenusBox = $("#typemenus-box"); 8 var timerAdjustCarouselCard = null; 9 var timerSearchSwitch = null; 10 var searchRunId = ''; 11 var searchRequest = null; 12 13 init(); 14 15 function init() { 16 initComm(); 17 typeMenusInit(); 18 } 19 20 function initAjax() { 21 initComm(); 22 } 23 function initComm() { 24 25 //for pc 26 if (isPc()) { 27 //program page, all program cover 28 $("#program-all").navGallery(); 29 //program page, carousel 30 //search page, filter:year,sort,subtitles 31 filterBarStatus(); 32 carouselCardAdjust(); 33 34 $("#program-all").find("[id=nav-point]").on("click.top", function () { 35 $("html,body").animate({ scrollTop: 0 }, 0); 36 }); 37 38 $(window).off("resize.program").on("resize.program", function () { 39 try { clearTimeout(timerAdjustCarouselCard); } catch (e) { } 40 timerAdjustCarouselCard = setTimeout(carouselCardAdjust, 10); 41 }); 42 43 } 44 45 historyInit(); 46 searchByDateInit(); 47 filterMenusInit(); 48 programPageListStyle(); 49 programPageBtnsInit(); 50 DownloadBtnDialog().init(); 51 pagesInit(); 52 } 53 54 //press back button, refresh page 55 function historyInit() { 56 if (window.location.href.indexOf("byapi") == -1 && window.location.href.indexOf("bygoogle") == -1) { 57 window.addEventListener('popstate', function (event) { 58 window.location.href = document.location; 59 }); 60 } 61 } 62 63 //click page button, modifiy link
64 function pagesInit() { 65 $("#npages").find("a").on("click", function () { 66 if ($("#pagetype").val() == "program") { 67 return checkLinkAction({ "obj": $(this), "type": "programPages" }); 68 } else { 69 return checkLinkAction({ "obj": $(this) }); 70 } 71 }); 72 } 73 74 //program page,sort btns 75 function programPageBtnsInit() { 76 $("[id=btn-program-sort]").on("click", function () { 77 return checkLinkAction({ "obj": $(this), "type": "programPages" }); 78 }); 79 } 80 81 //program page, css patch, video box:square/normal 82 function programPageListStyle() { 83 var urlCurrent = window.location.href; 84 85 //program List Style 86 var programListStyle = getCookie("programListStyle"); 87 programListStyle = programListStyle == "" ? "1" : programListStyle; 88 89 //only program page, mobile show square list 90 if (urlCurrent.indexOf("program") > -1 && isMobile()) { 91 programPageListStyleSet("2"); 92 } 93 //pc use user set 94 if (urlCurrent.indexOf("program") > -1 && isPc() && urlCurrent.indexOf("all") == -1) { 95 programPageListStyleSet(programListStyle); 96 } 97 98 $("#btn-list-style1").off("click").on("click", function () { 99 programPageListStyleSet("1"); 100 }); 101 102 $("#btn-list-style2").off("click").on("click", function () { 103 programPageListStyleSet("2"); 104 }); 105 } 106 107 //program page, save page list style 108 function programPageListStyleSet(style) { 109 $("#btn-list-style1").removeClass("current"); 110 $("#btn-list-style2").removeClass("current"); 111 112 if (style == "1") { 113 $("#items").addClass("items-square-list"); 114 $("#btn-list-style1").addClass("current"); 115 if (isPc()) { 116 setCookie("programListStyle", "1", 1); 117 } 118 } else { 119 $("#items").removeClass("items-square-list"); 120 $("#btn-list-style2").addClass("current"); 121 if (isPc()) { 122 setCookie("programListStyle", "2", 1); 123 } 124 } 125 } 126 127 128 //search page, filter status, date/sort/subtitles 129 function filterBarStatus() { 130 var filterStatus = getCookie("filterStatus"); 131 filterStatus = filterStatus == "" ? "open" : filterStatus; 132 133 if (filterStatus == "open") { 134 $("#filter").show(); 135 $("#btn-filter-bar").removeClass("selection-c"); 136 } else { 137 $("#filter").hide(); 138 $("#btn-filter-bar").addClass("selection-c"); 139 } 140 141 // 142 $("#btn-filter-bar").on("click", function () { 143 if (filterStatus == "open") { 144 filterStatus = "close"; 145 setCookie("filterStatus", "close", 1); 146 $("#btn-filter-bar").addClass("selection-c"); 147 $("#filter").slideUp(); 148 } else { 149 filterStatus = "open"; 150 setCookie("filterStatus", "open", 1); 151 $("#btn-filter-bar").removeClass("selection-c"); 152 $("#filter").slideDown(); 153 } 154 }); 155 } 156 157 158 //search page, select date box 159 function searchByDateInit() { 160 var objPrompt = $("#search-date-prompt"); 161 162 $("#btn-search-date-submit").on("click", function () { 163 var dateFrom = $("#search-date-from").val(); 164 var dateTo = $("#search-date-to").val(); 165 166 var regex = /^\d{4}(\.|-|\/)\d{1,2}(\.|-|\/)\d{1,2}$/; 167 if (!regex.test(dateFrom)) { 168 objPrompt.html("Start date format is incorrect"); 169 return; 170 }; 171 172 var dateBy = "b"; 173 $("[id=btn-search-date-by]").each(function(){ 174 var data = $(this).attr("data"); 175 var className = $(this).attr("class"); 176 if(String(className).indexOf("current")>-1){ 177 dateBy = data; 178 } 179 }); 180 181 var url = varsSearchDate + "&dateby="+dateBy+"&date1=" + dateFrom + "&date2=" + dateTo; 182 if ($("#pagetype").val() == "program") { 183 window.location.href = url; 184 } else { 185 checkLinkAction({ "obj": url }); 186 } 187 }); 188 189 $("[id=btn-search-date-clear]").on("click", function () { 190 var url = varsSearchDate; 191 checkLinkAction({ "obj": url }); 192 return false; 193 }); 194 195 $("[id=btn-search-date-by]").on("click", function () { 196 $("[id=btn-search-date-by]").removeClass("current"); 197 $(this).addClass("current"); 198 }); 199 } 200 201 //search page, filter menus, date/sort/subtitles/language 202 function filterMenusInit() { 203 $("#btn-subtitles").on("click", function () { 204 dialogShow("dialogbox-subtitles"); 205 });
206 207 $("#btn-audio").on("click", function () { 208 dialogShow("dialogbox-audio"); 209 }); 210 211 $("#float-menu-sort").find("a").on("click", function () { 212 return checkLinkAction({ "obj": $(this) }); 213 }); 214 215 //subtitles 216 var objSubtitlesBtn = $("[id=subtitle-btns]"); 217 objSubtitlesBtn.find("label").off("click.search").on("click.search", function () { 218 var obj = $(this).parent(); 219 var code = obj.attr("id"); 220 var url = varsSearchSubtitle + "&subtitle=" + code; 221 222 //lang code in sys langs, redirect lang page 223 var langStr = '/' + code + LANG_DIR_ADD + '/'; 224 225 switch (code) { 226 case 'ZH-HANT': langStr = '/ch' + LANG_DIR_ADD + '/'; break; 227 case 'ZH-HANS': langStr = '/gb' + LANG_DIR_ADD + '/'; break; 228 case 'JA': langStr = '/jp' + LANG_DIR_ADD + '/'; break; 229 case 'KO': langStr = '/kr' + LANG_DIR_ADD + '/'; break; 230 case 'VI': langStr = '/vn' + LANG_DIR_ADD + '/'; break; 231 case 'KR': langStr = ''; break; // KR is not ko 232 } 233 langStr = langStr.toLowerCase(); 234 if (langStr != "" && LANGS_ARRAY.includes(langStr)) { 235 var urlCurrent = new URL(window.location.href); 236 var urlN = urlCurrent.origin + urlCurrent.pathname; 237 for (var i = 0; i < LANGS_ARRAY.length; i++) { 238 urlN = urlN.replace(LANGS_ARRAY[i], langStr); 239 } 240 urlN = urlN + url; 241 window.location = urlN; 242 return; 243 } 244 245 objSubtitlesBtn.find("div").removeClass("current"); 246 obj.addClass("current"); 247 checkLinkAction({ "obj": url }); 248 dialogClose(); 249 }); 250 251 //language 252 var objAudioBtn = $("[id=audio-btns]"); 253 objAudioBtn.find("label").off("click.search").on("click.search", function () { 254 var obj = $(this).parent(); 255 var code = obj.attr("id"); 256 var url = varsSearchAudio + "&audio=" + code; 257 258 objAudioBtn.find("div").removeClass("current"); 259 obj.addClass("current"); 260 checkLinkAction({ "obj": url }); 261 dialogClose(); 262 }); 263 264 265 $("[id=btn-sort-clear]").on("click", function () { 266 var url = varsSearchSort; 267 checkLinkAction({ "obj": url }); 268 return false; 269 }); 270 271 $("[id=btn-subtitle-clear]").on("click", function () { 272 var url = varsSearchSubtitle; 273 checkLinkAction({ "obj": url }); 274 return false; 275 }); 276 277 $("[id=btn-audio-clear]").on("click", function () { 278 var url = varsSearchAudio; 279 checkLinkAction({ "obj": url }); 280 return false; 281 }); 282 283 $("[id=btn-type-category-clear]").on("click", function () { 284 var url = varsSearchTypeCateogry; 285 checkLinkAction({ "obj": url }); 286 return false; 287 }); 288 289 } 290 291 292 //left menu 293 var menuHeightClose = Array(); 294 var menuHeightOpen = Array(); 295 function typeMenusInit() { 296 297 //for left type menus 298 if (objTypeMenus.css("visibility") == "hidden") { 299 objTypeMenus.css({ "visibility": "visible" }); 300 objTypeMenus.hide(); 301 } 302 303 //mobile, show 304 $("#btn-type").off("click.search").on("click.search", function () { 305 objTypeMenus.fadeIn(200); 306 scrollDisable(); 307 }); 308 309 //mobile, hidden 310 $("#btn-typemenus-close").off("click.search").on("click.search", function () { 311 objTypeMenus.fadeOut(200); 312 scrollEnable(); 313 }); 314 315 //left type menus, more button 316 317 $(".btn-typemenus-more").off("click.search").on("click.search", function () { 318 var id = $(this).attr("id"); 319 if (typeof (menuHeightOpen[id]) == "undefined") { 320 menuHeightClose[id] = $(this).parent().height(); 321 menuHeightOpen[id] = $(this).parent().find(".typemenus-items-se").height(); 322 } 323 var obj = $(this).parent(); 324 var classBtn = obj.attr("class"); 325 if (classBtn.indexOf("open") > -1) { 326 obj.removeClass("typemenus-seopen"); 327 obj.height(menuHeightClose[id]); 328 } else { 329 obj.addClass("typemenus-seopen"); 330 obj.height(menuHeightOpen[id]); 331 } 332 }); 333 334 //left type menu, click set current 335 if (isPc()) {
336 $("[id=btn-program-type]").off("click.search").on("click.search", function () { 337 //clear 338 $("[id=btn-program-type]").each(function () { 339 $(this).removeClass("current"); 340 $(this).removeClass("current-se"); 341 }); 342 //find current, set css 343 if (String($(this).attr("class")).indexOf("se") > -1) { 344 $(this).addClass("current-se"); 345 objParent = $(this).parent(); 346 for (var i = 0; i < 5; i++) { 347 if (String(objParent.attr("id")) == "typemenus-second-container") { 348 var objMenu = objParent.prev(); 349 objMenu.find("#btn-program-type").addClass("current"); 350 break; 351 } 352 var objParent = objParent.parent(); 353 } 354 } else { 355 $(this).addClass("current"); 356 } 357 358 //program page 359 if ($("#pagetype").val() == "program") { 360 return checkLinkAction({ "obj": $(this), "type": "programLeftMenu" }); 361 //search page 362 } else { 363 return checkLinkAction({ "obj": $(this) }); 364 } 365 }); 366 } 367 368 $(window).off("scroll", updateTypeMenusStyle).on("scroll", updateTypeMenusStyle); 369 updateTypeMenusStyle(); 370 //wait page inited, refresh 371 setTimeout(updateTypeMenusStyle, 200); 372 } 373 374 //left type menu, when scroll page, change top css 375 function updateTypeMenusStyle() { 376 if (isMobile()) { return; } 377 if (objTypeMenus.length == 0) { return; } 378 var typeMenusTop = objTypeMenus.offset().top; 379 var windowScrollTop = $(window).scrollTop() 380 var bodyBoxTop = $("#body-box").offset().top; 381 var bodyBoxHeight = $("#body-box").height(); 382 var windowHeight = $(window).height(); 383 384 //top min blank is 10 385 var typeMenusY = 10; 386 if (mainHeaderStatus["style"] == "small" && mainHeaderStatus["visibility"] == "visible") { 387 typeMenusY = $("#header").height(); 388 } 389 390 //scroll to bottom, left menu need scroll 391 if (windowScrollTop > bodyBoxTop + bodyBoxHeight - windowHeight) { 392 objTypeMenusBox.css({ "position": "absolute" }); 393 objTypeMenusBox.css({ "top": "auto" }); 394 objTypeMenusBox.css({ "bottom": "0px" }); 395 396 } else { 397 //scroll to type menus top, don't move menu 398 if (windowScrollTop - typeMenusTop > 0) { 399 objTypeMenusBox.css({ "position": "fixed" }); 400 } else { 401 objTypeMenusBox.css({ "position": "static" }); 402 } 403 objTypeMenusBox.css({ "bottom": "auto" }); 404 objTypeMenusBox.css({ "top": typeMenusY }); 405 } 406 } 407 408 // opts vars: {"obj":url/obj, type:programLeftMenu/programPages, urlHistory: display in url} 409 function checkLinkAction(opts) { 410 411 //confirm have data container 412 if ($("#data-container").length > 0) { 413 var urlLoad = ""; 414 var urlHistory = ""; 415 416 if (typeof (opts["obj"]) == "object") { 417 urlLoad = opts["obj"].attr("href"); 418 } else { 419 urlLoad = opts["obj"]; 420 } 421 422 423 //user custom history 424 urlHistory = urlLoad; 425 if (typeof (opts["urlHistory"]) == "string") { 426 urlHistory = opts["urlHistory"]; 427 } 428 429 //program left menu, need fix link 430 if (typeof (opts["type"]) != "undefined" && opts["type"] == "programLeftMenu") { 431 urlLoad = String(urlLoad).replace("?","&"); 432 var types = String(urlLoad).split("_"); 433 var urlNew = "type=" + types[0]; 434 if (typeof (types[1]) != "undefined") { 435 urlNew += "&category=" + types[1]; 436 } 437 if (typeof (types[2]) != "undefined") { 438 urlNew += "_" + types[2]; 439 } 440 if (typeof (types[3]) != "undefined") { 441 urlNew += "_" + types[3]; 442 } 443 urlLoad = "?" + urlNew; 444 } 445 446 //program pages button, need fix link 447 if (typeof (opts["type"]) != "undefined" && opts["type"] == "programPages") { 448 var urlArray = urlLoad.split("?"); 449 var types = String(urlArray[0]).split("_"); 450 var urlNew = "type=" + types[0]; 451 if (typeof (types[1]) != "undefined") { 452 urlNew += "&category=" + types[1]; 453 } 454 if (typeof (types[2]) != "undefined") { 455 urlNew += "_" + types[2]; 456 } 457 if (typeof (urlArray[1]) != "undefined") { 458 urlNew += "&" + urlArray[1]; 459 } 460 urlLoad = "?" + urlNew; 461 } 462 463 //show link in browser url 464 if(location.search!=urlHistory){ 465 history.pushState('', '', urlHistory); 466 } 467 468 // 469 checkSearchRuning(urlLoad); 470 return false; 471 } 472 return true; 473 } 474 475 //check search run status 476 function checkSearchRuning(urlLoad) { 477 var regex = /q=([^&]{1,})/i; 478 var isSearch = regex.test(urlLoad); 479 480 //search keywords 481 if (isSearch) { 482 searchRunId = Math.floor(Math.random() * 10000) + 1;
483 loadData({ url: urlLoad, runId: searchRunId }); 484 console.log('searchRunId1:' + searchRunId); 485 try { clearTimeout(timerSearchSwitch); } catch (e) { } 486 timerSearchSwitch = setTimeout(function () { 487 var urlLoadSwitch = urlLoad + '&usedb'; 488 searchRunId = Math.floor(Math.random() * 10000) + 1; 489 console.log('searchRunId2:' + searchRunId); 490 loadData({ url: urlLoadSwitch, runId: searchRunId }); 491 }, 6000); 492 493 } else { 494 try { 495 searchRunId = ''; 496 clearTimeout(timerSearchSwitch); 497 } catch (e) { } 498 loadData(urlLoad); 499 } 500 } 501 502 503 //scroll data page to top 504 function scrollPageTopOnLoad() { 505 var windowScrollTop = $(window).scrollTop() 506 var dataContainerTop = $("#data-container").offset().top; 507 dataContainerTop = dataContainerTop - 10; 508 509 if (windowScrollTop > dataContainerTop) { 510 $(window).scrollTop(dataContainerTop); 511 } 512 updateTypeMenusStyle(); 513 } 514 515 //loaddata 516 function loadData(opts) { 517 //run id 518 var runId = ''; 519 if (typeof (opts['runId']) != "undefined") { 520 runId = opts['runId']; 521 } 522 523 //load url 524 var loadUrl = ''; 525 if (typeof (opts) == "string") { 526 loadUrl = opts; 527 } 528 529 if (typeof (opts) == "object") { 530 loadUrl = opts['url']; 531 } 532 533 if (loadUrl.indexOf("loadmore") == -1) { 534 loadUrl = "loadmore" + loadUrl; 535 } 536 537 scrollPageTopOnLoad(); 538 var objDataContainer = $("#data-container"); 539 mainObjSearch.srchLoadingShow(); 540 try{ searchRequest.abort(); } catch(e){ } 541 searchRequest = $.post(loadUrl, {}, function (data) { 542 console.log('result searchRunId:' + searchRunId + ',runId:' + runId); 543 if (runId != searchRunId) { 544 console.log(runId + ' cancel'); 545 return; 546 } 547 //clear 548 try { 549 searchRunId = ''; 550 clearTimeout(timerSearchSwitch); 551 } catch (e) { } 552 553 objDataContainer.html(data); 554 mainObjSearch.srchLoadingHide(); 555 556 initAjax(); 557 mainObjSearch.init(); 558 FloatMenus(); 559 likeInit(); 560 updateCounter(); 561 DownloadBtnDialog().init(); 562 ShareDialog(); 563 a2a.init('page'); 564 FloatMenus({ menus: "float-menus-srchs", btnMenu: "btn-srch-limit" }); 565 typeMenusInit(); 566 refreshLeftMenuData(); 567 scrollEnable(); 568 }); 569 } 570 571 function refreshLeftMenuData(){ 572 //refreshLeftMenuLink 573 if ($("#pagetype").val() == "search") { 574 var objLeftMenuLinkStr = String($("#left-menu-link-str").val()); 575 if (objLeftMenuLinkStr != "undefined" && objLeftMenuLinkStr != "") { 576 $("[id=btn-program-type]").each(function () { 577 var types = $(this).attr("data").split("_"); 578 var videoType = types[0]; 579 var videoCategory = ""; 580 if (typeof (types[1]) != "undefined") { 581 videoCategory = types[1]; 582 } 583 if (typeof (types[2]) != "undefined") { 584 videoCategory = videoCategory + "_" + types[2]; 585 } 586 var linkNew = "?type=" + videoType + "&category=" + videoCategory + objLeftMenuLinkStr; 587 $(this).attr("href", linkNew); 588 }); 589 } 590 } 591 592 //refresh left menu num 593 var tobalDataNum = String($("#total-data-num").val()); 594 if (tobalDataNum != "undefined" && tobalDataNum != "") { 595 var objTypeMenus = $("#typemenus"); 596 var totalDataNum = tobalDataNum.split(","); 597 if (totalDataNum.length > 0) { 598 for (var i = 0; i < totalDataNum.length; i++) { 599 var dataNum = totalDataNum[i].split("="); 600 if (dataNum.length > 1) { 601 $("#typemenus").find("#num-" + dataNum[0]).text(dataNum[1]); 602 } 603 } 604 } 605 } 606 } 607 608 609 function carouselCardAdjust() { 610 var obj = $("#carousel-card"); 611 obj.removeClass("carousel-card4"); 612 obj.removeClass("carousel-card3"); 613 obj.removeClass("carousel-card2"); 614 615 var objWidth = parseInt(obj.width()); 616 617 if (objWidth >= 910) { 618 obj.addClass("carousel-card4"); 619 } else if (910 > objWidth && objWidth >= 678.75) { 620 obj.addClass("carousel-card3"); 621 } else if (678.75 > objWidth && objWidth >= 447.75) { 622 obj.addClass("carousel-card2"); 623 } 624 } 625 626 return { 627 initAjax: initAjax, 628 scrollPageTopOnLoad: scrollPageTopOnLoad, 629 checkLinkAction: checkLinkAction, 630 refreshLeftMenuData: refreshLeftMenuData,
631 loadData: loadData 632 } 633 634}); 635 636 637$(function () { 638 searchPage = SearchPage(); 639 ShareDialog(); 640 FloatMenus(); 641});
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.