unicorn commit: ~ dropdown menu for language selection instead of list

changeset:   1429:12b0b32da7cc
tag:         tip
user:        Thomas Gambet <tgambet@w3.org>
date:        Thu Aug 05 22:09:42 2010 -0400
files:       WebContent/WEB-INF/resources/templates/includes/footer.vm WebContent/scripts/w3c_unicorn_index.js WebContent/scripts/w3c_unicorn_results.js WebContent/style/base_ucn.css src/org/w3c/unicorn/Framework.java src/org/w3c/unicorn/action/IndexAction.java src/org/w3c/unicorn/action/ObserveAction.java
description:
~ dropdown menu for language selection instead of list


diff -r 77c330f4173e -r 12b0b32da7cc WebContent/WEB-INF/resources/templates/includes/footer.vm
--- a/WebContent/WEB-INF/resources/templates/includes/footer.vm	Thu Aug 05 15:28:10 2010 +0200
+++ b/WebContent/WEB-INF/resources/templates/includes/footer.vm	Thu Aug 05 22:09:42 2010 -0400
@@ -4,21 +4,30 @@
 			<li><a href="http://code.w3.org/unicorn/#Feedback" title="$feedback_title">$feedback</a></li>
 			<li><a href="${baseUri}translations" hreflang="en" title="$translations_title">$translations</a></li>
 	</ul>
-	<ul id="lang_choice">
+	<form action="$!{language_action}" method="get" id="lang_choice">
+		<fieldset>
+#foreach( $key in $requestParameters.keySet() )
+	#if($key != 'ucn_lang')
+	<input type="hidden" name="$key" value="$requestParameters.get($key)"/>
+	#end
+#end
+		<select name="ucn_lang">
 #foreach( $locale in $languages )
 #if ($locale.getName() != "lolcat" && $locale.getName() != "l33t" && $locale.getName() != "buccaneer")
-		<li>
-			#set($localeName = $strUtils.capitalize($locale.getDisplayName($locale)))
-			#if ($locale.getName() == $lang)
-			$localeName
-			#else
-			#set($langKey = $strUtils.replace($locale.getName(), '_', '-'))
-			<a href="${queryString}ucn_lang=$langKey" lang="$langKey" xml:lang="$langKey" hreflang="$langKey" rel="alternate">$localeName</a>
-			#end
-		</li>
+#set($localeName = $locale.getDisplayName($locale))
+#if ($locale.getName() == $lang)
+			<option value="$lang" selected="selected">$localeName</option>
+#else
+#set($langKey = $strUtils.replace($locale.getName(), '_', '-'))
+			<option value="$langKey">$localeName ($locale.getDisplayName($currentLocale))</option>
 #end
 #end
-	</ul>
+#end
+		</select>
+		<input id="lang_change" type="submit" value="OK" />
+		</fieldset>
+	</form>
+	
 	<div id="footer">
 		<p id="activity_logos">
 			<a href="http://www.w3.org/Status" title="$download_title">
diff -r 77c330f4173e -r 12b0b32da7cc WebContent/scripts/w3c_unicorn_index.js
--- a/WebContent/scripts/w3c_unicorn_index.js	Thu Aug 05 15:28:10 2010 +0200
+++ b/WebContent/scripts/w3c_unicorn_index.js	Thu Aug 05 22:09:42 2010 -0400
@@ -11,6 +11,8 @@
 		W3C.TaskOptions = W3C.TaskSelect.getChildren('option');
 		W3C.TaskDescrip = $('task_descrip');
 		W3C.TaskInputs = $$('input.task');
+		
+		W3C.LanguagesForm = $('lang_choice');
 		
 		W3C.LangParameter = $$('html').getProperty('lang')[0];
 		
@@ -39,11 +41,16 @@
 	prepareDocument: function(){
 		
 		$$('input#task_change').setStyle('display', 'none');
+		$$('input#lang_change').setStyle('display', 'none');
 		
 		W3C.TaskSelect.addEvent('change', function (event) {
 			event.stop();
 			W3C.selectTask(this.selectedIndex, true);
 			W3C.updateHash();
+		});
+		
+		W3C.LanguagesForm.addEvent('change', function(event) {
+			window.location = "./" + W3C.LanguagesForm.getProperty('action') + "?" + this.toQueryString() + window.location.hash;
 		});
 		
 		W3C.TabLinks.each(function(link, i) {
@@ -73,12 +80,6 @@
 			}
 		});
 		
