Changeset 3383704
- Timestamp:
- 10/24/2025 03:10:12 AM (5 months ago)
- Location:
- myd-delivery
- Files:
-
- 20 edited
- 1 copied
-
tags/1.2.2 (copied) (copied from myd-delivery/trunk)
-
tags/1.2.2/README.txt (modified) (2 diffs)
-
tags/1.2.2/assets/js/admin/custom-fields/repeater.min.js (modified) (1 diff)
-
tags/1.2.2/includes/custom-fields/class-custom-fields.php (modified) (2 diffs)
-
tags/1.2.2/myd-delivery.php (modified) (2 diffs)
-
tags/1.2.2/src/js/admin/custom-fields/repeater.js (modified) (10 diffs)
-
tags/1.2.2/src/js/modules/input-mask.js (modified) (1 diff)
-
tags/1.2.2/src/js/order/controller.js (modified) (1 diff)
-
tags/1.2.2/src/js/order/modules/autocomplete-address.js (modified) (1 diff)
-
tags/1.2.2/src/js/order/modules/checkout.js (modified) (1 diff)
-
tags/1.2.2/src/js/order/modules/shipping.js (modified) (7 diffs)
-
trunk/README.txt (modified) (2 diffs)
-
trunk/assets/js/admin/custom-fields/repeater.min.js (modified) (1 diff)
-
trunk/includes/custom-fields/class-custom-fields.php (modified) (2 diffs)
-
trunk/myd-delivery.php (modified) (2 diffs)
-
trunk/src/js/admin/custom-fields/repeater.js (modified) (10 diffs)
-
trunk/src/js/modules/input-mask.js (modified) (1 diff)
-
trunk/src/js/order/controller.js (modified) (1 diff)
-
trunk/src/js/order/modules/autocomplete-address.js (modified) (1 diff)
-
trunk/src/js/order/modules/checkout.js (modified) (1 diff)
-
trunk/src/js/order/modules/shipping.js (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
myd-delivery/tags/1.2.2/README.txt
r3383604 r3383704 5 5 Requires at least: 5.5 6 6 Tested up to: 6.8 7 Stable tag: 1.2. 17 Stable tag: 1.2.2 8 8 Requires PHP: 7.4 9 9 License: GPL-3.0+ … … 76 76 == Changelog == 77 77 78 = 1.2.2 = 79 * Changed: code improvements. 80 * Fix: product extra repeater dont working as expected in some conditions. 81 78 82 = 1.2.1 = 79 83 * Changed: code improvements. 80 * Fix: Custom message selector in settings.84 * Fix: custom message selector in settings. 81 85 82 86 = 1.2 = -
myd-delivery/tags/1.2.2/assets/js/admin/custom-fields/repeater.min.js
r3379132 r3383704 1 (()=>{const e=document.querySelectorAll(".myd-repeater-summary__action--remove");e.length>0&&e.forEach(e=>{e.addEventListener("click", l)});const t=document.querySelectorAll(".myd-repeater-container__remove");t.length>0&&t.forEach(e=>{e.addEventListener("click",a)});const r=document.querySelectorAll(".myd-repeater-add-option");r.length>0&&r.forEach(e=>{e.addEventListener("click",t=>{t.preventDefault(),o(e)})});const n=document.querySelectorAll(".myd-repeater-add-extra");function a(){if(this.parentNode.previousElementSibling||!this.parentNode.previousElementSibling&&!this.parentNode.nextElementSibling.matches("button"))this.parentNode.remove();else{const e=this.parentNode;if(e){let t=e.querySelector(".myd-repeater-summary__title");t&&(t.innerText="")}const t=e.querySelectorAll(".myd-repeater-input");t.length>0&&t.forEach(e=>{"checkbox"!==e.type&&"hidden"!==e.type?e.value="":e.checked=!1})}}function l(){if(this.parentNode.parentNode.previousElementSibling.matches("details")||!this.parentNode.parentNode.previousElementSibling.matches("details")&&this.parentNode.parentNode.nextElementSibling.matches("details"))this.parentNode.parentNode.remove();else{const e=this.parentNode.parentNode;if(e){let t=e.querySelector(".myd-repeater-summary__title");t&&(t.innerText="")}const t=e.querySelectorAll(".myd-repeater-input");t.length>0&&t.forEach(e=>{"checkbox"!==e.type&&"hidden"!==e.type?e.value="":e.checked=!1})}}function o(e){const t=e.parentNode.querySelector("details:last-of-type").cloneNode(!0);let r=t.querySelector(".myd-repeater-summary__title");r&&(r.innerText="");const n=t.querySelectorAll(".myd-repeater-input");n.length>0&&n.forEach(e=>{let t=e.dataset.mainIndex,r=e.dataset.name,n=e.dataset.internalIndex||"";if(t&&r){let a=Number(n)+1;r=r.replace(/{{main-index}}/,t),r=r.replace(/{{internal-index}}/,a),e.name=r,e.dataset.internalIndex=a,"checkbox"!==e.type&&"hidden"!==e.type?e.value="":e.checked=!1}});const a=t.querySelector(".myd-repeater-summary__action--remove");a&&a.addEventListener("click",l),e.parentNode.insertBefore(t,e)}n.length>0&&n.forEach(e=>{e.addEventListener("click",t=>{t.preventDefault(),function(e){const t=e.parentNode.querySelector(".myd-repeater-container--top-level:last-of-type").cloneNode(!0);let r=t.querySelectorAll("details.myd-repeater-container:not(:first-of-type)");r.length>0&&r.forEach(e=>{e.remove()});let n=t.querySelector(".myd-repeater-summary__title");n&&(n.innerText="");const l=t.querySelectorAll(".myd-repeater-input");l.length>0&&l.forEach(e=>{let t=e.dataset.mainIndex,r=e.dataset.name,n=e.dataset.internalIndex||"";if(t&&r){let a=Number(t)+1;r=r.replace(/{{main-index}}/,a),r=r.replace(/{{internal-index}}/,n),e.name=r,e.dataset.mainIndex=a,"checkbox"!==e.type&&"hidden"!==e.type?e.value="":e.checked=!1}});const d=t.querySelector(".myd-repeater-container__remove");d&&d.addEventListener("click",a);const c=t.querySelector(".myd-repeater-add-option");c&&c.addEventListener("click",e=>{e.preventDefault(),o(c)}),e.parentNode.insertBefore(t,e)}(e)})})})();1 (()=>{const e=document.querySelectorAll(".myd-repeater-summary__action--remove");e.length>0&&e.forEach(e=>{e.addEventListener("click",o)});const t=document.querySelectorAll(".myd-repeater-container__remove");t.length>0&&t.forEach(e=>{e.addEventListener("click",a)});const n=document.querySelectorAll(".myd-repeater-add-option");n.length>0&&n.forEach(e=>{e.addEventListener("click",t=>{t.preventDefault(),l(e)})});const r=document.querySelectorAll(".myd-repeater-add-extra");function a(){if(this.parentNode.previousElementSibling||!this.parentNode.previousElementSibling&&!this.parentNode.nextElementSibling.matches("button"))this.parentNode.remove();else{const e=this.parentNode;if(e){let t=e.querySelector(".myd-repeater-summary__title");t&&(t.innerText="")}const t=e.querySelectorAll(".myd-repeater-input");t.length>0&&t.forEach(e=>{"checkbox"!==e.type&&"hidden"!==e.type?e.value="":e.checked=!1})}}function o(){if(this.parentNode.parentNode.previousElementSibling.matches("details")||!this.parentNode.parentNode.previousElementSibling.matches("details")&&this.parentNode.parentNode.nextElementSibling.matches("details"))this.parentNode.parentNode.remove();else{const e=this.parentNode.parentNode;if(e){const t=e.querySelector(".myd-repeater-summary__title");t&&(t.innerText="")}const t=e.querySelectorAll(".myd-repeater-input");t.length>0&&t.forEach(e=>{"checkbox"!==e.type&&"hidden"!==e.type?e.value="":e.checked=!1})}}function l(e){const t=e.parentNode.querySelector("details:last-of-type").cloneNode(!0),n=t.querySelector(".myd-repeater-summary__title");n&&(n.innerText="");const r=t.querySelectorAll(".myd-repeater-input");r.length>0&&r.forEach(e=>{let t=e.dataset.name;const n=e.dataset.mainIndex,r=e.dataset.internalIndex||"";if(n&&t){const a=Number(r)+1;t=t.replace(/{{main-index}}/,n),t=t.replace(/{{internal-index}}/,a),e.name=t,e.dataset.internalIndex=a,"checkbox"!==e.type&&"hidden"!==e.type?e.value="":e.checked=!1}});const a=t.querySelector(".myd-repeater-summary__action--remove");a&&a.addEventListener("click",o),e.parentNode.insertBefore(t,e)}r.length>0&&r.forEach(e=>{e.addEventListener("click",t=>{t.preventDefault(),function(e){const t=e.parentNode.querySelector(".myd-repeater-container--top-level:last-of-type").cloneNode(!0),n=t.querySelectorAll("details.myd-repeater-container:not(:first-of-type)");n.length>0&&n.forEach(e=>{e.remove()});const r=t.querySelector(".myd-repeater-summary__title");r&&(r.innerText="");const o=t.querySelectorAll(".myd-repeater-input");o.length>0&&o.forEach(e=>{let t=e.dataset.mainIndex,n=e.dataset.name,r=e.dataset.internalIndex||"";if(t&&n){let a=Number(t)+1;n=n.replace(/{{main-index}}/,a),n=n.replace(/{{internal-index}}/,r),e.name=n,e.dataset.mainIndex=a,"checkbox"!==e.type&&"hidden"!==e.type?e.value="":e.checked=!1}});const c=t.querySelector(".myd-repeater-container__remove");c&&c.addEventListener("click",a);const d=t.querySelector(".myd-repeater-add-option");d&&d.addEventListener("click",e=>{e.preventDefault(),l(d)}),e.parentNode.insertBefore(t,e)}(e)})})})(); -
myd-delivery/tags/1.2.2/includes/custom-fields/class-custom-fields.php
r3379132 r3383704 180 180 } 181 181 182 return implode( $output_data_attr );182 return implode( ' ', $output_data_attr ); 183 183 } 184 184 … … 244 244 isset( $args['required'] ) && $args['required'] === true ? 'required' : '', 245 245 isset( $args['data'] ) ? $this->build_data_attr( $args['data'] ) : '', 246 esc_ attr( $value )246 esc_textarea( $value ) 247 247 ); 248 248 } -
myd-delivery/tags/1.2.2/myd-delivery.php
r3383604 r3383704 6 6 * Author: EduardoVillao.me 7 7 * Author URI: https://eduardovillao.me/ 8 * Version: 1.2. 18 * Version: 1.2.2 9 9 * Requires PHP: 7.4 10 10 * Requires at least: 5.5 … … 26 26 define( 'MYDDELIVERY_BASENAME', plugin_basename( __FILE__ ) ); 27 27 define( 'MYDDELIVERY_DIRNAME', plugin_basename( __DIR__ ) ); 28 define( 'MYDDELIVERY_VERSION', '1.2. 1' );28 define( 'MYDDELIVERY_VERSION', '1.2.2' ); 29 29 define( 'MYDDELIVERY_MIN_PHP_VERSION', '7.4' ); 30 30 define( 'MYDDELIVERY_MIN_WP_VERSION', '5.5' ); -
myd-delivery/tags/1.2.2/src/js/admin/custom-fields/repeater.js
r3379132 r3383704 2 2 * Remove extra option 3 3 */ 4 const removeOption = document.querySelectorAll('.myd-repeater-summary__action--remove'); 4 const removeOption = document.querySelectorAll( 5 '.myd-repeater-summary__action--remove' 6 ); 5 7 if (removeOption.length > 0) { 6 8 removeOption.forEach((item) => { … … 12 14 * Remove product extra 13 15 */ 14 const removeProductExtraButtons = document.querySelectorAll('.myd-repeater-container__remove'); 16 const removeProductExtraButtons = document.querySelectorAll( 17 '.myd-repeater-container__remove' 18 ); 15 19 if (removeProductExtraButtons.length > 0) { 16 20 removeProductExtraButtons.forEach((item) => { … … 18 22 }); 19 23 } 20 21 24 22 25 /** … … 50 53 */ 51 54 function removeProductExtra() { 52 if (55 if ( 53 56 this.parentNode.previousElementSibling || 54 !this.parentNode.previousElementSibling &&55 !this.parentNode.nextElementSibling.matches('button')56 ) {57 (!this.parentNode.previousElementSibling && 58 !this.parentNode.nextElementSibling.matches('button')) 59 ) { 57 60 this.parentNode.remove(); 58 61 } else { 59 62 const extraOptionItem = this.parentNode; 60 if(extraOptionItem) { 61 let summaryTitle = extraOptionItem.querySelector('.myd-repeater-summary__title'); 62 if(summaryTitle) { 63 if (extraOptionItem) { 64 let summaryTitle = extraOptionItem.querySelector( 65 '.myd-repeater-summary__title' 66 ); 67 if (summaryTitle) { 63 68 summaryTitle.innerText = ''; 64 69 } … … 66 71 67 72 const inputs = extraOptionItem.querySelectorAll('.myd-repeater-input'); 68 if (inputs.length > 0) {73 if (inputs.length > 0) { 69 74 inputs.forEach((item) => { 70 if (item.type !== 'checkbox' && item.type !== 'hidden') {75 if (item.type !== 'checkbox' && item.type !== 'hidden') { 71 76 item.value = ''; 72 77 } else { … … 82 87 */ 83 88 function removeExtraOption() { 84 if (89 if ( 85 90 this.parentNode.parentNode.previousElementSibling.matches('details') || 86 !this.parentNode.parentNode.previousElementSibling.matches('details') && 87 this.parentNode.parentNode.nextElementSibling.matches('details') 88 ) { 91 (!this.parentNode.parentNode.previousElementSibling.matches( 92 'details' 93 ) && 94 this.parentNode.parentNode.nextElementSibling.matches('details')) 95 ) { 89 96 this.parentNode.parentNode.remove(); 90 97 } else { 91 98 const extraOptionItem = this.parentNode.parentNode; 92 if(extraOptionItem) { 93 let summaryTitle = extraOptionItem.querySelector('.myd-repeater-summary__title'); 94 if(summaryTitle) { 99 if (extraOptionItem) { 100 const summaryTitle = extraOptionItem.querySelector( 101 '.myd-repeater-summary__title' 102 ); 103 if (summaryTitle) { 95 104 summaryTitle.innerText = ''; 96 105 } … … 98 107 99 108 const inputs = extraOptionItem.querySelectorAll('.myd-repeater-input'); 100 if (inputs.length > 0) {109 if (inputs.length > 0) { 101 110 inputs.forEach((item) => { 102 if (item.type !== 'checkbox' && item.type !== 'hidden') {111 if (item.type !== 'checkbox' && item.type !== 'hidden') { 103 112 item.value = ''; 104 113 } else { … … 110 119 } 111 120 112 113 121 /** 114 122 * Add new option 115 123 */ 116 124 function addNewOption(element) { 117 const lastElement = element.parentNode.querySelector('details:last-of-type'), 118 newElement = lastElement.cloneNode(true); 119 120 let summaryTitle = newElement.querySelector('.myd-repeater-summary__title'); 121 if(summaryTitle) { 125 const lastElement = element.parentNode.querySelector( 126 'details:last-of-type' 127 ), 128 newElement = lastElement.cloneNode(true); 129 130 const summaryTitle = newElement.querySelector( 131 '.myd-repeater-summary__title' 132 ); 133 if (summaryTitle) { 122 134 summaryTitle.innerText = ''; 123 135 } 124 136 125 137 const inputs = newElement.querySelectorAll('.myd-repeater-input'); 126 if (inputs.length > 0) {138 if (inputs.length > 0) { 127 139 inputs.forEach((item) => { 128 let mainIndex = item.dataset.mainIndex,129 loopName = item.dataset.name,130 internalIndex = item.dataset.internalIndex || '';131 132 if (mainIndex && loopName) {133 let newInternalKey = Number(internalIndex) + 1;140 let loopName = item.dataset.name; 141 const mainIndex = item.dataset.mainIndex, 142 internalIndex = item.dataset.internalIndex || ''; 143 144 if (mainIndex && loopName) { 145 const newInternalKey = Number(internalIndex) + 1; 134 146 135 147 loopName = loopName.replace(/{{main-index}}/, mainIndex); 136 loopName = loopName.replace(/{{internal-index}}/, newInternalKey); 148 loopName = loopName.replace( 149 /{{internal-index}}/, 150 newInternalKey 151 ); 137 152 item.name = loopName; 138 153 item.dataset.internalIndex = newInternalKey; 139 if(item.type !== 'checkbox' && item.type !== 'hidden') { 140 item.value = ''; 141 } else { 142 item.checked = false; 143 } 144 } 145 }); 146 } 147 148 const removeExtraButton = newElement.querySelector('.myd-repeater-summary__action--remove'); 149 if(removeExtraButton) { 154 if (item.type !== 'checkbox' && item.type !== 'hidden') { 155 item.value = ''; 156 } else { 157 item.checked = false; 158 } 159 } 160 }); 161 } 162 163 const removeExtraButton = newElement.querySelector( 164 '.myd-repeater-summary__action--remove' 165 ); 166 if (removeExtraButton) { 150 167 removeExtraButton.addEventListener('click', removeExtraOption); 151 168 } … … 159 176 */ 160 177 function addNewExtra(element) { 161 const extraContainer = element.parentNode.querySelector('.myd-repeater-container--top-level:last-of-type'), 162 newExtra = extraContainer.cloneNode(true); 178 const extraContainer = element.parentNode.querySelector( 179 '.myd-repeater-container--top-level:last-of-type' 180 ), 181 newExtra = extraContainer.cloneNode(true); 163 182 164 183 /** 165 184 * Clean extra items 166 185 */ 167 let details = newExtra.querySelectorAll('details.myd-repeater-container:not(:first-of-type)'); 168 if(details.length > 0) { 186 const details = newExtra.querySelectorAll( 187 'details.myd-repeater-container:not(:first-of-type)' 188 ); 189 if (details.length > 0) { 169 190 details.forEach((item) => { 170 191 item.remove(); … … 172 193 } 173 194 174 let summaryTitle = newExtra.querySelector('.myd-repeater-summary__title');175 if (summaryTitle) {195 const summaryTitle = newExtra.querySelector('.myd-repeater-summary__title'); 196 if (summaryTitle) { 176 197 summaryTitle.innerText = ''; 177 198 } 178 199 179 200 const inputs = newExtra.querySelectorAll('.myd-repeater-input'); 180 if (inputs.length > 0) {201 if (inputs.length > 0) { 181 202 inputs.forEach((item) => { 182 203 let mainIndex = item.dataset.mainIndex, 183 loopName = item.dataset.name,184 internalIndex = item.dataset.internalIndex || '';185 186 if (mainIndex && loopName) {204 loopName = item.dataset.name, 205 internalIndex = item.dataset.internalIndex || ''; 206 207 if (mainIndex && loopName) { 187 208 let newMainKey = Number(mainIndex) + 1; 188 209 189 210 loopName = loopName.replace(/{{main-index}}/, newMainKey); 190 loopName = loopName.replace(/{{internal-index}}/, internalIndex); 211 loopName = loopName.replace( 212 /{{internal-index}}/, 213 internalIndex 214 ); 191 215 item.name = loopName; 192 216 item.dataset.mainIndex = newMainKey; 193 if(item.type !== 'checkbox' && item.type !== 'hidden') { 194 item.value = ''; 195 } else { 196 item.checked = false; 197 } 198 } 199 }); 200 } 201 202 const removeExtraButton = newExtra.querySelector('.myd-repeater-container__remove'); 203 if(removeExtraButton) { 217 if (item.type !== 'checkbox' && item.type !== 'hidden') { 218 item.value = ''; 219 } else { 220 item.checked = false; 221 } 222 } 223 }); 224 } 225 226 const removeExtraButton = newExtra.querySelector( 227 '.myd-repeater-container__remove' 228 ); 229 if (removeExtraButton) { 204 230 removeExtraButton.addEventListener('click', removeProductExtra); 205 231 } 206 232 207 233 const addOptionButton = newExtra.querySelector('.myd-repeater-add-option'); 208 if (addOptionButton) {234 if (addOptionButton) { 209 235 addOptionButton.addEventListener('click', (event) => { 210 236 event.preventDefault(); -
myd-delivery/tags/1.2.2/src/js/modules/input-mask.js
r3379132 r3383704 30 30 handleBackspace(event) { 31 31 const input = event.target; 32 if (event.key === 'Backspace' && input.selectionStart === input.selectionEnd) { 32 if ( 33 event.key === 'Backspace' && 34 input.selectionStart === input.selectionEnd 35 ) { 33 36 const pos = input.selectionStart; 34 37 if (pos > 0) { -
myd-delivery/tags/1.2.2/src/js/order/controller.js
r3379132 r3383704 77 77 78 78 // TODO: move to inside a shipping class 79 if (window.MydOrder.shipping.validateZipcodeShipping(window.MydOrder.type) === false) { 79 if ( 80 window.MydOrder.shipping.validateZipcodeShipping( 81 window.MydOrder.type 82 ) === false 83 ) { 80 84 window.Myd.notificationBar( 81 85 'error', -
myd-delivery/tags/1.2.2/src/js/order/modules/autocomplete-address.js
r3379132 r3383704 22 22 if (!('erro' in dados)) { 23 23 if (dados.logradouro !== '') { 24 document.getElementById('input-delivery-street-name').value = dados.logradouro; 25 document.getElementById('input-delivery-street-name').style.background = '#efefef'; 26 document.getElementById('input-delivery-address-number').focus(); 24 document.getElementById( 25 'input-delivery-street-name' 26 ).value = dados.logradouro; 27 document.getElementById( 28 'input-delivery-street-name' 29 ).style.background = '#efefef'; 30 document 31 .getElementById( 32 'input-delivery-address-number' 33 ) 34 .focus(); 27 35 } else { 28 document.getElementById('input-delivery-street-name').value = ''; 36 document.getElementById( 37 'input-delivery-street-name' 38 ).value = ''; 29 39 } 30 40 31 41 if (dados.logradouro !== '') { 32 document.getElementById('input-delivery-neighborhood').value = dados.bairro; 42 document.getElementById( 43 'input-delivery-neighborhood' 44 ).value = dados.bairro; 33 45 } 34 46 } -
myd-delivery/tags/1.2.2/src/js/order/modules/checkout.js
r3379132 r3383704 37 37 couponCode: document.getElementById('input-coupon'), 38 38 street: document.getElementById('input-delivery-street-name'), 39 streetNumber: document.getElementById('input-delivery-address-number'), 39 streetNumber: document.getElementById( 40 'input-delivery-address-number' 41 ), 40 42 addressComplement: document.getElementById('input-delivery-comp'), 41 neighborhood: document.getElementById('input-delivery-neighborhood'), 43 neighborhood: document.getElementById( 44 'input-delivery-neighborhood' 45 ), 42 46 zipcode: document.getElementById('input-delivery-zipcode'), 43 47 table: document.getElementById('input-in-store-table'), -
myd-delivery/tags/1.2.2/src/js/order/modules/shipping.js
r3379132 r3383704 28 28 29 29 SetGoogleMapsApi() { 30 const input = document.getElementById('input-delivery-autocomplete-address'); 30 const input = document.getElementById( 31 'input-delivery-autocomplete-address' 32 ); 31 33 const options = { 32 34 fields: ['formatted_address', 'geometry', 'address_components'], … … 39 41 } 40 42 41 const autocomplete = new google.maps.places.Autocomplete(input, options); 43 const autocomplete = new google.maps.places.Autocomplete( 44 input, 45 options 46 ); 42 47 autocomplete.addListener('place_changed', () => { 43 48 const place = autocomplete.getPlace(); 44 if (!place.geometry || !place.geometry.location || !place.address_components) { 45 window.alert("No details available for input: '" + place.name + "'"); 49 if ( 50 !place.geometry || 51 !place.geometry.location || 52 !place.address_components 53 ) { 54 window.alert( 55 "No details available for input: '" + place.name + "'" 56 ); 46 57 return; 47 58 } 48 59 49 const inputFormatedAddress = document.getElementsByName('input-delivery-formated-address'); 50 const inputLatitude = document.getElementsByName('input-delivery-latitude'); 51 const inputLongitude = document.getElementsByName('input-delivery-longitude'); 60 const inputFormatedAddress = document.getElementsByName( 61 'input-delivery-formated-address' 62 ); 63 const inputLatitude = document.getElementsByName( 64 'input-delivery-latitude' 65 ); 66 const inputLongitude = document.getElementsByName( 67 'input-delivery-longitude' 68 ); 52 69 if (inputLatitude && inputLongitude && inputFormatedAddress) { 53 70 inputFormatedAddress[0].value = place.formatted_address; … … 57 74 58 75 if (place.address_components.length > 0) { 59 const streetNumber = place.address_components.filter((address_data) => { 60 return address_data.types.includes('street_number'); 61 }); 62 63 const zipcode = place.address_components.filter((address_data) => { 64 return address_data.types.includes('postal_code'); 65 }); 66 67 const streetName = place.address_components.filter((address_data) => { 68 return address_data.types.includes('route'); 69 }); 70 71 const neighborhood = place.address_components.filter((address_data) => { 72 return address_data.types.includes('sublocality_level_1'); 73 }); 74 75 const streetNumberInput = document.getElementById('input-delivery-address-number'); 76 const streetNumber = place.address_components.filter( 77 (address_data) => { 78 return address_data.types.includes('street_number'); 79 } 80 ); 81 82 const zipcode = place.address_components.filter( 83 (address_data) => { 84 return address_data.types.includes('postal_code'); 85 } 86 ); 87 88 const streetName = place.address_components.filter( 89 (address_data) => { 90 return address_data.types.includes('route'); 91 } 92 ); 93 94 const neighborhood = place.address_components.filter( 95 (address_data) => { 96 return address_data.types.includes( 97 'sublocality_level_1' 98 ); 99 } 100 ); 101 102 const streetNumberInput = document.getElementById( 103 'input-delivery-address-number' 104 ); 76 105 if (streetNumberInput) { 77 streetNumberInput.value = streetNumber.length > 0 ? streetNumber[0].long_name : ''; 78 } 79 80 const zipcodeInput = document.getElementById('input-delivery-zipcode'); 106 streetNumberInput.value = 107 streetNumber.length > 0 108 ? streetNumber[0].long_name 109 : ''; 110 } 111 112 const zipcodeInput = document.getElementById( 113 'input-delivery-zipcode' 114 ); 81 115 if (zipcodeInput) { 82 zipcodeInput.value = zipcode.length > 0 ? zipcode[0].long_name : '00000000'; 83 } 84 85 const streetNameInput = document.getElementById('input-delivery-street-name'); 116 zipcodeInput.value = 117 zipcode.length > 0 ? zipcode[0].long_name : '00000000'; 118 } 119 120 const streetNameInput = document.getElementById( 121 'input-delivery-street-name' 122 ); 86 123 if (streetNameInput) { 87 streetNameInput.value = streetName.length > 0 ? streetName[0].long_name : ''; 88 } 89 90 const neighborhoodInput = document.getElementById('input-delivery-neighborhood'); 124 streetNameInput.value = 125 streetName.length > 0 ? streetName[0].long_name : ''; 126 } 127 128 const neighborhoodInput = document.getElementById( 129 'input-delivery-neighborhood' 130 ); 91 131 if (neighborhoodInput) { 92 neighborhoodInput.value = neighborhood.length > 0 ? neighborhood[0].long_name : ''; 132 neighborhoodInput.value = 133 neighborhood.length > 0 134 ? neighborhood[0].long_name 135 : ''; 93 136 } 94 137 } … … 98 141 async getPriceByDistance() { 99 142 const options = mydStoreInfo.deliveryShipping.options; 100 const inputLatitude = document.getElementsByName('input-delivery-latitude'); 101 const inputLongitude = document.getElementsByName('input-delivery-longitude'); 143 const inputLatitude = document.getElementsByName( 144 'input-delivery-latitude' 145 ); 146 const inputLongitude = document.getElementsByName( 147 'input-delivery-longitude' 148 ); 102 149 if (!inputLatitude || !inputLongitude) { 103 150 console.error('Missed latitude and longitude to destination'); … … 149 196 getPriceByNeighborhood() { 150 197 const neighborhoodList = mydStoreInfo.deliveryShipping.options, 151 neighborhoodInputValue = document.getElementById('input-delivery-neighborhood').value, 198 neighborhoodInputValue = document.getElementById( 199 'input-delivery-neighborhood' 200 ).value, 152 201 val = []; 153 202 154 203 Object.keys(neighborhoodList.options).forEach((item) => { 155 if(neighborhoodList.options[item].from === neighborhoodInputValue) { 204 if ( 205 neighborhoodList.options[item].from === neighborhoodInputValue 206 ) { 156 207 val.push(neighborhoodList.options[item].price); 157 208 } … … 167 218 ), 168 219 val = []; 169 Object.keys(zipcodeList.options).forEach( item=> {220 Object.keys(zipcodeList.options).forEach((item) => { 170 221 if ( 171 222 zipcodeInputValue >= zipcodeList.options[item].from && … … 193 244 ) { 194 245 let zipcodeList = mydStoreInfo.deliveryShipping.options, 195 zipcodeInputValue = parseInt(document.getElementById('input-delivery-zipcode').value), 196 val = []; 197 198 Object.keys(zipcodeList.options).forEach( item => { 199 if (zipcodeInputValue >= zipcodeList.options[item].from && zipcodeInputValue <= zipcodeList.options[item].to) { 246 zipcodeInputValue = parseInt( 247 document.getElementById('input-delivery-zipcode').value 248 ), 249 val = []; 250 251 Object.keys(zipcodeList.options).forEach((item) => { 252 if ( 253 zipcodeInputValue >= zipcodeList.options[item].from && 254 zipcodeInputValue <= zipcodeList.options[item].to 255 ) { 200 256 val.push(true); 201 257 } -
myd-delivery/trunk/README.txt
r3383604 r3383704 5 5 Requires at least: 5.5 6 6 Tested up to: 6.8 7 Stable tag: 1.2. 17 Stable tag: 1.2.2 8 8 Requires PHP: 7.4 9 9 License: GPL-3.0+ … … 76 76 == Changelog == 77 77 78 = 1.2.2 = 79 * Changed: code improvements. 80 * Fix: product extra repeater dont working as expected in some conditions. 81 78 82 = 1.2.1 = 79 83 * Changed: code improvements. 80 * Fix: Custom message selector in settings.84 * Fix: custom message selector in settings. 81 85 82 86 = 1.2 = -
myd-delivery/trunk/assets/js/admin/custom-fields/repeater.min.js
r3379132 r3383704 1 (()=>{const e=document.querySelectorAll(".myd-repeater-summary__action--remove");e.length>0&&e.forEach(e=>{e.addEventListener("click", l)});const t=document.querySelectorAll(".myd-repeater-container__remove");t.length>0&&t.forEach(e=>{e.addEventListener("click",a)});const r=document.querySelectorAll(".myd-repeater-add-option");r.length>0&&r.forEach(e=>{e.addEventListener("click",t=>{t.preventDefault(),o(e)})});const n=document.querySelectorAll(".myd-repeater-add-extra");function a(){if(this.parentNode.previousElementSibling||!this.parentNode.previousElementSibling&&!this.parentNode.nextElementSibling.matches("button"))this.parentNode.remove();else{const e=this.parentNode;if(e){let t=e.querySelector(".myd-repeater-summary__title");t&&(t.innerText="")}const t=e.querySelectorAll(".myd-repeater-input");t.length>0&&t.forEach(e=>{"checkbox"!==e.type&&"hidden"!==e.type?e.value="":e.checked=!1})}}function l(){if(this.parentNode.parentNode.previousElementSibling.matches("details")||!this.parentNode.parentNode.previousElementSibling.matches("details")&&this.parentNode.parentNode.nextElementSibling.matches("details"))this.parentNode.parentNode.remove();else{const e=this.parentNode.parentNode;if(e){let t=e.querySelector(".myd-repeater-summary__title");t&&(t.innerText="")}const t=e.querySelectorAll(".myd-repeater-input");t.length>0&&t.forEach(e=>{"checkbox"!==e.type&&"hidden"!==e.type?e.value="":e.checked=!1})}}function o(e){const t=e.parentNode.querySelector("details:last-of-type").cloneNode(!0);let r=t.querySelector(".myd-repeater-summary__title");r&&(r.innerText="");const n=t.querySelectorAll(".myd-repeater-input");n.length>0&&n.forEach(e=>{let t=e.dataset.mainIndex,r=e.dataset.name,n=e.dataset.internalIndex||"";if(t&&r){let a=Number(n)+1;r=r.replace(/{{main-index}}/,t),r=r.replace(/{{internal-index}}/,a),e.name=r,e.dataset.internalIndex=a,"checkbox"!==e.type&&"hidden"!==e.type?e.value="":e.checked=!1}});const a=t.querySelector(".myd-repeater-summary__action--remove");a&&a.addEventListener("click",l),e.parentNode.insertBefore(t,e)}n.length>0&&n.forEach(e=>{e.addEventListener("click",t=>{t.preventDefault(),function(e){const t=e.parentNode.querySelector(".myd-repeater-container--top-level:last-of-type").cloneNode(!0);let r=t.querySelectorAll("details.myd-repeater-container:not(:first-of-type)");r.length>0&&r.forEach(e=>{e.remove()});let n=t.querySelector(".myd-repeater-summary__title");n&&(n.innerText="");const l=t.querySelectorAll(".myd-repeater-input");l.length>0&&l.forEach(e=>{let t=e.dataset.mainIndex,r=e.dataset.name,n=e.dataset.internalIndex||"";if(t&&r){let a=Number(t)+1;r=r.replace(/{{main-index}}/,a),r=r.replace(/{{internal-index}}/,n),e.name=r,e.dataset.mainIndex=a,"checkbox"!==e.type&&"hidden"!==e.type?e.value="":e.checked=!1}});const d=t.querySelector(".myd-repeater-container__remove");d&&d.addEventListener("click",a);const c=t.querySelector(".myd-repeater-add-option");c&&c.addEventListener("click",e=>{e.preventDefault(),o(c)}),e.parentNode.insertBefore(t,e)}(e)})})})();1 (()=>{const e=document.querySelectorAll(".myd-repeater-summary__action--remove");e.length>0&&e.forEach(e=>{e.addEventListener("click",o)});const t=document.querySelectorAll(".myd-repeater-container__remove");t.length>0&&t.forEach(e=>{e.addEventListener("click",a)});const n=document.querySelectorAll(".myd-repeater-add-option");n.length>0&&n.forEach(e=>{e.addEventListener("click",t=>{t.preventDefault(),l(e)})});const r=document.querySelectorAll(".myd-repeater-add-extra");function a(){if(this.parentNode.previousElementSibling||!this.parentNode.previousElementSibling&&!this.parentNode.nextElementSibling.matches("button"))this.parentNode.remove();else{const e=this.parentNode;if(e){let t=e.querySelector(".myd-repeater-summary__title");t&&(t.innerText="")}const t=e.querySelectorAll(".myd-repeater-input");t.length>0&&t.forEach(e=>{"checkbox"!==e.type&&"hidden"!==e.type?e.value="":e.checked=!1})}}function o(){if(this.parentNode.parentNode.previousElementSibling.matches("details")||!this.parentNode.parentNode.previousElementSibling.matches("details")&&this.parentNode.parentNode.nextElementSibling.matches("details"))this.parentNode.parentNode.remove();else{const e=this.parentNode.parentNode;if(e){const t=e.querySelector(".myd-repeater-summary__title");t&&(t.innerText="")}const t=e.querySelectorAll(".myd-repeater-input");t.length>0&&t.forEach(e=>{"checkbox"!==e.type&&"hidden"!==e.type?e.value="":e.checked=!1})}}function l(e){const t=e.parentNode.querySelector("details:last-of-type").cloneNode(!0),n=t.querySelector(".myd-repeater-summary__title");n&&(n.innerText="");const r=t.querySelectorAll(".myd-repeater-input");r.length>0&&r.forEach(e=>{let t=e.dataset.name;const n=e.dataset.mainIndex,r=e.dataset.internalIndex||"";if(n&&t){const a=Number(r)+1;t=t.replace(/{{main-index}}/,n),t=t.replace(/{{internal-index}}/,a),e.name=t,e.dataset.internalIndex=a,"checkbox"!==e.type&&"hidden"!==e.type?e.value="":e.checked=!1}});const a=t.querySelector(".myd-repeater-summary__action--remove");a&&a.addEventListener("click",o),e.parentNode.insertBefore(t,e)}r.length>0&&r.forEach(e=>{e.addEventListener("click",t=>{t.preventDefault(),function(e){const t=e.parentNode.querySelector(".myd-repeater-container--top-level:last-of-type").cloneNode(!0),n=t.querySelectorAll("details.myd-repeater-container:not(:first-of-type)");n.length>0&&n.forEach(e=>{e.remove()});const r=t.querySelector(".myd-repeater-summary__title");r&&(r.innerText="");const o=t.querySelectorAll(".myd-repeater-input");o.length>0&&o.forEach(e=>{let t=e.dataset.mainIndex,n=e.dataset.name,r=e.dataset.internalIndex||"";if(t&&n){let a=Number(t)+1;n=n.replace(/{{main-index}}/,a),n=n.replace(/{{internal-index}}/,r),e.name=n,e.dataset.mainIndex=a,"checkbox"!==e.type&&"hidden"!==e.type?e.value="":e.checked=!1}});const c=t.querySelector(".myd-repeater-container__remove");c&&c.addEventListener("click",a);const d=t.querySelector(".myd-repeater-add-option");d&&d.addEventListener("click",e=>{e.preventDefault(),l(d)}),e.parentNode.insertBefore(t,e)}(e)})})})(); -
myd-delivery/trunk/includes/custom-fields/class-custom-fields.php
r3379132 r3383704 180 180 } 181 181 182 return implode( $output_data_attr );182 return implode( ' ', $output_data_attr ); 183 183 } 184 184 … … 244 244 isset( $args['required'] ) && $args['required'] === true ? 'required' : '', 245 245 isset( $args['data'] ) ? $this->build_data_attr( $args['data'] ) : '', 246 esc_ attr( $value )246 esc_textarea( $value ) 247 247 ); 248 248 } -
myd-delivery/trunk/myd-delivery.php
r3383604 r3383704 6 6 * Author: EduardoVillao.me 7 7 * Author URI: https://eduardovillao.me/ 8 * Version: 1.2. 18 * Version: 1.2.2 9 9 * Requires PHP: 7.4 10 10 * Requires at least: 5.5 … … 26 26 define( 'MYDDELIVERY_BASENAME', plugin_basename( __FILE__ ) ); 27 27 define( 'MYDDELIVERY_DIRNAME', plugin_basename( __DIR__ ) ); 28 define( 'MYDDELIVERY_VERSION', '1.2. 1' );28 define( 'MYDDELIVERY_VERSION', '1.2.2' ); 29 29 define( 'MYDDELIVERY_MIN_PHP_VERSION', '7.4' ); 30 30 define( 'MYDDELIVERY_MIN_WP_VERSION', '5.5' ); -
myd-delivery/trunk/src/js/admin/custom-fields/repeater.js
r3379132 r3383704 2 2 * Remove extra option 3 3 */ 4 const removeOption = document.querySelectorAll('.myd-repeater-summary__action--remove'); 4 const removeOption = document.querySelectorAll( 5 '.myd-repeater-summary__action--remove' 6 ); 5 7 if (removeOption.length > 0) { 6 8 removeOption.forEach((item) => { … … 12 14 * Remove product extra 13 15 */ 14 const removeProductExtraButtons = document.querySelectorAll('.myd-repeater-container__remove'); 16 const removeProductExtraButtons = document.querySelectorAll( 17 '.myd-repeater-container__remove' 18 ); 15 19 if (removeProductExtraButtons.length > 0) { 16 20 removeProductExtraButtons.forEach((item) => { … … 18 22 }); 19 23 } 20 21 24 22 25 /** … … 50 53 */ 51 54 function removeProductExtra() { 52 if (55 if ( 53 56 this.parentNode.previousElementSibling || 54 !this.parentNode.previousElementSibling &&55 !this.parentNode.nextElementSibling.matches('button')56 ) {57 (!this.parentNode.previousElementSibling && 58 !this.parentNode.nextElementSibling.matches('button')) 59 ) { 57 60 this.parentNode.remove(); 58 61 } else { 59 62 const extraOptionItem = this.parentNode; 60 if(extraOptionItem) { 61 let summaryTitle = extraOptionItem.querySelector('.myd-repeater-summary__title'); 62 if(summaryTitle) { 63 if (extraOptionItem) { 64 let summaryTitle = extraOptionItem.querySelector( 65 '.myd-repeater-summary__title' 66 ); 67 if (summaryTitle) { 63 68 summaryTitle.innerText = ''; 64 69 } … … 66 71 67 72 const inputs = extraOptionItem.querySelectorAll('.myd-repeater-input'); 68 if (inputs.length > 0) {73 if (inputs.length > 0) { 69 74 inputs.forEach((item) => { 70 if (item.type !== 'checkbox' && item.type !== 'hidden') {75 if (item.type !== 'checkbox' && item.type !== 'hidden') { 71 76 item.value = ''; 72 77 } else { … … 82 87 */ 83 88 function removeExtraOption() { 84 if (89 if ( 85 90 this.parentNode.parentNode.previousElementSibling.matches('details') || 86 !this.parentNode.parentNode.previousElementSibling.matches('details') && 87 this.parentNode.parentNode.nextElementSibling.matches('details') 88 ) { 91 (!this.parentNode.parentNode.previousElementSibling.matches( 92 'details' 93 ) && 94 this.parentNode.parentNode.nextElementSibling.matches('details')) 95 ) { 89 96 this.parentNode.parentNode.remove(); 90 97 } else { 91 98 const extraOptionItem = this.parentNode.parentNode; 92 if(extraOptionItem) { 93 let summaryTitle = extraOptionItem.querySelector('.myd-repeater-summary__title'); 94 if(summaryTitle) { 99 if (extraOptionItem) { 100 const summaryTitle = extraOptionItem.querySelector( 101 '.myd-repeater-summary__title' 102 ); 103 if (summaryTitle) { 95 104 summaryTitle.innerText = ''; 96 105 } … … 98 107 99 108 const inputs = extraOptionItem.querySelectorAll('.myd-repeater-input'); 100 if (inputs.length > 0) {109 if (inputs.length > 0) { 101 110 inputs.forEach((item) => { 102 if (item.type !== 'checkbox' && item.type !== 'hidden') {111 if (item.type !== 'checkbox' && item.type !== 'hidden') { 103 112 item.value = ''; 104 113 } else { … … 110 119 } 111 120 112 113 121 /** 114 122 * Add new option 115 123 */ 116 124 function addNewOption(element) { 117 const lastElement = element.parentNode.querySelector('details:last-of-type'), 118 newElement = lastElement.cloneNode(true); 119 120 let summaryTitle = newElement.querySelector('.myd-repeater-summary__title'); 121 if(summaryTitle) { 125 const lastElement = element.parentNode.querySelector( 126 'details:last-of-type' 127 ), 128 newElement = lastElement.cloneNode(true); 129 130 const summaryTitle = newElement.querySelector( 131 '.myd-repeater-summary__title' 132 ); 133 if (summaryTitle) { 122 134 summaryTitle.innerText = ''; 123 135 } 124 136 125 137 const inputs = newElement.querySelectorAll('.myd-repeater-input'); 126 if (inputs.length > 0) {138 if (inputs.length > 0) { 127 139 inputs.forEach((item) => { 128 let mainIndex = item.dataset.mainIndex,129 loopName = item.dataset.name,130 internalIndex = item.dataset.internalIndex || '';131 132 if (mainIndex && loopName) {133 let newInternalKey = Number(internalIndex) + 1;140 let loopName = item.dataset.name; 141 const mainIndex = item.dataset.mainIndex, 142 internalIndex = item.dataset.internalIndex || ''; 143 144 if (mainIndex && loopName) { 145 const newInternalKey = Number(internalIndex) + 1; 134 146 135 147 loopName = loopName.replace(/{{main-index}}/, mainIndex); 136 loopName = loopName.replace(/{{internal-index}}/, newInternalKey); 148 loopName = loopName.replace( 149 /{{internal-index}}/, 150 newInternalKey 151 ); 137 152 item.name = loopName; 138 153 item.dataset.internalIndex = newInternalKey; 139 if(item.type !== 'checkbox' && item.type !== 'hidden') { 140 item.value = ''; 141 } else { 142 item.checked = false; 143 } 144 } 145 }); 146 } 147 148 const removeExtraButton = newElement.querySelector('.myd-repeater-summary__action--remove'); 149 if(removeExtraButton) { 154 if (item.type !== 'checkbox' && item.type !== 'hidden') { 155 item.value = ''; 156 } else { 157 item.checked = false; 158 } 159 } 160 }); 161 } 162 163 const removeExtraButton = newElement.querySelector( 164 '.myd-repeater-summary__action--remove' 165 ); 166 if (removeExtraButton) { 150 167 removeExtraButton.addEventListener('click', removeExtraOption); 151 168 } … … 159 176 */ 160 177 function addNewExtra(element) { 161 const extraContainer = element.parentNode.querySelector('.myd-repeater-container--top-level:last-of-type'), 162 newExtra = extraContainer.cloneNode(true); 178 const extraContainer = element.parentNode.querySelector( 179 '.myd-repeater-container--top-level:last-of-type' 180 ), 181 newExtra = extraContainer.cloneNode(true); 163 182 164 183 /** 165 184 * Clean extra items 166 185 */ 167 let details = newExtra.querySelectorAll('details.myd-repeater-container:not(:first-of-type)'); 168 if(details.length > 0) { 186 const details = newExtra.querySelectorAll( 187 'details.myd-repeater-container:not(:first-of-type)' 188 ); 189 if (details.length > 0) { 169 190 details.forEach((item) => { 170 191 item.remove(); … … 172 193 } 173 194 174 let summaryTitle = newExtra.querySelector('.myd-repeater-summary__title');175 if (summaryTitle) {195 const summaryTitle = newExtra.querySelector('.myd-repeater-summary__title'); 196 if (summaryTitle) { 176 197 summaryTitle.innerText = ''; 177 198 } 178 199 179 200 const inputs = newExtra.querySelectorAll('.myd-repeater-input'); 180 if (inputs.length > 0) {201 if (inputs.length > 0) { 181 202 inputs.forEach((item) => { 182 203 let mainIndex = item.dataset.mainIndex, 183 loopName = item.dataset.name,184 internalIndex = item.dataset.internalIndex || '';185 186 if (mainIndex && loopName) {204 loopName = item.dataset.name, 205 internalIndex = item.dataset.internalIndex || ''; 206 207 if (mainIndex && loopName) { 187 208 let newMainKey = Number(mainIndex) + 1; 188 209 189 210 loopName = loopName.replace(/{{main-index}}/, newMainKey); 190 loopName = loopName.replace(/{{internal-index}}/, internalIndex); 211 loopName = loopName.replace( 212 /{{internal-index}}/, 213 internalIndex 214 ); 191 215 item.name = loopName; 192 216 item.dataset.mainIndex = newMainKey; 193 if(item.type !== 'checkbox' && item.type !== 'hidden') { 194 item.value = ''; 195 } else { 196 item.checked = false; 197 } 198 } 199 }); 200 } 201 202 const removeExtraButton = newExtra.querySelector('.myd-repeater-container__remove'); 203 if(removeExtraButton) { 217 if (item.type !== 'checkbox' && item.type !== 'hidden') { 218 item.value = ''; 219 } else { 220 item.checked = false; 221 } 222 } 223 }); 224 } 225 226 const removeExtraButton = newExtra.querySelector( 227 '.myd-repeater-container__remove' 228 ); 229 if (removeExtraButton) { 204 230 removeExtraButton.addEventListener('click', removeProductExtra); 205 231 } 206 232 207 233 const addOptionButton = newExtra.querySelector('.myd-repeater-add-option'); 208 if (addOptionButton) {234 if (addOptionButton) { 209 235 addOptionButton.addEventListener('click', (event) => { 210 236 event.preventDefault(); -
myd-delivery/trunk/src/js/modules/input-mask.js
r3379132 r3383704 30 30 handleBackspace(event) { 31 31 const input = event.target; 32 if (event.key === 'Backspace' && input.selectionStart === input.selectionEnd) { 32 if ( 33 event.key === 'Backspace' && 34 input.selectionStart === input.selectionEnd 35 ) { 33 36 const pos = input.selectionStart; 34 37 if (pos > 0) { -
myd-delivery/trunk/src/js/order/controller.js
r3379132 r3383704 77 77 78 78 // TODO: move to inside a shipping class 79 if (window.MydOrder.shipping.validateZipcodeShipping(window.MydOrder.type) === false) { 79 if ( 80 window.MydOrder.shipping.validateZipcodeShipping( 81 window.MydOrder.type 82 ) === false 83 ) { 80 84 window.Myd.notificationBar( 81 85 'error', -
myd-delivery/trunk/src/js/order/modules/autocomplete-address.js
r3379132 r3383704 22 22 if (!('erro' in dados)) { 23 23 if (dados.logradouro !== '') { 24 document.getElementById('input-delivery-street-name').value = dados.logradouro; 25 document.getElementById('input-delivery-street-name').style.background = '#efefef'; 26 document.getElementById('input-delivery-address-number').focus(); 24 document.getElementById( 25 'input-delivery-street-name' 26 ).value = dados.logradouro; 27 document.getElementById( 28 'input-delivery-street-name' 29 ).style.background = '#efefef'; 30 document 31 .getElementById( 32 'input-delivery-address-number' 33 ) 34 .focus(); 27 35 } else { 28 document.getElementById('input-delivery-street-name').value = ''; 36 document.getElementById( 37 'input-delivery-street-name' 38 ).value = ''; 29 39 } 30 40 31 41 if (dados.logradouro !== '') { 32 document.getElementById('input-delivery-neighborhood').value = dados.bairro; 42 document.getElementById( 43 'input-delivery-neighborhood' 44 ).value = dados.bairro; 33 45 } 34 46 } -
myd-delivery/trunk/src/js/order/modules/checkout.js
r3379132 r3383704 37 37 couponCode: document.getElementById('input-coupon'), 38 38 street: document.getElementById('input-delivery-street-name'), 39 streetNumber: document.getElementById('input-delivery-address-number'), 39 streetNumber: document.getElementById( 40 'input-delivery-address-number' 41 ), 40 42 addressComplement: document.getElementById('input-delivery-comp'), 41 neighborhood: document.getElementById('input-delivery-neighborhood'), 43 neighborhood: document.getElementById( 44 'input-delivery-neighborhood' 45 ), 42 46 zipcode: document.getElementById('input-delivery-zipcode'), 43 47 table: document.getElementById('input-in-store-table'), -
myd-delivery/trunk/src/js/order/modules/shipping.js
r3379132 r3383704 28 28 29 29 SetGoogleMapsApi() { 30 const input = document.getElementById('input-delivery-autocomplete-address'); 30 const input = document.getElementById( 31 'input-delivery-autocomplete-address' 32 ); 31 33 const options = { 32 34 fields: ['formatted_address', 'geometry', 'address_components'], … … 39 41 } 40 42 41 const autocomplete = new google.maps.places.Autocomplete(input, options); 43 const autocomplete = new google.maps.places.Autocomplete( 44 input, 45 options 46 ); 42 47 autocomplete.addListener('place_changed', () => { 43 48 const place = autocomplete.getPlace(); 44 if (!place.geometry || !place.geometry.location || !place.address_components) { 45 window.alert("No details available for input: '" + place.name + "'"); 49 if ( 50 !place.geometry || 51 !place.geometry.location || 52 !place.address_components 53 ) { 54 window.alert( 55 "No details available for input: '" + place.name + "'" 56 ); 46 57 return; 47 58 } 48 59 49 const inputFormatedAddress = document.getElementsByName('input-delivery-formated-address'); 50 const inputLatitude = document.getElementsByName('input-delivery-latitude'); 51 const inputLongitude = document.getElementsByName('input-delivery-longitude'); 60 const inputFormatedAddress = document.getElementsByName( 61 'input-delivery-formated-address' 62 ); 63 const inputLatitude = document.getElementsByName( 64 'input-delivery-latitude' 65 ); 66 const inputLongitude = document.getElementsByName( 67 'input-delivery-longitude' 68 ); 52 69 if (inputLatitude && inputLongitude && inputFormatedAddress) { 53 70 inputFormatedAddress[0].value = place.formatted_address; … … 57 74 58 75 if (place.address_components.length > 0) { 59 const streetNumber = place.address_components.filter((address_data) => { 60 return address_data.types.includes('street_number'); 61 }); 62 63 const zipcode = place.address_components.filter((address_data) => { 64 return address_data.types.includes('postal_code'); 65 }); 66 67 const streetName = place.address_components.filter((address_data) => { 68 return address_data.types.includes('route'); 69 }); 70 71 const neighborhood = place.address_components.filter((address_data) => { 72 return address_data.types.includes('sublocality_level_1'); 73 }); 74 75 const streetNumberInput = document.getElementById('input-delivery-address-number'); 76 const streetNumber = place.address_components.filter( 77 (address_data) => { 78 return address_data.types.includes('street_number'); 79 } 80 ); 81 82 const zipcode = place.address_components.filter( 83 (address_data) => { 84 return address_data.types.includes('postal_code'); 85 } 86 ); 87 88 const streetName = place.address_components.filter( 89 (address_data) => { 90 return address_data.types.includes('route'); 91 } 92 ); 93 94 const neighborhood = place.address_components.filter( 95 (address_data) => { 96 return address_data.types.includes( 97 'sublocality_level_1' 98 ); 99 } 100 ); 101 102 const streetNumberInput = document.getElementById( 103 'input-delivery-address-number' 104 ); 76 105 if (streetNumberInput) { 77 streetNumberInput.value = streetNumber.length > 0 ? streetNumber[0].long_name : ''; 78 } 79 80 const zipcodeInput = document.getElementById('input-delivery-zipcode'); 106 streetNumberInput.value = 107 streetNumber.length > 0 108 ? streetNumber[0].long_name 109 : ''; 110 } 111 112 const zipcodeInput = document.getElementById( 113 'input-delivery-zipcode' 114 ); 81 115 if (zipcodeInput) { 82 zipcodeInput.value = zipcode.length > 0 ? zipcode[0].long_name : '00000000'; 83 } 84 85 const streetNameInput = document.getElementById('input-delivery-street-name'); 116 zipcodeInput.value = 117 zipcode.length > 0 ? zipcode[0].long_name : '00000000'; 118 } 119 120 const streetNameInput = document.getElementById( 121 'input-delivery-street-name' 122 ); 86 123 if (streetNameInput) { 87 streetNameInput.value = streetName.length > 0 ? streetName[0].long_name : ''; 88 } 89 90 const neighborhoodInput = document.getElementById('input-delivery-neighborhood'); 124 streetNameInput.value = 125 streetName.length > 0 ? streetName[0].long_name : ''; 126 } 127 128 const neighborhoodInput = document.getElementById( 129 'input-delivery-neighborhood' 130 ); 91 131 if (neighborhoodInput) { 92 neighborhoodInput.value = neighborhood.length > 0 ? neighborhood[0].long_name : ''; 132 neighborhoodInput.value = 133 neighborhood.length > 0 134 ? neighborhood[0].long_name 135 : ''; 93 136 } 94 137 } … … 98 141 async getPriceByDistance() { 99 142 const options = mydStoreInfo.deliveryShipping.options; 100 const inputLatitude = document.getElementsByName('input-delivery-latitude'); 101 const inputLongitude = document.getElementsByName('input-delivery-longitude'); 143 const inputLatitude = document.getElementsByName( 144 'input-delivery-latitude' 145 ); 146 const inputLongitude = document.getElementsByName( 147 'input-delivery-longitude' 148 ); 102 149 if (!inputLatitude || !inputLongitude) { 103 150 console.error('Missed latitude and longitude to destination'); … … 149 196 getPriceByNeighborhood() { 150 197 const neighborhoodList = mydStoreInfo.deliveryShipping.options, 151 neighborhoodInputValue = document.getElementById('input-delivery-neighborhood').value, 198 neighborhoodInputValue = document.getElementById( 199 'input-delivery-neighborhood' 200 ).value, 152 201 val = []; 153 202 154 203 Object.keys(neighborhoodList.options).forEach((item) => { 155 if(neighborhoodList.options[item].from === neighborhoodInputValue) { 204 if ( 205 neighborhoodList.options[item].from === neighborhoodInputValue 206 ) { 156 207 val.push(neighborhoodList.options[item].price); 157 208 } … … 167 218 ), 168 219 val = []; 169 Object.keys(zipcodeList.options).forEach( item=> {220 Object.keys(zipcodeList.options).forEach((item) => { 170 221 if ( 171 222 zipcodeInputValue >= zipcodeList.options[item].from && … … 193 244 ) { 194 245 let zipcodeList = mydStoreInfo.deliveryShipping.options, 195 zipcodeInputValue = parseInt(document.getElementById('input-delivery-zipcode').value), 196 val = []; 197 198 Object.keys(zipcodeList.options).forEach( item => { 199 if (zipcodeInputValue >= zipcodeList.options[item].from && zipcodeInputValue <= zipcodeList.options[item].to) { 246 zipcodeInputValue = parseInt( 247 document.getElementById('input-delivery-zipcode').value 248 ), 249 val = []; 250 251 Object.keys(zipcodeList.options).forEach((item) => { 252 if ( 253 zipcodeInputValue >= zipcodeList.options[item].from && 254 zipcodeInputValue <= zipcodeList.options[item].to 255 ) { 200 256 val.push(true); 201 257 }
Note: See TracChangeset
for help on using the changeset viewer.