Convert CSS to Javascript

This is where you share YOUR scripts with others

Moderators: macek, egami, gesf

Post Reply
mayhemiz
New php-forum User
New php-forum User
Posts: 38
Joined: Thu Dec 09, 2010 8:13 am

Convert CSS to Javascript

Post by mayhemiz » Wed Apr 27, 2011 12:11 pm

Hello,okay about the subject :)
I wrote a script what converts CSS to jquery css.
I mean this:

$('#element').css('thing':'thing');

It's converts simple things what not containts :hover :active :etc.

Why i did this?
Because i hate the simple CSS,sometimes do big problem when i want to make a website for all browser :)
I wanted to do IF and browser checking.
I did my website without CSS,and looks nice,because it's compatible with Safari,Chrome,Mozilla,IE, i didn't tested the other ones.

How to use:
First upload it to your website or where u can open it.
Open it,and u will see 1 blank textarea,this is where u paste your css.
If u done,click on Convert.
After convert u will see TEXTAREA BUTTON TEXTAREA2
In textarea2 u will see the converted css.
Please report bugs :)

So here it is: (Sorry i don't know how to upload the script)

Code: Select all



<html> 
<head> 
<title>Convert CSS to Javascript</title> 
<style>
html {
padding:0px;
margin:0px;
}
</style>
</head> 
<body> 
<link type='text/css' href='tiddy/cssparse.css' rel='stylesheet'>
<form method="post" action="<?php echo $PHP_SELF;?>">
 
		<textarea rows="50" style="float: left;   height: 100%;   width: 47.5%; " cols="70" name="jscontent" id="jscontent"></textarea>
		<input style='float:left;bottom:0px;left:0px;width:5%;height:100%;' type='submit' value='Convert'>
</form>
<?php 
function dodo($jsc) {
	$element = explode('{',$jsc);
	$element[0] = preg_replace('/\s+/', '', $element[0]);
	$c = $element[1];
	$element = $element[0]; // ELEMENT(S)
	$hasa = explode(':',$element);
	
	
	$c = str_replace('}','',$c);
	$snum = explode(";",$c);
	$styles = $snum;
	unset($snum[count($snum)-1]);
	$snum = count($snum);
	$i = 0;
	$content = "// ".strtoupper($element)."\n\tcssObj = {\n";
	while ($snum != $i && $snum > $i) {
	
		$style = explode(':',$styles[$i]);
		$style[0] = preg_replace('/\s+/', '', $style[0]);
		if ($snum == $i+1) { $content .= "\t\t'".$style[0]."' : '".$style[1]."'\n"; $i += 2;
		} else {
			$content .= "\t\t'".$style[0]."' : '".$style[1]."',\n";
			$i++;
		}
	}
	$content .= "\t};\n";
	$content .= "\t$('".$element."').css(cssObj);\n\n";
	
	
	
	return $content;
}

if (isset($_POST["jscontent"])) {
	//$css = new csstidy();
	//$css->parse($_POST["jscontent"]);
	//$jscontent = $css->print->plain();
	$jscontent = $_POST["jscontent"];
	$fcontent = "<textarea rows=\"50\" style=\"float: left;   height: 100%;   width: 47.5%; \" cols=\"70\" name=\"jscontent2\" id=\"jscontent2\">\n";
	
	$expes = explode("}",$jscontent);
	unset($expes[count($expes)-1]);
	foreach ($expes as $a) {
	
	$fcontent .= dodo($a);
	
	}
	
	$fcontent .= "</textarea>";
	echo $fcontent;
}
	
?>


Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests