feat(gift): 받을 주소 관리 및 카카오 주소 검색 추가
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
let loading
|
||||
|
||||
export function loadPostcode() {
|
||||
if (window.daum && window.daum.Postcode) return Promise.resolve(window.daum.Postcode)
|
||||
if (loading) return loading
|
||||
loading = new Promise((resolve, reject) => {
|
||||
const script = document.createElement('script')
|
||||
const finish = error => {
|
||||
clearTimeout(timer)
|
||||
script.onload = null
|
||||
script.onerror = null
|
||||
if (error) {
|
||||
script.remove()
|
||||
loading = null
|
||||
reject(error)
|
||||
} else {
|
||||
resolve(window.daum.Postcode)
|
||||
}
|
||||
}
|
||||
const timer = setTimeout(() => finish(new Error('주소 검색을 불러오지 못했습니다. 다시 시도해주세요.')), 15000)
|
||||
script.src = 'https://t1.daumcdn.net/mapjsapi/bundle/postcode/prod/postcode.v2.js'
|
||||
script.async = true
|
||||
script.onload = () => finish(window.daum && window.daum.Postcode ? null : new Error('주소 검색을 불러오지 못했습니다. 다시 시도해주세요.'))
|
||||
script.onerror = () => finish(new Error('주소 검색을 불러오지 못했습니다. 다시 시도해주세요.'))
|
||||
document.head.appendChild(script)
|
||||
})
|
||||
return loading
|
||||
}
|
||||
Reference in New Issue
Block a user