404 متاسفانه صفحه مورد نظر شما پیدا نشد.

جهت استفاده از امکانات کامل مدیلیب وارد شوید . ورود به پنل کاربری ثبت نام

آیا می خواهید مدیلیب را به صفحه اصلی خود اضافه کنید؟

const promptElement = document.querySelector('.pwaprompt'); const footerPromptElement = document.querySelector('#footerPromptElement'); const scrollTopElement = document.querySelector('.scrolltop'); // const installButton = promptElement.querySelector('.prompt__install'); const closeButton = promptElement.querySelector('.prompt__close'); let installEvent; function setWithExpiry(key, value, seconds) { const now = new Date() // `item` is an object which contains the original value // as well as the time when it's supposed to expire const item = { value: value, expiry: now.getTime() + (seconds * 1000), } localStorage.setItem(key, JSON.stringify(item)) } function getWithExpiry(key) { const itemStr = localStorage.getItem(key) // if the item doesn't exist, return null if (!itemStr) { return null } const item = JSON.parse(itemStr) const now = new Date() // compare the expiry time of the item with the current time if (now.getTime() > item.expiry) { // If the item is expired, delete the item from storage // and return null localStorage.removeItem(key) return null } return item.value } // checks if the localStorage item has been set function getVisited() { return getWithExpiry('install-prompt') // return localStorage.getItem('install-prompt'); } // sets the localStorage item function setVisited() { fiveDay = 5 * (24 * (60 * 60)) setWithExpiry('install-prompt', true, fiveDay) // localStorage.setItem('install-prompt', true); } closeButton.addEventListener('click', () => { // set localStorage to true setVisited(); // hide the prompt banner promptElement.style.display = 'none'; scrollTopElement.style.bottom = '30px'; // installEvent = null; }); // Detects if device is on iOS const isIos = () => { const userAgent = window.navigator.userAgent.toLowerCase(); return /iphone|ipad|ipod/.test(userAgent); } // Detects if device is in standalone mode const isInStandaloneMode = () => ('standalone' in window.navigator) && (window.navigator.standalone); // Checks if should display install popup notification: if (isIos() && !isInStandaloneMode()) { if (!getVisited()) { promptElement.style.display = 'block'; scrollTopElement.style.bottom = '80px'; } footerPromptElement.style.display = 'block'; } // this event will only fire if the user does not have the pwa installed window.addEventListener('beforeinstallprompt', (event) => { event.preventDefault(); // if no localStorage is set, first time visitor if (!getVisited()) { // show the prompt banner promptElement.style.display = 'block'; scrollTopElement.style.bottom = '80px'; // store the event for later use } footerPromptElement.style.display = 'block'; installEvent = event; }); $(document).on('click', '.prompt__install', function () { promptElement.style.display = 'none'; scrollTopElement.style.bottom = '30px'; if (isIos() && !isInStandaloneMode()) { setVisited(); $('#iphoneAddToHomeScreen').modal() } else { // trigger the prompt to show to the user installEvent.prompt(); // check what choice the user made installEvent.userChoice.then((choice) => { // if the user declined, we don't want to show the button again // set localStorage to true if (choice.outcome !== 'accepted') { setVisited(); } installEvent = null; }); } });