@wikala/spmkt 2.31.1 → 3.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/MIGRATION_GUIDE.md +310 -0
  2. package/api/product.js +1 -0
  3. package/api/request.js +12 -6
  4. package/api/user.js +1 -1
  5. package/components/Account/AccountDashboard.vue +101 -101
  6. package/components/Account/AccountStore.js +57 -31
  7. package/components/Account/AffiliateReport.vue +56 -60
  8. package/components/Account/{OrderDetail.vue → Orders/OrderDetail.vue} +44 -30
  9. package/components/Account/Orders/Orders.vue +124 -0
  10. package/components/Account/{AccountSettings.vue → Settings/AccountSettings.vue} +4 -4
  11. package/components/Account/Settings/ChangeEmail.vue +136 -0
  12. package/components/Account/Settings/ChangeName.vue +82 -0
  13. package/components/Account/Settings/ChangePassword.vue +91 -0
  14. package/components/Address/Address.vue +38 -57
  15. package/components/Address/AddressBook.vue +77 -57
  16. package/components/Address/AddressSelect.vue +94 -87
  17. package/components/Address/Edit.vue +253 -265
  18. package/components/Address/PostalCode.vue +22 -21
  19. package/components/AgeGate.vue +11 -5
  20. package/components/Auth/Login.vue +62 -44
  21. package/components/Auth/Register.vue +82 -60
  22. package/components/Auth/ResetPassword.vue +45 -30
  23. package/components/Cart/AgeVerification/AgeChecker.vue +3 -3
  24. package/components/Cart/CartBadge.vue +15 -4
  25. package/components/Cart/CartBox.vue +19 -11
  26. package/components/Cart/CartItem.vue +3 -3
  27. package/components/Cart/CartMode.vue +6 -5
  28. package/components/Cart/CartPreview.vue +24 -18
  29. package/components/Cart/CreditCard/Everyware.vue +10 -10
  30. package/components/Cart/CreditCard/ExtendedCreditCard.vue +5 -5
  31. package/components/Cart/CreditCard/SquarePay.vue +18 -16
  32. package/components/Cart/CreditCard/StandardCreditCard.vue +9 -9
  33. package/components/Cart/Delivery/Delivery.vue +16 -12
  34. package/components/Cart/Delivery/DeliveryAddress.vue +1 -1
  35. package/components/Cart/Delivery/DeliveryMethods.vue +1 -1
  36. package/components/Cart/Delivery/DeliveryOptions.vue +15 -9
  37. package/components/Cart/Delivery/DeliveryTypes.vue +8 -5
  38. package/components/Cart/Delivery/ReservationSlots.vue +14 -8
  39. package/components/Cart/Disclaimer.vue +1 -1
  40. package/components/Cart/OrderConfirmation.vue +1 -1
  41. package/components/Cart/Payment/Payment.vue +37 -33
  42. package/components/Cart/Payment/PaymentMethods.vue +6 -4
  43. package/components/Cart/ReviewAndSubmit.vue +9 -7
  44. package/components/Cart/ShoppingCart.vue +42 -31
  45. package/components/Cart/Store/actions.js +1 -1
  46. package/components/Cart/Store/getters.js +2 -1
  47. package/components/Cart/Store/index.js +1 -1
  48. package/components/Cart/Store/mutations.js +9 -7
  49. package/components/Cart/Store/state.js +2 -2
  50. package/components/Cart/UserIdentity.vue +1 -1
  51. package/components/Category/CategoryFilter.vue +128 -114
  52. package/components/Category/CategorySort.vue +44 -32
  53. package/components/Category/LoadMore.vue +39 -23
  54. package/components/DeliverTo.vue +10 -15
  55. package/components/DeliveryNotice.vue +72 -68
  56. package/components/DobInput.vue +24 -24
  57. package/components/Gmaps/GmapsAutocomplete.vue +139 -78
  58. package/components/Gmaps/GmapsLocations.vue +1 -1
  59. package/components/Gmaps/GmapsSingleLocation.vue +121 -87
  60. package/components/MobileMenu/icons/LeftArrowIcon.vue +1 -1
  61. package/components/MobileMenu/icons/MenuIcon.vue +1 -1
  62. package/components/MobileMenu/icons/RightArrowIcon.vue +1 -1
  63. package/components/ModalContainer/ModalContainer.vue +20 -13
  64. package/components/ModalContainer/index.js +62 -18
  65. package/components/Product/AddToCart.vue +237 -221
  66. package/components/Product/BoxAddToCart.vue +114 -86
  67. package/components/Product/Compare.vue +91 -49
  68. package/components/Product/CompareBox.vue +128 -123
  69. package/components/Product/Lookup.vue +92 -65
  70. package/components/Product/Photo.vue +105 -66
  71. package/components/Product/Price.vue +64 -43
  72. package/components/Product/ProductAutocomplete.vue +52 -57
  73. package/components/Product/ProductBox.vue +61 -38
  74. package/components/Product/ProductImages.vue +83 -86
  75. package/components/Product/Quantity.vue +115 -53
  76. package/components/Product/QuickView.vue +52 -45
  77. package/components/Product/RelatedProducts.vue +88 -23
  78. package/components/Product/SKU.vue +27 -8
  79. package/components/Product/Variants.vue +336 -342
  80. package/components/Product/reviews-questions/ProductQuestions.vue +226 -198
  81. package/components/Product/reviews-questions/ProductReviews.vue +122 -107
  82. package/components/Product/reviews-questions/Review.vue +54 -59
  83. package/components/Product/reviews-questions/ReviewForm.vue +222 -170
  84. package/components/Product/reviews-questions/ReviewImages.vue +197 -216
  85. package/components/Product/reviews-questions/Vote.vue +83 -57
  86. package/components/QuantityInput.vue +18 -8
  87. package/components/RangeInput.vue +15 -8
  88. package/components/Recaptcha.vue +8 -1
  89. package/components/SelectShippingCountry.vue +81 -62
  90. package/components/TimedOffer.vue +59 -74
  91. package/composables/globals.js +53 -0
  92. package/config.js +5 -2
  93. package/index.js +41 -10
  94. package/install.js +88 -0
  95. package/locales/en.json +2 -1
  96. package/locales/sr.json +2 -1
  97. package/package.json +49 -37
  98. package/utils/animate.css +50 -0
  99. package/utils/animate.js +1 -1
  100. package/utils/buefy.js +62 -0
  101. package/utils/directives.js +28 -45
  102. package/utils/event-bus.js +56 -0
  103. package/utils/filters.js +24 -7
  104. package/utils/format-date.js +17 -0
  105. package/utils/{gmaps.js → google/gmaps.js} +43 -10
  106. package/utils/{google-analytics-eec.js → google/google-analytics-eec.js} +7 -7
  107. package/utils/random-id.js +10 -0
  108. package/babel.config.js +0 -5
  109. package/components/Account/ChangeEmail.vue +0 -133
  110. package/components/Account/ChangeName.vue +0 -92
  111. package/components/Account/ChangePassword.vue +0 -94
  112. package/components/Account/CreditCards.vue +0 -18
  113. package/components/Account/Orders.vue +0 -110
  114. package/components/Account/Settings.vue +0 -18
  115. package/components/Cart/Delivery/DeliveryAddressGuest.spec.js +0 -128
  116. package/components/Cart/Delivery/DeliveryTypes.spec.js +0 -83
  117. package/components/Cart/PCIBadge/SecurityMetrics.vue +0 -11
  118. package/components/Instagram.vue +0 -49
  119. package/components/ProductImageModal.vue +0 -41
  120. package/jest.config.js +0 -16
  121. package/test/e2e/.babelrc.js +0 -8
  122. package/test/e2e/.eslintrc.js +0 -11
  123. package/test/e2e/accAuth.spec.js +0 -64
  124. package/test/e2e/ageGate.spec.js +0 -26
  125. package/test/e2e/checkout.spec.js +0 -106
  126. package/test/e2e/compare.spec.js +0 -52
  127. package/test/e2e/config/data.js +0 -21
  128. package/test/e2e/config/routes.js +0 -11
  129. package/test/e2e/region.spec.js +0 -46
  130. package/test/e2e/search.spec.js +0 -32
  131. package/tests/vueBuefy.js +0 -4
  132. package/tsconfig.json +0 -8
@@ -11,147 +11,152 @@
11
11
  <img :src="product.image" :alt="product.name" />
12
12
  </div>
13
13
  </div>
14
- <button name="compare_button" :disabled="products.length < 2" :class="['button', 'is-primary', { 'is-small': $mq === 'mobile' }]" @click="compare">
14
+ <button name="compare_button" :disabled="products.length < 2" :class="['button', 'is-primary', { 'is-small': mq === 'mobile' }]" @click="compare">
15
15
  {{ $t('product.compare') }}
16
16
  </button>
17
- <button name="clear_compare" :class="['button', 'btn-close', { 'is-small': $mq === 'mobile' }]" @click="hideCompareBox"> &times; </button>
17
+ <button name="clear_compare" :class="['button', 'btn-close', { 'is-small': mq === 'mobile' }]" @click="hideCompareBox"> &times; </button>
18
18
  </div>
19
19
  </div>
20
20
  </template>
21
21
 
22
- <script>
22
+ <script setup>
23
+ import { ref, onMounted, onBeforeUnmount } from 'vue'
24
+ import { useBuefy, useMq, useT } from '../../composables/globals'
23
25
  import _ from 'underscore'
24
26
  import Cookie from 'js-cookie'
27
+ import { eventBus } from '../../utils/event-bus'
25
28
 
