Return to Snippet

Revision: 19865
at November 2, 2009 12:18 by joe-bbb


Initial Code
function preferences () {

	function set_font_size(string) {
		switch(string) {
		 case 'largest':
				$('body').css({ 'font-size': '16px' });
			break;
			case 'large':
				$('body').css({ 'font-size': '15px' });
			break;
			case 'medium':
				$('body').css({ 'font-size': '14px' });
			break;
			case 'small':
				$('body').css({ 'font-size': '13px' });
			break;
			case 'smallest':
				$('body').css({ 'font-size': '12px' });
			break;
		 }
	}

	function set_contrast(body_class) {
		$('body').attr('class','');
		switch(body_class) {
		 case 'default':
			$('body').addClass('default');
		break;
		case 'high-contrast':
			$('body').addClass('high-contrast');
		break;
		case 'high-contrast-inverse':
			$('body').addClass('high-contrast-inverse');
		break;
	 }
	}
	var current_font_size = $.cookie('font-size');
	set_font_size(current_font_size);

	var current_contrast = $.cookie('contrast');
	$('body').attr('class','').addClass(current_contrast);

	$('#font-sizes li input:checked').attr('checked','');
	$('#font-sizes li input#'+current_font_size).attr('checked','checked');

	$('#contrasts li input:checked').attr('checked','');
	$('#contrasts li input#'+current_contrast).attr('checked','checked');

	$('ul#font-sizes li input').click(function(){
		var new_value = $(this).attr('value');
		$.cookie('font-size', '');
		$.cookie('font-size', new_value, { path: '/', expires: 10 });
		set_font_size(new_value);
	});

	$('ul#contrasts li input').click(function(){
		var new_value = $(this).attr('value');
		$.cookie('contrast', '');
		$.cookie('contrast', new_value, { path: '/', expires: 10 });
		set_contrast(new_value);
	});

}

Initial URL

                                

Initial Description
It could be a lot more reduced, but I have left the cases etc. in as I'll probably be changing more properties

Initial Title
preferences panel cookies - font-size and body class

Initial Tags

                                

Initial Language
jQuery