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 } else if (name
== 'charsetCustomize') {
14 //do nothing - please remove this else statement, once the charset prefs moves to the pref window
16 SetForcedCharset(node
.getAttribute('id'));
20 function MailMultiplexHandler(event
)
22 var node
= event
.target
;
23 var name
= node
.getAttribute('name');
25 if (name
== 'detectorGroup') {
26 SelectDetector(event
, true);
27 } else if (name
== 'charsetGroup') {
28 var charset
= node
.getAttribute('id');
29 charset
= charset
.substring('charset.'.length
, charset
.length
)
30 MessengerSetForcedCharacterSet(charset
);
31 } else if (name
== 'charsetCustomize') {
32 //do nothing - please remove this else statement, once the charset prefs moves to the pref window
34 MessengerSetForcedCharacterSet(node
.getAttribute('id'));
38 function ComposerMultiplexHandler(event
)
40 var node
= event
.target
;
41 var name
= node
.getAttribute('name');
43 if (name
== 'detectorGroup') {
44 ComposerSelectDetector(event
, true);
45 } else if (name
== 'charsetGroup') {
46 var charset
= node
.getAttribute('id');
47 charset
= charset
.substring('charset.'.length
, charset
.length
)
48 EditorSetDocumentCharacterSet(charset
);
49 } else if (name
== 'charsetCustomize') {
50 //do nothing - please remove this else statement, once the charset prefs moves to the pref window
52 SetForcedEditorCharset(node
.getAttribute('id'));
56 function SelectDetector(event
, doReload
)
58 dump("Charset Detector menu item pressed: " + event
.target
.getAttribute('id') + "\n");
60 var uri
= event
.target
.getAttribute("id");
61 var prefvalue
= uri
.substring('chardet.'.length
, uri
.length
);
62 if ("off" == prefvalue
) { // "off" is special value to turn off the detectors
67 var pref
= Components
.classes
["@mozilla.org/preferences-service;1"]
68 .getService(Components
.interfaces
.nsIPrefBranch
);
69 var str
= Components
.classes
["@mozilla.org/supports-string;1"]
70 .createInstance(Components
.interfaces
.nsISupportsString
);
73 pref
.setComplexValue("intl.charset.detector",
74 Components
.interfaces
.nsISupportsString
, str
);
75 if (doReload
) window
.content
.location
.reload();
78 dump("Failed to set the intl.charset.detector preference.\n");
82 function ComposerSelectDetector(event
)
84 //dump("Charset Detector menu item pressed: " + event.target.getAttribute('id') + "\n");
86 var uri
= event
.target
.getAttribute("id");
87 var prefvalue
= uri
.substring('chardet.'.length
, uri
.length
);
88 if ("off" == prefvalue
) { // "off" is special value to turn off the detectors
93 var pref
= Components
.classes
["@mozilla.org/preferences-service;1"]
94 .getService(Components
.interfaces
.nsIPrefBranch
);
95 var str
= Components
.classes
["@mozilla.org/supports-string;1"]
96 .createInstance(Components
.interfaces
.nsISupportsString
);
99 pref
.setComplexValue("intl.charset.detector",
100 Components
.interfaces
.nsISupportsString
, str
);
101 EditorLoadUrl(GetDocumentUrl());
104 dump("Failed to set the intl.charset.detector preference.\n");
108 function SetForcedDetector(doReload
)
110 BrowserSetForcedDetector(doReload
);
113 function SetForcedCharset(charset
)
115 BrowserSetForcedCharacterSet(charset
);
118 var gPrevCharset
= null;
119 function UpdateCurrentCharset()
121 // extract the charset from DOM
122 var wnd
= document
.commandDispatcher
.focusedWindow
;
123 if ((window
== wnd
) || (wnd
== null)) wnd
= window
.content
;
125 // Uncheck previous item
127 var pref_item
= document
.getElementById('charset.' + gPrevCharset
);
129 pref_item
.setAttribute('checked', 'false');
132 var menuitem
= document
.getElementById('charset.' + wnd
.document
.characterSet
);
134 menuitem
.setAttribute('checked', 'true');
138 function UpdateCurrentMailCharset()
140 var charset
= msgWindow
.mailCharacterSet
;
141 var menuitem
= document
.getElementById('charset.' + charset
);
144 menuitem
.setAttribute('checked', 'true');
148 function UpdateCharsetDetector()
153 var pref
= Components
.classes
["@mozilla.org/preferences-service;1"]
154 .getService(Components
.interfaces
.nsIPrefBranch
);
155 prefvalue
= pref
.getComplexValue("intl.charset.detector",
156 Components
.interfaces
.nsIPrefLocalizedString
).data
;
162 if (prefvalue
== "") prefvalue
= "off";
163 dump("intl.charset.detector = "+ prefvalue
+ "\n");
165 prefvalue
= 'chardet.' + prefvalue
;
166 var menuitem
= document
.getElementById(prefvalue
);
169 menuitem
.setAttribute('checked', 'true');
173 function UpdateMenus(event
)
175 // use setTimeout workaround to delay checkmark the menu
176 // when onmenucomplete is ready then use it instead of oncreate
177 // see bug 78290 for the detail
178 UpdateCurrentCharset();
179 setTimeout(UpdateCurrentCharset
, 0);
180 UpdateCharsetDetector();
181 setTimeout(UpdateCharsetDetector
, 0);
184 function CreateMenu(node
)
186 var observerService
= Components
.classes
["@mozilla.org/observer-service;1"].getService(Components
.interfaces
.nsIObserverService
);
187 observerService
.notifyObservers(null, "charsetmenu-selected", node
);
190 function UpdateMailMenus(event
)
192 // use setTimeout workaround to delay checkmark the menu
193 // when onmenucomplete is ready then use it instead of oncreate
194 // see bug 78290 for the detail
195 UpdateCurrentMailCharset();
196 setTimeout(UpdateCurrentMailCharset
, 0);
197 UpdateCharsetDetector();
198 setTimeout(UpdateCharsetDetector
, 0);
201 var gCharsetMenu
= Components
.classes
['@mozilla.org/rdf/datasource;1?name=charset-menu'].getService().QueryInterface(Components
.interfaces
.nsICurrentCharsetListener
);
202 var gLastBrowserCharset
= null;
204 function charsetLoadListener (event
)
206 var charset
= window
.content
.document
.characterSet
;
208 if (charset
.length
> 0 && (charset
!= gLastBrowserCharset
)) {
209 gCharsetMenu
.SetCurrentCharset(charset
);
210 gPrevCharset
= gLastBrowserCharset
;
211 gLastBrowserCharset
= charset
;
216 function composercharsetLoadListener (event
)
218 var charset
= window
.content
.document
.characterSet
;
221 if (charset
.length
> 0 ) {
222 gCharsetMenu
.SetCurrentComposerCharset(charset
);
226 function SetForcedEditorCharset(charset
)
228 if (charset
.length
> 0 ) {
229 gCharsetMenu
.SetCurrentComposerCharset(charset
);
231 EditorSetDocumentCharacterSet(charset
);
235 var gLastMailCharset
= null;
237 function mailCharsetLoadListener (event
)
240 var charset
= msgWindow
.mailCharacterSet
;
241 if (charset
.length
> 0 && (charset
!= gLastMailCharset
)) {
242 gCharsetMenu
.SetCurrentMailCharset(charset
);
243 gLastMailCharset
= charset
;
248 var wintype
= document
.documentElement
.getAttribute('windowtype');
249 if (window
&& (wintype
== "navigator:browser"))
251 var contentArea
= window
.document
.getElementById("appcontent");
253 contentArea
.addEventListener("pageshow", charsetLoadListener
, true);
257 var arrayOfStrings
= wintype
.split(":");
258 if (window
&& arrayOfStrings
[0] == "mail")
260 var messageContent
= window
.document
.getElementById("messagepane");
262 messageContent
.addEventListener("pageshow", mailCharsetLoadListener
, true);
265 if (window
&& arrayOfStrings
[0] == "composer")
267 contentArea
= window
.document
.getElementById("appcontent");
269 contentArea
.addEventListener("pageshow", composercharsetLoadListener
, true);