26
- import { Compare } from '../../api'
29
+ defineOptions({ name: 'CompareBox' })
27
30
 
28
- export default {
29
- name: 'CompareBox',
30
- data() {
31
- return {
32
- attTemplateId: 0,
33
- products: [],
34
- viewProducts: true
35
- }
36
- },
37
-
38
- methods: {
39
- initCompareList() {
40
- let cCompareList = ''
41
- try {
42
- cCompareList = JSON.parse(Cookie.get('compareList'))
43
- } catch (e) {
44
- console.log('Cannot parse compareList', Cookie.get('compareList'))
45
- }
46
- if (cCompareList) {
47
- this.products = _.compact(cCompareList)
48
- this.products.forEach((product) => {
49
- this.setCompareIconStatus(product.id, 'on')
50
- })
51
- this.setAttTemplateId()
52
- }
53
- },
31
+ const $buefy = useBuefy()
32
+ const { t: $t } = useT()
33
+ const mq = useMq()
54
34
 
55
- setAttTemplateId() {
56
- if (this.products.length > 0) {
57
- this.attTemplateId = this.products[0]['att_template_id']
58
- }
59
- },
60
-
61
- setProducts(products) {
62
- this.products = products
63
- this.setAttTemplateId()
64
- Cookie.set('compareList', JSON.stringify(this.products), { expires: 1 })
65
- },
66
-
67
- addProduct(product) {
68
- if (this.products.length >= 4) {
69
- this.$buefy.dialog.alert({
70
- title: this.$t('product.compareErrorDialogTitle'),
71
- message: this.$t('product.compareErrorMaxProducts'),
72
- canCancel: ['button', 'escape'],
73
- confirmText: this.$t('product.compareErrorDialogConfirm'),
74
- cancelText: this.$t('global.cancel'),
75
- onConfirm: () => {
76
- this.compare()
77
- }
78
- })
79
- return false
35
+ // Reactive state
36
+ const attTemplateId = ref(0)
37
+ const products = ref([])
38
+ const viewProducts = ref(true)
39
+
40
+ // Methods
41
+ const setCompareIconStatus = (product_id, status) => {
42
+ let productIconEl = document.getElementById('prod-compare-' + product_id)
43
+ if (!productIconEl) {
44
+ return false
45
+ }
46
+ if (status == 'on') {
47
+ productIconEl.classList.add('has-text-info')
48
+ } else {
49
+ productIconEl.classList.remove('has-text-info')
50
+ }
51
+ }
52
+
53
+ const initCompareList = () => {
54
+ let cCompareList = ''
55
+ try {
56
+ cCompareList = JSON.parse(Cookie.get('compareList'))
57
+ } catch (e) {
58
+ console.log('Cannot parse compareList', Cookie.get('compareList'))
59
+ }
60
+ if (cCompareList) {
61
+ products.value = _.compact(cCompareList)
62
+ products.value.forEach((product) => {
63
+ setCompareIconStatus(product.id, 'on')
64
+ })
65
+ setAttTemplateId()
66
+ }
67
+ }
68
+
69
+ const setAttTemplateId = () => {
70
+ if (products.value.length > 0) {
71
+ attTemplateId.value = products.value[0]['att_template_id']
72
+ }
73
+ }
74
+
75
+ const setProducts = (newProducts) => {
76
+ products.value = newProducts
77
+ setAttTemplateId()
78
+ Cookie.set('compareList', JSON.stringify(products.value), { expires: 1 })
79
+ }
80
+
81
+ const addProduct = (product) => {
82
+ if (products.value.length >= 4) {
83
+ $buefy.dialog.alert({
84
+ title: $t('product.compareErrorDialogTitle'),
85
+ message: $t('product.compareErrorMaxProducts'),
86
+ canCancel: ['button', 'escape'],
87
+ confirmText: $t('product.compareErrorDialogConfirm'),
88
+ cancelText: $t('global.cancel'),
89
+ onConfirm: () => {
90
+ compare()
80
91
  }
81
- this.products.push(product)
82
- this.setCompareIconStatus(product.id, 'on')
83
- this.setAttTemplateId()
84
- Cookie.set('compareList', JSON.stringify(this.products), { expires: 1 })
85
- },
86
-
87
- compare() {
88
- const productList = this.products.map((el) => el.id)
89
- window.location.href = `/compare-products?products=${productList}`
90
- },
91
-
92
- removeProd(id) {
93
- this.setProducts(_.reject(this.products, (product) => product.id == id))
94
- this.setCompareIconStatus(id, 'off')
95
- },
96
-
97
- clear() {
98
- this.products.forEach((product) => {
99
- this.setCompareIconStatus(product.id, 'off')
100
- })
101
- this.setProducts([])
102
- },
92
+ })
93
+ return false
94
+ }
95
+ products.value.push(product)
96
+ setCompareIconStatus(product.id, 'on')
97
+ setAttTemplateId()
98
+ Cookie.set('compareList', JSON.stringify(products.value), { expires: 1 })
99
+ }
100
+
101
+ const compare = () => {
102
+ const productList = products.value.map((el) => el.id)
103
+ window.location.href = `/compare-products?products=${productList}`
104
+ }
105
+
106
+ const removeProd = (id) => {
107
+ setProducts(_.reject(products.value, (product) => product.id == id))
108
+ setCompareIconStatus(id, 'off')
109
+ }
110
+
111
+ const clear = () => {
112
+ products.value.forEach((product) => {
113
+ setCompareIconStatus(product.id, 'off')
114
+ })
115
+ setProducts([])
116
+ }
117
+
118
+ const hideCompareBox = () => {
119
+ $buefy.dialog.alert({
120
+ title: $t('product.compareCloseDialogTitle'),
121
+ message: $t('product.compareCloseDialogMsg'),
122
+ canCancel: ['button', 'escape'],
123
+ confirmText: $t('product.compareClear'),
124
+ cancelText: $t('global.cancel'),
125
+ onConfirm: () => {
126
+ clear()
127
+ }
128
+ })
129
+ }
103
130
 
104
- hideCompareBox() {
105
- this.$buefy.dialog.alert({
106
- title: this.$t('product.compareCloseDialogTitle'),
107
- message: this.$t('product.compareCloseDialogMsg'),
131
+ const handleCompareProduct = (productData) => {
132
+ if (_.findWhere(products.value, { id: productData.id })) {
133
+ removeProd(productData.id)
134
+ } else {
135
+ if (products.value.length > 0 && productData.att_template_id !== attTemplateId.value) {
136
+ $buefy.dialog.alert({
137
+ title: $t('global.error'),
138
+ message: $t('product.compareErrorDifferentCategories'),
108
139
  canCancel: ['button', 'escape'],
109
- confirmText: this.$t('product.compareClear'),
110
- cancelText: this.$t('global.cancel'),
140
+ confirmText: $t('product.compareClear'),
141
+ cancelText: $t('global.cancel'),
111
142
  onConfirm: () => {
112
- this.clear()
143
+ clear()
144
+ addProduct(productData)
113
145
  }
114
146
  })
115
- //this.viewProducts = !this.viewProducts
116
- },
117
-
118
- setCompareIconStatus(product_id, status) {
119
- let productIconEl = document.getElementById('prod-compare-' + product_id)
120
- if (!productIconEl) {
121
- return false
122
- }
123
- if (status == 'on') {
124
- productIconEl.classList.add('has-text-info')
125
- } else {
126
- productIconEl.classList.remove('has-text-info')
127
- }
147
+ return false
128
148
  }
129
- },
130
-
131
- mounted() {
132
- this.initCompareList()
133
-
134
- this.$bus.$on('compareProduct', (productData) => {
135
- if (_.findWhere(this.products, { id: productData.id })) {
136
- this.removeProd(productData.id)
137
- } else {
138
- if (this.products.length > 0 && productData.att_template_id !== this.attTemplateId) {
139
- this.$buefy.dialog.alert({
140
- title: this.$t('global.error'),
141
- message: this.$t('product.compareErrorDifferentCategories'),
142
- canCancel: ['button', 'escape'],
143
- confirmText: this.$t('product.compareClear'),
144
- cancelText: this.$t('global.cancel'),
145
- onConfirm: () => {
146
- this.clear()
147
- this.addProduct(productData)
148
- }
149
- })
150
- return false
151
- }
152
- this.addProduct(productData)
153
- }
154
- })
149
+ addProduct(productData)
155
150
  }
156
151
  }
152
+
153
+ // Lifecycle hooks
154
+ onMounted(() => {
155
+ initCompareList()
156
+ eventBus.on('compareProduct', handleCompareProduct)
157
+ })
158
+
159
+ onBeforeUnmount(() => {
160
+ eventBus.off('compareProduct', handleCompareProduct)
161
+ })
157
162
  </script>
@@ -10,7 +10,7 @@
10
10
  @typing="getAsyncData"
11
11
  @select="select($event)"
12
12
  >
13
- <template slot-scope="props">
13
+ <template #default="props">
14
14
  <div class="media">
15
15
  <div class="media-left">
16
16
  <img width="32" :src="props.option.image" />
@@ -25,81 +25,108 @@
25
25
  </div>
26
26
  </template>
27
27
 
28
- <script>
28
+ <script setup>
29
+ import { ref, onMounted, onBeforeUnmount } from 'vue'
30
+ import { useBuefy, useBus } from '../../composables/globals'
29
31
  import _ from 'underscore'
30
32
  import { request } from '../../api'
31
33
 
32
- export default {
33
- name: 'ProductLookup',
34
- props: ['position', 'productOnPosition', 'label', 'attTemplateId'],
35
- data() {
36
- return {
37
- data: [],
38
- selected: null,
39
- isFetching: false,
40
- selectedIds: []
41
- }
42
- },
34
+ defineOptions({ name: 'ProductLookup' })
43
35
 
44
- methods: {
45
- getAsyncData: _.debounce(function (query) {
46
- if (!query.length) {
47
- this.data = []
48
- return
49
- }
36
+ const props = defineProps({
37
+ position: {
38
+ type: [Number, String],
39
+ default: -1
40
+ },
41
+ productOnPosition: {
42
+ type: [Number, String],
43
+ default: null
44
+ },
45
+ label: {
46
+ type: String,
47
+ default: ''
48
+ },
49
+ attTemplateId: {
50
+ type: [Number, String],
51
+ default: null
52
+ }
53
+ })
50
54
 
51
- //console.log('query ', query)
52
- this.isFetching = true
55
+ // Get global properties and injections
56
+ const $bus = useBus()
57
+ const $buefy = useBuefy()
53
58
 
54
- return request({
55
- baseURL: '',
56
- url: '/products/lookup?q=' + query + '&tid=' + this.attTemplateId,
57
- method: 'get'
58
- })
59
- .then((response) => {
60
- console.log('response: ', response)
61
- this.data = response.data.slice(0, 6)
62
- this.isFetching = false
63
- })
64
- .catch((error) => {
65
- console.log(error)
66
- this.isFetching = false
67
- })
68
- }, 500),
59
+ // Reactive state
60
+ const data = ref([])
61
+ const selected = ref(null)
62
+ const isFetching = ref(false)
63
+ const selectedIds = ref([])
69
64
 
70
- select(option) {
71
- if (!option) {
72
- return
73
- }
74
- if (this.selectedIds.indexOf(option.id.toString()) === -1) {
75
- if (parseInt(this.position) >= 0) {
76
- this.selectedIds[this.position] = option.id
77
- } else {
78
- this.selectedIds.push(option.id.toString())
79
- }
80
- window.location.href = '/compare-products?products=' + this.selectedIds.join(',')
81
- } else {
82
- this.$buefy.dialog.alert({
83
- title: '',
84
- message: "You've already selected " + option.name,
85
- confirmText: 'OK'
86
- })
87
- }
88
- },
65
+ // Methods
66
+ const getAsyncData = _.debounce(function (query) {
67
+ if (!query.length) {
68
+ data.value = []
69
+ return
70
+ }
89
71
 
90
- remove(position) {
91
- this.selectedIds.splice(position, 1)
92
- window.location.href = '/compare-products?products=' + this.selectedIds.join(',')
93
- }
94
- },
72
+ isFetching.value = true
95
73
 
96
- mounted() {
97
- let urlProductIds = new URL(window.location.href).searchParams.get('products').split(',')
98
- this.selectedIds = urlProductIds
74
+ return request({
75
+ baseURL: '',
76
+ url: '/products/lookup?q=' + query + '&tid=' + props.attTemplateId,
77
+ method: 'get'
78
+ })
79
+ .then((response) => {
80
+ console.log('response: ', response)
81
+ data.value = response.data.slice(0, 6)
82
+ isFetching.value = false
83
+ })
84
+ .catch((error) => {
85
+ console.log(error)
86
+ isFetching.value = false
87
+ })
88
+ }, 500)
99
89
 
100
- this.$bus.$on('removeFromCompare', (position) => {
101
- this.remove(position)
90
+ const select = (option) => {
91
+ if (!option) {
92
+ return
93
+ }
94
+ if (selectedIds.value.indexOf(option.id.toString()) === -1) {
95
+ if (parseInt(props.position) >= 0) {
96
+ selectedIds.value[props.position] = option.id
97
+ } else {
98
+ selectedIds.value.push(option.id.toString())
99
+ }
100
+ window.location.href = '/compare-products?products=' + selectedIds.value.join(',')
101
+ } else {
102
+ $buefy.dialog.alert({
103
+ title: '',
104
+ message: "You've already selected " + option.name,
105
+ confirmText: 'OK'
102
106
  })
103
107
  }
104
108
  }
109
+
110
+ const remove = (position) => {
111
+ selectedIds.value.splice(position, 1)
112
+ window.location.href = '/compare-products?products=' + selectedIds.value.join(',')
113
+ }
114
+
115
+ const onRemoveFromCompare = (position) => {
116
+ remove(position)
117
+ }
118
+
119
+ // Lifecycle hooks
120
+ onMounted(() => {
121
+ const urlParams = new URL(window.location.href).searchParams.get('products')
122
+ if (urlParams) {
123
+ selectedIds.value = urlParams.split(',')
124
+ }
125
+
126
+ $bus.on('removeFromCompare', onRemoveFromCompare)
127
+ })
128
+
129
+ onBeforeUnmount(() => {
130
+ $bus.off('removeFromCompare', onRemoveFromCompare)
131
+ })
105
132
  </script>
@@ -1,76 +1,115 @@
1
1
  <template>
2
- <div class="photo-container">
2
+ <div ref="container" class="photo-container">
3
3
  <figure class="zoom" @mousemove="zoom($event)" :style="{ backgroundImage: `url('${photoSrc}')` }">
4
4
  <img ref="img" :src="src" :alt="alt" />
5
5
  </figure>
6
6
  </div>
7
7
  </template>
8
8
 
9
- <script>
10
- export default {
11
- name: 'Photo',
12
- props: {
13
- src: String,
14
- alt: String
15
- },
16
-
17
- data() {
18
- return {
19
- photoSrc: ''
20
- }
21
- },
22
-
23
- methods: {
24
- swapSrc(src = '') {
25
- if (src) {
26
- this.photoSrc = src
27
- } else {
28
- this.photoSrc = this.src
29
- }
30
-
31
- let image = this.$refs.img
32
- let downloadingImage = new Image()
33
-
34
- let photoLoading = null
35
-
36
- downloadingImage.onload = () => {
37
- image.src = this.photoSrc
38
- photoLoading.close()
39
- }
40
-
41
- photoLoading = this.$buefy.loading.open({ container: this.$el })
42
- downloadingImage.src = this.photoSrc
43
- },
44
-
45
- zoom(e) {
46
- let zoomer = e.currentTarget
47
- let offsetX
48
- let offsetY
49
- let x
50
- let y
51
- //console.log(e)
52
- if (e.offsetX && e.offsetY) {
53
- offsetX = e.offsetX
54
- offsetY = e.offsetY
55
- } else if (e.touches && e.touches[0]) {
56
- offsetX = e.touches[0].pageX
57
- offsetY = e.touches[0].pageY
58
- }
59
- x = (offsetX / zoomer.offsetWidth) * 100
60
- y = (offsetY / zoomer.offsetHeight) * 100
61
- zoomer.style.backgroundPosition = x + '% ' + y + '%'
62
- e.preventDefault()
63
- }
64
- },
65
-
66
- mounted() {
67
- this.swapSrc()
68
- this.$bus.$on('changePhoto', src => {
69
- if (!src) {
70
- return false
71
- }
72
- this.swapSrc(src)
73
- })
9
+ <script setup>
10
+ import { ref, onMounted, onBeforeUnmount } from 'vue'
11
+ import { useBuefy } from '../../composables/globals'
12
+ import { eventBus } from '../../utils/event-bus'
13
+
14
+ defineOptions({ name: 'Photo' })
15
+
16
+ const props = defineProps({
17
+ src: String,
18
+ alt: String
19
+ })
20
+
21
+ // Get global properties
22
+ const $buefy = useBuefy()
23
+
24
+ // Template refs
25
+ const img = ref(null)
26
+ const container = ref(null)
27
+
28
+ // Reactive state
29
+ const photoSrc = ref('')
30
+
31
+ // Methods
32
+ const swapSrc = (src = '') => {
33
+ if (src) {
34
+ photoSrc.value = src
35
+ } else {
36
+ photoSrc.value = props.src
37
+ }
38
+
39
+ const image = img.value
40
+ const downloadingImage = new Image()
41
+
42
+ let photoLoading = null
43
+
44
+ downloadingImage.onload = () => {
45
+ image.src = photoSrc.value
46
+ photoLoading.close()
47
+ }
48
+
49
+ photoLoading = $buefy.loading.open({ container: container.value })
50
+ downloadingImage.src = photoSrc.value
51
+ }
52
+
53
+ const zoom = (e) => {
54
+ const zoomer = e.currentTarget
55
+ let offsetX
56
+ let offsetY
57
+ let x
58
+ let y
59
+
60
+ if (e.offsetX && e.offsetY) {
61
+ offsetX = e.offsetX
62
+ offsetY = e.offsetY
63
+ } else if (e.touches && e.touches[0]) {
64
+ offsetX = e.touches[0].pageX
65
+ offsetY = e.touches[0].pageY
66
+ }
67
+ x = (offsetX / zoomer.offsetWidth) * 100
68
+ y = (offsetY / zoomer.offsetHeight) * 100
69
+ zoomer.style.backgroundPosition = x + '% ' + y + '%'
70
+ e.preventDefault()
71
+ }
72
+
73
+ const handleChangePhoto = (src) => {
74
+ if (!src) {
75
+ return false
74
76
  }
77
+ swapSrc(src)
75
78
  }
79
+
80
+ // Lifecycle hooks
81
+ onMounted(() => {
82
+ swapSrc()
83
+ eventBus.on('changePhoto', handleChangePhoto)
84
+ })
85
+
86
+ onBeforeUnmount(() => {
87
+ eventBus.off('changePhoto', handleChangePhoto)
88
+ })
76
89
  </script>
90
+
91
+ <style scoped>
92
+ .photo-container {
93
+ display: flex;
94
+ justify-content: center;
95
+ }
96
+
97
+ figure.zoom {
98
+ background-position: 50% 50%;
99
+ background-size: 200%;
100
+ position: relative;
101
+ overflow: hidden;
102
+ cursor: zoom-in;
103
+ margin: 0;
104
+ }
105
+
106
+ figure.zoom img {
107
+ display: block;
108
+ width: 100%;
109
+ transition: opacity 0.3s;
110
+ }
111
+
112
+ figure.zoom:hover img {
113
+ opacity: 0;
114
+ }
115
+ </style>