# HG changeset patch # Parent 888ab93ad3f027b64ffd5283b5c8a36629709a81 # User Marco Bonardo diff --git a/browser/base/content/aboutHome.js b/browser/base/content/aboutHome.js new file mode 100644 --- /dev/null +++ b/browser/base/content/aboutHome.js @@ -0,0 +1,104 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * 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 aboutHome.xhtml. + * + * The Initial Developer of the Original Code is the Mozilla Foundation. + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Marco Bonardo (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifdef MOZ_OFFICIAL_BRANDING +const MOZ_OFFICIAL = "official"; +#else +const MOZ_OFFICIAL = "unofficial"; +#endif +#expand const MOZ_DISTRIBUTION_ID = "__MOZ_DISTRIBUTION_ID__"; +const MOZ_CLIENT = MOZ_OFFICIAL === "official" ? "firefox-a" : "firefox"; + +let gSearchEngine = SEARCH_ENGINES[0]; // Fallback to the first engine. + + +function onLoad(event) +{ + setupSearchEngine(); + document.searchForm.searchText.focus(); +} + + +function onSearchSubmit(event) { + let searchTerms = document.searchForm.searchText.value; + if (searchTerms.length > 0) { + window.location.href = parseSearchEngineUrl(gSearchEngine.searchurl, + searchTerms); + } + event.preventDefault(); +} + + +function setupSearchEngine() { + for (let i = 0; i < SEARCH_ENGINES.length; i++) { + let localizedEngine = SEARCH_ENGINES[i].locales.indexOf(gUILocale) != -1; + if (localizedEngine) { + gSearchEngine = SEARCH_ENGINES[i]; + break; + } + } + + // Set logo source. + let logoElt = document.getElementById("searchEngineLogo"); + logoElt.src = gSearchEngine.image; + + // Add search engine links. + let linksElt = document.getElementById("searchEngineLinks"); + gSearchEngine.links.forEach(function(aLink) { + let linkElt = document.createElement('a'); + linkElt.href = parseSearchEngineUrl(aLink.href); + linkElt.appendChild(document.createTextNode(gEngineLinksLabels[aLink.id])); + linksElt.appendChild(linkElt); + }); +} + + +function parseSearchEngineUrl(aUrl, aTerms) { + const SEARCH_TOKENS = { + "{moz:client}": MOZ_CLIENT + , "{moz:official}": MOZ_OFFICIAL + , "{moz:distributionID}": MOZ_DISTRIBUTION_ID + , "{moz:locale}": gUILocale + , "{locale}": gSearchEngine.convertLocale(gUILocale) + , "{searchTerms}": typeof(aTerms) == "string" ? encodeURIComponent(aTerms) : "" + } + for (let key in SEARCH_TOKENS) { + aUrl = aUrl.replace(key, SEARCH_TOKENS[key]); + } + return aUrl; +} diff --git a/browser/base/content/aboutHome.xhtml b/browser/base/content/aboutHome.xhtml new file mode 100644 --- /dev/null +++ b/browser/base/content/aboutHome.xhtml @@ -0,0 +1,102 @@ + + +# ***** BEGIN LICENSE BLOCK ***** +# Version: MPL 1.1/GPL 2.0/LGPL 2.1 +# +# 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 aboutHome.xhtml. +# +# The Initial Developer of the Original Code is the Mozilla Foundation. +# Portions created by the Initial Developer are Copyright (C) 2010 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# Marco Bonardo (original author) +# +# Alternatively, the contents of this file may be used under the terms of +# either the GNU General Public License Version 2 or later (the "GPL"), or +# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), +# in which case the provisions of the GPL or the LGPL are applicable instead +# of those above. If you wish to allow use of your version of this file only +# under the terms of either the GPL or the LGPL, and not to allow others to +# use your version of this file under the terms of the MPL, indicate your +# decision by deleting the provisions above and replace them with the notice +# and other provisions required by the GPL or the LGPL. If you do not delete +# the provisions above, a recipient may use your version of this file under +# the terms of any one of the MPL, the GPL or the LGPL. +# +# ***** END LICENSE BLOCK ***** + + + %htmlDTD; + + %globalDTD; + + %aboutHomeDTD; +]> + + + + &abouthome.pageTitle; + + + +