home *** CD-ROM | disk | FTP | other *** search
/ ftp.swcp.com / ftp.swcp.com.zip / ftp.swcp.com / mac / mozilla-macos9-1.3.1.sea.bin / Mozilla1.3.1 / Chrome / comm.jar / content / communicator / profile / selectLang.js < prev    next >
Text File  |  2003-06-08  |  4KB  |  144 lines

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3.  *
  4.  * The contents of this file are subject to the Mozilla Public License Version
  5.  * 1.1 (the "License"); you may not use this file except in compliance with
  6.  * the License. You may obtain a copy of the License at
  7.  * http://www.mozilla.org/MPL/
  8.  *
  9.  * Software distributed under the License is distributed on an "AS IS" basis,
  10.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11.  * for the specific language governing rights and limitations under the
  12.  * License.
  13.  *
  14.  * The Original Code is Mozilla Communicator client code, released
  15.  * March 31, 1998.
  16.  *
  17.  * The Initial Developer of the Original Code is Netscape
  18.  * Communications Corporation. Portions created by Netscape are
  19.  * Copyright (C) 1998-1999 Netscape Communications Corporation. All
  20.  * Rights Reserved.
  21.  *
  22.  * Contributor(s):   Ben Goodger     (ben@netscape.com)
  23.  *                   Joe Hewitt      (hewitt@netscape.com)
  24.  *                   Blake Ross      (blaker@netscape.com)
  25.  *                   Stephen Walker  (walk84@usa.net)
  26.  *                   J.Betak         (jbetak@netscape.com)
  27.  *
  28.  *
  29.  * Alternatively, the contents of this file may be used under the terms of
  30.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  31.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  32.  * in which case the provisions of the GPL or the LGPL are applicable instead
  33.  * of those above. If you wish to allow use of your version of this file only
  34.  * under the terms of either the GPL or the LGPL, and not to allow others to
  35.  * use your version of this file under the terms of the MPL, indicate your
  36.  * decision by deleting the provisions above and replace them with the notice
  37.  * and other provisions required by the GPL or the LGPL. If you do not delete
  38.  * the provisions above, a recipient may use your version of this file under
  39.  * the terms of any one of the MPL, the GPL or the LGPL.
  40.  *
  41.  * ***** END LICENSE BLOCK ***** */
  42.  
  43.  
  44. function SelectListItem(listRef, itemValue)
  45. {
  46.  
  47.   try {
  48.  
  49.     var selectedItem;
  50.  
  51.     if (itemValue) {
  52.       var elements = listRef.getElementsByAttribute("value", itemValue);
  53.       selectedItem = elements.length ? elements[0] : null;
  54.     }
  55.  
  56.     if (selectedItem)
  57.     {
  58.       listRef.selectedItem = selectedItem;
  59.       return true;
  60.     }
  61.     else
  62.       return false;
  63.   } 
  64.  
  65.   catch(e)
  66.   {
  67.     return false;
  68.   }
  69.  
  70. }
  71.  
  72.  
  73. function Startup()
  74. {
  75.  
  76.   var prefInterface;
  77.   
  78.   var defaultLanguage;
  79.   var languageList = document.getElementById("langList");
  80.   var selectedLanguage = window.arguments.length ? window.arguments[0] : null;
  81.   
  82.   var defaultRegion;
  83.   var regionList = document.getElementById("regionList");
  84.   var selectedRegion = window.arguments.length ? window.arguments[1] : null;
  85.  
  86.   //get pref defaults
  87.   try
  88.   {
  89.     prefInterface =    Components.classes["@mozilla.org/preferences;1"].
  90.                        getService(Components.interfaces.nsIPref);
  91.  
  92.     defaultLanguage =  prefInterface.
  93.                        getLocalizedUnicharPref("general.useragent.locale");
  94.  
  95.     defaultRegion =   prefInterface.
  96.                        getLocalizedUnicharPref("general.useragent.contentlocale");
  97.   }
  98.  
  99.   catch(e) 
  100.   {}
  101.  
  102.   //persist previous user selection, highlight a default otherwise
  103.   if (!SelectListItem(languageList, selectedLanguage))
  104.     if (!SelectListItem(languageList, defaultLanguage))
  105.       languageList.selectedIndex = 0;
  106.  
  107.  
  108.   //persist previous user selection, highlight a default otherwise
  109.   if (!SelectListItem(regionList, selectedRegion))
  110.     if (!SelectListItem(regionList, defaultRegion))
  111.       regionList.selectedIndex = 1;
  112.  
  113. }
  114.  
  115.  
  116. function onAccept()
  117. {
  118.   //cache language on the parent window
  119.   var languageList = document.getElementById("langList");
  120.   var selectedItem = languageList.selectedItems.length ? languageList.selectedItems[0] : null;
  121.  
  122.   if (selectedItem) {
  123.     var langName = selectedItem.getAttribute("value");
  124.     var langStore = opener.document.getElementById("ProfileLanguage");
  125.  
  126.     if (langStore)
  127.       langStore.setAttribute("data", langName);
  128.   }
  129.  
  130.   //cache region on the parent window
  131.   var regionList = document.getElementById("regionList");
  132.   selectedItem = regionList.selectedItem;
  133.  
  134.   if (selectedItem) {
  135.     var regionName = selectedItem.getAttribute("value");
  136.     var regionStore = opener.document.getElementById("ProfileRegion");
  137.  
  138.     if (regionStore)
  139.       regionStore.setAttribute("data", regionName);
  140.   }
  141.  
  142.   return true;
  143. }
  144.