PageSourceSearch

https://artely.art/wp-content/plugins/artely-hng-mediator/js/klarna-echo-address.js?ver=1791592247

js artely.art collected 2026-10-10 02:29:46 UTC 8,662 bytes, 209 lines download raw bytes

1/**
2 * Created by jakeroid on 1/9/17.
3 */
4
5jQuery(function ($) {
6
7    //set interval for render postal code inside klarna, VATS, translations
8    setInterval(renderPostalCodeElement, 500);
9    var renderVATRows = setInterval(renderVATRows, 500);
10	setTimeout(() => { clearInterval(renderVATRows);}, 5000);
11    //renderVATRows();
12    setInterval(renderTranslations, 100);
13
14    //get postal code on event and put it inside data body
15    $(document.body).on('kco_change', function (event, data) {
16        addPostalCodeToBody(data.postal_code);
17    });
18
19    //woocommerce-cart-form processing
20    $( document ).on( 'updated_cart_totals', function() {
21        renderVATRows();
22        $('.remove_vat').remove();
23    });
24
25
26
27    //render table row inside klarna cart widget
28    function renderPostalCodeElement() {
29
30        if (getCurrentShippingMethodId() != hngMediator.ArtelyShippingMethodArtmoveId) {
31            return;
32        }
33
34        var bodyEl = $('body');
35        var postalCode = bodyEl.data('postal-code-value');
36
37        if (postalCode == undefined || postalCode == '') {
38            return;
39        }
40
41        var tableElement = $('tr#kco-page-shipping');
42        var oldElement = $('tr#postalcode-custom');
43
44        if (oldElement.length > 0) {
45            oldElement.find('#postal-code-value').text(postalCode);
46        } else {
47            var resultHtml = '<tr id="postalcode-custom">';
48            resultHtml += '<td colspan="2"><strong>'
49            resultHtml += hngMediator.textPhrases.postalCode + ': <span id="postal-code-value">';
50            resultHtml += postalCode + '</span></strong>';
51            resultHtml += '<br><span>' + hngMediator.textPhrases.artworkText + '</span>';
52            resultHtml += '</td></tr>';
53            var newTableElement = $(resultHtml);
54            tableElement.after(newTableElement);
55        }
56    }
57
58    //add postal code to body data tag
59    function addPostalCodeToBody(postalCode) {
60        var bodyEl = $('body');
61        bodyEl.attr('data-postal-code-value', postalCode);
62    }
63
64    //get selected shipping method directly from page
65    function getCurrentShippingMethodId() {
66        return $('#shipping_method').find('input[checked="checked"]').val();
67    }
68
69    //function for render VAT rows
70    function renderVATRows() {
71        var resultArtworkHtml = '';
72        var resultFAPHtml = '';
73        var productPriceFAP = 0;
74        for (var i = 0; i < hngMediator.productPrice.length; i++) {
75            var productPrice = 0;
76            var artworkVat = 0;
77            var artworkVatRes = 0;
78
79            if(hngMediator.productFAP[i] == false){
80                productPrice = hngMediator.productPrice[i];
81                switch (hngMediator.artworkVAT[i]) {
82                    case 'vat0':
83                        artworkVat = 0;
84                        artworkVatRes = 0;
85                        break;
86                    case 'vat12':
87                        artworkVat = 12;
88                        artworkVatRes = productPrice - (productPrice * 100 / 112);
89                        break;
90                    case 'vat25':
91                        artworkVat = 25;
92                        artworkVatRes = productPrice - (productPrice * 100 / 125);
93                        break;
94                }
95                var shippingVat = 25;
96                var shippingVatRes = 180;
97                artworkVatRes = artworkVatRes.toFixed(2).replace(".", ",");
98                artworkVatRes = artworkVatRes.toString().replace(/\B(?=(\d{3})+(?!\d))/g, " ");
99                var totalElement = $('.order-total');
100
101                var oldArtworkElement = $('#vats-custom-artwork');
102                if (oldArtworkElement.length > 0) {
103                    oldArtworkElement.remove();
104                }
105                var remove_pr = $('.cart-collaterals').data('remove-product');
106                if(remove_pr != hngMediator.productId[i]){
107                    resultArtworkHtml += '<tr id="vats-custom-artwork" class="vat_'+hngMediator.productId[i]+'" >';
108                    resultArtworkHtml += '<th>' + hngMediator.textPhrases.artworkVAT + ', ' + hngMediator.productTitle[i] + ', ' + hngMediator.textPhrases.VAT + ' ' + artworkVat + '%</th>';
109                    resultArtworkHtml += '<td class="kco-rightalign" data-title="' + hngMediator.textPhrases.artworkVAT + ', ' + hngMediator.productTitle[i] + ', ' + hngMediator.textPhrases.VAT + ' ' + artworkVat + '%">' + artworkVatRes + ' kr</td>';
110                    resultArtworkHtml += '</tr>';
111                }
112
113            } else {
114				if(hngMediator.productFAP[i] == true){
115					var coupon = 0;
116					var subtotal_res = 0;
117					var discount = '';
118					var full_html = '';
119					var coupon1 = '';
120					$('.cart-discount').each(function () {
121						full_html = $(this).find('.amount').html();
122						discount = full_html.replace('&nbsp;<span class="woocommerce-Price-currencySymbol">kr</span>', '');
123						coupon1 = discount.replace(' ','');
124						coupon += parseInt(coupon1);
125					});
126					$('.cart_item').each(function () {
127						var subtotal = $(this).find('.product-subtotal').html();
128						if(subtotal){
129							subtotal = subtotal.replace(' kr', '');
130
131							var search = subtotal.search(/span/i);
132
133							if(search == -1){
134								subtotal_res += parseInt(subtotal.replace(' ',''));
135							}
136						}
137
138					});
139					// productPriceFAP += (+hngMediator.productPrice[i] * hngMediator.productQuantity[i] + +hngMediator.frameFAPprice[i]) - coupon;
140					if(subtotal_res){
141						productPriceFAP = +subtotal_res - coupon ;
142					} else {
143						productPriceFAP += (+hngMediator.productPrice[i] * hngMediator.productQuantity[i] + +hngMediator.frameFAPprice[i]) - coupon;
144					}
145
146					artworkVat = 25;
147					artworkVatRes = productPriceFAP - (productPriceFAP * 100 / 125);
148					artworkVatRes = artworkVatRes.toFixed(2).replace(".", ",");
149					artworkVatRes = artworkVatRes.toString().replace(/\B(?=(\d{3})+\b)/g, " ");
150
151					var totalElement = $('.order-total');
152
153					var oldArtworkElement = $('#vats-custom-artwork');
154					if (oldArtworkElement.length > 0) {
155						oldArtworkElement.remove();
156					}
157
158					resultFAPHtml = '';
159					resultFAPHtml += '<tr id="vats-custom-artwork">';
160					resultFAPHtml += '<th>' + hngMediator.textPhrases.fine_art_printsVAT + ' ' + artworkVat + '%</th>';
161					resultFAPHtml += '<td class="kco-rightalign" data-title="' + hngMediator.textPhrases.fine_art_printsVAT + ' ' + artworkVat + '%">' + artworkVatRes + ' kr</td>';
162					resultFAPHtml += '</tr>';
163				}
164            }
165
166        }
167        var newArtworkElement = $(resultArtworkHtml + resultFAPHtml);
168        if(totalElement){
169            totalElement.after(newArtworkElement);
170        }
171		
172
173        var currMethod = getCurrentShippingMethodId();
174
175
176        if (currMethod == hngMediator.ArtelyShippingMethodArtmoveId || currMethod == hngMediator.ArtelyShippingMethodArtmoveId || currMethod === undefined) {
177            var oldShippingElement = $('#vats-custom-shipping');
178            if (oldShippingElement.length > 0) {
179                oldShippingElement.remove();
180            }
181            var resultShippingElement = '<tr id="vats-custom-shipping">';
182            // resultShippingElement += '<td>' + hngMediator.textPhrases.shippingVAT + ' ' + shippingVat + '%</td>';
183            // resultShippingElement += '<td class="kco-rightalign">' + shippingVatRes + ' kr</td>';
184            resultShippingElement += '</tr>';
185
186            var newShippingElement = $(resultShippingElement);
187            if(newArtworkElement){
188                newArtworkElement.after(newShippingElement);
189            }
190        }
191    }
192
193    //render translation
194    function renderTranslations() {
195        // $(':lang(en-US)[for="shipping_method_0_artely-shipping-free"]').text('Pick up directly from seller 0 kr');
196        // $(':lang(en-US)[for="shipping_method_0_artely-shipping-artmove"]').text('Home delivery with ArtMove 900 kr');
197        $(':lang(sv-SE)#kco-page-total td:not(#kco-page-total-amount)').text('Totalt');
198        $("#kco-page-shipping-total:contains('Free!')").hide();
199        $("#kco-page-shipping-total:contains('Gratis!')").hide();
200    }
201
202    $('.product-remove').click( function () {
203        var cart = $('.cart-collaterals');
204        cart.attr('data-remove-product', '');
205        var product_id = $(this).find('a').data('product_id');
206        cart.attr('data-remove-product', product_id);
207        $('#vats-custom-artwork.vat_'+product_id).addClass('remove_vat');
208    });
209});

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.