home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 January / 01_02.iso / software / netscape62win / browser.xpi / bin / chrome / toolkit.jar / content / global / charsetOverlay.js < prev    next >
Encoding:
Text File  |  2001-05-22  |  7.3 KB  |  242 lines

  1. function MultiplexHandler(event)
  2. {
  3.   var node = event.target;
  4.   var name = node.getAttribute('name');
  5.   var charset;
  6.  
  7.   if (name == 'detectorGroup') {
  8.     SetForcedDetector();
  9.     SelectDetector(event, true);
  10.   } else if (name == 'charsetGroup') {
  11.     charset = node.getAttribute('id');
  12.     charset = charset.substring('charset.'.length, charset.length)
  13.     SetForcedCharset(charset);
  14.     SetDefaultCharacterSet(charset);
  15.   } else if (name == 'charsetCustomize') {
  16.     //do nothing - please remove this else statement, once the charset prefs moves to the pref window
  17.   } else {
  18.     SetForcedCharset(node.getAttribute('id'));
  19.     SetDefaultCharacterSet(node.getAttribute('id'));
  20.   }
  21. }
  22.  
  23. function MailMultiplexHandler(event)
  24. {
  25.   var node = event.target;
  26.   var name = node.getAttribute('name');
  27.   var charset;
  28.  
  29.   if (name == 'detectorGroup') {
  30.     SelectDetector(event, false);
  31.   } else if (name == 'charsetGroup') {
  32.     charset = node.getAttribute('id');
  33.     charset = charset.substring('charset.'.length, charset.length)
  34.     MessengerSetDefaultCharacterSet(charset);
  35.   } else if (name == 'charsetCustomize') {
  36.     //do nothing - please remove this else statement, once the charset prefs moves to the pref window
  37.   } else {
  38.     MessengerSetDefaultCharacterSet(node.getAttribute('id'));
  39.   }
  40. }
  41.  
  42. function ComposerMultiplexHandler(event)
  43. {
  44.   var node = event.target;
  45.   var name = node.getAttribute('name');
  46.   var charset;
  47.  
  48.   if (name == 'detectorGroup') {
  49.     ComposerSelectDetector(event, true);
  50.   } else if (name == 'charsetGroup') {
  51.     charset = node.getAttribute('id');
  52.     charset = charset.substring('charset.'.length, charset.length)
  53.     EditorSetDocumentCharacterSet(charset);
  54.   } else if (name == 'charsetCustomize') {
  55.     //do nothing - please remove this else statement, once the charset prefs moves to the pref window
  56.   } else {
  57.     EditorSetDocumentCharacterSet(node.getAttribute('id'));
  58.   }
  59. }
  60.  
  61. function SetDefaultCharacterSet(charset)
  62. {
  63.     dump("Charset Overlay menu item pressed: " + charset + "\n");
  64.     BrowserSetDefaultCharacterSet(charset);
  65. }
  66.  
  67. function SelectDetector(event, doReload)
  68. {
  69.     dump("Charset Detector menu item pressed: " + event.target.getAttribute('id') + "\n");
  70.  
  71.     var uri =  event.target.getAttribute("id");
  72.     var prefvalue = uri.substring('chardet.'.length, uri.length);
  73.     if("off" == prefvalue) { // "off" is special value to turn off the detectors
  74.         prefvalue = "";
  75.     }
  76.  
  77.     var pref = Components.classes['@mozilla.org/preferences;1'];
  78.     if (pref) {
  79.         pref = pref.getService();
  80.         pref = pref.QueryInterface(Components.interfaces.nsIPref);
  81.     }
  82.  
  83.     if (pref) {
  84.         pref.SetCharPref("intl.charset.detector", prefvalue);
  85.         if (doReload) window._content.location.reload();
  86.     }
  87. }
  88.  
  89. function ComposerSelectDetector(event)
  90. {
  91.     //dump("Charset Detector menu item pressed: " + event.target.getAttribute('id') + "\n");
  92.  
  93.     var uri =  event.target.getAttribute("id");
  94.     var prefvalue = uri.substring('chardet.'.length, uri.length);
  95.     if("off" == prefvalue) { // "off" is special value to turn off the detectors
  96.         prefvalue = "";
  97.     }
  98.  
  99.     var pref = Components.classes['@mozilla.org/preferences;1'];
  100.     if (pref) {
  101.         pref = pref.getService();
  102.         pref = pref.QueryInterface(Components.interfaces.nsIPref);
  103.     }
  104.  
  105.     if (pref) {
  106.         pref.SetCharPref("intl.charset.detector", prefvalue);
  107.           editorShell.LoadUrl(editorShell.editorDocument.location);    
  108.     }
  109. }
  110.  
  111. function SetForcedDetector()
  112. {
  113.   BrowserSetForcedDetector();
  114. }
  115.  
  116. function SetForcedCharset(charset)
  117. {
  118.   BrowserSetForcedCharacterSet(charset);
  119. }
  120.  
  121. function UpdateCurrentCharset()
  122. {
  123.     var wnd = document.commandDispatcher.focusedWindow;
  124.     if ((window == wnd) || (wnd == null)) wnd = window._content;
  125.  
  126.     var charset = wnd.document.characterSet;
  127.     var menuitem = document.getElementById('charset.' + charset);
  128.  
  129.     if (menuitem) {
  130.         menuitem.setAttribute('checked', 'true');
  131.     }
  132. }
  133.  
  134. function UpdateCurrentMailCharset()
  135. {
  136.     var charset = msgWindow.mailCharacterSet;
  137.     dump("Update current mail charset: " + charset + " \n");
  138.  
  139.     var menuitem = document.getElementById('charset.' + charset);
  140.  
  141.     if (menuitem) {
  142.         menuitem.setAttribute('checked', 'true');
  143.     }
  144. }
  145.  
  146. function UpdateCharsetDetector()
  147. {
  148.     var pref = Components.classes['@mozilla.org/preferences;1'];
  149.     if (pref) {
  150.         pref = pref.getService();
  151.         pref = pref.QueryInterface(Components.interfaces.nsIPref);
  152.     }
  153.  
  154.     if (pref) {
  155.         prefvalue = pref.getLocalizedUnicharPref("intl.charset.detector");
  156.         if (prefvalue == "") prefvalue = "off";
  157. dump("intl.charset.detector = "+ prefvalue + "\n");
  158.     }
  159.  
  160.     var prefvalue = 'chardet.' + prefvalue;
  161.     var menuitem = document.getElementById(prefvalue);
  162.  
  163.     if (menuitem) {
  164.         menuitem.setAttribute('checked', 'true');
  165.     }
  166. }
  167.  
  168. function UpdateMenus(event)
  169. {
  170.     // use setTimeout workaround to delay checkmark the menu
  171.     // when onmenucomplete is ready then use it instead of oncreate
  172.     // see bug 78290 for the detail
  173.     UpdateCurrentCharset();
  174.     setTimeout("UpdateCurrentCharset()", 0);
  175.     UpdateCharsetDetector();
  176.     setTimeout("UpdateCharsetDetector()", 0);
  177. }
  178.  
  179. function UpdateMailMenus(event)
  180. {
  181.     // use setTimeout workaround to delay checkmark the menu
  182.     // when onmenucomplete is ready then use it instead of oncreate
  183.     // see bug 78290 for the detail
  184.     UpdateCurrentMailCharset();
  185.     setTimeout("UpdateCurrentMailCharset()", 0);
  186.     UpdateCharsetDetector();
  187.     setTimeout("UpdateCharsetDetector()", 0);
  188. }
  189.  
  190. function charsetLoadListener (event)
  191. {
  192.     var menu = Components.classes['@mozilla.org/rdf/datasource;1?name=charset-menu'];
  193.  
  194.     if (menu) {
  195.         menu = menu.getService();
  196.         menu = menu.QueryInterface(Components.interfaces.nsICurrentCharsetListener);
  197.     }
  198.  
  199.     var charset = window._content.document.characterSet;
  200.  
  201.     if (menu) {
  202.         menu.SetCurrentCharset(charset);
  203.     }
  204.  
  205.     // XXX you know, here I could also set the checkmark, for the case when a 
  206.     // doc finishes loading after the menu is already diplayed. But I get a
  207.     // weird assertion!
  208. }
  209.  
  210. var gCharsetMenu = Components.classes['@mozilla.org/rdf/datasource;1?name=charset-menu'].getService().QueryInterface(Components.interfaces.nsICurrentCharsetListener);
  211. var gLastCurrentCharset = null;
  212.  
  213. function mailCharsetLoadListener (event)
  214. {
  215.     if (msgWindow) {
  216.             var charset = msgWindow.mailCharacterSet;
  217.             if (charset.length > 0 && (charset != gLastCurrentCharset)) {
  218.                 gCharsetMenu.SetCurrentMailCharset(charset);
  219.                 gLastCurrentCharset = charset;
  220.                 dump("mailCharsetLoadListener: " + charset + " \n");
  221.             }
  222.     }
  223. }
  224.  
  225. var wintype = document.firstChild.getAttribute('windowtype');
  226. if (window && (wintype == "navigator:browser"))
  227. {
  228.   var contentArea = window.document.getElementById("appcontent");
  229.   if (contentArea)
  230.     contentArea.addEventListener("load", charsetLoadListener, true);
  231. }
  232. else
  233. {
  234.   var arrayOfStrings = wintype.split(":");
  235.   if (window && arrayOfStrings[0] == "mail") 
  236.   {
  237.     var messageContent = window.document.getElementById("messagepane");
  238.     if (messageContent)
  239.       messageContent.addEventListener("load", mailCharsetLoadListener, true);
  240.   }
  241. }
  242.