Last active
November 11, 2020 02:38
-
-
Save caglarorhan/2c4aa23b6a81562ce710da396f384408 to your computer and use it in GitHub Desktop.
Modal popup basic structure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const WDS_modal = { | |
lifeHour: 1, | |
mSecondAnHour: 3600000, | |
mSecondToNow: new Date().getTime(), | |
expDateTime (){return this.mSecondToNow + (this.lifeHour * this.mSecondAnHour)}, | |
createModal(modalData){ | |
const backDrop = document.createElement('div'); | |
const modal = document.createElement('div'); | |
const modalClosingButton = document.createElement('span'); | |
backDrop.id = "modal_"+ modalData.content_id.toString(); | |
backDrop.style.cssText = "width:100%; height:100%; overflow:hidden; position: fixed; z-index: 100;left:0;top:0; background-color: rgba(0,0,0,0.5);"; | |
backDrop.innerHTML=''; | |
document.body.append(backDrop); | |
modal.style.cssText = `width:${modalData.width}; height: ${modalData.height}; position:relative; margin: 200px auto; background-color:white; z-index: 101; border-radius: 3px; padding:10px; background-color: white;border: 1px solid #ccc; box-shadow: 1px 1px 1px black; box-sizing: border-box;`; | |
modalClosingButton.innerHTML = modalData.closing_button_content; | |
modalClosingButton.style.cssText="position: absolute; float:right; z-index:1002; cursor:pointer; top:5px; right:5px; padding:8px; cursor:pointer"; | |
backDrop.append(modal); | |
modal.innerHTML = modalData.content; | |
modal.append(modalClosingButton); | |
modalClosingButton.addEventListener('click',()=>{ | |
this.closeModal(backDrop.id); | |
}) | |
modal.addEventListener('click', (e)=>{ | |
e.stopPropagation(); | |
}) | |
backDrop.addEventListener('click', ()=>{this.closeModal(backDrop.id)}); | |
}, | |
closeModal(backDropID){ | |
console.log(backDropID); | |
window.localStorage.setItem(backDropID,this.expDateTime()); | |
document.querySelector('#'+backDropID).style.display='none'; | |
}, | |
firstLoad(){ | |
let result = fetch('http://login.wdc.studio/gecici/banner_test_3.php').then(response=>response.json()).then(data=>{ | |
let modalRegisteredDateTime = window.localStorage.getItem("modal_"+data.content_id); | |
let expired=true; | |
window.localStorage.removeItem("modal_"+data.content_id) | |
if(modalRegisteredDateTime){ | |
expired = parseInt(WDS_modal.mSecondToNow)-parseInt(modalRegisteredDateTime)>0 | |
} | |
console.log(` | |
Registered Exp Date: ${modalRegisteredDateTime} | |
Current Date : ${WDS_modal.mSecondToNow} | |
Kalan sure: ${Math.abs((WDS_modal.mSecondToNow-modalRegisteredDateTime)/WDS_modal.mSecondAnHour)} saat | |
Data.show:${data.show} | |
Expired: ${expired} | |
Gosterilsin mi: ${(data.show && expired)} | |
`) | |
if(data.show && expired){ | |
WDS_modal.createModal(data); | |
}else{ | |
return false; | |
} | |
}) | |
} | |
} | |
window.addEventListener('load',WDS_modal.firstLoad); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment