1// å·¥å · 2$.extend({ 3 // å®ä¹å ¨å±è¯è¨è®¾ç½® 4 langs: [ 5 "fr", 6 "jp", 7 "de", 8 "it", 9 "pt", 10 "es", 11 "tw", 12 "zh", 13 "en", 14 "ar", 15 "pl", 16 "nl", 17 "ru" 18 ], 19 /** 20 * è·åå½åè¯è¨ 21 * @return {string} è¿åå½åè¯è¨ç®ç§° 22 */ 23 getCurrentLang: function () { 24 var b = window.location.pathname.substring(1).split("/")[0]; 25 var c = this.langs.indexOf(b) > -1 ? b : "en"; 26 if (/www.aomei.de|92.168.0.27:8023|wwwtest.aomei.de/.test(window.location.host)) { 27 c = "de"; 28 } else if (/www.aomei.fr|92.168.0.27:8024|wwwtest.aomei.fr/.test(window.location.host)) { 29 c = "fr"; 30 } else if (/www.aomei.jp|partition.aomei.jp|192.168.0.27:8025|wwwtest.aomei.jp/.test(window.location.host)) { 31 c = "jp" 32 } else if (/twtest.aomeitech.com|tw.aomeitech.com|192.168.0.27:8026/.test(window.location.host)) { 33 c = 'tw' 34 }else if(/es.aomeitech.com|192.168.0.27:8028/.test(window.location.host)){ 35 c= 'es' 36 }else if(/it.aomeitech.com|192.168.0.27:8027/.test(window.location.host)){ 37 c= 'it' 38 } 39 // a.currentLang = c; 40 return c; 41 }, 42 /** 43 * @return {string} è¿åå½åè¯è¨åç¼ä¾å¦en=/,de=/de,jp=/jp 44 */ 45 getPrefixer: function () { 46 let prefixer = ''; 47 if (/www.aomei.de|www.aomei.fr|www.aomei.jp|partition.aomei.jp/.test(window.location.host) || this.getCurrentLang() === "en") { 48 prefixer = '/' 49 } else { 50 prefixer = `/${this.getCurrentLang()}` 51 } 52 return prefixer; 53 }, 54 /** 55 * è·åURLåæ° 56 * @param {string} name 为searchçé® 57 * @param {string} url æ¯ä¸ä¸ªå¯é项ï¼ä¸ä¼ æ¶ä¸ºå½å页é¢å°å 58 * */ 59 getUrlParameter: function (name, url) { 60 var e = url || window.location.search; 61 var c = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); 62 var d = e.substr(1).match(c); 63 if (d != null) { 64 return decodeURIComponent(d[2]); 65 } 66 return null; 67 }, 68 /** 69 * 鲿彿° 70 * @param {Function} func: è¦æ§è¡ç彿° 71 * @param {number}delay: å»¶è¿æ¶é´ï¼æ¯«ç§ï¼ 72 * @return {Function} 鲿ç彿° 73 */ 74 debounce: function (func, delay = 500) { 75 let timeout; 76 return function () { 77 const context = this, 78 args = arguments; 79 // æ¸ é¤ä¹åç宿¶å¨ 80 clearTimeout(timeout); 81 // 设置æ°ç宿¶å¨ 82 timeout = setTimeout(() => func.apply(context, args), delay); 83 }; 84 }, 85 /** 86 * èæµå½æ° 87 * @param {Function} func: è¦æ§è¡ç彿° 88 * @param {number} limit: æ¶é´é´éï¼æ¯«ç§ï¼ï¼å¨æ¤æ¶é´å åªæ§è¡ä¸æ¬¡ 89 * @return {Function} èæµç彿° 90 */ 91 throttle: function (func, limit) { 92 let lastFunc; 93 let lastRan; 94 return function () { 95 const context = this, 96 args = arguments; 97 // å¦ææ²¡æä¸ä¸æ¬¡æ§è¡æ¶é´ï¼ç«å³æ§è¡å½æ° 98 if (!lastRan) { 99 func.apply(context, args); 100 lastRan = Date.now(); 101 } else { 102 // æ¸ é¤ä¹åç宿¶å¨ 103 clearTimeout(lastFunc); 104 lastFunc = setTimeout(function () { 105 // 夿æ¯å¦è¶ è¿æ¶é´é´éï¼å¦æè¶ è¿åæ§è¡å½æ° 106 if ((Date.now() - lastRan) >= limit) { 107 func.apply(context, args); 108 lastRan = Date.now(); 109 } 110 }, limit - (Date.now() - lastRan)); 111 } 112 }; 113 }, 114 // æ£æ¥å ç´ æ¯å¦å¨è§å£ä¸ 115 isInViewport: function ($elem) { 116 if (!($elem instanceof jQuery)) { 117 // console.error("è¯·ä¼ å ¥jquery对象") 118 return 119 } 120 const rect = $elem[0].getBoundingClientRect(); 121 return ( 122 rect.top >= 0 && 123 rect.left >= 0 && 124 rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && 125 rect.right <= (window.innerWidth || document.documentElement.clientWidth) 126 ); 127 }, 128 // 夿å½åè®¾å¤æ¯å¦æ¶ç§»å¨ç«¯ 129 isMobile: function () { 130 return /Mobi|Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent); 131 }, 132 // cookie start 133 // è·åå½åååç主åé¨åï¼ç¨äºè®¾ç½®cookieçå 134 cookieDomain: function () { 135 const a = window.location.hostname; 136 return "." + a.split(".")[1] + "." + a.split(".")[2]; 137 }, 138 /** 139 * 设置cookie 140 * @param {string} name: cookieçåç§° 141 * @param {string} value: cookieçå¼ 142 * @param {object=} options: å¯éåæ°ï¼å æ¬è¿æå¤©æ°ãè·¯å¾ååå 143 */
144 setCookie: function (name, value, options = {}) { 145 const { 146 days = null, path = "/", domain = this.cookieDomain() 147 } = options; 148 let expires = ""; 149 // 妿æå®äºè¿æå¤©æ°ï¼å计ç®è¿ææ¶é´ 150 if (days !== null) { 151 const date = new Date(); 152 date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000); 153 expires = `expires=${date.toUTCString()};`; 154 } 155 // çæcookieå符串 156 let cookie = `${name}=${encodeURIComponent(value)};${expires}path=${path}`; 157 if (domain) { 158 cookie += `;domain=${domain}`; 159 } 160 // 设置cookie 161 document.cookie = cookie; 162 }, 163 164 /** 165 * è·åæå®åç§°çcookieå¼ 166 * @param {string} name: cookieçåç§° 167 */ 168 getCookie: function (name) { 169 const cookies = document.cookie.split(";"); 170 // éåææcookieï¼æ¥æ¾æå®åç§°çcookie 171 for (let i = 0; i < cookies.length; i++) { 172 const cookie = cookies[i].trim(); 173 if (cookie.startsWith(`${name}=`)) { 174 // è¿åè§£ç åçcookieå¼ 175 return decodeURIComponent(cookie.substring(name.length + 1)); 176 } 177 } 178 // å¦ææªæ¾å°cookieï¼åè¿ånull 179 return null; 180 }, 181 /** 182 * ç§»é¤æå®åç§°çcookie 183 * @param {string} name: cookieçåç§° 184 */ 185 removeCookie: function (name) { 186 // 设置cookieçè¿ææ¶é´ä¸ºè¿å»ï¼æ¥å é¤cookie 187 document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/; domain=${this.cookieDomain()}`; 188 }, 189 // cookie end 190 // è´§å¸æ ¼å¼è®¾ç½® 191 currencySettings: { 192 en: { 193 symbol: "$", 194 format: "%s%v", 195 decimal: ".", 196 thousand: ",", 197 precision: 2, 198 }, 199 fr: { 200 symbol: "â¬", 201 format: "%v %s", 202 decimal: ",", 203 thousand: " ", 204 precision: 2, 205 }, 206 it: { 207 symbol: "â¬", 208 format: "%v %s", 209 decimal: ",", 210 thousand: ".", 211 precision: 2, 212 }, 213 de: { 214 symbol: "â¬", 215 format: "%v %s", 216 decimal: ",", 217 thousand: ".", 218 precision: 2, 219 }, 220 es: { 221 symbol: "â¬", 222 format: "%v %s", 223 decimal: ",", 224 thousand: ".", 225 precision: 2, 226 }, 227 tw: { 228 symbol: "NT$", 229 format: "%s%v", 230 decimal: ".", 231 thousand: ",", 232 precision: 0, 233 }, 234 jp: { 235 symbol: "å", 236 format: "%v%s", 237 decimal: ".", 238 thousand: ",", 239 precision: 0, 240 }, 241 pl: { 242 symbol: "â¬", 243 format: "%v %s", 244 decimal: ",", 245 thousand: ".", 246 precision: 2, 247 }, 248 nl: { 249 symbol: "â¬", 250 format: "%v %s", 251 decimal: ",", 252 thousand: ".", 253 precision: 2, 254 }, 255 }, 256 /** 257 * è·åå½åè¯è¨çè´§å¸æ ¼å¼ 258 * @param {string=} b æ¯è¯è¨ç®ç§°ï¼é»è®¤å¼å½åè¯è¨ 259 * @return {object} è¿åä¸ä¸ªå½åè¯è¨è´§å¸æ ¼å¼å¯¹è±¡ 260 */ 261 getCurrencySettings: function (b = this.getCurrentLang()) { 262 var a = this; 263 if (!a.currencySettings.hasOwnProperty(b)) { 264 b = "en"; 265 } 266 return a.currencySettings[b]; 267 }, 268 // å ³äºè´§å¸ç end 269 270 // å¤å¶å 容å°åªåæ¿ 271 copyToClipboard: function (text) { 272 if (navigator.clipboard && navigator.clipboard.writeText) { 273 navigator.clipboard.writeText(text).then(() => {}).catch(err => { 274 console.error('å¤å¶å¤±è´¥', err); 275 }); 276 } else { 277 // ä½¿ç¨ document.execCommand ä½ä¸ºå¤éæ¹æ¡ 278 const textarea = document.createElement('textarea'); 279 textarea.value = text; 280 textarea.style.position = 'fixed'; // 鲿¢é¡µé¢è·³å¨ 281 document.body.appendChild(textarea); 282 textarea.focus(); 283 textarea.select(); 284 285 try { 286 const successful = document.execCommand('copy');
287 const msg = successful ? 'å¤å¶æå' : 'å¤å¶å¤±è´¥'; 288 } catch (err) { 289 console.error('æ æ³å¤å¶', err); 290 } 291 292 document.body.removeChild(textarea); 293 } 294 } 295}) 296 297$.fn.extend({ 298 /** 299 * å¨å ç´ é¦æ¬¡åºç°å¨å¯è§åºåå æ·»å å ¥åºå¨ç» 300 * data-animation 屿§ä¸ºæ¯ä¸ªå ç´ è®¾ç½®èªå®ä¹å¨ç»ç±» 301 * 妿å ç´ æ²¡æè®¾ç½® data-anim 屿§ï¼åä¼ä½¿ç¨ä¼ å ¥çé»è®¤å¨ç»ç±» 302 // * @param {string} defaultAnimationClass å¨ç»ç±»å, 303 * @param {number} offset 为å¯è§åºå䏿¹çåç§»é,é»è®¤ä¸º0 304 */ 305 animateOnScroll: function (offset = 0.2) { 306 // éæ©ææå¸¦æ data-anim 屿§çå ç´ 307 var elementsToAnimate = $("[data-anim]"); 308 // å建 IntersectionObserver å®ä¾ 309 var observer = new IntersectionObserver( 310 function (entries) { 311 entries.forEach(function (entry) { 312 if (entry.isIntersecting) { 313 var $target = $(entry.target); 314 var $thisClassName = $target.data("anim"); // è·åå¨ç»ç±»å 315 var duration = $target.attr("data-animation-delay"); // è·åå¨ç»å»¶è¿æ¶é´ï¼é»è®¤ 1s 316 317 // 设置å¨ç»å»¶è¿æ¶é´ 318 duration && $target.css("animation-delay", duration); 319 320 // æ·»å å¨ç»è§¦åç±» 321 $target.addClass("anim " + $thisClassName); 322 323 // 䏿¦å¨ç»è§¦åï¼åæ¢è§å¯æ¤å ç´ 324 observer.unobserve(entry.target); 325 } 326 }); 327 }, { 328 threshold: offset, // å½å ç´ è³å° 20% è¿å ¥è§å£æ¶è§¦å 329 } 330 ); 331 332 // è§å¯ææç®æ å ç´ 333 elementsToAnimate.each(function () { 334 observer.observe(this); 335 }); 336 }, 337 /** 338 * é项å¡åæ¢åè½ 339 * @param {string} tabSelector: é项å¡çéæ©å¨ 340 * @param {string} contentSelector: å 容çéæ©å¨ 341 */ 342 tabSwitch: function (tabSelector, contentSelector) { 343 344 // éåæ¯ä¸ªå®¹å¨ï¼ä½¿å ¶ç¬ç«å·¥ä½ 345 this.each(function () { 346 const $tabContainer = $(this); 347 // console.log($tabContainer.attr('class')); 348 const type = $tabContainer.attr('data-event') || 'click'; 349 $tabContainer.find(tabSelector).css({ 350 cursor: "pointer" 351 }); 352 $tabContainer.find(contentSelector).hide(); 353 $tabContainer.find(contentSelector + '.active').show(); 354 // ç»å®ç¹å»äºä»¶å°æ¯ä¸ªéé¡¹å¡æé® 355 $tabContainer.find(tabSelector).on(type, function () { 356 const $thisBtn = $(this); 357 const $tableBtnParent = $thisBtn.parent(); // å½åé项å¡ç¶çº§ 358 // ç§»é¤å½åç»çææé项塿é®åå å®¹çæ¿æ´»ç¶æ 359 $tabContainer.find(tabSelector).removeClass('active'); 360 $tabContainer.find(contentSelector).removeClass('active'); 361 362 // 设置å½åç¹å»çæé®ä¸ºæ¿æ´»ç¶æ 363 $thisBtn.addClass('active'); 364 365 // 设置å½åé项å¡ç¶çº§ä½ç½®åé 366 // $tableBtnParent.css('--tab-btn-slider', $thisBtn.offset().left - $tableBtnParent.offset().left); 367 $tableBtnParent[0].style.setProperty('--tab-btn-slider', ($thisBtn.offset().left - $tableBtnParent.offset().left) + 'px'); 368 369 // æ ¹æ®ç´¢å¼æ¾ç¤ºå¯¹åºçå 容 370 const index = $thisBtn.index(); 371 $tabContainer.find(contentSelector).hide().eq(index).addClass('active').show(); 372 373 // è§£å³slick容å¨å¨åå§å为display:noneçæ åµä¸ï¼slickæ æ³å徿£å¸¸å®½åº¦ 374 $('[data-slick="content"]').each(function (i, item) { 375 $(item).slick('setPosition'); // å¨å°ºå¯¸ååæ¶éæ°è®¡ç® 376 }) 377 }); 378 }); 379 }, 380 381 /** 382 * æé£ç´ææ 383 * @param {string} headerSelector: æé£ç´æ é¢çéæ©å¨ 384 * @param {string} contentSelector: æé£ç´å 容çéæ©å¨ 385 */ 386 accordion: function (headerSelector, contentSelector) { 387 $(headerSelector).css({ 388 cursor: "pointer" 389 }); 390 // éåæ¯ä¸ªæé£ç´å®¹å¨ï¼ä½¿å ¶ç¬ç«å·¥ä½ 391 this.each(function () { 392 const $accordionContainer = $(this); 393 394 // åå§åï¼éèææå 容åºå 395 396 $accordionContainer.find(contentSelector).hide(); 397 $accordionContainer.find('.active').find(contentSelector).show(); 398 399 // ç»å®ç¹å»äºä»¶å°æ¯ä¸ªæé£ç´æ é¢ 400 $accordionContainer.find(headerSelector).on('click', function () { 401 const $thisHeader = $(this); 402 const $content = $thisHeader.next(contentSelector); 403 $accordionContainer.find(contentSelector).not($content).slide
403Up().parent().removeClass('active'); 404 $content.slideToggle().parent().toggleClass('active'); 405 }); 406 }); 407 }, 408 /** 409 * è¡¨æ ¼çæ¯å¦å±ç¤ºä¸åçé项ï¼å ³éç¸åé项 410 * @param {object} options 411 * @param {string} options.titleAttr åç»æé®ç屿§åï¼é»è®¤ä¸ºgroud-title 412 * @param {string} options.contentAttr åç»å 容ç屿§åï¼é»è®¤ä¸ºgroud-content 413 * @param {number} options.mode å±å¼å ³éçæ¨¡å¼ï¼æ1åé1ï¼é»è®¤å¼ä¸º1(表示åªå±ç¤ºä¸ç»æ°æ®)ï¼ é1ï¼æ¯ç»å±å¼å ³éäºç¸æ²¡æå ³ç³»ï¼ 414 */ 415 tableDisplayDifferent: function () { 416 var def = { 417 titleAttr: "groud-title", 418 contentAttr: "groud-content", 419 mode: 1 420 } 421 options = { 422 ...def, 423 ...options 424 } 425 this.each(function (i, it) { 426 var $table = $(it); 427 var $trBtn = $table.find(`[${options.titleAttr}]`); 428 // var $trContent = $table.find('[groud-content]'); 429 $trBtn.on('click', function () { 430 431 var $this = $(this); 432 var openKey = $this.attr(options.titleAttr); 433 434 $this.parents('table').find(`[${options.contentAttr}="${openKey}"]`).toggle(); 435 if (options.mode == 1) { 436 $this.parents('table').find(`[${options.contentAttr}]`).not(`[${options.contentAttr}="${openKey}"]`).hide(); 437 } 438 439 440 }) 441 }) 442 }, 443 /** 444 * åºå®è¡¨æ ¼è¡¨å¤´ 445 * 446 */ 447 fixedTableHeader: function () { 448 this.each(function (i, it) { 449 const $table = $(it); 450 const tableHeight = $table.height(); 451 const headerHeight = $table.find('thead').height(); 452 453 $(window).on('scroll', function () { 454 const scrollTop = $(this).scrollTop(); 455 if (scrollTop > $table.offset().top && scrollTop < tableHeight + $table.offset().top - headerHeight - 100) { 456 $table.addClass('fixed-head').find('thead').css({ 457 position: "sticky", 458 top: 0, 459 "z-index": 90 460 }); 461 } else { 462 $table.removeClass('fixed-head').find('thead').css({ 463 position: 'static' 464 }); 465 } 466 }); 467 }) 468 469 // return this; // æ¯æé¾å¼è°ç¨ 470 }, 471 472 /** 473 * è¡¨æ ¼ä¸äºæä½æ¹æ³ 474 * æ¾ç¤º/éèç¸åå 容ãåç»è¡çå±å¼/æ¶èµ·åè½ 475 * @param {object} options 476 * @param {string} options.sameBtnSelector 触åéè/æ¾ç¤ºç¸åå 容çæé®éæ©å¨ï¼é»è®¤'[data-same="btn"]' 477 * @param {string} options.sameContentSelector 表示ç¸åå 容çè¡éæ©å¨ï¼é»è®¤'[data-same="content"]' 478 * @param {string} options.groupTitleAttr åç»æ é¢ç屿§åï¼é»è®¤ groud-title,åä¸ç»åç»æ é¢ååç»å 容就åºå½å䏿 ·ç屿§å¼ 479 * @param {string} options.groupContentAttr åç»å 容ç屿§åï¼é»è®¤'groud-content'ï¼åä¸ç»åç»æ é¢ååç»å 容就åºå½å䏿 ·ç屿§å¼ 480 * @param {number} options.groudSwitchMode åç»åæ¢æ¨¡å¼ (1: ä» å±å¼ä¸ä¸ªç»ï¼å ¶ä»ç»èªå¨æ¶èµ·; é1: æ¯ä¸ªç»åç¬æ§å¶)ï¼é»è®¤ä¸º1 481 * @param {string} options.sameBtnSelector 表示å½åæ´»å¨ç¶æçç±»å,é»è®¤ä¸ºactive 482 * 483 */ 484 tableEvents: function (options) { 485 var settings = $.extend({ 486 sameBtnSelector: '[data-same="btn"]', 487 sameContentSelector: '[data-same="content"]', 488 groupTitleAttr: "groud-title", 489 groupContentAttr: "groud-content", 490 groudSwitchMode: 1, 491 activeClass: "active" 492 }, options); 493 494 495 // æ¯å¦éèç¸åï¼åªå±ç¤ºä¸å 496 var viewDif = function () { 497 $(settings.sameBtnSelector).on("click", function (e) { 498 499 var $this = $(this); 500 var $currTable = $this.parents('table'); 501 var $sameCnt = $currTable.find(settings.sameContentSelector) 502 if (!$this.hasClass(settings.activeClass)) { 503 $this.addClass(settings.activeClass); 504 $sameCnt.hide(); 505 } else { 506 $this.removeClass(settings.activeClass); 507 // 夿åç»æ¯å¦æå¼ï¼åªå¯¹åç»æå¼ç项 508 $sameCnt.each(function (i, sameCntIt) { 509 var $sameCntIt = $(sameCntIt); 510 var groudName = $sameCntIt.attr(settings.groupContentAttr); 511 // isOpen表示æ¯å¦å¯¹å½åsameCntå±å¼ 512 var isOpen = $currTable.find(`[${settings.groupTitleAttr}="${groudName}"]`).hasClass(settings.activeClass); // 夿å½åç»æ¯å¦æ¯å ³éç¶æ 513 isOpen && $sameCntIt.show(); 514 // 没æåç»çå±å¼ 515 !groudName && $sameCntIt.show(); 516 517 }); 518 } 519 }); 520 }; 521 522 // åç» 523 var slideTr = function () { 524 $(`[${settings.groupTitleAttr}]`).click(function () { 525 var $this = $(this); 526 var $table = $this.parents('table'); 527 var name = $this.attr(settings.groupTitleAttr); // ç»å 528 var isOpen = $this.hasClass(settings.activeClass); 529 // 鿍¡å¼1åªç®¡èªèº«çå±å¼æ¶èµ·ï¼ä¸ç®¡å ¶ä»ç» 530 if (settings.groudSwitchMode !== 1) { 531 this.toggleClass(settings.activeClass); 532 $table.find(`${settings.groupContentAttr}=""${name}`).toggle(); 533 return 534 } 535 536 537 // 模å¼1åªå±ç¤ºä¸ä¸ªç»æ°ç» 538 if (!isOpen) { 539 540 // éèå级çå ¶ä»ç» 541 $table.find(`[${settings.groupTitleAttr}]`).removeClass(settings.activeClass); 542 $table.find(`[${settings.groupContentAttr}]`).hide(); 543 544 // å±å¼å½åç» 545 $this.addClass(settings.activeClass); 546 // 夿æ¯å¦éæ©äºéèç¸å 547 if ($table.find(settings.sameBtnSelector).hasClass(settings.activeClass)) { 548 $table.find(`[${settings.groupContentAttr}="${name}"]`).each(function (i, currGourdCntIt) { 549 var $currGourdCntIt = $(currGourdCntIt).not(settings.sameContentSelector); 550 $currGourdCntIt.show(); 551 }) 552 } else { 553 $table.find(`[${settings.groupContentAttr}="${name}"]`).show(); 554 } 555 } else { 556 $this.removeClass(settings.activeClass); 557 $table.find(`[${settings.groupContentAttr}="${name}"]`).hide(); 558 } 559 }); 560 }; 561 562 // åå§éèç»å 容 563 var hideTr = function () { 564 $(`[${settings.groupTitleAttr}]`).each(function () { 565 var $this = $(this); 566 var name = $this.attr(settings.groupTitleAttr); 567 if (!$this.hasClass(settings.activeClass)) { 568 $this.parents('table').find(`[${settings.groupContentAttr}="${name}"]`).hide(); 569 } 570 }); 571 }; 572 // åå§å 573 viewDif(); 574 slideTr(); 575 hideTr(); 576 // è¿åå½å jQuery 对象ï¼ä»¥ä¾¿ç»§ç»é¾å¼è°ç¨ 577 return this; 578 579 }, 580 /** 581 * å°å ç´ çææ¬å 容å¤å¶å°åªåæ¿ï¼å¹¶æ¯ææåå¤å¶åçåè° 582 * @param {function=} callback - å¯éçåè°å½æ°ï¼å¨å¤å¶æååæ§è¡ 583 * @returns {jQuery} æ¯æé¾å¼è°ç¨ 584 */ 585 copyToClipboard: function (callback) { 586 // éå jQuery 对象ä¸çæ¯ä¸ªå ç´ 587 this.each(function () { 588 const $this = $(this); 589 const textToCopy = $this.text(); // è·åå ç´ çææ¬å 容 590 591 // å建ä¸ä¸ªä¸´æ¶çææ¬åºåæ¥è¿è¡å¤å¶ 592 const tempInput = $("<textarea>"); 593 $("body").append(tempInput); 594 tempInput.val(textToCopy).select(); 595 596 // å°è¯æ§è¡å¤å¶æä½ 597 const success = document.execCommand("copy"); 598 tempInput.remove(); // ç§»é¤ä¸´æ¶å ç´ 599 600 // 妿æåä¸åè°å½æ°åå¨ï¼åè°ç¨åè°å½æ° 601 if (success && typeof callback === "function") { 602 callback.call(this, textToCopy); 603 } 604 }); 605 606 return this; // æ¯æé¾å¼è°ç¨ 607 }, 608 dropdown: function (selectHead, options) { 609 return this.each(function () { 610 var $select = $(this); 611 var $selectHead = $select.find(selectHead); 612 var $selectedOption = $select.find('.current'); 613 // var $arrow = $select.find('.arrow'); 614 var $options = $select.find(options); 615 var $optionItems = $options.children();
616 617 // éèé项å表 618 $options.hide(); 619 620 // ç¹å»å¤´é¨æ¶ï¼æ¾ç¤ºæéèé项å表 621 $selectHead.on('click', function () { 622 $options.toggle(); 623 $select.toggleClass('open'); // å¯ä»¥ä¸ºç®å¤´æ·»å å±å¼çææ 624 }); 625 626 // ç¹å»é项æ¶ï¼æ´æ°éä¸çå 容ï¼å¹¶éèé项å表 627 $optionItems.on('click', function () { 628 var selectedText = $(this).text(); 629 $selectedOption.text(selectedText); // æ´æ°å¤´é¨æ¾ç¤º 630 $options.hide(); // éèé项 631 $select.removeClass('open'); // æ¶èµ·ç®å¤´ 632 633 // 触å change äºä»¶ï¼ä¼ ééä¸å¼ 634 $select.trigger('change', selectedText); 635 }); 636 637 // ç¹å»é¡µé¢å ¶ä»å°æ¹æ¶ï¼å ³éä¸ææ¡ 638 $(document).on('click', function (e) { 639 if (!$(e.target).closest($select).length) { 640 $options.hide(); 641 $select.removeClass('open'); 642 } 643 }); 644 }); 645 } 646})
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.