-		$$('ul#lang_choice').getElements('a').each(function (a) {
-			a.addEvent('click', function(event) {
-				this.setProperty('href', this.getProperty('href') +  window.location.hash);
-			});
-		});
-		
 		W3C.Forms.filter('form[method=get]').each(function (form) {
 			new FormValidator(form, {
 				onFormValidate: function(passed, form, event) {
@@ -100,7 +101,7 @@
 				}
 			});
 		});
-
+		
 	},
 	
 	addOptionEvents: function () {
diff -r 77c330f4173e -r 12b0b32da7cc WebContent/scripts/w3c_unicorn_results.js
--- a/WebContent/scripts/w3c_unicorn_results.js	Thu Aug 05 15:28:10 2010 +0200
+++ b/WebContent/scripts/w3c_unicorn_results.js	Thu Aug 05 22:09:42 2010 -0400
@@ -3,12 +3,18 @@
 var W3C = {
 	
 	start: function() {
-	
+		
 		W3C.cleanHash();
-	
+		
 		W3C.ContextsToShow = 7;
 		
 		W3C.Observers = $$('.observer');
+		
+		$$('input#lang_change').setStyle('display', 'none');
+		W3C.LanguagesForm = $('lang_choice');
+		W3C.LanguagesForm.addEvent('change', function(event) {
+			window.location = "./" + W3C.LanguagesForm.getProperty('action') + "?" + this.toQueryString() + window.location.hash;
+		});
 		
 		var slideDuration = 500;
 		var invalidObservers = $$('.observer.invalid');
@@ -98,8 +104,8 @@
 		});
 		
 		var mySmoothScroll = new Fx.SmoothScroll({
-		    links: '.smooth',
-		    wheelStops: true
+			links: '.smooth',
+			wheelStops: true
 		});
 		
 		W3C.parseHash();
@@ -109,18 +115,18 @@
 		var re = new RegExp(/contextShow:'[^']*'/);
 		var m = re.exec(classes);
 		var s =  "";
-	    for (i = 0; i < m.length; i++) {
-	      s = s + m[i];
-	    }
-	    var showString = s.replace('contextShow:', '').replace(/'/g, '');
-	    
-	    var re = new RegExp(/contextHide:'[^']*'/);
+		for (i = 0; i < m.length; i++) {
+			s = s + m[i];
+		}
+		var showString = s.replace('contextShow:', '').replace(/'/g, '');
+		
+		var re = new RegExp(/contextHide:'[^']*'/);
 		var m = re.exec(classes);
 		var s =  "";
-	    for (i = 0; i < m.length; i++) {
-	      s = s + m[i];
-	    }
-	    var hideString = s.replace('contextHide:', '').replace(/'/g, '');
+		for (i = 0; i < m.length; i++) {
+			s = s + m[i];
+		}
+		var hideString = s.replace('contextHide:', '').replace(/'/g, '');
 		
 		$$('td.message').each(function (td) {
 			if (td.getProperty('rowspan') > W3C.ContextsToShow) {
@@ -180,7 +186,6 @@
 							}
 							
 						});
-						
 					}
 					
 					tr = tr.getNext('tr');
@@ -197,23 +202,23 @@
 	toggle: function(section) {
 		var title = section.getElement('.title');
 		var slide = section.retrieve('fxSlide');
-	    if (section.retrieve('open')) {
-	    	W3C.close(section, true);
-	    } else {
-	    	W3C.open(section, true);
-	    }
+		if (section.retrieve('open')) {
+			W3C.close(section, true);
+		} else {
+			W3C.open(section, true);
+		}
 	},
 	
 	close: function(section, withFx) {
 		var opened = section.retrieve('open');
 		var title = section.getElement('.title');
 		var slide = section.retrieve('fxSlide');
-	    title.removeClass('toggled');
-	    section.store('open', false);
+		title.removeClass('toggled');
+		section.store('open', false);
 		if (withFx && opened) {
 			slide.slideOut().chain(function(){
 				section.getElement('div').setStyle('display', 'none');
-		    	slide.callChain();
+				slide.callChain();
 			});
 		} else {
 			slide.hide();
@@ -225,18 +230,18 @@
 		var closed = !section.retrieve('open');
 		var title = section.getElement('.title');
 		var slide = section.retrieve('fxSlide');
-	    title.addClass('toggled');
-	    section.store('open', true);
-	    section.getElement('div').setStyle('display', '');
-	    if (withFx && closed) {
-	    	slide.slideIn().chain(function(){
-		    	section.getElement('div').setStyle('height', 'auto');
-		    	slide.callChain();
+		title.addClass('toggled');
+		section.store('open', true);
+		section.getElement('div').setStyle('display', '');
+		if (withFx && closed) {
+			slide.slideIn().chain(function(){
+				section.getElement('div').setStyle('height', 'auto');
+				slide.callChain();
 			});
 		} else {
-	    	slide.show();
-	    	section.getElement('div').setStyle('height', 'auto');
-	    }
+			slide.show();
+			section.getElement('div').setStyle('height', 'auto');
+		}
 	},
 	
 	closeAllObserversBut: function(observer, withFx) {
diff -r 77c330f4173e -r 12b0b32da7cc WebContent/style/base_ucn.css
--- a/WebContent/style/base_ucn.css	Thu Aug 05 15:28:10 2010 +0200
+++ b/WebContent/style/base_ucn.css	Thu Aug 05 22:09:42 2010 -0400
@@ -202,19 +202,15 @@
 	text-decoration:underline;
 }
 #lang_choice {
-	margin-right:3em;
-	min-width:40em;
-	padding:0.5em 0;
+	margin-right:2em;
 	position:absolute;
 	right:0;
 	top:0;
-	text-align:right;
+	height:1em;
+}
+#lang_choice select {
 	font-size:0.7em;
-	line-height:100%;
-}
-#lang_choice li {
-	display:inline;
-	padding-left:0.5em;
+	height:2em;
 }
 #menu {
 	text-align:center;
diff -r 77c330f4173e -r 12b0b32da7cc src/org/w3c/unicorn/Framework.java
--- a/src/org/w3c/unicorn/Framework.java	Thu Aug 05 15:28:10 2010 +0200
+++ b/src/org/w3c/unicorn/Framework.java	Thu Aug 05 22:09:42 2010 -0400
@@ -558,6 +558,7 @@
 			context.put("param_prefix", Property.get("UNICORN_PARAMETER_PREFIX"));
 			context.put("languages", Language.getUiLocales());
 			context.put("lang", locale.getName());
+			context.put("currentLocale", locale);
 			context.put("direction", Language.getLocaleDirection(locale));
 			context.put("defaultLocale", Language.getDefaultLocale());
 			context.put("year", (new SimpleDateFormat("yyyy")).format(new Date()));
diff -r 77c330f4173e -r 12b0b32da7cc src/org/w3c/unicorn/action/IndexAction.java
--- a/src/org/w3c/unicorn/action/IndexAction.java	Thu Aug 05 15:28:10 2010 +0200
+++ b/src/org/w3c/unicorn/action/IndexAction.java	Thu Aug 05 22:09:42 2010 -0400
@@ -54,6 +54,7 @@
 		velocityContext.put("current_task", Framework.mapOfTask.get(task));
 		velocityContext.put("default_task", Framework.mapOfTask.getDefaultTask());
 		velocityContext.put("baseUri", "./");
+		velocityContext.put("language_action", "./");
 		
 		Enumeration<?> paramEnum = req.getParameterNames();
 		while (paramEnum.hasMoreElements()) {
diff -r 77c330f4173e -r 12b0b32da7cc src/org/w3c/unicorn/action/ObserveAction.java
--- a/src/org/w3c/unicorn/action/ObserveAction.java	Thu Aug 05 15:28:10 2010 +0200
+++ b/src/org/w3c/unicorn/action/ObserveAction.java	Thu Aug 05 22:09:42 2010 -0400
@@ -107,6 +107,7 @@
 		mapOfStringObject.put("messages", messages);
 		mapOfStringObject.put("unicorncall", aUnicornCall);
 		mapOfStringObject.put("baseUri", "./");
+		mapOfStringObject.put("language_action", "./");
 		
 		// Retrieve the parameters from the request
 		Map<String, Object> reqParams;
@@ -119,6 +120,8 @@
 			aOutputModule.produceError(mapOfStringObject, resp.getWriter());
 			return;
 		}
+		
+		mapOfStringObject.put("requestParameters", reqParams);
 		
 		// Process the parameters
 		for (String key : reqParams.keySet()) {
@@ -175,6 +178,7 @@
 						else
 							uriParam = req.getHeader("Referer");
 					}
+					mapOfStringObject.put("language_action", "check");
 					logger.trace("Uri parameter: " + key + " - " + uriParam);
 					aUnicornCall.setInputParameter(new URIInputParameter(uriParam));
 				} else if (paramName.equals("text")) {

Received on Friday, 6 August 2010 02:17:47 UTC