1
function MultiplexHandler(event)
3
var node = event.target;
4
var name = node.getAttribute('name');
6
if (name == 'detectorGroup') {
7
SetForcedDetector(true);
8
SelectDetector(event, false);
9
} else if (name == 'charsetGroup') {
10
var charset = node.getAttribute('id');
11
charset = charset.substring('charset.'.length, charset.length)
12
SetForcedCharset(charset);
13
SetDefaultCharacterSet(charset);
14
} else if (name == 'charsetCustomize') {
15
// please remove this else statement, once the charset prefs moves to the pref window
16
window.openDialog("chrome://communicator/content/pref/pref-charset.xul",
17
"_blank", "chrome,modal,resizable", "browser");
19
SetForcedCharset(node.getAttribute('id'));
20
SetDefaultCharacterSet(node.getAttribute('id'));
24
function MailMultiplexHandler(event)
26
var node = event.target;
27
var name = node.getAttribute('name');
29
if (name == 'detectorGroup') {
30
SelectDetector(event, true);
31
} else if (name == 'charsetGroup') {
32
var charset = node.getAttribute('id');
33
charset = charset.substring('charset.'.length, charset.length)
34
MessengerSetDefaultCharacterSet(charset);
35
} else if (name == 'charsetCustomize') {
36
// please remove this else statement, once the charset prefs moves to the pref window
37
window.openDialog("chrome://communicator/content/pref/pref-charset.xul",
38
"_blank", "chrome,modal,resizable", "browser");
40
MessengerSetDefaultCharacterSet(node.getAttribute('id'));
44
function ComposerMultiplexHandler(event)
46
var node = event.target;
47
var name = node.getAttribute('name');
49
if (name == 'detectorGroup') {
50
ComposerSelectDetector(event, true);
51
} else if (name == 'charsetGroup') {
52
var charset = node.getAttribute('id');
53
charset = charset.substring('charset.'.length, charset.length)
54
EditorSetDocumentCharacterSet(charset);
55
} else if (name == 'charsetCustomize') {
56
// please remove this else statement, once the charset prefs moves to the pref window
57
window.openDialog("chrome://communicator/content/pref/pref-charset.xul",
58
"_blank", "chrome,modal,resizable", "browser");
60
SetForcedEditorCharset(node.getAttribute('id'));
64
function MaileditMultiplexHandler(event)
66
var node = event.target;
67
var name = node.getAttribute('name');
69
if (name == 'charsetCustomize') {
70
// please remove this else statement, once the charset prefs moves to the pref window
71
window.openDialog("chrome://communicator/content/pref/pref-charset.xul",
72
"_blank", "chrome,modal,resizable", "mailedit");
74
SetDocumentCharacterSet(node.id);
78
function SetDefaultCharacterSet(charset)
80
dump("Charset Overlay menu item pressed: " + charset + "\n");
81
BrowserSetDefaultCharacterSet(charset);
84
function SelectDetector(event, doReload)
86
dump("Charset Detector menu item pressed: " + event.target.getAttribute('id') + "\n");
88
var uri = event.target.getAttribute("id");
89
var prefvalue = uri.substring('chardet.'.length, uri.length);
90
if ("off" == prefvalue) { // "off" is special value to turn off the detectors
95
var pref = Components.classes["@mozilla.org/preferences-service;1"]
96
.getService(Components.interfaces.nsIPrefBranch);
97
var str = Components.classes["@mozilla.org/supports-string;1"]
98
.createInstance(Components.interfaces.nsISupportsString);
100
str.data = prefvalue;
101
pref.setComplexValue("intl.charset.detector",
102
Components.interfaces.nsISupportsString, str);
103
if (doReload) window._content.location.reload();
106
dump("Failed to set the intl.charset.detector preference.\n");
110
function ComposerSelectDetector(event)
112
//dump("Charset Detector menu item pressed: " + event.target.getAttribute('id') + "\n");
114
var uri = event.target.getAttribute("id");
115
var prefvalue = uri.substring('chardet.'.length, uri.length);
116
if ("off" == prefvalue) { // "off" is special value to turn off the detectors
121
var pref = Components.classes["@mozilla.org/preferences-service;1"]
122
.getService(Components.interfaces.nsIPrefBranch);
123
var str = Components.classes["@mozilla.org/supports-string;1"]
124
.createInstance(Components.interfaces.nsISupportsString);
126
str.data = prefvalue;
127
pref.setComplexValue("intl.charset.detector",
128
Components.interfaces.nsISupportsString, str);
129
EditorLoadUrl(GetDocumentUrl());
132
dump("Failed to set the intl.charset.detector preference.\n");
136
function SetForcedDetector(doReload)
138
BrowserSetForcedDetector(doReload);
141
function SetForcedCharset(charset)
143
BrowserSetForcedCharacterSet(charset);
146
var gPrevCharset = null;
147
function UpdateCurrentCharset()
151
// exctract the charset from DOM
152
var wnd = document.commandDispatcher.focusedWindow;
153
if ((window == wnd) || (wnd == null)) wnd = window._content;
154
menuitem = document.getElementById('charset.' + wnd.document.characterSet);
157
// uncheck previously checked item to workaround Mac checkmark problem
160
var pref_item = document.getElementById('charset.' + gPrevCharset);
162
pref_item.setAttribute('checked', 'false');
164
menuitem.setAttribute('checked', 'true');
168
function UpdateCurrentMailCharset()
170
var charset = msgWindow.mailCharacterSet;
171
dump("Update current mail charset: " + charset + " \n");
173
var menuitem = document.getElementById('charset.' + charset);
176
menuitem.setAttribute('checked', 'true');
180
function UpdateCharsetDetector()
185
var pref = Components.classes["@mozilla.org/preferences-service;1"]
186
.getService(Components.interfaces.nsIPrefBranch);
187
prefvalue = pref.getComplexValue("intl.charset.detector",
188
Components.interfaces.nsIPrefLocalizedString).data;
194
if (prefvalue == "") prefvalue = "off";
195
dump("intl.charset.detector = "+ prefvalue + "\n");
197
prefvalue = 'chardet.' + prefvalue;
198
var menuitem = document.getElementById(prefvalue);
201
menuitem.setAttribute('checked', 'true');
205
function UpdateMenus(event)
207
// use setTimeout workaround to delay checkmark the menu
208
// when onmenucomplete is ready then use it instead of oncreate
209
// see bug 78290 for the detail
210
UpdateCurrentCharset();
211
setTimeout("UpdateCurrentCharset()", 0);
212
UpdateCharsetDetector();
213
setTimeout("UpdateCharsetDetector()", 0);
216
function CreateMenu(node)
218
var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
219
observerService.notifyObservers(null, "charsetmenu-selected", node);
222
function UpdateMailMenus(event)
224
// use setTimeout workaround to delay checkmark the menu
225
// when onmenucomplete is ready then use it instead of oncreate
226
// see bug 78290 for the detail
227
UpdateCurrentMailCharset();
228
setTimeout("UpdateCurrentMailCharset()", 0);
229
UpdateCharsetDetector();
230
setTimeout("UpdateCharsetDetector()", 0);
233
var gCharsetMenu = Components.classes['@mozilla.org/rdf/datasource;1?name=charset-menu'].getService().QueryInterface(Components.interfaces.nsICurrentCharsetListener);
234
var gLastBrowserCharset = null;
236
function charsetLoadListener (event)
238
var charset = window._content.document.characterSet;
240
if (charset.length > 0 && (charset != gLastBrowserCharset)) {
241
gCharsetMenu.SetCurrentCharset(charset);
242
gPrevCharset = gLastBrowserCharset;
243
gLastBrowserCharset = charset;
248
function composercharsetLoadListener (event)
250
var charset = window._content.document.characterSet;
253
if (charset.length > 0 ) {
254
gCharsetMenu.SetCurrentComposerCharset(charset);
258
function SetForcedEditorCharset(charset)
260
if (charset.length > 0 ) {
261
gCharsetMenu.SetCurrentComposerCharset(charset);
263
EditorSetDocumentCharacterSet(charset);
267
var gLastMailCharset = null;
269
function mailCharsetLoadListener (event)
272
var charset = msgWindow.mailCharacterSet;
273
if (charset.length > 0 && (charset != gLastMailCharset)) {
274
gCharsetMenu.SetCurrentMailCharset(charset);
275
gLastMailCharset = charset;
276
dump("mailCharsetLoadListener: " + charset + " \n");
281
var wintype = document.firstChild.getAttribute('windowtype');
282
if (window && (wintype == "navigator:browser"))
284
var contentArea = window.document.getElementById("appcontent");
286
contentArea.addEventListener("load", charsetLoadListener, true);
290
var arrayOfStrings = wintype.split(":");
291
if (window && arrayOfStrings[0] == "mail")
293
var messageContent = window.document.getElementById("messagepane");
295
messageContent.addEventListener("load", mailCharsetLoadListener, true);
298
if (window && arrayOfStrings[0] == "composer")
300
contentArea = window.document.getElementById("appcontent");
302
contentArea.addEventListener("load", composercharsetLoadListener, true);