1document.addEventListener("DOMContentLoaded", function(event) { 2 let deferredPrompt; 3// let availablePortlets = ['portlet-boundary_carpeta_fiscal_portlet_', 'portlet-boundary_carpeta_ciudadana_portlet_']; 4 let availablePortlets = ['portlet-boundary_carpeta_fiscal_portlet_']; 5 let found = false; 6 let scriptElement = document.querySelector('script[src$="installApp.js"]'); 7 let parameterValue = scriptElement.dataset.param; 8 9 let userOS = detectOS(); 10 if (userOS == 'Android' || userOS == 'iOS') { 11 let titleText = null; 12 let portletName = null; 13 let iconPath = null; 14 let iconAlt = null; 15 16 for (let i = 0; i < availablePortlets.length; i++) { 17 if (!found) { 18 let divName = availablePortlets[i]; 19 let divElement = document.getElementsByClassName(divName); 20 21 // Este portlet esta añadido 22 if (divElement != null && divElement.length > 0) { 23 // 1- Identificar cual es 24 portletName = divName.split("_")[2]; 25 console.log("PWA "+portletName); 26 // 2- Poner el texto y path que tendrÃa que tener 27 switch (portletName) { 28 case "fiscal": 29 titleText = '¿Quieres tener "Mi Carpeta Fiscal" en tu móvil?'; 30 // iconPath = parameterValue+'/manifest/carpeta_fiscal/icons/Logo_App_Fiscal.png'; 31 iconPath = parameterValue+'/manifest/carpeta_fiscal/icons/Logo_App_512x512.png'; 32 console.log("PWA "+portletName+" iconPath: "+iconPath); 33 iconAlt = 'Carpeta Fiscal'; 34 break; 35 case "ciudadana": 36 titleText = '¿Quieres tener "Mi Carpeta Ciudadana" en tu móvil?'; 37 iconPath = parameterValue+'/manifest/carpeta_ciudadana/icons/Logo_App_Ciudadana.png'; 38 console.log("PWA "+portletName+" iconPath: "+iconPath); 39 iconAlt = 'Carpeta Ciudadana'; 40 break; 41 default: 42 titleText = null; 43 iconPath = null; 44 iconAlt = null; 45 } 46 found = true; 47 } 48 } 49 } 50 51 if (found) { 52 window.addEventListener('beforeinstallprompt', (event) => { 53 console.log("installApp -> beforeInstallpropmt"); 54 // Prevent Chrome 67 and earlier from automatically showing the prompt 55 event.preventDefault(); 56 57 // Stash the event so it can be triggered later. 58 deferredPrompt = event; 59 60 let navbarContainer = document.getElementsByClassName("navbar");
61 if (navbarContainer != null && navbarContainer.length > 0) { 62 if (navbarContainer[0].role = "navigation") { 63 navbarContainer[0].className = navbarContainer[0].className+ ' app_open'; 64 } 65 } 66 67 let sectionContainer = document.getElementById("content"); 68 sectionContainer.className = sectionContainer.className + ' app_open'; 69 70 let voidDiv = document.getElementsByClassName("void")[0]; 71 if (voidDiv != null) { 72 let iconContainer = document.getElementById('appIcon'); 73 iconContainer.src = iconPath; 74 iconContainer.alt = iconAlt; 75 76 let titleContainer = document.getElementById("installTitle"); 77 titleContainer.innerText = titleText; 78 79 voidDiv.className = voidDiv.className +` app_open`; 80 } 81 82 }); 83 84 document.getElementById('downloadAppBtn').addEventListener('click', () => { 85 // Show the install prompt 86 deferredPrompt.prompt(); 87 88 // Wait for the user to respond to the prompt 89 deferredPrompt.userChoice.then((choiceResult) => { 90 if (choiceResult.outcome === 'accepted') { 91 console.log('User accepted the install prompt'); 92 } else { 93 console.log('User dismissed the install prompt'); 94 } 95 96 // Clear the deferredPrompt variable, as it can only be used once. 97 deferredPrompt = null; 98 }); 99 }); 100 101 document.getElementById('closeInstallBtn').addEventListener('click', () => { 102 let sectionContainer = document.getElementById("content"); 103 sectionContainer.classList.remove('app_open'); 104 105 let voidDiv = document.getElementsByClassName("void")[0]; 106 voidDiv.classList.remove('app_open'); 107 108 let navbarContainer = document.getElementsByClassName("navbar")[0]; 109 navbarContainer.classList.remove('app_open'); 110 111 }); 112 113 } 114 115 } 116}); 117 118 119// Esto escucha el evento después de que la aplicación se ha instalado. 120window.addEventListener('appinstalled', (event) => { 121 let sectionContainer = document.getElementById("content"); 122 sectionContainer.classList.remove('app_open'); 123 124 let voidDiv = document.getElementsByClassName("void")[0]; 125 voidDiv.classList.remove('app_open'); 126 127 let navbarContainer = document.getElementsByClassName("navbar")[0];
128 navbarContainer.classList.remove('app_open'); 129}); 130 131function detectOS() { 132 let userAgent = window.navigator.userAgent, 133 platform = window.navigator.platform, 134 macosPlatforms = ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'], 135 windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE'], 136 iosPlatforms = ['iPhone', 'iPad', 'iPod'], 137 os = null; 138 139 if (macosPlatforms.indexOf(platform) !== -1) { 140 os = 'Mac OS'; 141 } else if (iosPlatforms.indexOf(platform) !== -1 || 142 (userAgent.includes('iPhone') && !userAgent.includes('Macintosh')) || 143 (userAgent.includes('iPad') && !userAgent.includes('Macintosh'))) { 144 os = 'iOS'; 145 } else if (windowsPlatforms.indexOf(platform) !== -1) { 146 os = 'Windows'; 147 } else if (/Android/.test(userAgent)) { 148 os = 'Android'; 149 } else if (!os && /Linux/.test(platform)) { 150 os = 'Linux'; 151 } 152 153 return os; 154}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.