home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / mozil06.zip / bin / chrome / toolkit.jar / content / global / charsetOverlay.js < prev    next >
Text File  |  2001-02-14  |  7KB  |  237 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 = window._content;
  125.  
  126.     var charset = wnd.document.characterSet;
  127.     dump("Update current charset: " + charset + "\n");
  128.  
  129.     var menuitem = document.getElementById('charset.' + charset);
  130.  
  131.     if (menuitem) {
  132.         menuitem.setAttribute('checked', 'true');
  133.     }
  134. }
  135.  
  136. function UpdateCurrentMailCharset()
  137. {
  138.     var charset = msgWindow.mailCharacterSet;
  139.     dump("UPdate current mail charset: " + charset + " \n");
  140.  
  141.     var menuitem = document.getElementById('charset.' + charset);
  142.  
  143.     if (menuitem) {
  144.         menuitem.setAttribute('checked', 'true');
  145.     }
  146. }
  147.  
  148. function UpdateCharsetDetector()
  149. {
  150.     var pref = Components.classes['@mozilla.org/preferences;1'];
  151.     if (pref) {
  152.         pref = pref.getService();
  153.         pref = pref.QueryInterface(Components.interfaces.nsIPref);
  154.     }
  155.  
  156.     if (pref) {
  157.         prefvalue = pref.getLocalizedUnicharPref("intl.charset.detector");
  158.         if (prefvalue == "") prefvalue = "off";
  159. dump("intl.charset.detector = "+ prefvalue + "\n");
  160.     }
  161.  
  162.     var prefvalue = 'chardet.' + prefvalue;
  163.     var menuitem = document.getElementById(prefvalue);
  164.  
  165.     if (menuitem) {
  166.         menuitem.setAttribute('checked', 'true');
  167.     }
  168. }
  169.  
  170. function UpdateMenus(event)
  171. {
  172.     UpdateCurrentCharset();
  173.     UpdateCharsetDetector();
  174. }
  175.  
  176. function UpdateMailMenus(event)
  177. {
  178.     UpdateCurrentMailCharset();
  179.     UpdateCharsetDetector();
  180. }
  181.  
  182. function charsetLoadListener (event)
  183. {
  184.     var menu = Components.classes['@mozilla.org/rdf/datasource;1?name=charset-menu'];
  185.  
  186.     if (menu) {
  187.         menu = menu.getService();
  188.         menu = menu.QueryInterface(Components.interfaces.nsICurrentCharsetListener);
  189.     }
  190.  
  191.     var charset = window._content.document.characterSet;
  192.  
  193.     if (menu) {
  194.         menu.SetCurrentCharset(charset);
  195.     }
  196.  
  197.     // XXX you know, here I could also set the checkmark, for the case when a 
  198.     // doc finishes loading after the menu is already diplayed. But I get a
  199.     // weird assertion!
  200. }
  201.  
  202. function mailCharsetLoadListener (event)
  203. {
  204.     var menu = Components.classes['@mozilla.org/rdf/datasource;1?name=charset-menu'];
  205.  
  206.     if (menu) {
  207.         menu = menu.getService();
  208.         menu = menu.QueryInterface(Components.interfaces.nsICurrentCharsetListener);
  209.         
  210.         if (msgWindow) {
  211.             var charset = msgWindow.mailCharacterSet;
  212.             if (charset.length > 0) {
  213.                 menu.SetCurrentMailCharset(charset);
  214.                 dump("mailCharsetLoadListener: " + charset + " \n");
  215.             }
  216.         }
  217.     }
  218. }
  219.  
  220. var wintype = document.firstChild.getAttribute('windowtype');
  221. if (window && (wintype == "navigator:browser"))
  222. {
  223.   var contentArea = window.document.getElementById("appcontent");
  224.   if (contentArea)
  225.     contentArea.addEventListener("load", charsetLoadListener, true);
  226. }
  227. else
  228. {
  229.   var arrayOfStrings = wintype.split(":");
  230.   if (window && arrayOfStrings[0] == "mail") 
  231.   {
  232.     var messageContent = window.document.getElementById("messagepane");
  233.     if (messageContent)
  234.       messageContent.addEventListener("load", mailCharsetLoadListener, true);
  235.   }
  236. }
  237.