Bug 956657 Share more charset menu code between the view source window and the browser r=Unfocused
This commit is contained in:
@@ -657,84 +657,13 @@ function BrowserCharsetReload()
|
||||
}
|
||||
}
|
||||
|
||||
function BrowserSetForcedCharacterSet(aCharset)
|
||||
function BrowserSetCharacterSet(aEvent)
|
||||
{
|
||||
gBrowser.docShell.charset = aCharset;
|
||||
if (aEvent.target.hasAttribute("charset"))
|
||||
gBrowser.docShell.charset = aEvent.target.getAttribute("charset");
|
||||
BrowserCharsetReload();
|
||||
}
|
||||
|
||||
function MultiplexHandler(event)
|
||||
{
|
||||
var node = event.target;
|
||||
var name = node.getAttribute("name");
|
||||
|
||||
if (name == "detectorGroup") {
|
||||
SelectDetector(event);
|
||||
BrowserCharsetReload();
|
||||
} else if (name == "charsetGroup") {
|
||||
var charset = node.getAttribute("id");
|
||||
charset = charset.substring(charset.indexOf("charset.") + "charset.".length);
|
||||
BrowserSetForcedCharacterSet(charset);
|
||||
}
|
||||
}
|
||||
|
||||
function SelectDetector(event)
|
||||
{
|
||||
var uri = event.target.getAttribute("id");
|
||||
var prefvalue = uri.substring(uri.indexOf("chardet.") + "chardet.".length);
|
||||
if ("off" == prefvalue) { // "off" is special value to turn off the detectors
|
||||
prefvalue = "";
|
||||
}
|
||||
|
||||
try {
|
||||
var str = Cc["@mozilla.org/supports-string;1"].
|
||||
createInstance(Ci.nsISupportsString);
|
||||
str.data = prefvalue;
|
||||
gPrefService.setComplexValue("intl.charset.detector", Ci.nsISupportsString, str);
|
||||
}
|
||||
catch (ex) {
|
||||
dump("Failed to set the intl.charset.detector preference.\n");
|
||||
}
|
||||
}
|
||||
|
||||
function FoldCharset(charset) {
|
||||
// For substantially similar encodings, treat two encodings as the same
|
||||
// for the purpose of the check mark.
|
||||
if (charset == "ISO-8859-8-I") {
|
||||
return "windows-1255";
|
||||
} else if (charset == "gb18030") {
|
||||
return "gbk";
|
||||
}
|
||||
return charset;
|
||||
}
|
||||
|
||||
function UpdateCurrentCharset() {
|
||||
var menuitem = document.getElementById("charset." + FoldCharset(content.document.characterSet));
|
||||
if (menuitem)
|
||||
menuitem.setAttribute("checked", "true");
|
||||
}
|
||||
|
||||
function UpdateCharsetDetector() {
|
||||
var prefvalue;
|
||||
|
||||
try {
|
||||
prefvalue = gPrefService.getComplexValue("intl.charset.detector", Ci.nsIPrefLocalizedString).data;
|
||||
}
|
||||
catch (ex) {}
|
||||
|
||||
if (!prefvalue)
|
||||
prefvalue = "off";
|
||||
|
||||
var menuitem = document.getElementById("chardet." + prefvalue);
|
||||
if (menuitem)
|
||||
menuitem.setAttribute("checked", "true");
|
||||
}
|
||||
|
||||
function UpdateMenus() {
|
||||
UpdateCurrentCharset();
|
||||
UpdateCharsetDetector();
|
||||
}
|
||||
|
||||
function BrowserForward(aEvent) {
|
||||
try {
|
||||
gBrowser.goForward();
|
||||
|
||||
Reference in New Issue
Block a user