Interesting Challenge for the JS gurus

I am looking for a very lightweight script that has to accomplish the following…first the setup:

I have a web site that has 4 skin possibilities:

  1. Light colored suitable for 800 width browsers
  2. Light colored suitable for browsers with greater than 800 width
  3. Dark colored for 800 and
  4. Dark colored for > 800.

Due to graphics considerations the script needs to be all inclusive and once the variables are read and set it will write a cookie so on subsequent page loads we can bypass the script by just reading the cookie which will call the proper CSS file (light800.css, light1024.css, dark800.css, dark1024.css).

By default [noscript] we’re going with Light+800. So the initial page load will load the CSS file light800.css unless the browser width is greater than 800 at which time it would load light+1024.

To change the color I want to have text links that change the color from light to dark or dark to light. But it has to change on the fly without reloading the page. So the clicks need to read the current cookie so it knows whether to load the alternate color’s 800 or 1024 CSS file for the color selected.

I think that explains it pretty good. I originally was doing this with an auto browser detect and setting a cookie for that then reading and writing a separate cookie for the color switcher. The problem I encountered was with the graphics packages. The color-switcher didn’t know which resolution I was running and vice versa.

Get it? I would love to see what the creative minds here can come up with to make this function.

Any Q’s? Throw 'em at me!

Thanks!

No one else has a clue either, huh?

Hmm…

Got a lot off clues but this forum is not for doing your work for you but to help you develop your own. If you want someone to build it for you:
PAY HIM!

[quote=borrob;2345544]Got a lot off clues but this forum is not for doing your work for you but to help you develop your own. If you want someone to build it for you:
PAY HIM![/quote]
What makes you think I wouldn’t? I am not a kid nor am I a pauper and I don’t think someone who replies as you did would get my business but someone who was helpful certainly could.

[QUOTE=GFX.Wiz;2345288]I am looking for a very lightweight script that has to accomplish the following…first the setup:

I have a web site that has 4 skin possibilities:

  1. Light colored suitable for 800 width browsers
  2. Light colored suitable for browsers with greater than 800 width
  3. Dark colored for 800 and
  4. Dark colored for > 800.

Due to graphics considerations the script needs to be all inclusive and once the variables are read and set it will write a cookie so on subsequent page loads we can bypass the script by just reading the cookie which will call the proper CSS file (light800.css, light1024.css, dark800.css, dark1024.css).

By default [noscript] we’re going with Light+800. So the initial page load will load the CSS file light800.css unless the browser width is greater than 800 at which time it would load light+1024.

To change the color I want to have text links that change the color from light to dark or dark to light. But it has to change on the fly without reloading the page. So the clicks need to read the current cookie so it knows whether to load the alternate color’s 800 or 1024 CSS file for the color selected.

I think that explains it pretty good. I originally was doing this with an auto browser detect and setting a cookie for that then reading and writing a separate cookie for the color switcher. The problem I encountered was with the graphics packages. The color-switcher didn’t know which resolution I was running and vice versa.

Get it? I would love to see what the creative minds here can come up with to make this function.

Any Q’s? Throw 'em at me!

Thanks![/QUOTE]

I’ll have to admit, I thought that this would be quite interesting so I went ahead and did it cause I thought it’d be a fun challenge. Took me about 30min to finish up but here it is, free to use but you can always send me money if you felt like it :stuck_out_tongue: :D. I only ask that you keep the credits in place.

