2006-05-17 02:27:51 +00:00
|
|
|
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape Communications
|
|
|
|
* Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 2000 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
2006-05-17 02:28:51 +00:00
|
|
|
* Contributor(s):
|
2006-05-17 02:27:51 +00:00
|
|
|
* Adrian Havill <havill@redhat.com>
|
|
|
|
*/
|
|
|
|
|
2006-05-17 02:25:34 +00:00
|
|
|
//GLOBALS
|
|
|
|
|
|
|
|
|
|
|
|
//locale bundles
|
2006-05-17 02:22:36 +00:00
|
|
|
var regionsBundle;
|
|
|
|
var languagesBundle;
|
|
|
|
var acceptedBundle;
|
2006-05-17 02:27:51 +00:00
|
|
|
var prefLangBundle;
|
2006-05-17 02:25:34 +00:00
|
|
|
|
|
|
|
//dictionary of all supported locales
|
2006-05-17 02:22:36 +00:00
|
|
|
var availLanguageDict;
|
|
|
|
|
2006-05-17 02:25:34 +00:00
|
|
|
//XUL tree handles
|
|
|
|
var available_languages;
|
|
|
|
var available_languages_treeroot;
|
|
|
|
|
|
|
|
//XUL tree handles
|
|
|
|
var active_languages;
|
|
|
|
var active_languages_treeroot;
|
|
|
|
|
|
|
|
//XUL window pref window interface object
|
2006-05-17 02:25:40 +00:00
|
|
|
var pref_string = new String();
|
2006-05-17 02:22:36 +00:00
|
|
|
|
2006-05-17 02:30:04 +00:00
|
|
|
//Reg expression for splitting multiple pref values
|
|
|
|
var separatorRe = /\s*,\s*/;
|
|
|
|
|
2006-05-17 02:22:36 +00:00
|
|
|
function GetBundles()
|
|
|
|
{
|
2006-05-17 02:28:51 +00:00
|
|
|
if (!regionsBundle) regionsBundle = srGetStrBundle("chrome://global/locale/regionNames.properties");
|
|
|
|
if (!languagesBundle) languagesBundle = srGetStrBundle("chrome://global/locale/languageNames.properties");
|
|
|
|
if (!prefLangBundle) prefLangBundle = srGetStrBundle("chrome://communicator/locale/pref/pref-languages.properties");
|
|
|
|
if (!acceptedBundle) acceptedBundle = srGetStrBundle("resource:/res/language.properties");
|
2006-05-17 02:22:36 +00:00
|
|
|
}
|
2006-05-17 02:22:35 +00:00
|
|
|
|
|
|
|
|
2006-05-17 02:25:34 +00:00
|
|
|
function Init()
|
2006-05-17 02:22:35 +00:00
|
|
|
{
|
2006-05-17 02:25:34 +00:00
|
|
|
try {
|
2006-05-17 02:27:52 +00:00
|
|
|
GetBundles();
|
2006-05-17 02:25:34 +00:00
|
|
|
}
|
2006-05-17 02:22:36 +00:00
|
|
|
|
2006-05-17 02:25:34 +00:00
|
|
|
catch(ex) {
|
|
|
|
}
|
2006-05-17 02:22:36 +00:00
|
|
|
|
2006-05-17 02:27:51 +00:00
|
|
|
ReadAvailableLanguages();
|
|
|
|
|
2006-05-17 02:28:01 +00:00
|
|
|
if (!("arguments" in window)) {
|
2006-05-17 02:28:51 +00:00
|
|
|
|
|
|
|
//no caller arguments - load base window
|
|
|
|
|
2006-05-17 02:25:34 +00:00
|
|
|
try {
|
2006-05-17 02:28:51 +00:00
|
|
|
active_languages = document.getElementById('active_languages');
|
|
|
|
active_languages_treeroot = document.getElementById('active_languages_root');
|
2006-05-17 02:25:34 +00:00
|
|
|
} //try
|
|
|
|
|
|
|
|
catch(ex) {
|
|
|
|
} //catch
|
|
|
|
|
|
|
|
try {
|
2006-05-17 02:26:48 +00:00
|
|
|
parent.initPanel('chrome://communicator/content/pref/pref-languages.xul');
|
2006-05-17 02:22:36 +00:00
|
|
|
}
|
|
|
|
|
2006-05-17 02:25:34 +00:00
|
|
|
catch(ex) {
|
|
|
|
//pref service backup
|
|
|
|
} //catch
|
2006-05-17 02:22:36 +00:00
|
|
|
|
2006-05-17 02:30:03 +00:00
|
|
|
pref_string = active_languages.getAttribute("prefvalue");
|
2006-05-17 02:25:40 +00:00
|
|
|
LoadActiveLanguages();
|
2006-05-17 02:30:06 +00:00
|
|
|
SelectLanguage();
|
2006-05-17 02:22:35 +00:00
|
|
|
|
2006-05-17 02:25:34 +00:00
|
|
|
} else {
|
2006-05-17 02:22:36 +00:00
|
|
|
|
2006-05-17 02:25:40 +00:00
|
|
|
//load available languages popup
|
2006-05-17 02:25:34 +00:00
|
|
|
try {
|
2006-05-17 02:22:36 +00:00
|
|
|
|
2006-05-17 02:25:34 +00:00
|
|
|
//add language popup
|
2006-05-17 02:28:51 +00:00
|
|
|
available_languages = document.getElementById('available_languages');
|
2006-05-17 02:25:34 +00:00
|
|
|
available_languages_treeroot = document.getElementById('available_languages_root');
|
2006-05-17 02:28:51 +00:00
|
|
|
active_languages = window.opener.document.getElementById('active_languages');
|
|
|
|
active_languages_treeroot = window.opener.document.getElementById('active_languages_root');
|
|
|
|
pref_string = window.opener.document.getElementById('intlAcceptLanguages').label;
|
2006-05-17 02:25:34 +00:00
|
|
|
|
|
|
|
} //try
|
|
|
|
|
|
|
|
catch(ex) {
|
2006-05-17 02:25:40 +00:00
|
|
|
} //catch
|
|
|
|
|
2006-05-17 02:27:52 +00:00
|
|
|
LoadAvailableLanguages();
|
2006-05-17 02:25:34 +00:00
|
|
|
}
|
2006-05-17 02:22:36 +00:00
|
|
|
}
|
2006-05-17 02:22:35 +00:00
|
|
|
|
|
|
|
|
2006-05-17 02:28:51 +00:00
|
|
|
function AddLanguage()
|
|
|
|
{
|
2006-05-17 02:25:40 +00:00
|
|
|
//cludge: make pref string available from the popup
|
2006-05-17 02:28:51 +00:00
|
|
|
document.getElementById('intlAcceptLanguages').label = pref_string;
|
2006-05-17 02:30:06 +00:00
|
|
|
window.openDialog("chrome://communicator/content/pref/pref-languages-add.xul","_blank","modal,chrome,centerscreen,resizable=yes,titlebar", "addlangwindow");
|
2006-05-17 02:25:40 +00:00
|
|
|
UpdateSavePrefString();
|
2006-05-17 02:28:01 +00:00
|
|
|
SelectLanguage();
|
2006-05-17 02:22:35 +00:00
|
|
|
}
|
|
|
|
|
2006-05-17 02:22:36 +00:00
|
|
|
|
2006-05-17 02:22:35 +00:00
|
|
|
function ReadAvailableLanguages()
|
|
|
|
{
|
|
|
|
|
2006-05-17 02:28:51 +00:00
|
|
|
availLanguageDict = new Array();
|
2006-05-17 02:25:34 +00:00
|
|
|
var visible = new String();
|
2006-05-17 02:22:36 +00:00
|
|
|
var str = new String();
|
|
|
|
var i =0;
|
|
|
|
|
2006-05-17 02:28:51 +00:00
|
|
|
var acceptedBundleEnum = acceptedBundle.getSimpleEnumeration();
|
2006-05-17 02:27:51 +00:00
|
|
|
|
|
|
|
var curItem;
|
2006-05-17 02:28:51 +00:00
|
|
|
var stringName;
|
|
|
|
var stringNameProperty;
|
2006-05-17 02:22:36 +00:00
|
|
|
|
2006-05-17 02:28:51 +00:00
|
|
|
while (acceptedBundleEnum.hasMoreElements()) {
|
2006-05-17 02:22:36 +00:00
|
|
|
|
2006-05-17 02:28:51 +00:00
|
|
|
//progress through the bundle
|
|
|
|
curItem = acceptedBundleEnum.getNext();
|
2006-05-17 02:22:36 +00:00
|
|
|
|
2006-05-17 02:28:51 +00:00
|
|
|
//"unpack" the item, nsIPropertyElement is now partially scriptable
|
|
|
|
curItem = curItem.QueryInterface(Components.interfaces.nsIPropertyElement);
|
2006-05-17 02:22:36 +00:00
|
|
|
|
2006-05-17 02:28:51 +00:00
|
|
|
//dump string name (key)
|
2006-05-17 02:31:40 +00:00
|
|
|
stringName = curItem.key;
|
2006-05-17 02:22:36 +00:00
|
|
|
stringNameProperty = stringName.split('.');
|
|
|
|
|
|
|
|
if (stringNameProperty[1] == 'accept') {
|
|
|
|
|
2006-05-17 02:28:51 +00:00
|
|
|
//dump the UI string (value)
|
2006-05-17 02:31:40 +00:00
|
|
|
visible = curItem.value;
|
2006-05-17 02:22:36 +00:00
|
|
|
|
2006-05-17 02:25:34 +00:00
|
|
|
//if (visible == 'true') {
|
2006-05-17 02:22:36 +00:00
|
|
|
|
|
|
|
str = stringNameProperty[0];
|
2006-05-17 02:27:51 +00:00
|
|
|
var stringLangRegion = stringNameProperty[0].split('-');
|
2006-05-17 02:28:51 +00:00
|
|
|
|
2006-05-17 02:22:36 +00:00
|
|
|
if (stringLangRegion[0]) {
|
2006-05-17 02:27:51 +00:00
|
|
|
var tit;
|
2006-05-17 02:28:51 +00:00
|
|
|
try {
|
2006-05-17 02:27:51 +00:00
|
|
|
tit = languagesBundle.GetStringFromName(stringLangRegion[0]);
|
2006-05-17 02:22:36 +00:00
|
|
|
}
|
2006-05-17 02:28:51 +00:00
|
|
|
|
2006-05-17 02:22:36 +00:00
|
|
|
catch (ex) {
|
2006-05-17 02:27:51 +00:00
|
|
|
tit = "";
|
2006-05-17 02:22:36 +00:00
|
|
|
}
|
2006-05-17 02:25:34 +00:00
|
|
|
|
|
|
|
|
2006-05-17 02:27:51 +00:00
|
|
|
if (stringLangRegion.length > 1) {
|
2006-05-17 02:28:51 +00:00
|
|
|
|
|
|
|
try {
|
2006-05-17 02:27:51 +00:00
|
|
|
tit += "/" + regionsBundle.GetStringFromName(stringLangRegion[1]);
|
2006-05-17 02:25:34 +00:00
|
|
|
}
|
2006-05-17 02:28:51 +00:00
|
|
|
|
2006-05-17 02:25:34 +00:00
|
|
|
catch (ex) {
|
2006-05-17 02:28:51 +00:00
|
|
|
tit += "["+str+"]";
|
2006-05-17 02:25:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} //if region
|
|
|
|
|
|
|
|
tit = tit + " [" + str + "]";
|
|
|
|
|
2006-05-17 02:22:36 +00:00
|
|
|
} //if language
|
2006-05-17 02:28:51 +00:00
|
|
|
|
2006-05-17 02:27:51 +00:00
|
|
|
if (str && tit) {
|
|
|
|
|
2006-05-17 02:28:51 +00:00
|
|
|
availLanguageDict[i] = new Array(3);
|
|
|
|
availLanguageDict[i][0] = tit;
|
|
|
|
availLanguageDict[i][1] = str;
|
|
|
|
availLanguageDict[i][2] = visible;
|
2006-05-17 02:22:36 +00:00
|
|
|
i++;
|
2006-05-17 02:28:51 +00:00
|
|
|
|
2006-05-17 02:22:36 +00:00
|
|
|
} // if str&tit
|
2006-05-17 02:25:34 +00:00
|
|
|
//} //if visible
|
2006-05-17 02:28:51 +00:00
|
|
|
} //if accepted
|
2006-05-17 02:27:51 +00:00
|
|
|
} //while
|
2006-05-17 02:30:07 +00:00
|
|
|
availLanguageDict.sort( // sort on first element
|
|
|
|
function (a, b) {
|
|
|
|
if (a[0] < b[0]) return -1;
|
|
|
|
if (a[0] > b[0]) return 1;
|
|
|
|
return 0;
|
|
|
|
});
|
2006-05-17 02:22:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function LoadAvailableLanguages()
|
2006-05-17 02:28:51 +00:00
|
|
|
{
|
|
|
|
if (availLanguageDict)
|
2006-05-17 02:27:51 +00:00
|
|
|
for (var i = 0; i < availLanguageDict.length; i++) {
|
2006-05-17 02:22:35 +00:00
|
|
|
|
2006-05-17 02:28:51 +00:00
|
|
|
if (availLanguageDict[i][2] == 'true') {
|
2006-05-17 02:22:35 +00:00
|
|
|
|
2006-05-17 02:25:34 +00:00
|
|
|
AddTreeItem(document, available_languages_treeroot, availLanguageDict[i][1], availLanguageDict[i][0]);
|
2006-05-17 02:28:51 +00:00
|
|
|
|
2006-05-17 02:25:34 +00:00
|
|
|
} //if
|
2006-05-17 02:22:35 +00:00
|
|
|
|
2006-05-17 02:27:51 +00:00
|
|
|
} //for
|
2006-05-17 02:22:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function LoadActiveLanguages()
|
|
|
|
{
|
2006-05-17 02:28:01 +00:00
|
|
|
if (pref_string) {
|
2006-05-17 02:30:04 +00:00
|
|
|
var arrayOfPrefs = pref_string.split(separatorRe);
|
2006-05-17 02:22:35 +00:00
|
|
|
|
2006-05-17 02:28:01 +00:00
|
|
|
for (var i = 0; i < arrayOfPrefs.length; i++) {
|
2006-05-17 02:27:51 +00:00
|
|
|
var str = arrayOfPrefs[i];
|
|
|
|
var tit = GetLanguageTitle(str);
|
2006-05-17 02:28:51 +00:00
|
|
|
|
2006-05-17 02:27:51 +00:00
|
|
|
if (str) {
|
2006-05-17 02:28:51 +00:00
|
|
|
if (!tit)
|
2006-05-17 02:26:53 +00:00
|
|
|
tit = '[' + str + ']';
|
2006-05-17 02:25:34 +00:00
|
|
|
AddTreeItem(document, active_languages_treeroot, str, tit);
|
2006-05-17 02:22:35 +00:00
|
|
|
|
2006-05-17 02:28:51 +00:00
|
|
|
} //if
|
2006-05-17 02:27:51 +00:00
|
|
|
} //for
|
2006-05-17 02:28:01 +00:00
|
|
|
}
|
2006-05-17 02:22:36 +00:00
|
|
|
}
|
2006-05-17 02:22:35 +00:00
|
|
|
|
|
|
|
|
2006-05-17 02:25:34 +00:00
|
|
|
function LangAlreadyActive(langId)
|
2006-05-17 02:22:36 +00:00
|
|
|
{
|
2006-05-17 02:26:52 +00:00
|
|
|
var found = false;
|
2006-05-17 02:22:36 +00:00
|
|
|
try {
|
2006-05-17 02:30:04 +00:00
|
|
|
var arrayOfPrefs = pref_string.split(separatorRe);
|
2006-05-17 02:26:52 +00:00
|
|
|
|
2006-05-17 02:28:51 +00:00
|
|
|
if (arrayOfPrefs)
|
2006-05-17 02:27:51 +00:00
|
|
|
for (var i = 0; i < arrayOfPrefs.length; i++) {
|
2006-05-17 02:26:52 +00:00
|
|
|
if (arrayOfPrefs[i] == langId) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return found;
|
2006-05-17 02:22:36 +00:00
|
|
|
}
|
2006-05-17 02:22:35 +00:00
|
|
|
|
2006-05-17 02:25:34 +00:00
|
|
|
catch(ex){
|
|
|
|
return false;
|
2006-05-17 02:22:36 +00:00
|
|
|
}
|
2006-05-17 02:22:35 +00:00
|
|
|
}
|
|
|
|
|
2006-05-17 02:27:51 +00:00
|
|
|
function isAlpha(mixedCase) {
|
|
|
|
var allCaps = mixedCase.toUpperCase();
|
|
|
|
for (var i = allCaps.length - 1; i >= 0; i--) {
|
|
|
|
var c = allCaps.charAt(i);
|
|
|
|
if (c < 'A' || c > 'Z') return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function isAlphaNum(mixedCase) {
|
|
|
|
var allCaps = mixedCase.toUpperCase();
|
|
|
|
for (var i = allCaps.length - 1; i >= 0; i--) {
|
|
|
|
var c = allCaps.charAt(i);
|
|
|
|
if ((c < 'A' || c > 'Z') && (c < '0' || c > '9')) return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function IsRFC1766LangTag(candidate) {
|
|
|
|
/* Valid language codes examples:
|
|
|
|
i.e. ja-JP-kansai (Kansai dialect of Japanese)
|
|
|
|
en-US-texas (Texas dialect)
|
|
|
|
i-klingon-tng (did TOS Klingons speak in non-English?)
|
|
|
|
sgn-US-MA (Martha Vineyard's Sign Language)
|
|
|
|
*/
|
|
|
|
var tags = candidate.split('-');
|
|
|
|
|
|
|
|
/* if not IANA "i" or a private "x" extension, the primary
|
|
|
|
tag should be a ISO 639 country code, two or three letters long.
|
|
|
|
we don't check if the country code is bogus or not.
|
|
|
|
*/
|
|
|
|
var checkedTags = 0;
|
|
|
|
if (tags[0].toLowerCase() != "x" && tags[0].toLowerCase() != "i") {
|
|
|
|
if (tags[0].length != 2 && tags[0].length != 3) return false;
|
|
|
|
if (!isAlpha(tags[0])) return false;
|
|
|
|
checkedTags++;
|
|
|
|
|
|
|
|
/* the first subtag can be either a 2 letter ISO 3166 country code,
|
|
|
|
or an IANA registered tag from 3 to 8 characters.
|
|
|
|
*/
|
|
|
|
if (tags.length > 1) {
|
|
|
|
if (tags[1].length < 2 || tags[1].length > 3) return false;
|
|
|
|
if (!isAlphaNum(tags[1])) return false;
|
|
|
|
|
|
|
|
/* do not allow user-assigned ISO 3166 country codes */
|
|
|
|
if (tags[1].length == 2 && isAlpha(tags[1])) {
|
|
|
|
var countryCode = tags[1].toUpperCase();
|
|
|
|
if (countryCode == "AA" || countryCode == "ZZ") return false;
|
|
|
|
if (countryCode[0] == 'X') return false;
|
|
|
|
if (countryCode[0] == 'Q' && countryCode[1] > 'L') return false;
|
|
|
|
}
|
|
|
|
checkedTags++;
|
2006-05-17 02:28:51 +00:00
|
|
|
}
|
2006-05-17 02:27:51 +00:00
|
|
|
}
|
|
|
|
else if (tags.length < 2) return false;
|
|
|
|
else {
|
|
|
|
if ((tags[1].length < 1) || (tags[1].length > 8)) return false;
|
|
|
|
if (!isAlphaNum(tags[1])) return false;
|
|
|
|
checkedTags++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* any remaining subtags must be one to eight alphabetic characters */
|
|
|
|
|
|
|
|
for (var i = checkedTags; i < tags.length; i++) {
|
|
|
|
if ((tags[1].length < 1) || (tags[i].length > 8)) return false;
|
|
|
|
if (!isAlphaNum(tags[i])) return false;
|
|
|
|
checkedTags++;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2006-05-17 02:22:35 +00:00
|
|
|
|
|
|
|
function AddAvailableLanguage()
|
|
|
|
{
|
2006-05-17 02:25:34 +00:00
|
|
|
var Languagename = new String();
|
2006-05-17 02:28:51 +00:00
|
|
|
var Languageid = new String();
|
2006-05-17 02:22:35 +00:00
|
|
|
|
2006-05-17 02:25:34 +00:00
|
|
|
|
|
|
|
//selected languages
|
2006-05-17 02:22:35 +00:00
|
|
|
for (var nodeIndex=0; nodeIndex < available_languages.selectedItems.length; nodeIndex++) {
|
2006-05-17 02:28:51 +00:00
|
|
|
|
2006-05-17 02:22:35 +00:00
|
|
|
var selItem = available_languages.selectedItems[nodeIndex];
|
|
|
|
var selRow = selItem.firstChild;
|
|
|
|
var selCell = selRow.firstChild;
|
|
|
|
|
2006-05-17 02:28:51 +00:00
|
|
|
Languagename = selCell.getAttribute('label');
|
|
|
|
Languageid = selCell.getAttribute('id');
|
|
|
|
|
2006-05-17 02:25:34 +00:00
|
|
|
if (!LangAlreadyActive(Languageid)) {
|
2006-05-17 02:22:35 +00:00
|
|
|
|
2006-05-17 02:25:34 +00:00
|
|
|
AddTreeItem(window.opener.document, active_languages_treeroot, Languageid, Languagename);
|
2006-05-17 02:22:35 +00:00
|
|
|
|
2006-05-17 02:28:51 +00:00
|
|
|
}//if
|
2006-05-17 02:22:35 +00:00
|
|
|
|
|
|
|
} //loop selected languages
|
|
|
|
|
|
|
|
|
2006-05-17 02:25:34 +00:00
|
|
|
//user-defined languages
|
|
|
|
var otherField = document.getElementById( "languages.other" );
|
2006-05-17 02:28:51 +00:00
|
|
|
|
2006-05-17 02:25:34 +00:00
|
|
|
if (otherField.value) {
|
|
|
|
|
2006-05-17 02:27:51 +00:00
|
|
|
/* reject bogus lang strings, INCLUDING those with HTTP "q"
|
|
|
|
values kludged on the end of them
|
|
|
|
*/
|
|
|
|
if (!IsRFC1766LangTag(otherField.value)) {
|
|
|
|
window.alert(prefLangBundle.GetStringFromName("illegalOtherLanguage"));
|
|
|
|
return false;
|
|
|
|
}
|
2006-05-17 02:28:51 +00:00
|
|
|
|
|
|
|
Languageid = otherField.value;
|
2006-05-17 02:25:34 +00:00
|
|
|
Languageid = Languageid.toLowerCase();
|
2006-05-17 02:28:51 +00:00
|
|
|
Languagename = GetLanguageTitle(Languageid);
|
2006-05-17 02:27:48 +00:00
|
|
|
if (!Languagename)
|
|
|
|
Languagename = '[' + Languageid + ']';
|
2006-05-17 02:28:51 +00:00
|
|
|
|
2006-05-17 02:25:34 +00:00
|
|
|
if (!LangAlreadyActive(Languageid)) {
|
2006-05-17 02:22:35 +00:00
|
|
|
|
2006-05-17 02:25:34 +00:00
|
|
|
AddTreeItem(window.opener.document, active_languages_treeroot, Languageid, Languagename);
|
2006-05-17 02:22:35 +00:00
|
|
|
|
2006-05-17 02:28:51 +00:00
|
|
|
}//if
|
2006-05-17 02:25:34 +00:00
|
|
|
}
|
2006-05-17 02:22:35 +00:00
|
|
|
|
2006-05-17 02:32:32 +00:00
|
|
|
available_languages.clearSelection();
|
2006-05-17 02:27:51 +00:00
|
|
|
return true;
|
2006-05-17 02:22:35 +00:00
|
|
|
} //AddAvailableLanguage
|
|
|
|
|
2006-05-17 02:28:00 +00:00
|
|
|
function HandleDoubleClick(node)
|
|
|
|
{
|
|
|
|
var languageId = node.id;
|
2006-05-17 02:28:51 +00:00
|
|
|
var languageName = node.getAttribute('label');
|
2006-05-17 02:28:00 +00:00
|
|
|
|
|
|
|
if (languageName && languageName.length > 0)
|
|
|
|
{
|
|
|
|
if (!LangAlreadyActive(languageId)) {
|
|
|
|
AddTreeItem(window.opener.document, active_languages_treeroot, languageId, languageName);
|
|
|
|
}
|
|
|
|
window.close();
|
|
|
|
}//if
|
|
|
|
} //HandleDoubleClick
|
2006-05-17 02:22:35 +00:00
|
|
|
|
|
|
|
function RemoveActiveLanguage()
|
|
|
|
{
|
2006-05-17 02:25:34 +00:00
|
|
|
|
2006-05-17 02:22:35 +00:00
|
|
|
var nextNode = null;
|
2006-05-17 02:25:34 +00:00
|
|
|
var numSelected = active_languages.selectedItems.length;
|
2006-05-17 02:22:35 +00:00
|
|
|
var deleted_all = false;
|
|
|
|
|
2006-05-17 02:25:34 +00:00
|
|
|
while (active_languages.selectedItems.length > 0) {
|
2006-05-17 02:28:51 +00:00
|
|
|
|
|
|
|
var selectedNode = active_languages.selectedItems[0];
|
2006-05-17 02:22:35 +00:00
|
|
|
nextNode = selectedNode.nextSibling;
|
2006-05-17 02:28:51 +00:00
|
|
|
|
|
|
|
if (!nextNode)
|
|
|
|
|
|
|
|
if (selectedNode.previousSibling)
|
|
|
|
nextNode = selectedNode.previousSibling;
|
|
|
|
|
2006-05-17 02:22:35 +00:00
|
|
|
var row = selectedNode.firstChild;
|
|
|
|
var cell = row.firstChild;
|
|
|
|
|
2006-05-17 02:28:51 +00:00
|
|
|
row.removeChild(cell);
|
|
|
|
selectedNode.removeChild(row);
|
2006-05-17 02:22:35 +00:00
|
|
|
active_languages_treeroot.removeChild(selectedNode);
|
|
|
|
|
|
|
|
} //while
|
2006-05-17 02:28:51 +00:00
|
|
|
|
2006-05-17 02:22:35 +00:00
|
|
|
if (nextNode) {
|
2006-05-17 02:25:34 +00:00
|
|
|
active_languages.selectItem(nextNode)
|
2006-05-17 02:22:35 +00:00
|
|
|
} else {
|
2006-05-17 02:32:32 +00:00
|
|
|
//active_languages.clearSelection();
|
2006-05-17 02:22:35 +00:00
|
|
|
}
|
2006-05-17 02:25:34 +00:00
|
|
|
|
2006-05-17 02:25:40 +00:00
|
|
|
UpdateSavePrefString();
|
2006-05-17 02:25:34 +00:00
|
|
|
|
2006-05-17 02:22:35 +00:00
|
|
|
} //RemoveActiveLanguage
|
|
|
|
|
|
|
|
|
2006-05-17 02:28:51 +00:00
|
|
|
function GetLanguageTitle(id)
|
2006-05-17 02:25:34 +00:00
|
|
|
{
|
2006-05-17 02:28:51 +00:00
|
|
|
|
|
|
|
if (availLanguageDict)
|
2006-05-17 02:27:51 +00:00
|
|
|
for (var j = 0; j < availLanguageDict.length; j++) {
|
|
|
|
|
2006-05-17 02:28:51 +00:00
|
|
|
if ( availLanguageDict[j][1] == id) {
|
|
|
|
//title =
|
|
|
|
return availLanguageDict[j][0];
|
|
|
|
}
|
2006-05-17 02:27:51 +00:00
|
|
|
}
|
|
|
|
return '';
|
2006-05-17 02:25:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function AddTreeItem(doc, treeRoot, langID, langTitle)
|
|
|
|
{
|
2006-05-17 02:28:51 +00:00
|
|
|
try { //let's beef up our error handling for languages without label / title
|
2006-05-17 02:25:34 +00:00
|
|
|
|
2006-05-17 02:28:51 +00:00
|
|
|
// Create a treerow for the new Language
|
|
|
|
var item = doc.createElement('treeitem');
|
|
|
|
var row = doc.createElement('treerow');
|
|
|
|
var cell = doc.createElement('treecell');
|
2006-05-17 02:25:34 +00:00
|
|
|
|
2006-05-17 02:28:51 +00:00
|
|
|
// Copy over the attributes
|
|
|
|
cell.setAttribute('label', langTitle);
|
|
|
|
cell.setAttribute('id', langID);
|
2006-05-17 02:25:34 +00:00
|
|
|
|
2006-05-17 02:28:51 +00:00
|
|
|
// Add it to the active languages tree
|
|
|
|
item.appendChild(row);
|
|
|
|
row.appendChild(cell);
|
2006-05-17 02:25:34 +00:00
|
|
|
|
2006-05-17 02:28:51 +00:00
|
|
|
treeRoot.appendChild(item);
|
2006-05-17 02:25:34 +00:00
|
|
|
|
2006-05-17 02:28:51 +00:00
|
|
|
} //try
|
2006-05-17 02:25:34 +00:00
|
|
|
|
2006-05-17 02:28:51 +00:00
|
|
|
catch (ex) {
|
|
|
|
} //catch
|
2006-05-17 02:25:34 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-17 02:25:40 +00:00
|
|
|
function UpdateSavePrefString()
|
2006-05-17 02:25:34 +00:00
|
|
|
{
|
|
|
|
var num_languages = 0;
|
2006-05-17 02:30:05 +00:00
|
|
|
pref_string = "";
|
2006-05-17 02:25:34 +00:00
|
|
|
|
|
|
|
for (var item = active_languages_treeroot.firstChild; item != null; item = item.nextSibling) {
|
|
|
|
|
2006-05-17 02:27:51 +00:00
|
|
|
var row = item.firstChild;
|
|
|
|
var cell = row.firstChild;
|
|
|
|
var languageid = cell.getAttribute('id');
|
2006-05-17 02:25:34 +00:00
|
|
|
|
2006-05-17 02:28:51 +00:00
|
|
|
if (languageid.length > 1) {
|
|
|
|
|
2006-05-17 02:25:34 +00:00
|
|
|
num_languages++;
|
|
|
|
|
2006-05-17 02:28:51 +00:00
|
|
|
//separate >1 languages by commas
|
|
|
|
if (num_languages > 1) {
|
|
|
|
pref_string = pref_string + "," + " " + languageid;
|
|
|
|
} else {
|
|
|
|
pref_string = languageid;
|
|
|
|
} //if
|
|
|
|
} //if
|
2006-05-17 02:25:34 +00:00
|
|
|
}//for
|
|
|
|
|
2006-05-17 02:30:03 +00:00
|
|
|
active_languages.setAttribute("prefvalue", pref_string);
|
2006-05-17 02:25:34 +00:00
|
|
|
}
|
|
|
|
|
2006-05-17 02:22:35 +00:00
|
|
|
|
|
|
|
function MoveUp() {
|
2006-05-17 02:25:34 +00:00
|
|
|
|
|
|
|
if (active_languages.selectedItems.length == 1) {
|
|
|
|
var selected = active_languages.selectedItems[0];
|
2006-05-17 02:22:35 +00:00
|
|
|
var before = selected.previousSibling
|
|
|
|
if (before) {
|
|
|
|
before.parentNode.insertBefore(selected, before);
|
2006-05-17 02:25:34 +00:00
|
|
|
active_languages.selectItem(selected);
|
|
|
|
active_languages.ensureElementIsVisible(selected);
|
2006-05-17 02:22:35 +00:00
|
|
|
}
|
|
|
|
}
|
2006-05-17 02:32:34 +00:00
|
|
|
|
|
|
|
if (active_languages.selectedIndex == 0)
|
|
|
|
{
|
|
|
|
// selected item is first
|
|
|
|
var moveUp = document.getElementById("up");
|
|
|
|
moveUp.disabled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (active_languages_treeroot.childNodes.length > 1)
|
|
|
|
{
|
|
|
|
// more than one item so we can move selected item back down
|
|
|
|
var moveDown = document.getElementById("down");
|
|
|
|
moveDown.disabled = false;
|
|
|
|
}
|
2006-05-17 02:22:35 +00:00
|
|
|
|
2006-05-17 02:25:40 +00:00
|
|
|
UpdateSavePrefString();
|
2006-05-17 02:25:34 +00:00
|
|
|
|
2006-05-17 02:22:35 +00:00
|
|
|
} //MoveUp
|
|
|
|
|
2006-05-17 02:28:51 +00:00
|
|
|
|
2006-05-17 02:22:35 +00:00
|
|
|
function MoveDown() {
|
2006-05-17 02:25:34 +00:00
|
|
|
|
|
|
|
if (active_languages.selectedItems.length == 1) {
|
|
|
|
var selected = active_languages.selectedItems[0];
|
2006-05-17 02:22:35 +00:00
|
|
|
if (selected.nextSibling) {
|
|
|
|
if (selected.nextSibling.nextSibling) {
|
|
|
|
selected.parentNode.insertBefore(selected, selected.nextSibling.nextSibling);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
selected.parentNode.appendChild(selected);
|
|
|
|
}
|
2006-05-17 02:25:34 +00:00
|
|
|
active_languages.selectItem(selected);
|
2006-05-17 02:22:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-17 02:32:34 +00:00
|
|
|
if (active_languages.selectedIndex ==
|
|
|
|
(active_languages_treeroot.childNodes.length - 1))
|
|
|
|
{
|
|
|
|
// selected item is last
|
|
|
|
var moveDown = document.getElementById("down");
|
|
|
|
moveDown.disabled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (active_languages_treeroot.childNodes.length > 1)
|
|
|
|
{
|
|
|
|
// more than one item so we can move selected item back up
|
|
|
|
var moveUp = document.getElementById("up");
|
|
|
|
moveUp.disabled = false;
|
|
|
|
}
|
|
|
|
|
2006-05-17 02:25:40 +00:00
|
|
|
UpdateSavePrefString();
|
2006-05-17 02:25:34 +00:00
|
|
|
|
2006-05-17 02:22:35 +00:00
|
|
|
} //MoveDown
|
2006-05-17 02:28:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
function SelectLanguage() {
|
|
|
|
if (active_languages.selectedItems.length) {
|
|
|
|
document.getElementById("remove").disabled = false;
|
|
|
|
var selected = active_languages.selectedItems[0];
|
|
|
|
document.getElementById("down").disabled = !selected.nextSibling;
|
|
|
|
|
|
|
|
document.getElementById("up").disabled = !selected.previousSibling;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
document.getElementById("remove").disabled = true;
|
|
|
|
document.getElementById("down").disabled = true;
|
|
|
|
document.getElementById("up").disabled = true;
|
|
|
|
}
|
2006-05-17 02:29:28 +00:00
|
|
|
|
|
|
|
if (parent.hPrefWindow.getPrefIsLocked(document.getElementById("up").getAttribute("prefstring")))
|
|
|
|
document.getElementById("up").disabled = true;
|
|
|
|
if (parent.hPrefWindow.getPrefIsLocked(document.getElementById("down").getAttribute("prefstring")))
|
|
|
|
document.getElementById("down").disabled = true;
|
|
|
|
if (parent.hPrefWindow.getPrefIsLocked(document.getElementById("add").getAttribute("prefstring")))
|
|
|
|
document.getElementById("add").disabled = true;
|
|
|
|
if (parent.hPrefWindow.getPrefIsLocked(document.getElementById("remove").getAttribute("prefstring")))
|
|
|
|
document.getElementById("remove").disabled = true;
|
2006-05-17 02:28:01 +00:00
|
|
|
} // SelectLanguage
|