2006/unicorn/WebContent/scripts w3c-validator.js,1.1.2.8,1.1.2.9

Update of /sources/public/2006/unicorn/WebContent/scripts
In directory hutz:/tmp/cvs-serv338/WebContent/scripts

Modified Files:
      Tag: dev2
	w3c-validator.js 
Log Message:
updated interface

Index: w3c-validator.js
===================================================================
RCS file: /sources/public/2006/unicorn/WebContent/scripts/Attic/w3c-validator.js,v
retrieving revision 1.1.2.8
retrieving revision 1.1.2.9
diff -u -d -r1.1.2.8 -r1.1.2.9
--- w3c-validator.js	21 Aug 2009 16:11:28 -0000	1.1.2.8
+++ w3c-validator.js	24 Aug 2009 09:17:48 -0000	1.1.2.9
@@ -1,222 +1,259 @@
 var W3C = {
 	
 	start: function(){
-
-		W3C.TabSet = $('tabset_tabs');
-		W3C.Tabs = W3C.TabSet.getElements('li');
-		W3C.TabLinks = W3C.TabSet.getElements('a');
-		W3C.Sections = $$('fieldset.tabset_content');
-		W3C.Submits = $$('input.js[type=submit]');
-		W3C.Forms = $$('form.ucn');
-		W3C.TaskButtons = $$('input.change_task');
-		W3C.TaskButtons.setStyle('display', 'none');
-		W3C.Tasks = $$('select.ucn_task');
-		// The current TaskID
-		W3C.TaskID = $$('input.task')[0].getProperty('value');
-		W3C.SectionFx = [];
-		W3C.OptionsFx = [];
 		
-		//creating event listeners on tabs
-		W3C.Tabs.each(function(li, i){
-			var link = li.getFirst();
-			link.href = link.original = '#' + link.href.split('#')[1].replace(/-/g, '_');
-			li.addEvent('click', function(){
-				W3C.updateLocation();
-				W3C.displaySection(i);
-			});
-		});
-	
-		//updating the location
-		//W3C.updateLocation();
+		W3C.Tabs = $('tabset_tabs');
+		W3C.TabLinks = W3C.Tabs.getChildren('li a');
 		
-		W3C.initializeOptions();
+		W3C.TaskSelect = $('tasks');
+		W3C.TaskOptions = W3C.TaskSelect.getChildren('option');
+		W3C.TaskDescrip = $('task_descrip');
+		W3C.TaskInputs = $$('input.task');
 		
-		//setting the initial display of the options, based on the location
-		W3C.refreshOptionLinks(W3C.WithOptions);
+		W3C.LangParameter = $$('input.lang')[0].value;
+		W3C.Forms = $$('form[action=observe]');
 		
-		//attaching the Sections effects, and display section based on the uri
-		W3C.Sections.each(function(section, i){
-			var fakeId = section.id.replace(/-/g, '_');
-			W3C.SectionFx[i] = new Fx.Tween(section, {property: 'opacity', 'duration': 220, 'wait': false});
-			section.setStyle('display', 'none');
-			if (W3C.Location[0] && fakeId.contains(W3C.Location[0].replace(/-/g, '_'))){
-				W3C.displaySection(i, true);
-				W3C.Located = true;
-			}
-		});
+		// index of selected tab
+		W3C.SelectedTab = 0;
+		// index of selected task
+		W3C.SelectedTask = W3C.TaskOptions.getProperty('value').indexOf(W3C.TaskInputs[0].value);
+		// boolean: expand options
+		W3C.WithOptions = false;
 		
-		//displaying the first section if no one is located
-		if (!W3C.Located) W3C.displaySection(0, true);
+		W3C.Loader = new Element('img', {'src': 'images/ajax-loader.gif', 'class': 'loader'});
+		W3C.prepareDocument();
+		W3C.parseHash();
+		W3C.updateHash();
 		
-		//if (window.ie) $$('legend').setStyle('margin-left', '-0.4em');
+		W3C.showTab(W3C.SelectedTab, false);
+		W3C.selectTask(W3C.SelectedTask, false);
+		W3C.toggleOptions(false);
+		W3C.addOptionEvents();
+	},
 	
-		//changing submit buttons
-		if ($$('input.js + a').length == 0) {
-			W3C.Submits.each(function(submit, i){
-				var value = submit.value;
-				submit.setStyle('display', 'none');
-				var link = new Element('a', {'class': 'submit', 'href': '#'});
-				var span = new Element('span').set('html', value).inject(link);
-				link.injectAfter(submit).addEvent('click', function(event){
-					new Event(event).stop();
-					event.stop();
-					W3C.Forms[i].submit();
-				});
-			});
-		}
+	prepareDocument: function(){
 		
-		//adding mouseover events to the task options
-		$$('select.ucn_task option').addEvent('mouseover', function(event) {
-			var title = this.title;
-			$$('span.task_description').each(function (span) {
-				span.set('text', title);
-			});
+		$$('input#task_change').setStyle('display', 'none');
+		
+		W3C.TaskSelect.addEvent('change', function (event) {
 			event.stop();
+			W3C.selectTask(this.selectedIndex, true);
+			W3C.updateHash();
 		});
 		
-		//adding change events to task selects (sends ajax request)
-		W3C.Tasks.addEvent('change', function(event){
-			var title = this.options[this.selectedIndex].title;
-			$$('span.task_description').each(function (span) {
-				span.set('text', title);
-			});
-			event.stop();
-			var taskId = this.options[this.selectedIndex].value;
-			
-			var req = new Request.HTML({url: window.location.pathname,
-				method: 'get',
-				onRequest: function() {
-					$$('div.options_container').each(function (div) {
-						div.set('html', '<img src="images/ajax-loader.gif" style="margin: 1em 0;" />');
-					});
-				},
-				onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript) {
-					$$('div.options_container').each(function (div) {
-						div.set('html', responseHTML);
-					});
-					$$('p.submit_button input.task').each(function (input) {
-						input.setProperty('value', taskId);
-					});
-					$$('select.ucn_task option').each(function (option, i) {
-						if (option.getProperty('value') == taskId) {
-							option.setProperty('selected', 'selected');
-						} else {
-							option.setProperty('selected', '');
-						};
-					});
-					W3C.TaskID = taskID;
-					W3C.initializeOptions(); 
-					
-					
-				},
-				onFailure: function() {
-					$$('fieldset.options').set('html', '');
-				}
+		W3C.TabLinks.each(function(link, i) {
+			link.addEvent('click', function (event) {
+				event.stop();
+				W3C.showTab(i, true);
+				W3C.updateHash();
 			});
-			var queryString = 'ucn_task=' + taskId + '&ucn_lang=' + $$('input.lang')[0].getProperty('value'); 
-			req.send(queryString);
 		});
+		
+		W3C.TaskOptions.addEvent('mouseover', function() {
+			W3C.TaskDescrip.set('text', this.title);
+		});
+		
+		W3C.TaskOptions.addEvent('mouseout', function() {
+			W3C.TaskDescrip.set('text', W3C.TaskOptions[W3C.SelectedTask].title);
+		});
+		
 	},
 	
-	initializeOptions: function(){
-		W3C.Legends = $$('legend.toggletext');
-		W3C.Options = $$('fieldset.slide div.options');
-		W3C.OptionsFx = [];
+	addOptionEvents: function () {
+		$$('fieldset.advanced legend').removeEvent('click');
 		
-		//creating the Effects for the Options
-		$$('fieldset.slide div.options').each(function(option, i){
-			W3C.OptionsFx[i] = new Fx.Slide(option, {'wait': false, 'duration': 180});
-			W3C.OptionsFx[i].addEvent('onComplete', function(){
-				if (this.element.getStyle('margin-top').toInt() == 0){
-					this.wrapper.setStyle('height', 'auto');
-				}
-				else {
-					this.element.setStyle('display','none');  // if a slideOut completed, set display:none
-				}
-			});
+		$$('fieldset.advanced legend').addEvent('click', function (event) {
+			W3C.WithOptions = !W3C.WithOptions;
+			W3C.toggleOptions(true);
+			W3C.updateHash();
 		});
+	},
+	
+	showTab: function(tabIndex, withFX) {
+		if (W3C.Tabs.getElements('li')[tabIndex] == W3C.Tabs.getElement('li.selected'))
+			return;
 		
-		//creating links on legends, with event listeners
-		$$('legend.toggletext').each(function(legend, i){
-			var html = legend.innerHTML;
-			var pid = W3C.Sections[i].id.replace(/-/g, '_');
-			var opt = '+with_options';
-			legend.set('html', '<a href="#'+ pid + opt + '">' + html + '</a>');
-			var option = W3C.Options[i];
-			var link = legend.getFirst();
-			link.addEvent('click', function(event){
-				option.setStyle('display', 'block'); // before any slide effect, set display:block
-				var block = (option.getStyle('margin-top').toInt() == 0);
-				W3C.setHash((block) ? pid + task : pid + task + opt);
-				event.stop();
-				W3C.refreshOptionLinks(!block, i);
-			});
-			
+		W3C.SelectedTab = tabIndex;
+		W3C.Forms.each(function(form, i) {
+			if (i != tabIndex) {
+				form.setStyle('display', 'none');
+			} else {
+				if (withFX)
+					form.setStyle('opacity', 0);
+				form.setStyle('display', 'block');
+			}
+		});
+		W3C.TabLinks.each(function(link, i) {
+			if (i != tabIndex) {
+				link.setProperty('class', '');
+			} else {
+				link.setProperty('class', 'selected');
+			}
 		});
 		
-		W3C.updateLocation();
+		W3C.toggleOptions(false);
 		
-		//var task = '+task_' + $$('input.task')[0].getProperty('value');
-		//W3C.setHash(W3C.Location[0].replace(/-/g, '_') + task + (W3C.WithOptions ? '+with_options' : ''));
+		if (withFX) {
+			W3C.Forms[tabIndex].set('tween', {'duration': 350});
+			W3C.Forms[tabIndex].tween('opacity', 0, 1);
+		}
+	},
+	
+	selectTask: function(taskIndex, withFX) {
+		W3C.SelectedTask = taskIndex;
+		var options = $$('fieldset.options');
+		var taskId;
 		
-		W3C.refreshOptionLinks(W3C.WithOptions);
+		W3C.TaskOptions.each(function(option, i) {
+			if (i != taskIndex) {
+				option.removeProperty('selected');
+			} else {
+				taskId = option.value;
+				option.setProperty('selected', 'selected');
+			}
+		});
+		W3C.TaskDescrip.set('text', W3C.TaskOptions[taskIndex].title);
 		
-		W3C.OptionsFx.each(function (fx) {
-			if (W3C.WithOptions) fx.show().fireEvent('onComplete');
-			else fx.hide();
+		W3C.TaskInputs.each(function (input) {
+			input.value = taskId;
 		});
+		
+		var foundOptions = false;
+		
+		var options = $$('fieldset.options');
+		options.setStyle('display', 'none');
+		
+		var currentOptions = options.filter('fieldset.' + taskId);
+		
+		if (!currentOptions.length > 0)
+			W3C.requestOptions(taskIndex, withFX);
+		else {
+			currentOptions.setStyle('opacity', 0);
+			currentOptions.setStyle('display', 'block');
+			if (withFX) {
+				currentOptions.set('tween', {'duration': 350});
+				currentOptions.tween('opacity', 0, 1);
+			}
+			currentOptions.setStyle('opacity', 1);
+		}
 	},
 	
-	updateLocation: function(){
-		W3C.Location = window.location.hash.replace('#', '').split('+');
-		W3C.WithOptions = (W3C.Location[1] && W3C.Location[1].contains('with_options')) || (W3C.Location[2] && W3C.Location[2].contains('with_options'));
+	requestOptions: function(taskIndex, withFX) {
 		
-		// check if there is a task defined in the url, if so the task id is added to W3C.TaskID
-		window.location.hash.replace('#', '').split('+').each(function (string) {
-			if (string.contains('task_')) {
-				W3C.TaskID = string.replace('task_', '');
-				alert("W3C.task: " + W3C.TaskID);
+		var req = new Request.HTML({url: window.location.pathname,
+			method: 'get',
+			onRequest: function() {
+				W3C.Loader.injectBefore(W3C.Forms[W3C.SelectedTab].getElement('div.submit'));
+			},
+			onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript) {
+				var option;
+				responseElements.filter('fieldset.options').each(function(fieldset) {
+					W3C.Forms.each(function (form, i) {
+						var clone = fieldset.clone();
+						clone.setStyle('opacity', 0);
+						clone.injectBefore(form.getElement('div.submit'));
+						if (withFX) {
+							clone.set('tween', {'duration': 350});
+							clone.tween('opacity', 0, 1);
+						}
+						clone.setStyle('opacity', 1);
+					});
+				});
+				W3C.Loader.dispose();
+				W3C.toggleOptions(false);
+				W3C.addOptionEvents();
+				return true;
+			},
+			onFailure: function() {
+				// TODO
+				return false;
 			}
 		});
+		var queryString = 'ucn_task=' + W3C.TaskOptions[taskIndex].value + '&ucn_lang=' + W3C.LangParameter; 
+		req.send(queryString);
 	},
 	
-	refreshOptionLinks: function(options, idx){
+	toggleOptions: function(withFX) {
+		var fieldsets = $$('fieldset.advanced');
+		if (fieldsets.length == 0)
+			return;
 		
-		if (!options){
-			if ($chk(idx)) W3C.OptionsFx[idx].slideOut();
-			$$('legend.toggletext').removeClass('toggled');
-		} else {
-			if ($chk(idx)) W3C.OptionsFx[idx].slideIn();
-			$$('legend.toggletext').addClass('toggled');
+		if (W3C.WithOptions) {
+			fieldsets.addClass('toggled');
+			fieldsets.removeClass('toggles');
+		}
+		else {
+			fieldsets.addClass('toggles');
+			fieldsets.removeClass('toggled');
 		}
 		
-		W3C.TabLinks.each(function(link){
-			var original = link.original + (W3C.TaskID ? '+task_' + W3C.TaskID : '');//$$('input.task')[0].getProperty('value');
-			link.href = (options) ? original + '+with_options' : original;
-		});
-	},
-	
-	displaySection: function(i, sudden){
-		W3C.Sections.each(function(section, j){
-			var block = section.getStyle('display') == 'block';
-			if (j == i){
-				if (block) return;
-				W3C.Sections[j].setStyles({'opacity': sudden ? 1 : 0, 'display': 'block'});
-				if (!sudden) W3C.SectionFx[j].start(1);
-				if (j < W3C.OptionsFx.length) {
-					if (W3C.WithOptions) W3C.OptionsFx[j].show().fireEvent('onComplete');
-					else W3C.OptionsFx[j].hide();
+		W3C.Forms.each(function (form, i) {
+			
+			var advancedOptions = form.getElements('fieldset.advanced div.options');
+			
+			if (withFX && i == W3C.SelectedTab) {
+				if (W3C.WithOptions) {
+					advancedOptions.slide('in');
+				} else {
+					advancedOptions.slide('out');
 				}
 			} else {
-				if (!block) return;
-				W3C.Sections[j].setStyles({'display': 'none', 'opacity': 0});
+				if (W3C.WithOptions) {
+					advancedOptions.slide('show');
+				} else {
+					advancedOptions.slide('hide');
+				}
 			}
 		});
+	},
+	
+	parseHash: function(){
 		
-		W3C.Tabs.each(function(link, j){
-			if (j == i) link.addClass('selected');
-			else link.removeClass('selected');
-		});
+		var hash = window.location.hash;
+		
+		if (hash == "") {
+			return;
+		}
+		
+		var tab = hash.replace('#', '').split('+');
+		var selectedTab = tab[0];
+		var selectedTask = tab[1];
+		var withOptions = tab[2];
+		
+		// get selected tab
+		var index = W3C.Forms.getProperty('id').indexOf(selectedTab);
+		if (index == -1) {
+			W3C.setHash('');
+			return;
+		}
+		W3C.SelectedTab = index;
+		
+		// get selected task
+		if (!selectedTask || !selectedTask.contains("task_")) {
+			W3C.setHash(selectedTab);
+			return;
+		}
+		var taskIndex =  W3C.TaskOptions.getProperty('value').indexOf(selectedTask.replace('task_', ''));
+		if (taskIndex == -1) {
+			W3C.setHash(selectedTab);
+			return;
+		}
+		W3C.SelectedTask = taskIndex;
+		
+		// with_options ?
+		if (!withOptions || !withOptions == "with_options") {
+			W3C.setHash(selectedTab + "+" + selectedTask);
+			return;
+		}
+		W3C.WithOptions = true;
+	},
+	
+	updateHash: function(){
+		var tab = W3C.Forms[W3C.SelectedTab].getProperty('id');
+		var task = '+task_' + W3C.TaskOptions[W3C.SelectedTask].getProperty('value');
+		var withOptions = W3C.WithOptions ? '+with_options' : '';
+				
+		W3C.setHash(tab + task + withOptions);
 	},
 	
 	setHash: function(hash){
@@ -227,6 +264,7 @@
 			window.location.hash = hash;
 		}
 	}
+	
 };
 
-window.addEvent('domready', W3C.start);
+window.addEvent('domready', W3C.start);
\ No newline at end of file

Received on Monday, 24 August 2009 09:18:08 UTC