1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
|
function MultiplexHandler(event)
{
var node = event.target;
var name = node.getAttribute('name');
if (name == 'detectorGroup') {
SetForcedDetector(true);
SelectDetector(event, false);
} else if (name == 'charsetGroup') {
var charset = node.getAttribute('id');
charset = charset.substring('charset.'.length, charset.length)
SetForcedCharset(charset);
SetDefaultCharacterSet(charset);
} else if (name == 'charsetCustomize') {
//do nothing - please remove this else statement, once the charset prefs moves to the pref window
} else {
SetForcedCharset(node.getAttribute('id'));
SetDefaultCharacterSet(node.getAttribute('id'));
}
}
function MailMultiplexHandler(event)
{
var node = event.target;
var name = node.getAttribute('name');
if (name == 'detectorGroup') {
SelectDetector(event, true);
} else if (name == 'charsetGroup') {
var charset = node.getAttribute('id');
charset = charset.substring('charset.'.length, charset.length)
MessengerSetForcedCharacterSet(charset);
} else if (name == 'charsetCustomize') {
//do nothing - please remove this else statement, once the charset prefs moves to the pref window
} else {
MessengerSetForcedCharacterSet(node.getAttribute('id'));
}
}
function ComposerMultiplexHandler(event)
{
var node = event.target;
var name = node.getAttribute('name');
if (name == 'detectorGroup') {
ComposerSelectDetector(event, true);
} else if (name == 'charsetGroup') {
var charset = node.getAttribute('id');
charset = charset.substring('charset.'.length, charset.length)
EditorSetDocumentCharacterSet(charset);
} else if (name == 'charsetCustomize') {
//do nothing - please remove this else statement, once the charset prefs moves to the pref window
} else {
SetForcedEditorCharset(node.getAttribute('id'));
}
}
function SetDefaultCharacterSet(charset)
{
dump("Charset Overlay menu item pressed: " + charset + "\n");
BrowserSetDefaultCharacterSet(charset);
}
function SelectDetector(event, doReload)
{
dump("Charset Detector menu item pressed: " + event.target.getAttribute('id') + "\n");
var uri = event.target.getAttribute("id");
var prefvalue = uri.substring('chardet.'.length, uri.length);
if ("off" == prefvalue) { // "off" is special value to turn off the detectors
prefvalue = "";
}
try {
var pref = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
var str = Components.classes["@mozilla.org/supports-string;1"]
.createInstance(Components.interfaces.nsISupportsString);
str.data = prefvalue;
pref.setComplexValue("intl.charset.detector",
Components.interfaces.nsISupportsString, str);
if (doReload) window.content.location.reload();
}
catch (ex) {
dump("Failed to set the intl.charset.detector preference.\n");
}
}
function ComposerSelectDetector(event)
{
//dump("Charset Detector menu item pressed: " + event.target.getAttribute('id') + "\n");
var uri = event.target.getAttribute("id");
var prefvalue = uri.substring('chardet.'.length, uri.length);
if ("off" == prefvalue) { // "off" is special value to turn off the detectors
prefvalue = "";
}
try {
var pref = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
var str = Components.classes["@mozilla.org/supports-string;1"]
.createInstance(Components.interfaces.nsISupportsString);
str.data = prefvalue;
pref.setComplexValue("intl.charset.detector",
Components.interfaces.nsISupportsString, str);
EditorLoadUrl(GetDocumentUrl());
}
catch (ex) {
dump("Failed to set the intl.charset.detector preference.\n");
}
}
function SetForcedDetector(doReload)
{
BrowserSetForcedDetector(doReload);
}
function SetForcedCharset(charset)
{
BrowserSetForcedCharacterSet(charset);
}
var gPrevCharset = null;
function UpdateCurrentCharset()
{
var menuitem = null;
// exctract the charset from DOM
var wnd = document.commandDispatcher.focusedWindow;
if ((window == wnd) || (wnd == null)) wnd = window.content;
menuitem = document.getElementById('charset.' + wnd.document.characterSet);
if (menuitem) {
// uncheck previously checked item to workaround Mac checkmark problem
// bug 98625
if (gPrevCharset) {
var pref_item = document.getElementById('charset.' + gPrevCharset);
if (pref_item)
pref_item.setAttribute('checked', 'false');
}
menuitem.setAttribute('checked', 'true');
}
}
function UpdateCurrentMailCharset()
{
var charset = msgWindow.mailCharacterSet;
var menuitem = document.getElementById('charset.' + charset);
if (menuitem) {
menuitem.setAttribute('checked', 'true');
}
}
function UpdateCharsetDetector()
{
var prefvalue;
try {
var pref = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
prefvalue = pref.getComplexValue("intl.charset.detector",
Components.interfaces.nsIPrefLocalizedString).data;
}
catch (ex) {
prefvalue = "";
}
if (prefvalue == "") prefvalue = "off";
dump("intl.charset.detector = "+ prefvalue + "\n");
prefvalue = 'chardet.' + prefvalue;
var menuitem = document.getElementById(prefvalue);
if (menuitem) {
menuitem.setAttribute('checked', 'true');
}
}
function UpdateMenus(event)
{
// use setTimeout workaround to delay checkmark the menu
// when onmenucomplete is ready then use it instead of oncreate
// see bug 78290 for the detail
UpdateCurrentCharset();
setTimeout(UpdateCurrentCharset, 0);
UpdateCharsetDetector();
setTimeout(UpdateCharsetDetector, 0);
}
function CreateMenu(node)
{
var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
observerService.notifyObservers(null, "charsetmenu-selected", node);
}
function UpdateMailMenus(event)
{
// use setTimeout workaround to delay checkmark the menu
// when onmenucomplete is ready then use it instead of oncreate
// see bug 78290 for the detail
UpdateCurrentMailCharset();
setTimeout(UpdateCurrentMailCharset, 0);
UpdateCharsetDetector();
setTimeout(UpdateCharsetDetector, 0);
}
var gCharsetMenu = Components.classes['@mozilla.org/rdf/datasource;1?name=charset-menu'].getService().QueryInterface(Components.interfaces.nsICurrentCharsetListener);
var gLastBrowserCharset = null;
function charsetLoadListener (event)
{
var charset = window.content.document.characterSet;
if (charset.length > 0 && (charset != gLastBrowserCharset)) {
gCharsetMenu.SetCurrentCharset(charset);
gPrevCharset = gLastBrowserCharset;
gLastBrowserCharset = charset;
}
}
function composercharsetLoadListener (event)
{
var charset = window.content.document.characterSet;
if (charset.length > 0 ) {
gCharsetMenu.SetCurrentComposerCharset(charset);
}
}
function SetForcedEditorCharset(charset)
{
if (charset.length > 0 ) {
gCharsetMenu.SetCurrentComposerCharset(charset);
}
EditorSetDocumentCharacterSet(charset);
}
var gLastMailCharset = null;
function mailCharsetLoadListener (event)
{
if (msgWindow) {
var charset = msgWindow.mailCharacterSet;
if (charset.length > 0 && (charset != gLastMailCharset)) {
gCharsetMenu.SetCurrentMailCharset(charset);
gLastMailCharset = charset;
}
}
}
var wintype = document.firstChild.getAttribute('windowtype');
if (window && (wintype == "navigator:browser"))
{
var contentArea = window.document.getElementById("appcontent");
if (contentArea)
contentArea.addEventListener("pageshow", charsetLoadListener, true);
}
else
{
var arrayOfStrings = wintype.split(":");
if (window && arrayOfStrings[0] == "mail")
{
var messageContent = window.document.getElementById("messagepane");
if (messageContent)
messageContent.addEventListener("pageshow", mailCharsetLoadListener, true);
}
else
if (window && arrayOfStrings[0] == "composer")
{
contentArea = window.document.getElementById("appcontent");
if (contentArea)
contentArea.addEventListener("pageshow", composercharsetLoadListener, true);
}
}
|