[size=3]DEMO:[/size]
http://dev.beyondthepixel.com/_lab/kirupa_widthskinswitch/v1


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-language" content="en-US" />
<title>Window width theme switcher</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="jquery.cookie.js"></script>
<style type="text/css" media="screen">
	body { font: normal 75%/1.5em Helvetica, "Helvetica Neue", Arial, sans-serif; }
	.dark800 { background: #000; color: #fff; }
	.dark1024 { background: #333; color: #fff; }
	.light800 { background: #fff; color: #333; }
	.light1024 { background: #eee; color: #333; }
</style>
<script>
	/**
	* Window width theme switcher
	*
	* Requires jQuery http://jquery.com & jQuery cookie plugin http://plugins.jquery.com/project/cookie
	*
	* Copyright (c) 2008 Lucas Williams aka simplistik (beyondthepixel.com)
	* Dual licensed under the MIT and GPL licenses:
	* http://www.opensource.org/licenses/mit-license.php
	* http://www.gnu.org/licenses/gpl.html
	* @author Lucas Williams aka simplistik (beyondthepixel.com)
	*/

	var getTheme = $.cookie('theme');
	var getWindowSize = $.cookie('size');
	var minWidth = 800;
	var maxWidth = 1024;

	if ( !getTheme ) { $.cookie('theme', 'light') };
	if ( !getWindowSize ) 
	{ 
		if ( $(window).width() <= minWidth ) 
		$.cookie('size', minWidth);
		else
		$.cookie('size', maxWidth);
	};
	
	$(document).ready( function() {
		
		// Set default attributes
		$('body').removeAttr('class').addClass($.cookie('theme')+$.cookie('size'));
		$('#changetheme span').html("("+$.cookie('theme')+" / "+$(window).width()+" ["+$.cookie('size')+"])"); 
		$('p span').html($.cookie('theme')+$.cookie('size')).append('.css');
		
		// theme switcher
		$('#changetheme').click( function() {
			if ( $.cookie('theme') == 'light' )
			{
				$.cookie('theme', 'dark');
				$('body').removeAttr('class').addClass('dark'+$.cookie('size'));
				
				// optional for demo
				$('#changetheme span').html("("+$.cookie('theme')+" / "+$(window).width()+" ["+$.cookie('size')+"])");
				$('p span').html($.cookie('theme')+$.cookie('size')).append('.css');
			} else { 
				$.cookie('theme', 'light');
				$('body').removeAttr('class').addClass('light'+$.cookie('size'));
				
				// optional for demo
				$('#changetheme span').html("("+$.cookie('theme')+" / "+$(window).width()+" ["+$.cookie('size')+"])");
				$('p span').html($.cookie('theme')+$.cookie('size')).append('.css');
			}
		});
		
		// Dynamically switch on browser resize
		$(window).resize( function() { 
			if ( $(window).width() <= minWidth ) 
			$.cookie('size', minWidth);
			else
			$.cookie('size', maxWidth);
			$('#changetheme span').html("("+$.cookie('theme')+" / "+$(window).width()+" ["+$.cookie('size')+"])");
			$('body').removeAttr('class').addClass($.cookie('theme')+$.cookie('size'));
			$('p span').html($.cookie('theme')+$.cookie('size')).append('.css');
		});
	});
</script>
</head>

<body>
<a href="javascript:void(0);" id="changetheme">Change theme <span></span></a>
<p>Stylesheet: <span></span></p>
Created on: Thurs, June 15, 2008 in response to: <a href="http://www.kirupa.com/forum/showthread.php?t=301450">http://www.kirupa.com/forum/showthread.php?t=301450</a>
</body>
</html>

[quote=simplistik;2345671]I only ask that you keep the credits in place.[/quote]:lol: I highly doubt he will. It’s worth a shot though. I guess.

Don’t see why not :stuck_out_tongue: I keep all the credits from other ppls crap intact all the time. There’s no shame in it at all. And besides, now it’s traceable back to here muahaha :lol:

New code per request. This one uses external stylesheets. The first css file linked is the one that will show on each page, the second one is the conditional one. The javascript changes the link with the title “switch”

[size=3]DEMO:[/size]
http://dev.beyondthepixel.com/_lab/kirupa_widthskinswitch/v2/

Download:
http://dev.beyondthepixel.com/_lab/kirupa_widthskinswitch/v2/wwts.zip


/**
* Window width theme switcher
*
* Requires jQuery http://jquery.com & jQuery cookie plugin http://plugins.jquery.com/project/cookie
*
* Copyright (c) 2008 Lucas Williams aka simplistik (beyondthepixel.com)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
* @author Lucas Williams aka simplistik (beyondthepixel.com)
*/

var getTheme = $.cookie('theme');
var getWindowSize = $.cookie('size');
var minWidth = 800;
var maxWidth = 1024;
var styleFolder = '_style/';

if ( !getTheme ) { $.cookie('theme', 'light') };
if ( !getWindowSize ) 
{ 
	if ( $(window).width() <= minWidth ) 
	$.cookie('size', minWidth);
	else
	$.cookie('size', maxWidth);
};

$(document).ready( function() {
	
	// Set default attributes
	$('link[title="switch"]').removeAttr('href').attr({href: styleFolder+$.cookie('theme')+$.cookie('size')+'.css'});
	$('#changetheme span').html("("+$.cookie('theme')+" / "+$(window).width()+" ["+$.cookie('size')+"])"); 
	$('p span').html($.cookie('theme')+$.cookie('size')).append('.css');
	
	// theme switcher
	$('#changetheme').click( function() {
		if ( $.cookie('theme') == 'light' )
		{
			$.cookie('theme', 'dark');
			$('link[title="switch"]').removeAttr('href').attr({href: styleFolder+$.cookie('theme')+$.cookie('size')+'.css'});

			// optional for demo
			$('#changetheme span').html("("+$.cookie('theme')+" / "+$(window).width()+" ["+$.cookie('size')+"])");
			$('p span').html($.cookie('theme')+$.cookie('size')).append('.css');
		} else { 
			$.cookie('theme', 'light');
			$('link[title="switch"]').removeAttr('href').attr({href: styleFolder+$.cookie('theme')+$.cookie('size')+'.css'});
			
			// optional for demo
			$('#changetheme span').html("("+$.cookie('theme')+" / "+$(window).width()+" ["+$.cookie('size')+"])");
			$('p span').html($.cookie('theme')+$.cookie('size')).append('.css');
		}
	});
	
	// Dynamically switch on browser resize
	$(window).resize( function() { 
		if ( $(window).width() <= minWidth ) 
		$.cookie('size', minWidth);
		else
		$.cookie('size', maxWidth);

		$('#changetheme span').html("("+$.cookie('theme')+" / "+$(window).width()+" ["+$.cookie('size')+"])");
		$('link[title="switch"]').removeAttr('href').attr({href: styleFolder+$.cookie('theme')+$.cookie('size')+'.css'});
		$('p span').html($.cookie('theme')+$.cookie('size')).append('.css');
	});
});


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-language" content="en-US" />
<title>Window width theme switcher</title>
<script type="text/javascript" src="_js/jquery.js"></script>
<script type="text/javascript" src="_js/jquery.cookie.js"></script>
<script type="text/javascript" src="_js/jquery.wwts.js"></script>
<link rel="stylesheet" type="text/css" href="_style/default.css" />
<link rel="stylesheet" type="text/css" href="_style/light800.css" title="switch" />
</head>

<body>
<a href="javascript:void(0);" id="changetheme">Change theme <span></span></a>
<p>Stylesheet: <span></span></p>
Created on: Thurs, June 15, 2008 in response to: <a href="http://www.kirupa.com/forum/showthread.php?t=301450">http://www.kirupa.com/forum/showthread.php?t=301450</a>
</body>
</html>

Simp, to get rid of the nasty inline call to void return a false from the click event handler function, i.e


	$('#changetheme').click( function() {
		if ( $.cookie('theme') == 'light' )
		{
			// cookie dark code
		} else { 
			// cookie light code
		}
                return false;
	});

and the link becomes… <a href="#" id=“changetheme”>Change theme…

[QUOTE=ramie;2345814]Simp, to get rid of the nasty inline call to void return a false from the click event handler function, i.e


	$('#changetheme').click( function() {
		if ( $.cookie('theme') == 'light' )
		{
			// cookie dark code
		} else { 
			// cookie light code
		}
                return false;
	});

and the link becomes… <a href="#" id=“changetheme”>Change theme…[/QUOTE]

Good call on that :slight_smile:

Hey simplistik!

Thanks for the help. PayPal sent and your credit will stay intact.

Esherido…you don’t know me a bit so you might not wish to judge people so quickly.

  • GFX.Wiz

I stereotype. Got a problem with it? :eye: I’m glad that you proved my stereotype wrong. (-:

[size=2]Some [color=#0000ff]Runescape[/color] Players come to our site and ask us if we have to get [color=#0000ff]runescape Autotyper[/color] or [color=#0000ff]runescape hacks[/color]. We alwsys told them that there is no [url=http://www.runescape2gold.net/][color=#0000ff]runescape gold[/color] hacks or [color=#0000ff]runescape account[/color] hacks or [url=http://www.runescape2gold.net/][color=#0000ff]Runescape Money[/color] here. we’re a professional [color=#0000ff]gold sellin[/color]g site, we have no time and interests to scam u, we only sell [color=#0000ff]Runscape Gold[/color].Ur acc is no use for us. We do this for clients hundres of times every day.We can guarantee we’re a site u can trust and u’ll come back again after this first successful business.In forward to know more abount what is is [color=#0000ff]runescape Autotyper[/color]. So I read some articles. There are some information about [color=#800080]RuneScape[/color] Autoty per. Shared!Just passing on the love.This is the best AutoTyper I swear to god. Undetecdable.To download do the following.Click on the linkhttp://www.megaupload.com/?d=BW7X98OPOn the top right corner type the numbers/letters shown into the box to the right of it.Then click enter. The download will start.NEW!:AutoWcer:Do the same as the AutoTyper.Auto WcerI found a auto wcer just for you! I just didnt think anyone was intrested I tested it, and it works properly, like the auto typer.http://www.megaupload.com/?d=2I5NINP4Post comments after you have tried out this auto typer and/or wcer!Most macro programs have key loggers though and virus, should always scan your computer after trying one to double check.How come im banned?!?I’m trying to spread the love of auto ing. Autoers WILL take over [color=#0000ff]Runescape[/color] and you cant stop it.Do u have to download the toolbar first?[color=#800080]Runescape News[/color] More from www.runescape2gold.net… [color=#800080]More>>[/color] [/size]