1class EasyStoreEvents { 2 3 constructor() { 4 this.stack = {}; 5 } 6 7 subscribe(event, callback) { 8 9 if(!this.stack[event]) this.stack[event] = [] 10 this.stack[event].push(callback); 11 12 console.log('EasyStore.Event.subscribe', event) 13 } 14 15 dispatch(event, data = {}) { 16 17 // New 18 if(event.includes('/')) { 19 20 data = { 21 store: { 22 host: 'https://' + location.hostname, 23 }, 24 ...data, 25 } 26 27 // Old 28 } else { 29 30 data = this.tempDataMapper(event, data) 31 32 } 33 34 console.log(event, data) 35 36 if(this.stack[event]) { 37 38 this.stack[event].forEach((subscriber) => { 39 subscriber(data) 40 }); 41 42 console.log('EasyStore.Event.dispatch', event, data) 43 44 } 45 46 } 47 48 // Deprecating 49 tempDataMapper(event, source) { 50 51 switch (event) { 52 case 'ProductView': 53 var data = { 54 product: { 55 id: source.product.id, 56 title: source.product.title, 57 url: source.store.host + source.product.url, 58 price: source.product.price, 59 collections: source.product.collections.map(function (value, index) { return value.title }).join(', '), 60 image_url: source.product.images[0].src, 61 } 62 } 63 break; 64 case 'CollectionView': 65 var data = { 66 collection: { 67 id: source.collection.id, 68 title: source.collection.title, 69 url: source.store.host + '/collections/' + source.collection.handle, 70 } 71 } 72 break; 73 case 'PageView': 74 var data = { 75 page: { 76 id: source.page.id, 77 title: source.page.title, 78 url: source.store.host + source.page.url, 79 } 80 } 81 break; 82 case 'ArticleView': 83 var data = { 84 article: { 85 id: source.article.id, 86 title: source.article.title, 87 url: source.store.host + source.article.url, 88 } 89 } 90 break; 91 case 'Search': 92 var data = { 93 search: { 94 term: source.search.terms, 95 url: source.store.host + '/search?q=' + source.search.terms, 96 } 97 } 98 break; 99 case 'CartItemAdd': 100 var data = { 101 item: { 102 product_id: source.item.product_id, 103 product_title: source.item.product_name, 104 variant_id: source.item.variant_id, 105 variant_title: source.item.variant_name, 106 collections: source.item.collections.split(',').join(', '), 107 price: source.item.price, 108 quantity: source.item.quantity, 109 url: source.store.host + source.item.url, 110 image_url: source.item.img_url, 111 } 112 } 113 break; 114 case 'CartItemRemove': 115 var data = { 116 item: { 117 product_id: source.item.product_id, 118 product_title: source.item.product_name, 119 variant_id: source.item.variant_id, 120 variant_title: source.item.variant_name, 121 collections: source.item.collections.split(',').join(', '), 122 price: source.item.price, 123 quantity: source.item.quantity, 124 url: source.store.host + source.item.url, 125 image_url: source.item.img_url, 126 } 127 } 128 break; 129 case 'CouponAdd': 130 131 var data = { 132 133 coupon: { 134 135 code: source.coupon.code 136 137 } 138 139 } 140 break; 141 case 'CheckoutInitial': 142 143 var data = { 144 145 checkout: { 146 147 item_count: source.checkout.item_count 148 149 } 150 151 } 152 break; 153 case 'DeliveryAddressAdd': 154 155 var data = { 156 157 delivery: { 158 159 method: source.delivery.method, 160 name: source.delivery.method == 'shipping' ? null : source.delivery.address.name, 161 first_name: source.delivery.address.first_name, 162 last_name: source.delivery.address.last_name, 163 country: source.delivery.address.country, 164 province: source.delivery.address.province, 165 city: source.delivery.address.city, 166 167 } 168 169 } 170 171 break; 172 case 'CheckoutCompleted': 173 174 var items = [] 175 176 source.order.order_item.forEach(item => { 177 178 items.push({ 179 180 order_number: source.order.order_number, 181 product_id: item.product_id, 182 product_title: item.product_name, 183 variant_id: item.variant_id, 184 variant_title: item.variant_name, 185 collections: item.collections.split(',').join(', '), 186 price: item.price, 187 quantity: item.quantity, 188 url: source.store.host + "/products/" + item.handle, 189 image_url: item.item_image.url, 190 191 }) 192 193 }); 194 195 var data = { 196 197 order: { 198 199 number: source.order.order_number, 200 item_count: source.order.order_item.length, 201 total_amount: source.order.total_amount_include_transaction, 202 transaction: source.order.transaction_records[0], 203 delivery_address: source.order.shipping_address, 204 items: items 205 206 } 207 208 } 209 210 if (source.order.pickup_location != null) { 211 212 data.order.delivery_address = source.order.pickup_location; 213 214 } 215 216 217 break; 218 219 default: 220 var data = null; 221 } 222 223 return data; 224 } 225 226} 227 228class EasyStoreSuperClass { 229 230 constructor() { 231 this.Event = new EasyStoreEvents(); 232 } 233 234} 235 236window.EasyStore = new EasyStoreSuperClass(); 237 238 239// Minify to storefront.min.js using https://jscompress.com/
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.