abcardoverlay.js
来自「现在很火的邮件客户端软件thunderbird的源码」· JavaScript 代码 · 共 597 行 · 第 1/2 页
JS
597 行
// And the phonetic fields document.getElementById(kPhoneticFields[0]).readOnly = true; document.getElementById(kPhoneticFields[3]).readOnly = true; // Also disable the mail format popup. document.getElementById("PreferMailFormatPopup").disabled = true; document.documentElement.buttons = "accept"; document.documentElement.removeAttribute("ondialogaccept"); } // hide remote content in HTML field for remote directories if (directory.isRemote) document.getElementById('allowRemoteContent').hidden = true; } }}// this is used by people who extend the ab card dialog// like Netscape does for screennamefunction RegisterSaveListener(func){ gOnSaveListeners[gOnSaveListeners.length] = func;}// this is used by people who extend the ab card dialog// like Netscape does for screennamefunction NotifySaveListeners(){ if (!gOnSaveListeners.length) return; for ( var i = 0; i < gOnSaveListeners.length; i++ ) gOnSaveListeners[i](); // the save listeners might have tweaked the card // in which case we need to commit it. gEditCard.card.editCardToDatabase(gEditCard.abURI);}function InitPhoneticFields(){ var showPhoneticFields = gPrefs.getComplexValue("mail.addr_book.show_phonetic_fields", Components.interfaces.nsIPrefLocalizedString).data; // hide phonetic fields if indicated by the pref if (showPhoneticFields == "true") { for (var i = kPhoneticFields.length; i-- > 0; ) document.getElementById(kPhoneticFields[i]).hidden = false; }}function InitEditCard(){ InitPhoneticFields(); gAddressBookBundle = document.getElementById("bundle_addressBook"); // Create gEditCard object that contains global variables for the current js // file. gEditCard = new Object(); gEditCard.prefs = gPrefs; // get specific prefs that gEditCard will need try { var displayLastNameFirst = gPrefs.getComplexValue("mail.addr_book.displayName.lastnamefirst", Components.interfaces.nsIPrefLocalizedString).data; gEditCard.displayLastNameFirst = (displayLastNameFirst == "true"); gEditCard.generateDisplayName = gPrefs.getBoolPref("mail.addr_book.displayName.autoGeneration"); } catch (ex) { dump("ex: failed to get pref" + ex + "\n"); }}function NewCardOKButton(){ if (gOkCallback) { if (!CheckAndSetCardValues(gEditCard.card, document, true)) return false; // don't close window var addressbook = Components.classes["@mozilla.org/addressbook;1"].createInstance(Components.interfaces.nsIAddressBook); gOkCallback(addressbook.abCardToEscapedVCard(gEditCard.card)); return true; // close the window } var popup = document.getElementById('abPopup'); if ( popup ) { var uri = popup.getAttribute('value'); // FIX ME - hack to avoid crashing if no ab selected because of blank option bug from template // should be able to just remove this if we are not seeing blank lines in the ab popup if ( !uri ) return false; // don't close window // ----- if (gEditCard.card) { if (!CheckAndSetCardValues(gEditCard.card, document, true)) return false; // don't close window // replace gEditCard.card with the card we added // so that save listeners can get / set attributes on // the card that got created. gEditCard.card = GetDirectoryFromURI(uri).addCard(gEditCard.card); NotifySaveListeners(); if ("arguments" in window && window.arguments[0]) window.arguments[0].allowRemoteContent = gEditCard.card.allowRemoteContent; } } return true; // close the window}// Move the data from the cardproperty to the dialogfunction GetCardValues(cardproperty, doc){ if (!cardproperty) return; for (var i = kVcardFields.length; i-- > 0; ) doc.getElementById(kVcardFields[i][0]).value = cardproperty[kVcardFields[i][1]]; var popup = document.getElementById("PreferMailFormatPopup"); if (popup) popup.value = cardproperty.preferMailFormat; var allowRemoteContentEl = document.getElementById("allowRemoteContent"); if (allowRemoteContentEl) allowRemoteContentEl.checked = cardproperty.allowRemoteContent; // get phonetic fields if exist try { doc.getElementById("PhoneticFirstName").value = cardproperty.phoneticFirstName; doc.getElementById("PhoneticLastName").value = cardproperty.phoneticLastName; } catch (ex) {}}// when the ab card dialog is being loaded to show a vCard,// hide the fields which aren't supported// by vCard so the user does not try to edit them.function HideNonVcardFields(){ for (var i = kNonVcardFields.length; i-- > 0; ) document.getElementById(kNonVcardFields[i]).collapsed = true;}// Move the data from the dialog to the cardproperty to be stored in the database// @Returns false - Some required data are missing (card values were not set);// true - Card values were set, or there is no card to set values on.function CheckAndSetCardValues(cardproperty, doc, check){ // If requested, check the required data presence. if (check && !CheckCardRequiredDataPresence(document)) return false; if (!cardproperty) return true; for (var i = kVcardFields.length; i-- > 0; ) cardproperty[kVcardFields[i][1]] = doc.getElementById(kVcardFields[i][0]).value; var popup = document.getElementById("PreferMailFormatPopup"); if (popup) cardproperty.preferMailFormat = popup.value; var allowRemoteContentEl = document.getElementById("allowRemoteContent"); if (allowRemoteContentEl) cardproperty.allowRemoteContent = allowRemoteContentEl.checked; // set phonetic fields if exist try { cardproperty.phoneticFirstName = doc.getElementById("PhoneticFirstName").value; cardproperty.phoneticLastName = doc.getElementById("PhoneticLastName").value; } catch (ex) {} return true;}function CleanUpWebPage(webPage){ // no :// yet so we should add something if ( webPage.length && webPage.search("://") == -1 ) { // check for missing / on http:// if ( webPage.substr(0, 6) == "http:/" ) return( "http://" + webPage.substr(6) ); else return( "http://" + webPage ); } else return(webPage);}// @Returns false - Some required data are missing;// true - All required data are present.function CheckCardRequiredDataPresence(doc){ // Bug 314995 We require at least one of the following fields to be // filled in: email address, first name, last name, display name, // organization (company name). var primaryEmail = doc.getElementById("PrimaryEmail"); var primaryEmailValue = primaryEmail.value; var primaryEmailValueLength = primaryEmailValue.length; if (primaryEmailValueLength == 0 && doc.getElementById("FirstName").value.length == 0 && doc.getElementById("LastName").value.length == 0 && doc.getElementById("DisplayName").value.length == 0 && doc.getElementById("Company").value.length == 0) { Components .classes["@mozilla.org/embedcomp/prompt-service;1"] .getService(Components.interfaces.nsIPromptService) .alert( window, gAddressBookBundle.getString("cardRequiredDataMissingTitle"), gAddressBookBundle.getString("cardRequiredDataMissingMessage")); return false; } // Simple checks that the primary email should be of the form |user@host|. // Note: if the length of the primary email is 0 then we skip the check // as some other field must have something as per the check above. var primaryEmailValueAtLastIndex = primaryEmailValue.lastIndexOf("@"); if (!((primaryEmailValueLength == 0) || ((primaryEmailValueLength >= 3) && (primaryEmailValueAtLastIndex > 0) && (primaryEmailValueAtLastIndex < primaryEmailValueLength - 1)))) { Components .classes["@mozilla.org/embedcomp/prompt-service;1"] .getService(Components.interfaces.nsIPromptService) .alert( window, gAddressBookBundle.getString("incorrectEmailAddressFormatTitle"), gAddressBookBundle.getString("incorrectEmailAddressFormatMessage")); // Focus the dialog field, to help the user. document.getElementById("abTabs").selectedIndex = 0; primaryEmail.focus(); return false; } return true;}function GenerateDisplayName(){ if (!gEditCard.generateDisplayName) return; var displayName; var firstNameValue = document.getElementById("FirstName").value; var lastNameValue = document.getElementById("LastName").value; if (lastNameValue && firstNameValue) { displayName = (gEditCard.displayLastNameFirst) ? gAddressBookBundle.getFormattedString("lastFirstFormat", [lastNameValue, firstNameValue]) : gAddressBookBundle.getFormattedString("firstLastFormat", [firstNameValue, lastNameValue]); } else { // one (or both) of these is empty, so this works. displayName = firstNameValue + lastNameValue; } document.getElementById("DisplayName").value = displayName; SetCardDialogTitle(displayName);}function DisplayNameChanged(){ // turn off generateDisplayName if the user changes the display name gEditCard.generateDisplayName = false; SetCardDialogTitle(document.getElementById("DisplayName").value);}function SetCardDialogTitle(displayName){ document.title = displayName ? gAddressBookBundle.getFormattedString(gEditCard.titleProperty + "WithDisplayName", [displayName]) : gAddressBookBundle.getString(gEditCard.titleProperty);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?