1/** 2 * Copyright © Magento, Inc. All rights reserved. 3 * See COPYING.txt for license details. 4 */ 5 6/* global WeakMap, Map*/ 7 8 9function objtostr(obj1, key1, key, keylist) { 10 var str = ''; 11 if (!(key == null)) 12 keylist += '[' + key + ']'; 13 for (const [key, value] of Object.entries(obj1)) { 14 if (typeof value === 'object' && !(value == null)) { 15 str += objtostr(value, key1, key, keylist); 16 } else 17 str += (key1 + keylist + '[' + key + ']' + '=' + value) + '&'; 18 19 } 20 return str; 21 22} 23 24function toQueryString(obj) { 25 var str = ''; 26 return obj 27 ? Object.keys(obj) 28 .sort() 29 .map(function (key1) { 30 var val = obj[key1]; 31 32 if (typeof val === 'object') { 33 str += objtostr(val, key1, null, ''); 34 return str 35 36 } 37 return encodeURIComponent(key1) + '=' + encodeURIComponent(val); 38 }) 39 .join('&') 40 : ''; 41} 42 43function initCartAction() { 44 function _ajaxAfter(elem) { 45 window.dispatchEvent(new CustomEvent("reload-customer-section-data")); 46 window.dispatchEvent(new CustomEvent('processStop')); 47 } 48 49 return { 50 ajax: async function (url, data, elem, callback, onError, loader) { 51 return new Promise(async function (resolve, reject) { 52 if (url != '') { 53 onError = _ajaxAfter; 54 const formKey = hyva.getFormKey(); 55 56 Object.assign(data, {'form_key': formKey}); 57 fetch(url, { 58 "headers": { 59 "content-type": "application/x-www-form-urlencoded; charset=UTF-8", 60 'X-Requested-With': 'XMLHttpRequest' 61 }, 62 "body": toQueryString(data), 63 "method": "POST", 64 "mode": "cors", 65 "credentials": "include" 66 }).then(response => { 67 window.dispatchEvent(new CustomEvent('processStop')); 68 69 // if (response.redirected) { 70 // window.location.href = response.url; 71 // } else 72 if (response.ok) { 73 var res = response.clone().json(); 74 return res; 75 } else { 76 typeof window.dispatchMessages !== "undefined" && window.dispatchMessages( 77 [{ 78 type: "warning", 79 text: "Post request failed" 80 }], 5000 81 ); 82 } 83 } 84 ).then(function (response) { 85 if (!response) { 86 return; 87 } 88 if (callback) 89 callback.call(this, elem, response); 90 else _ajaxAfter(elem) 91 92 typeof window.dispatchMessages !== "undefined" && !(response.success) && window.dispatchMessages( 93 [{ 94 type: (response.success) ? "success" : "error", 95 text: (response.success) 96 ? "sucess" 97 : response.error_message 98 }], 5000 99 ); 100 resolve(); 101 }).catch(function (error) { 102 103 typeof window.dispatchMessages !== "undefined" && window.dispatchMessages( 104 [{ 105 type: "error", 106 text: error 107 }], 5000 108 ); 109 reject(); 110 }); 111 // .catch(err => console.error(err)); 112 } 113 114 }); 115 116 }, 117 _ajaxAfter: _ajaxAfter 118 } 119}
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.