1/* 2---------------------------------------------------------------------- 3 4A compilation of common javascript for grits project. 5 6VIETRY CO., LTD. 7Lastest update 14/07/2020. 8Author: BaoPD 9 10---------------------------------------------------------------------- 11*/ 12 13// Common scripts 14 15$(function () { 16 "use strict"; 17 function createTabs(buttonSelector, contentSelector, extraHandler = null) { 18 const buttons = document.querySelectorAll(buttonSelector); 19 const contents = document.querySelectorAll(contentSelector); 20 21 // Guard clause 22 if (!buttons.length || !contents.length) { 23 console.warn("createTabs: Buttons or contents not found"); 24 return; 25 } 26 27 buttons.forEach((btn, index) => { 28 btn.addEventListener("click", () => { 29 if (!contents[index]) return; 30 31 buttons.forEach((b) => b.classList.remove("active")); 32 contents.forEach((ct) => ct.classList.remove("active")); 33 34 btn.classList.add("active"); 35 contents[index].classList.add("active"); 36 37 if (typeof extraHandler === "function") { 38 extraHandler(index); 39 } 40 41 // Trigger resize an toà n (không phụ thuá»c jQuery) 42 setTimeout(() => { 43 window.dispatchEvent(new Event("resize")); 44 }, 50); 45 }); 46 }); 47 } 48 createTabs(".idx05-tabButton li", ".idx05-tabContent > div"); 49 // idx07 start 50 const idx07_buttons = document.querySelectorAll(".idx07-btn"); 51 const idx07_contents = document.querySelectorAll(".idx07-content"); 52 const idx07_wrapper = document.querySelector(".idx07-tabContent"); 53 54 function fixedHeight() { 55 let maxHeight = 0; 56 57 idx07_contents.forEach((content) => { 58 content.style.height = "auto"; 59 }); 60 61 idx07_contents.forEach((content) => { 62 const h = content.offsetHeight; 63 if (h > maxHeight) maxHeight = h; 64 }); 65 66 idx07_contents.forEach((content) => { 67 content.style.height = maxHeight + "px"; 68 }); 69 70 if (idx07_wrapper) { 71 idx07_wrapper.style.height = maxHeight + "px"; 72 } 73 } 74 75 idx07_buttons.forEach((button, index) => { 76 button.addEventListener("click", function () { 77 // remove active 78 idx07_buttons.forEach((btn) => btn.classList.remove("active")); 79 idx07_contents.forEach((content) => { 80 content.classList.remove("active"); 81 }); 82 83 // add active 84 button.classList.add("active"); 85 idx07_contents[index].classList.add("active"); 86 87 // recalc height 88 fixedHeight(); 89 90 // mobile anchor 91 if (window.innerWidth <= 768) { 92 const targetBox = 93 idx07_contents[index].querySelector(".idx07-contenbox"); 94 95 if (targetBox) { 96 targetBox.scrollIntoView({ 97 behavior: "smooth", 98 block: "start", 99 }); 100 } 101 } 102 }); 103 }); 104 105 window.addEventListener("load", fixedHeight); 106 window.addEventListener("resize", fixedHeight); 107 // idx07 end 108 // idx04 start 109 const idx_tabs = document.querySelectorAll(".idx04-tabs .TabPager > div"); 110 111 if (idx_tabs.length) { 112 const changeImage = () => { 113 const active = document.querySelector(".TabPager > div.active"); 114 if (!active) return; 115 116 document 117 .querySelectorAll(".idx04-tabImg") 118 .forEach((img) => img.classList.remove("active")); 119 120 document 121 .querySelector(`.idx04-grTab .tab${parseInt(active.dataset.index)}`) 122 ?.classList.add("active"); 123 }; 124 125 idx_tabs.forEach((tab) => { 126 tab.onclick = () => { 127 idx_tabs.forEach((t) => t.classList.remove("active")); 128 tab.classList.add("active"); 129 changeImage(); 130 }; 131 }); 132 133 changeImage(); 134 } 135 // idx04 end 136 const tabs = document.querySelectorAll(".new-btn button"); 137 const contents = document.querySelectorAll(".new-content"); 138 const titleText = document.querySelector(".idx-title p"); 139 140 const removeActive = (elements) => 141 elements.forEach((el) => el.classList.remove("active")); 142 143 // mapping text theo tab 144 const textMap = ["ALL", "NEWS", "COLUMN"]; 145
146 tabs.forEach((tab, index) => { 147 tab.addEventListener("click", () => { 148 removeActive(tabs); 149 removeActive(contents); 150 151 tab.classList.add("active"); 152 contents[index].classList.add("active"); 153 154 const text = textMap[index]; 155 156 titleText.innerHTML = ` 157 <span>${text.charAt(0)}</span>${text.slice(1)} 158 `; 159 }); 160 }); 161 var isMobile = false; 162 function check_mobile() { 163 var check = false; 164 if ( 165 /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|ipad|iris|kindle|Android|Silk|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test( 166 navigator.userAgent, 167 ) || 168 /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(
169 navigator.userAgent.substr(0, 4), 170 ) 171 ) { 172 check = true; 173 } 174 return check; 175 } 176 check_mobile(); 177 isMobile = check_mobile(); 178 $(window).resize(function () { 179 check_mobile(); 180 isMobile = check_mobile(); 181 }); 182 183 $(".button-toggle, .menu_toggle a, .menu_toggle .close").on( 184 "click", 185 function () { 186 $(".button-toggle").stop().toggleClass("active"); 187 $("#nav-icon").stop().toggleClass("open"); 188 $(".menu_toggle").stop().toggleClass("active"); 189 $("html, body").stop().toggleClass("ovh"); 190 191 var text = $("#menu_btn").text(); 192 $("#menu_btn").text(text == "MENU" ? "CLOSE" : "MENU"); 193 }, 194 ); 195 196 function header_mobile() { 197 let y = 0; 198 $(document).on("scroll", function () { 199 y = $(this).scrollTop(); 200 if (y > 10) { 201 $("header").addClass("active"); 202 } else { 203 $("header").removeClass("active"); 204 } 205 switch (isMobile) { 206 case true: 207 if (y > 10) { 208 $(".fixed_banner").addClass("active"); 209 } else { 210 $(".fixed_banner").removeClass("active"); 211 } 212 break; 213 case false: 214 $(".fixed_banner").removeClass("active"); 215 break; 216 } 217 }); 218 } 219 header_mobile(); 220 221 // To Top 222 var mv_h, win_h; 223 var y = 0; 224 mv_h = $(".key").height(); 225 $(document).on("scroll", function () { 226 y = $(this).scrollTop(); 227 228 win_h = $(window).height() - 200; 229 if (y > 100 && y > mv_h - win_h) { 230 $(".totop, .bnr_corona").addClass("active"); 231 } else { 232 $(".totop, .bnr_corona").removeClass("active"); 233 } 234 }); 235 $(".totop").on("click", function () { 236 $("html,body").animate({ scrollTop: 0 }, 400); 237 }); 238 239 // Navi 240 if ($(".pc_navi").length) { 241 $(".pc_navi > ul > li").on("mouseenter", function () { 242 $(this).find(".subInner").addClass("active"); 243 }); 244 $(".pc_navi > ul > li").on("mouseleave", function () { 245 $(this).find(".subInner").removeClass("active"); 246 }); 247 } 248}); 249 250/******************************************************************************************* 251 ******************************************************************************************* 252 *******************************************************************************************/ 253 254// Common Library 255 256$(function () { 257 const lib = new gritsProjectCommonLib(); 258}); 259 260// Scripts constructor. 261// If not sure please leave this unchange. 262const gritsProjectCommonLib = function () { 263 this.tab = function (Container, Content, Pager) { 264 if ($(Container).length) { 265 $(Container).each(function () { 266 var content = $(this).find(Content); 267 var pager = $(this).find(Pager); 268 var item = content.children(); 269 var pagerItem = pager.children(); 270 item.first().addClass("active"); 271 pagerItem.first().addClass("active"); 272 273 var SetHeight = function () { 274 setTimeout(function () { 275 content.height(item.filter(".active").outerHeight(true)); 276 }, 100); 277 }; 278 279 SetHeight(); 280 $(window).resize(function () { 281 SetHeight(); 282 }); 283 284 pagerItem.on("click", function (e) { 285 e.preventDefault(); 286 e.stopPropagation(); 287 var index = $(this).attr("data-index"); 288 $(this).siblings().removeClass("active"); 289 $(this).addClass("active"); 290 item.removeClass("active"); 291 item.eq(index - 1).addClass("active"); 292 SetHeight(); 293 }); 294 }); 295 } 296 /* Usage 297 ââââââ¬Ã¢â⬠[HTML] 298 <div class="TabContainer"> 299 <ul id="Pager" class="TabPager"> 300 <li data-index="01" href="" class="active"><p>1</p></li> 301 <li data-index="02" href=""><p>2</p></li> 302 <li data-index="03" href=""><p>3</p></li> 303 </ul> 304 <div class="TabContent"> 305 <ul> 306 <li>Tab 01</li> 307 <li>Tab 02</li> 308 <li>Tab 03</li> 309 </ul> 310 </div> 311 </div> 312 ââââââ¬Ã¢â⬠[Script] 313 $.fn.tab(".TabContainer", ".TabContent ul", ".TabPager"); 314 */ 315 }; 316 317 this.accordian = function (Container, Content, Button, TIME) { 318 TIME = TIME ? TIME : 300; 319 $(Container + " " + Content) 320 .not(".active") 321 .hide(); 322 $(Container + " " + Button).on("click", function () { 323 $(this).toggleClass("rotate"); 324 $(this).closest(Container).find(Content).first().slideToggle(TIME); 325 }); 326 /* Usage 327 ââââââ¬Ã¢â⬠[HTML] 328 <div class="accContainer"> 329 <p class="accBtn"></p> 330 <div class="accBlock"> 331 <div class="accContainer lv2"> 332 ... 333 </div> 334 </div>
335 </div> 336 ââââââ¬Ã¢â⬠[Script] 337 $.fn.accordian(".accContainer", ".accBlock", ".accBtn", "300"); 338 */ 339 }; 340 341 this.fixedHeight = function (Container, Item) { 342 if ($(Item).length) { 343 function fixedHeight() { 344 $(Item).css({ height: "" }); 345 $(Container).each(function () { 346 var h = 0; 347 var item = $(this).find($(Item)); 348 item.each(function () { 349 $(this).innerHeight() >= h ? (h = $(this).innerHeight()) : h; 350 }); 351 item.innerHeight(h); 352 }); 353 } 354 $(window).on("resize", function () { 355 fixedHeight(); 356 }); 357 } 358 }; 359 // Initialization 360 this.init = function () { 361 this.tab(".TabContainer", ".TabContent > .content", ".TabPager"); 362 this.accordian(".accContainer", ".accBlock", ".accBtn"); 363 this.accordian(".menu_toggle .lv2", "ul", ".title", "300"); 364 this.accordian( 365 ".accContainer", 366 ".idx03-according .content", 367 ".idx03-according .button", 368 ); 369 if (window.innerWidth < 769) { 370 this.accordian(".accContainer", "ul", ".title"); 371 } 372 }; 373 this.init(); 374}; 375 376/******************************************************************************************* 377 ******************************************************************************************* 378 *******************************************************************************************/
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.