abcardviewoverlay.js
来自「现在很火的邮件客户端软件thunderbird的源码」· JavaScript 代码 · 共 540 行 · 第 1/2 页
JS
540 行
# -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-# ***** BEGIN LICENSE BLOCK *****# Version: MPL 1.1/GPL 2.0/LGPL 2.1## The contents of this file are subject to the Mozilla Public License Version# 1.1 (the "License"); you may not use this file except in compliance with# the License. You may obtain a copy of the License at# http://www.mozilla.org/MPL/## Software distributed under the License is distributed on an "AS IS" basis,# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License# for the specific language governing rights and limitations under the# License.## The Original Code is Mozilla Communicator client code, released# March 31, 1998.## The Initial Developer of the Original Code is# Netscape Communications Corporation.# Portions created by the Initial Developer are Copyright (C) 1998-1999# the Initial Developer. All Rights Reserved.## Contributor(s):# Paul Hangas <hangas@netscape.com># Alec Flett <alecf@netscape.com># Seth Spitzer <sspitzer@netscape.com>## Alternatively, the contents of this file may be used under the terms of# either the GNU General Public License Version 2 or later (the "GPL"), or# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),# in which case the provisions of the GPL or the LGPL are applicable instead# of those above. If you wish to allow use of your version of this file only# under the terms of either the GPL or the LGPL, and not to allow others to# use your version of this file under the terms of the MPL, indicate your# decision by deleting the provisions above and replace them with the notice# and other provisions required by the GPL or the LGPL. If you do not delete# the provisions above, a recipient may use your version of this file under# the terms of any one of the MPL, the GPL or the LGPL.## ***** END LICENSE BLOCK *****//NOTE: gAddressBookBundle must be defined and set or this Overlay won't workvar gPrefs = Components.classes["@mozilla.org/preferences-service;1"];gPrefs = gPrefs.getService();gPrefs = gPrefs.QueryInterface(Components.interfaces.nsIPrefBranch);var gProfileDirURL;var gMapItURLFormat = gPrefs.getComplexValue("mail.addr_book.mapit_url.format", Components.interfaces.nsIPrefLocalizedString).data;var gAddrbookSession = Components.classes["@mozilla.org/addressbook/services/session;1"].getService().QueryInterface(Components.interfaces.nsIAddrBookSession);var gIOService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);var gFileHandler = gIOService.getProtocolHandler("file").QueryInterface(Components.interfaces.nsIFileProtocolHandler);var zListName;var zPrimaryEmail;var zSecondaryEmail;var zScreenName;var zNickname;var zDisplayName;var zWork;var zHome;var zFax;var zCellular;var zPager;var zCustom1;var zCustom2;var zCustom3;var zCustom4;var cvData;function OnLoadCardView(){ zPrimaryEmail = gAddressBookBundle.getString("propertyPrimaryEmail"); zSecondaryEmail = gAddressBookBundle.getString("propertySecondaryEmail"); zScreenName = gAddressBookBundle.getString("propertyScreenName"); zNickname = gAddressBookBundle.getString("propertyNickname"); zDisplayName = gAddressBookBundle.getString("propertyDisplayName"); zListName = gAddressBookBundle.getString("propertyListName"); zWork = gAddressBookBundle.getString("propertyWork"); zHome = gAddressBookBundle.getString("propertyHome"); zFax = gAddressBookBundle.getString("propertyFax"); zCellular = gAddressBookBundle.getString("propertyCellular"); zPager = gAddressBookBundle.getString("propertyPager"); zCustom1 = gAddressBookBundle.getString("propertyCustom1"); zCustom2 = gAddressBookBundle.getString("propertyCustom2"); zCustom3 = gAddressBookBundle.getString("propertyCustom3"); zCustom4 = gAddressBookBundle.getString("propertyCustom4"); var doc = document; /* data for address book, prefixes: "cvb" = card view box "cvh" = crad view header "cv" = card view (normal fields) */ cvData = new Object; // Card View Box cvData.CardViewBox = doc.getElementById("CardViewInnerBox"); // Title cvData.CardTitle = doc.getElementById("CardTitle"); // Name section cvData.cvbContact = doc.getElementById("cvbContact"); cvData.cvhContact = doc.getElementById("cvhContact"); cvData.cvNickname = doc.getElementById("cvNickname"); cvData.cvDisplayName = doc.getElementById("cvDisplayName"); cvData.cvEmail1Box = doc.getElementById("cvEmail1Box"); cvData.cvEmail1 = doc.getElementById("cvEmail1"); cvData.cvScreennameBox = doc.getElementById("cvScreennameBox"); cvData.cvAimPresence = doc.getElementById("cvAimPresence"); cvData.cvScreenname = doc.getElementById("cvScreenname"); cvData.cvBuddyIcon = doc.getElementById("cvBuddyIcon"); cvData.cvListNameBox = doc.getElementById("cvListNameBox"); cvData.cvListName = doc.getElementById("cvListName"); cvData.cvEmail2Box = doc.getElementById("cvEmail2Box"); cvData.cvEmail2 = doc.getElementById("cvEmail2"); // Home section cvData.cvbHome = doc.getElementById("cvbHome"); cvData.cvhHome = doc.getElementById("cvhHome"); cvData.cvHomeAddress = doc.getElementById("cvHomeAddress"); cvData.cvHomeAddress2 = doc.getElementById("cvHomeAddress2"); cvData.cvHomeCityStZip = doc.getElementById("cvHomeCityStZip"); cvData.cvHomeCountry = doc.getElementById("cvHomeCountry"); cvData.cvbHomeMapItBox = doc.getElementById("cvbHomeMapItBox"); cvData.cvHomeMapIt = doc.getElementById("cvHomeMapIt"); cvData.cvHomeWebPageBox = doc.getElementById("cvHomeWebPageBox"); cvData.cvHomeWebPage = doc.getElementById("cvHomeWebPage"); // Other section cvData.cvbOther = doc.getElementById("cvbOther"); cvData.cvhOther = doc.getElementById("cvhOther"); cvData.cvCustom1 = doc.getElementById("cvCustom1"); cvData.cvCustom2 = doc.getElementById("cvCustom2"); cvData.cvCustom3 = doc.getElementById("cvCustom3"); cvData.cvCustom4 = doc.getElementById("cvCustom4"); cvData.cvNotes = doc.getElementById("cvNotes"); // Description section (mailing lists only) cvData.cvbDescription = doc.getElementById("cvbDescription"); cvData.cvhDescription = doc.getElementById("cvhDescription"); cvData.cvDescription = doc.getElementById("cvDescription"); // Addresses section (mailing lists only) cvData.cvbAddresses = doc.getElementById("cvbAddresses"); cvData.cvhAddresses = doc.getElementById("cvhAddresses"); cvData.cvAddresses = doc.getElementById("cvAddresses"); // Phone section cvData.cvbPhone = doc.getElementById("cvbPhone"); cvData.cvhPhone = doc.getElementById("cvhPhone"); cvData.cvPhWork = doc.getElementById("cvPhWork"); cvData.cvPhHome = doc.getElementById("cvPhHome"); cvData.cvPhFax = doc.getElementById("cvPhFax"); cvData.cvPhCellular = doc.getElementById("cvPhCellular"); cvData.cvPhPager = doc.getElementById("cvPhPager"); // Work section cvData.cvbWork = doc.getElementById("cvbWork"); cvData.cvhWork = doc.getElementById("cvhWork"); cvData.cvJobTitle = doc.getElementById("cvJobTitle"); cvData.cvDepartment = doc.getElementById("cvDepartment"); cvData.cvCompany = doc.getElementById("cvCompany"); cvData.cvWorkAddress = doc.getElementById("cvWorkAddress"); cvData.cvWorkAddress2 = doc.getElementById("cvWorkAddress2"); cvData.cvWorkCityStZip = doc.getElementById("cvWorkCityStZip"); cvData.cvWorkCountry = doc.getElementById("cvWorkCountry"); cvData.cvbWorkMapItBox = doc.getElementById("cvbWorkMapItBox"); cvData.cvWorkMapIt = doc.getElementById("cvWorkMapIt"); cvData.cvWorkWebPageBox = doc.getElementById("cvWorkWebPageBox"); cvData.cvWorkWebPage = doc.getElementById("cvWorkWebPage");} // XXX todo// some similar code (in spirit) already exists, see OnLoadEditList()// perhaps we could combine and put in abCommon.js?function GetAddressesFromURI(uri){ var addresses = ""; var editList = GetDirectoryFromURI(uri); var addressList = editList.addressLists; if (addressList) { var total = addressList.Count(); if (total > 0) addresses = addressList.GetElementAt(0).QueryInterface(Components.interfaces.nsIAbCard).primaryEmail; for (var i = 1; i < total; i++ ) { addresses += ", " + addressList.GetElementAt(i).QueryInterface(Components.interfaces.nsIAbCard).primaryEmail; } } return addresses;}function GoIM(){ LaunchUrl(top.cvData.cvAimPresence.getAttribute("url"));}function DisplayCardViewPane(card){ var generatedName = gAddrbookSession.generateNameFromCard(card, gPrefs.getIntPref("mail.addr_book.lastnamefirst")); var data = top.cvData; var visible; var titleString; if (generatedName == "") titleString = card.primaryEmail; // if no generatedName, use email else titleString = generatedName; // set fields in card view pane if (card.isMailList) cvSetNode(data.CardTitle, gAddressBookBundle.getFormattedString("viewListTitle", [generatedName])); else cvSetNode(data.CardTitle, gAddressBookBundle.getFormattedString("viewCardTitle", [titleString])); // Contact section cvSetNodeWithLabel(data.cvNickname, zNickname, card.nickName); if (card.isMailList) { // email1, display name and screenname always hidden when a mailing list. cvSetVisible(data.cvDisplayName, false); cvSetVisible(data.cvEmail1Box, false); cvSetVisible(data.cvScreennameBox, false); visible = HandleLink(data.cvListName, zListName, card.displayName, data.cvListNameBox, "mailto:" + encodeURIComponent(GenerateAddressFromCard(card))) || visible; } else { // listname always hidden if not a mailing list cvSetVisible(data.cvListNameBox, false); cvSetNodeWithLabel(data.cvDisplayName, zDisplayName, card.displayName); visible = HandleLink(data.cvEmail1, zPrimaryEmail, card.primaryEmail, data.cvEmail1Box, "mailto:" + card.primaryEmail) || visible; } var goimURL = "aim:goim?screenname=" + card.aimScreenName; var hasScreenName = HandleLink(data.cvScreenname, zScreenName, card.aimScreenName, data.cvScreennameBox, goimURL); data.cvAimPresence.removeAttribute("src"); data.cvAimPresence.removeAttribute("url"); data.cvAimPresence.setAttribute("width","0");#if 0 // for now, disable the presence check since we don't really support this anymore but we may again in the future. // I'm leaving the code here for historical reference. See Bug #295726. data.cvAimPresence.setAttribute("src","http://big.oscar.aol.com:80/" + card.aimScreenName + "?on_url=http://ncmail.netscape.com/include/nc/images/online.gif&off_url=http://ncmail.netscape.com/include/nc/images/offline.gif"); data.cvAimPresence.setAttribute("url", goimURL); data.cvAimPresence.setAttribute("width","16");#endif visible = hasScreenName || visible; visible = HandleLink(data.cvEmail2, zSecondaryEmail, card.secondEmail, data.cvEmail2Box, "mailto:" + card.secondEmail) || visible; // Home section visible = cvSetNode(data.cvHomeAddress, card.homeAddress); visible = cvSetNode(data.cvHomeAddress2, card.homeAddress2) || visible; visible = cvSetCityStateZip(data.cvHomeCityStZip, card.homeCity, card.homeState, card.homeZipCode) || visible; visible = cvSetNode(data.cvHomeCountry, card.homeCountry) || visible; if (visible) { var homeMapItUrl = CreateMapItURL(card.homeAddress, card.homeAddress2, card.homeCity, card.homeState, card.homeZipCode, card.homeCountry); if (homeMapItUrl) { cvSetVisible(data.cvbHomeMapItBox, true); data.cvHomeMapIt.setAttribute('url', homeMapItUrl); } else { cvSetVisible(data.cvbHomeMapItBox, false); } } else { cvSetVisible(data.cvbHomeMapItBox, false); }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?