?? addressingwidgetoverlay.js
字號:
# -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-# ***** 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):## 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 *****top.MAX_RECIPIENTS = 0;var inputElementType = "";var selectElementType = "";var selectElementIndexTable = null;var gNumberOfCols = 0;var gDragService = Components.classes["@mozilla.org/widget/dragservice;1"].getService();gDragService = gDragService.QueryInterface(Components.interfaces.nsIDragService);var gMimeHeaderParser = null;var test_addresses_sequence = false;try { if (sPrefs) test_addresses_sequence = sPrefs.getBoolPref("mail.debug.test_addresses_sequence");}catch (ex) {}function awGetMaxRecipients(){ return top.MAX_RECIPIENTS;}function awGetNumberOfCols(){ if (gNumberOfCols == 0) { var listbox = document.getElementById('addressingWidget'); var listCols = listbox.getElementsByTagName('listcol'); gNumberOfCols = listCols.length; if (!gNumberOfCols) gNumberOfCols = 1; /* if no cols defined, that means we have only one! */ } return gNumberOfCols;}function awInputElementName(){ if (inputElementType == "") inputElementType = document.getElementById("addressCol2#1").localName; return inputElementType;}function awSelectElementName(){ if (selectElementType == "") selectElementType = document.getElementById("addressCol1#1").localName; return selectElementType;}// TODO: replace awGetSelectItemIndex with recipient type index constantsfunction awGetSelectItemIndex(itemData){ if (selectElementIndexTable == null) { selectElementIndexTable = new Object(); var selectElem = document.getElementById("addressCol1#1"); for (var i = 0; i < selectElem.childNodes[0].childNodes.length; i ++) { var aData = selectElem.childNodes[0].childNodes[i].getAttribute("value"); selectElementIndexTable[aData] = i; } } return selectElementIndexTable[itemData];}function Recipients2CompFields(msgCompFields){ if (msgCompFields) { var i = 1; var addrTo = ""; var addrCc = ""; var addrBcc = ""; var addrReply = ""; var addrNg = ""; var addrFollow = ""; var addrOther = ""; var to_Sep = ""; var cc_Sep = ""; var bcc_Sep = ""; var reply_Sep = ""; var ng_Sep = ""; var follow_Sep = ""; gMimeHeaderParser = Components.classes["@mozilla.org/messenger/headerparser;1"].getService(Components.interfaces.nsIMsgHeaderParser); var recipientType; var inputField; var fieldValue; var recipient; while ((inputField = awGetInputElement(i))) { fieldValue = inputField.value; if (fieldValue == null) fieldValue = inputField.getAttribute("value"); if (fieldValue != "") { recipientType = awGetPopupElement(i).selectedItem.getAttribute("value"); recipient = null; switch (recipientType) { case "addr_to" : case "addr_cc" : case "addr_bcc" : case "addr_reply" : try { recipient = gMimeHeaderParser.reformatUnquotedAddresses(fieldValue); } catch (ex) {recipient = fieldValue;} break; } switch (recipientType) { case "addr_to" : addrTo += to_Sep + recipient; to_Sep = ","; break; case "addr_cc" : addrCc += cc_Sep + recipient; cc_Sep = ","; break; case "addr_bcc" : addrBcc += bcc_Sep + recipient; bcc_Sep = ","; break; case "addr_reply" : addrReply += reply_Sep + recipient; reply_Sep = ","; break; case "addr_newsgroups" : addrNg += ng_Sep + fieldValue; ng_Sep = ","; break; case "addr_followup" : addrFollow += follow_Sep + fieldValue; follow_Sep = ","; break; // do CRLF, same as PUSH_NEWLINE() in nsMsgSend.h / nsMsgCompUtils.cpp // see bug #195965 case "addr_other" : addrOther += awGetPopupElement(i).selectedItem.getAttribute("label") + " " + fieldValue + "\r\n";break; } } i ++; } msgCompFields.to = addrTo; msgCompFields.cc = addrCc; msgCompFields.bcc = addrBcc; msgCompFields.replyTo = addrReply; msgCompFields.newsgroups = addrNg; msgCompFields.followupTo = addrFollow; msgCompFields.otherRandomHeaders = addrOther; gMimeHeaderParser = null; } else dump("Message Compose Error: msgCompFields is null (ExtractRecipients)");}function CompFields2Recipients(msgCompFields, msgType){ if (msgCompFields) { gMimeHeaderParser = Components.classes["@mozilla.org/messenger/headerparser;1"].getService(Components.interfaces.nsIMsgHeaderParser); var listbox = document.getElementById('addressingWidget'); var newListBoxNode = listbox.cloneNode(false); var listBoxColsClone = listbox.firstChild.cloneNode(true); newListBoxNode.appendChild(listBoxColsClone); var templateNode = listbox.getElementsByTagName("listitem")[0]; top.MAX_RECIPIENTS = 0; var msgReplyTo = msgCompFields.replyTo; var msgTo = msgCompFields.to; var msgCC = msgCompFields.cc; var msgBCC = msgCompFields.bcc; var msgRandomHeaders = msgCompFields.otherRandomHeaders; var msgNewsgroups = msgCompFields.newsgroups; var msgFollowupTo = msgCompFields.followupTo; if(msgReplyTo) awSetInputAndPopupFromArray(msgCompFields.SplitRecipients(msgReplyTo, false), "addr_reply", newListBoxNode, templateNode); if(msgTo) awSetInputAndPopupFromArray(msgCompFields.SplitRecipients(msgTo, false), "addr_to", newListBoxNode, templateNode); if(msgCC) awSetInputAndPopupFromArray(msgCompFields.SplitRecipients(msgCC, false), "addr_cc", newListBoxNode, templateNode); if(msgBCC) awSetInputAndPopupFromArray(msgCompFields.SplitRecipients(msgBCC, false), "addr_bcc", newListBoxNode, templateNode); if(msgRandomHeaders) awSetInputAndPopup(msgRandomHeaders, "addr_other", newListBoxNode, templateNode); if(msgNewsgroups) awSetInputAndPopup(msgNewsgroups, "addr_newsgroups", newListBoxNode, templateNode); if(msgFollowupTo) awSetInputAndPopup(msgFollowupTo, "addr_followup", newListBoxNode, templateNode); //If it's a new message, we need to add an extrat empty recipient. if (!msgTo && !msgNewsgroups) _awSetInputAndPopup("", "addr_to", newListBoxNode, templateNode); // dump("replacing child in comp fields 2 recips \n"); var parent = listbox.parentNode; parent.replaceChild(newListBoxNode, listbox); awFitDummyRows(2); // CompFields2Recipients is called whenever a user replies or edits an existing message. We want to // add all of the recipients for this message to the ignore list for spell check addRecipientsToIgnoreList((gCurrentIdentity ? gCurrentIdentity.identityName + ', ' : '') + msgTo + ', ' + msgCC + ', ' + msgBCC); gMimeHeaderParser = null; //Release the mime parser }}function awSetInputAndPopupValue(inputElem, inputValue, popupElem, popupValue, rowNumber){ // remove leading spaces while (inputValue && inputValue[0] == " " ) inputValue = inputValue.substring(1, inputValue.length); inputElem.setAttribute("value", inputValue); inputElem.value = inputValue; popupElem.selectedItem = popupElem.childNodes[0].childNodes[awGetSelectItemIndex(popupValue)]; if (rowNumber >= 0) { inputElem.setAttribute("id", "addressCol2#" + rowNumber); popupElem.setAttribute("id", "addressCol1#" + rowNumber); } _awSetAutoComplete(popupElem, inputElem);}function _awSetInputAndPopup(inputValue, popupValue, parentNode, templateNode){ top.MAX_RECIPIENTS++; var newNode = templateNode.cloneNode(true); parentNode.appendChild(newNode); // we need to insert the new node before we set the value of the select element! var input = newNode.getElementsByTagName(awInputElementName()); var select = newNode.getElementsByTagName(awSelectElementName()); if (input && input.length == 1 && select && select.length == 1) awSetInputAndPopupValue(input[0], inputValue, select[0], popupValue, top.MAX_RECIPIENTS)}function awSetInputAndPopup(inputValue, popupValue, parentNode, templateNode){ if ( inputValue && popupValue ) { var addressArray = inputValue.split(","); for ( var index = 0; index < addressArray.length; index++ ) _awSetInputAndPopup(addressArray[index], popupValue, parentNode, templateNode); }}function awSetInputAndPopupFromArray(inputArray, popupValue, parentNode, templateNode){ if ( inputArray && popupValue ) { var recipient; for ( var index = 0; index < inputArray.count; index++ ) { recipient = null; if (gMimeHeaderParser) try { recipient = gMimeHeaderParser.unquotePhraseOrAddrWString(inputArray.StringAt(index), true); } catch (ex) {}; if (!recipient) recipient = inputArray.StringAt(index) _awSetInputAndPopup(recipient, popupValue, parentNode, templateNode); } }}function awRemoveRecipients(msgCompFields, recipientType, recipientsList){ if (!msgCompFields) return; var recipientArray = msgCompFields.SplitRecipients(recipientsList, false); if (! recipientArray) return; for ( var index = 0; index < recipientArray.count; index++ ) for (var row = 1; row <= top.MAX_RECIPIENTS; row ++) { var popup = awGetPopupElement(row); if (popup.selectedItem.getAttribute("value") == recipientType) { var input = awGetInputElement(row); if (input.value == recipientArray.StringAt(index)) { awSetInputAndPopupValue(input, "", popup, "addr_to", -1); break; } } }}function awAddRecipients(msgCompFields, recipientType, recipientsList){ if (!msgCompFields) return; var recipientArray = msgCompFields.SplitRecipients(recipientsList, false); if (! recipientArray) return; for ( var index = 0; index < recipientArray.count; index++ ) awAddRecipient(recipientType, recipientArray.StringAt(index));}// this was broken out of awAddRecipients so it can be re-used...adds a new row matching recipientType and// drops in the single address.function awAddRecipient(recipientType, address){ for (var row = 1; row <= top.MAX_RECIPIENTS; row ++) { if (awGetInputElement(row).value == "") break; } if (row > top.MAX_RECIPIENTS) awAppendNewRow(false); awSetInputAndPopupValue(awGetInputElement(row), address, awGetPopupElement(row), recipientType, row); /* be sure we still have an empty row left at the end */ if (row == top.MAX_RECIPIENTS) { awAppendNewRow(true); awSetInputAndPopupValue(awGetInputElement(top.MAX_RECIPIENTS), "", awGetPopupElement(top.MAX_RECIPIENTS), "addr_to", top.MAX_RECIPIENTS); } // add the recipient to our spell check ignore list addRecipientsToIgnoreList(address);}function awTestRowSequence(){ /* This function is for debug and testing purpose only, normal user should not run it! Everytime we insert or delete a row, we must be sure we didn't break the ID sequence of the addressing widget rows. This function will run a quick test to see if the sequence still ok You need to define the pref mail.debug.test_addresses_sequence to true in order to activate it */ if (! test_addresses_sequence) return true; /* debug code to verify the sequence still good */ var listbox = document.getElementById('addressingWidget'); var listitems = listbox.getElementsByTagName('listitem'); if (listitems.length >= top.MAX_RECIPIENTS ) { for (var i = 1; i <= listitems.length; i ++) { var item = listitems [i - 1]; var inputID = item.getElementsByTagName(awInputElementName())[0].getAttribute("id").split("#")[1]; var popupID = item.getElementsByTagName(awSelectElementName())[0].getAttribute("id").split("#")[1]; if (inputID != i || popupID != i) { dump("#ERROR: sequence broken at row " + i + ", inputID=" + inputID + ", popupID=" + popupID + "\n"); return false; } dump("---SEQUENCE OK---\n"); return true; } } else dump("#ERROR: listitems.length(" + listitems.length + ") < top.MAX_RECIPIENTS(" + top.MAX_RECIPIENTS + ")\n"); return false;}function awResetAllRows(){ var maxRecipients = top.MAX_RECIPIENTS; for (var row = 1; row <= maxRecipients ; row ++) {
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -