Last active
December 19, 2016 15:35
-
-
Save pelid/fe9a6d48c4d04ae75ecb6911d15b6cdb to your computer and use it in GitHub Desktop.
MyMechanic widget integration to car.ru
This file contains 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
// код для встраивания на страницу car.ru | |
// используется chrome extension https://chrome.google.com/webstore/detail/custom-javascript-for-web/poakhlngfciodnhlhhgnaaelnpjljija | |
var buttonsHTML = ( | |
'<p><button onclick="widget.expand()">Expand</button> <button onclick="widget.collapse()">Collapse</button></p>'+ | |
'<p>'+ | |
'<button onclick="widget.requestForQuote({presets: {carMake: \'BMW\', services: [85702, 52658]}})">Заказать диагностику BMW - button onclick</button>'+ | |
'<a href="#" class="js-activate-mymechanic" data-car-make="Ford" data-car-model="Focus" data-service-area="Москва" data-services="[85702, 52658]">ТО для Ford Focus в Москве - auto bind</a>'+ | |
'<button class="js-activate-mymechanic" data-car-make="Ford" data-car="Toyota Camry 2010">ремонт Toyota Camry 2010 - auto bind with car info as a string</button>'+ | |
'<button class="js-activate-mymechanic">Предпродажный осмотр</button>'+ | |
'</p>' | |
) | |
function insertButtons(container, widget){ | |
mymechanicPartnersWidgetApi.bindRequestForQuote(container, widget) | |
$(container).prepend(buttonsHTML) | |
} | |
function pluginAPI(onLoad){ | |
var n = document.getElementsByTagName("script")[0] | |
var s = document.createElement("script") | |
s.type = "text/javascript" | |
s.async = true | |
s.src = "https://mymechanic.ru/front/client/partners_widget/partners_api4car.ru.js" | |
s.onload = onLoad | |
n.parentNode.insertBefore(s, n) | |
} | |
function showArticle(articleId, widget){ | |
var container = $('.content-body-wrap').html('') | |
mymechanicPartnersWidgetApi.showArticle(articleId, '.content-body-wrap', widget) | |
} | |
function onLoad () { | |
window.widget = new mymechanicPartnersWidgetApi.Widget({ | |
presets: { | |
serviceArea: 'Москва', | |
// uncomment to setup application prompt | |
prompt: 'prepurchase_inspection', | |
// prompt: 'maintenance', | |
} | |
}) | |
// uncomment to show buttons | |
insertButtons(document.body, widget) | |
// uncomment to show article | |
showArticle('carru-maintenance', widget) | |
// showArticle('carru-main', widget) | |
// showArticle('carru-prepurchase-inspection', widget) | |
// uncomment to see widget state | |
console.log('Widget is ', {true: 'expanded', false: 'closed'}[widget.isExpanded]) | |
} | |
pluginAPI(onLoad) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment