Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- (function() {
- function getUrlParameter(name, URL) {
- name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
- var regex = new RegExp("[\\?&]" + name + "=([^&#]*)");
- var results = regex.exec(URL);
- return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, " "));
- }
- function adoricAddToCart(productId) {
- var data = {
- "id": productId,
- "quantity": 1
- };
- var xhr = new XMLHttpRequest();
- xhr.withCredentials = true;
- xhr.addEventListener('readystatechange', function() {
- if (this.readyState === 4) {
- console.log(this.responseText);
- window.location.reload();
- }
- });
- xhr.open('POST', window.location.origin + '/cart/add.js');
- xhr.setRequestHeader('content-type', 'application/json');
- xhr.setRequestHeader('cache-control', 'no-cache');
- xhr.send(JSON.stringify(data));
- }
- if (window.Element && !Element.prototype.closest) {
- Element.prototype.closest = function(s) {
- var matches = (this.document || this.ownerDocument).querySelectorAll(s),
- i, el = this;
- do {
- i = matches.length;
- while (--i >= 0 && matches.item(i) !== el) {};
- } while ((i < 0) && (el = el.parentElement));
- return el;
- };
- }
- var currentCampaignRepeater = document.querySelector('.' + self.identifier + ' .repeater-content');
- currentCampaignRepeater.addEventListener('click', function(event) {
- var productItem = event.target.closest('.repeater-item');
- event.preventDefault();
- if (event.target.getAttribute('role') === 'button' && productItem) {
- var productInformation = JSON.parse(productItem.dataset.productInfo);
- var productId = getUrlParameter('variant', productInformation.link);
- window.ga && window.ga('t0.send', 'event', {
- eventCategory: "Adoric - " + self.campaignTitle + '(' + self.versionTitle + ')',
- eventAction: 'click',
- eventLabel: 'Added to the cart - ' + productInformation.title,
- });
- adoricAddToCart(productId);
- }
- });
- })();
- </script>
Add Comment
Please, Sign In to add comment