VulpesOS/assets/webapps/emergency-call.gaiamobile.org/js/ice_contacts.js
OverSu b38dea0597 Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
2026-09-30 23:13:03 +02:00

13 lines
No EOL
2.9 KiB
JavaScript

;'use strict';(function(exports){var iceContactsDetails=[],iceContactsBar,contactListOverlay,contactInOverlay,contactList,contactListCancel;function init(){if(ICEContacts._initialized){return;}
iceContactsBar=document.getElementById('ice-contacts-bar');contactListOverlay=document.getElementById('contact-list-overlay');contactInOverlay=document.getElementById('contact-in-overlay');LazyLoader.load([contactListOverlay],function(){var contactListOverlayHeader=contactListOverlay.querySelector('header');contactListOverlayHeader.dataset.l10nId='ice-contacts-overlay-title';contactList=document.getElementById('contact-list');contactListCancel=document.getElementById('contact-list-overlay-cancel');iceContactsBar.addEventListener('click',showICEContactOverlay);contactListCancel.addEventListener('click',hideICEContactOverlay);ICEContacts._initialized=true;});}
function showICEContactsBar(){iceContactsBar.removeAttribute('hidden');}
function showICEContactOverlay(){contactListOverlay.classList.add('display');}
function hideICEContactOverlay(){contactListOverlay.classList.remove('display');}
function callICEContact(number){hideICEContactOverlay();CallHandler.call(number);}
function findContact(iceContact){return new Promise(function(resolve){var contactFilter={filterBy:['id'],filterValue:iceContact,filterOp:'equals',filterLimit:1};var contactRequest=navigator.mozContacts.find(contactFilter);contactRequest.onsuccess=function(){var contact=this.result[0];if(contact&&contact.tel){iceContactsDetails.push(contact);}
resolve(contact);};});}
function addContactToOverlay(contact){return new Promise(function(resolve){if(!contact||!contact.tel){resolve();return;}
contact.tel.forEach(function(tel){var iceContactOverlayEntry=contactInOverlay.cloneNode(true);iceContactOverlayEntry.removeAttribute('id');iceContactOverlayEntry.removeAttribute('hidden');iceContactOverlayEntry.querySelector('.js-name').textContent=contact.name[0];iceContactOverlayEntry.querySelector('.js-tel-type').dataset.l10nId=tel.type[0];iceContactOverlayEntry.querySelector('.js-tel').textContent=tel.value;contactList.insertBefore(iceContactOverlayEntry,contactListCancel);iceContactOverlayEntry.addEventListener('click',callICEContact.bind(null,tel.value));showICEContactsBar();});resolve();});}
function updateICEContacts(){init();return new Promise(function(resolve){LazyLoader.load([contactInOverlay],function(){ICEStore.getContacts().then(function(iceContacts){if(!iceContacts||!iceContacts.length){resolve();}else{var promises=[];iceContacts.forEach(function(iceContact){promises.push(findContact(iceContact).then(addContactToOverlay));});Promise.all(promises).then(resolve);}});});});}
function isFromICEContact(number){return iceContactsDetails.some(function(iceContact){return iceContact.tel.some(function(tel){return number==tel.value;});});}
var ICEContacts={_initialized:false,updateICEContacts:updateICEContacts,isFromICEContact:isFromICEContact};exports.ICEContacts=ICEContacts;})(window);