Last active
June 6, 2019 06:19
-
-
Save AlexPetrov7311/5a979a05fcb9f5dfaf9595dfc209b0df to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var searchControl; | |
| function test(param) { | |
| 'use strict'; | |
| console.info('KSDEV-18432 with parametrs - ', param); | |
| var streetInput; | |
| var pushExperimentData = { | |
| id: param.codeExperiment, | |
| variationId: param.codeVariant | |
| }; | |
| function addToCartEvent() { | |
| document.querySelector('.mount-sellers-offers').addEventListener('click', (e) => { | |
| const item = e.target.closest('.seller-item__buy-button'); | |
| if (item) { | |
| r46('track', 'cart', BACKEND.state.productId); | |
| } | |
| }); | |
| } | |
| testUtils.pushExperiment(pushExperimentData); | |
| if (param.codeVariant !== 'control') { | |
| function createScript(src, onload) { | |
| const js = document.createElement('script'); | |
| js.async = true; | |
| js.src = src; | |
| js.onload = onload; | |
| return js; | |
| } | |
| var provider = { | |
| suggest: function (request, options) { | |
| return ymaps.suggest('Казахстан, Алматы, ' + streetInput.value) | |
| .then(function (items) { | |
| // items - массив поисковых подсказок. | |
| console.log(items); | |
| return items | |
| }); | |
| } | |
| }; | |
| const js = createScript("https://api-maps.yandex.ru/2.1/?lang=ru_RU", | |
| function() { | |
| ymaps.ready(init); | |
| var selectedActionTrigeed = false; | |
| function init() { | |
| function itemSelected(e) { | |
| console.log('itemSelected', e.target); | |
| var pill = e.target.closest('.ymap-item'); | |
| if (pill ) { | |
| console.dir(e.target.dataset.value); | |
| streetInput.value = e.target.dataset.value; | |
| selectedActionTrigeed = true; | |
| document.querySelector('ymaps').style.display = 'none'; | |
| } | |
| var searchControl = new ymaps.control.SearchControl({ | |
| options: { | |
| float: 'right', | |
| floatIndex: 100, | |
| noPlacemark: true | |
| } | |
| }); | |
| searchControl.search('Казахстан, Алматы, ' + streetInput.value/*'4 Щербакова Алматы'*/) | |
| .then(function (res) { | |
| var geoObjectsArray =searchControl.getResultsArray(); | |
| if (geoObjectsArray.length) { | |
| // Выводит свойство name первого геообъекта из результатов запроса. | |
| console.log( geoObjectsArray | |
| .map((item) => item.properties.getAll().metaDataProperty.GeocoderMetaData.Address.Components) | |
| // .filter(item => item.find(el => el.kind === 'street')) | |
| // .map(item =>{ return item.find(el => el.kind === 'street').name }) | |
| ) | |
| } | |
| }); | |
| ymaps.geocode(streetInput.value).then(function (res) { | |
| console.log('res ', res, streetInput.value); | |
| // myMap.setBounds(res.geoObjects.get(0).properties.get('boundedBy')); | |
| }); | |
| } | |
| var streetComplete; | |
| var TemplateSearchCtrl = ymaps.templateLayoutFactory.createClass( | |
| [ | |
| `<style> .ymap-item { | |
| height: 40px; | |
| line-height: 40px; | |
| white-space: nowrap; | |
| text-overflow: ellipsis; | |
| overflow: hidden; | |
| border-bottom: 1px solid #eee; | |
| } | |
| .ymap-item:last-child { | |
| border-bottom: 0; | |
| } | |
| .ymap-item:active { | |
| background-color: #eee; | |
| } | |
| </style><ul class='g-bt-fat ymap-data-list' style='background: white;margin: 0;list-style-type: none;padding: 10px;'>`, | |
| "{% for item in state.items %}", | |
| "<li class='ymap-item' data-value=\"{{ item.value }}\">{{ item.displayName }}</li>", | |
| "{% endfor %}", | |
| "</ul>" | |
| ].join(''), { | |
| build: function () { | |
| TemplateSearchCtrl.superclass.build.call(this); | |
| if (selectedActionTrigeed) { | |
| document.querySelector('ymaps').style.display = 'block'; | |
| selectedActionTrigeed = false; | |
| } | |
| document.querySelector('.ymap-data-list').addEventListener('click', itemSelected); | |
| console.log('build ',this) | |
| this.events.add('select', this.FieldSelect, this); | |
| }, | |
| clear: function () { | |
| streetComplete.events.remove('select', this.FieldSelect, this); | |
| TemplateSearchCtrl.superclass.clear.call(this); | |
| }, | |
| FieldSelect: function (e) { | |
| console.lo | |
| ymaps.geocode(e.get('item').value).then(function (res) { | |
| console.log('res ', res); | |
| // myMap.setBounds(res.geoObjects.get(0).properties.get('boundedBy')); | |
| }); | |
| } | |
| }); | |
| console.log('sucessed'); | |
| streetInput = document.querySelector('.pickup-delivery input#streetName'); | |
| // Создаем выпадающую панель с поисковыми подсказками и прикрепляем ее к HTML-элементу по его id. | |
| streetComplete = new ymaps.SuggestView(streetInput, { layout: TemplateSearchCtrl, provider: provider, results: 3}); | |
| } | |
| } | |
| ); | |
| document.body.appendChild(js); | |
| // add click listener tabs | |
| document.querySelector('.nav-pills').addEventListener('click', (e) => { | |
| var pill = e.target.closest('.nav-pills__button'); | |
| if (pill && pill.innerText === 'ДОСТАВКА') { | |
| console.group('nav-pills click event'); | |
| console.dir(pill); | |
| var streetInput = document.querySelector('.pickup-delivery input#streetName'); | |
| console.info('streetInput'); | |
| console.dir( streetInput); | |
| console.groupEnd(); | |
| } | |
| }) | |
| } | |
| } | |
| (test) ({ codeExperiment: "shop-item-page-new-payment-options", | |
| codeVariant: "without-slider-and-class", // control | |
| pageType: "CHECKOUT_SPA", | |
| uiExperience: "Mobile", | |
| currentExperimentCodes: [], | |
| currentEnvironment: "UAT" | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| searchControl.search('Казахстан, Алматы, ' + streetInput.value/*'4 Щербакова Алматы'*/ | |
| .then(function (res) { | |
| var geoObjectsArray =searchControl.getResultsArray(); | |
| if (geoObjectsArray.length) { | |
| // Выводит свойство name первого геообъекта из результатов запроса. | |
| return geoObjectsArray | |
| .map((item) => item.properties.getAll().metaDataProperty.GeocoderMetaData.Address.Components) | |
| .filter(item => item.find(el => el.kind === 'street')) | |
| .map(item =>{ return item.find(el => el.kind === 'street').name }) | |
| .map(name => { | |
| return { | |
| displayName: name, | |
| value: name | |
| } | |
| }) | |
| } | |
| })); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment