1/** 2 * ÐнииализиÑÑÐµÑ Ð¿Ð¾Ð¸Ñк по Ñилиалам 3 * 4 * ÐавиÑÐ¸Ñ Ð¾Ñ autoComplete.js 5 */ 6new class Affiliate extends RsJsCore.classes.component 7{ 8 constructor() 9 { 10 super(); 11 let defaults = { 12 confirmDialog: '.affilliate-confirm', 13 confirmClose: '.modal-close', 14 15 inputSearch: '.rs-city-search', 16 autocompleteResult: '.rs-autocomplete-result', 17 affiliateConfirmTemplate: '#affiliate-confirm-template' 18 }; 19 20 this.settings = {...defaults, ...this.getExtendsSettings()}; 21 } 22 23 /** 24 * ÐÐ°Ñ Ð¾Ð´Ð¸Ñ Ð²Ñе autocomplete input'Ñ, вÑÑÑи newElement и акÑивиÑÑÐµÑ Ð¸Ñ 25 * 26 * @param newElement 27 */ 28 initSearchAffiliateInDialog(newElement) 29 { 30 let input = newElement.querySelector(this.settings.inputSearch); 31 let resultWrapper = input && input.parentNode.querySelector(this.settings.autocompleteResult); 32 let cancelController; 33 34 if (input && !input.rsInitialized) { 35 input.rsInitialized = true; 36 let autoCompleteInstance = new autoComplete({ 37 selector: () => input, 38 searchEngine: () => true, 39 wrapper:false, 40 data: { 41 src: async () => { 42 if (cancelController) cancelController.abort(); 43 cancelController = new AbortController(); 44 45 let data = await this.utils.fetchJSON(input.dataset.urlSearch + '&' + new URLSearchParams({ 46 term:autoCompleteInstance.input.value 47 }), { 48 signal: cancelController.signal 49 }); 50 51 return data ? data.list : []; 52 }, 53 keys:['label'] 54 }, 55 resultsList: { 56 class: '', 57 maxResults:20, 58 position:'beforeend', 59 destination:() => resultWrapper, 60 }, 61 resultItem: { 62 element: (element, data) => { 63 let tpl; 64 tpl = `<a class="dropdown-item" href="${data.value.url}"> 65 <div class="col">${data.value.label}</div> 66 </a>`; 67 element.innerHTML = tpl; 68 }, 69 selected: 'selected' 70 }, 71 events: { 72 input: { 73 selection: (event) => { 74 location.href = event.detail.selection.value.url; 75 } 76 } 77 } 78 }); 79 } 80 } 81 82 /** 83 * ÐÑовеÑÑем, нÑжно ли оÑобÑажаÑÑ Ð´Ð¸Ð°Ð»Ð¾Ð³ подÑвеÑÐ¶Ð´ÐµÐ½Ð¸Ñ Ð¾Ð¿Ñеделенного Ñилиала. 84 * ÐÑли да, Ñо оÑобÑажаем его 85 */ 86 checkNeedConfirmAffiliate() { 87 let template = document.querySelector(this.settings.affiliateConfirmTemplate); 88 if (template) { 89 document.body.appendChild(template.content); 90 let win = document.querySelector(this.settings.confirmDialog); 91 win.querySelectorAll(this.settings.confirmClose).forEach(it => { 92 it.addEventListener('click', event => this.closeConfirmAffiliate(event)); 93 }); 94 } 95 } 96 97 /** 98 * ÐакÑÑÐ²Ð°ÐµÑ Ð¾ÐºÐ½Ð¾ подÑвеÑÐ¶Ð´ÐµÐ½Ð¸Ñ Ñилиала 99 * 100 * @param event 101 */ 102 closeConfirmAffiliate(event) { 103 let context = event.target.closest(this.settings.confirmDialog); 104 context && context.remove(); 105 106 let domain = context.dataset.domain || ''; 107 108 this.plugins.cookie.setCookie('affiliate_already_select', 1, { 109 domain:domain 110 }); 111 } 112 113 /** 114 * ÐÑполнÑеÑÑÑ, когда ÑÑÑаниÑа загÑÑжаеÑÑÑ 115 */ 116 onDocumentReady() 117 { 118 this.checkNeedConfirmAffiliate(); 119 } 120 121 /** 122 * ÐÑполнÑеÑÑÑ, когда на ÑÑÑаниÑе поÑвл
122ÑеÑÑÑ Ð½Ð¾Ð²Ñй конÑÐµÐ½Ñ 123 * 124 * @param event 125 */ 126 onContentReady(event) 127 { 128 this.initSearchAffiliateInDialog(event.target); 129 } 130};
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.