<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>.NET Tips and Tricks &#187; CSS</title>
	<atom:link href="http://kossovsky.net/index.php/tag/css/feed/" rel="self" type="application/rss+xml" />
	<link>http://kossovsky.net</link>
	<description>C# Code Snippets, ASP.NET Code Samples, .NET Tips and Tricks</description>
	<lastBuildDate>Sat, 25 Dec 2010 08:32:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>jTemplates &#8211; jQuery Template Engine</title>
		<link>http://kossovsky.net/index.php/2009/10/jtemplates-jquery-template-engine/</link>
		<comments>http://kossovsky.net/index.php/2009/10/jtemplates-jquery-template-engine/#comments</comments>
		<pubDate>Sat, 03 Oct 2009 22:46:51 +0000</pubDate>
		<dc:creator>Xander</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[UI]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[c-sharp]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[dhtml]]></category>
		<category><![CDATA[dom template]]></category>
		<category><![CDATA[dynamic template]]></category>
		<category><![CDATA[endless event]]></category>
		<category><![CDATA[engine]]></category>
		<category><![CDATA[event handlers]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[javascript library]]></category>
		<category><![CDATA[javascript templates]]></category>
		<category><![CDATA[jquery templates]]></category>
		<category><![CDATA[JS]]></category>
		<category><![CDATA[js template]]></category>
		<category><![CDATA[net c#]]></category>
		<category><![CDATA[rapid web development]]></category>
		<category><![CDATA[render]]></category>
		<category><![CDATA[server side code]]></category>
		<category><![CDATA[side requests]]></category>
		<category><![CDATA[support parameters]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[template engine]]></category>
		<category><![CDATA[templates]]></category>
		<category><![CDATA[time manipulation]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[usable features]]></category>
		<category><![CDATA[web template]]></category>

		<guid isPermaLink="false">http://kossovsky.net/?p=789</guid>
		<description><![CDATA[jTemplates is a template engine for JavaScript, wich is wraped in a jQuery Plugin.
The syntax is very simple and  intuitive. It's support parameters, includes, if/else, loops, JavaScript functions and many other nice and usable  features.<br /><div><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx.php?value=4.9" /></div><div>Rating: 4.9/<strong>5</strong> (12 votes cast)</div><br /><a target="_blank" href="http://www.gdstarrating.com/"><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx/powered.png" border="0" width="80" height="15" /></a><br />]]></description>
			<content:encoded><![CDATA[<p>About a year ago i had to architucture some web application with a very rich client side UI.</p>
<p>ASP.NET was an easy choise for a server side code, but what about client side ?<br />
The heavy viewstate, endless event handlers and infinity number of server side requests just to make the GUI  friendly &#8211; well, it just didn&#8217;t sound as a proper way to do it.</p>
<p><span id="more-789"></span>So, what do we have ?<br />
.NET as a server side platform, but despite  all it&#8217;s powerful abilities it has nothing to do with client side. At the end of the day all those fancy control are just HTML and JavaScript.</p>
<p> JavaScript is still the engine that runs at the client side and it&#8217;s great, but we all know how many lines of code we have to write and time to spend to make it fast, modular and cross browser.</p>
<p><a title="jQuery" href="http://jquery.com/" target="_blank">jQuery</a> &#8211; it&#8217;s a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development.</p>
<p>Indeed, we can do a many things with jQuery and it realy simplify the coding, but what if we have to build a product list with complicated HMTL, complex logic and real time manipulation ?</p>
<p>As i mentioned before, ASP.NET and UpdatePanels are just to heavy and JavaScript is to long.</p>
<p>So, i did some research and find a couple of JavaScript Template Engines.<br />
The first one i bumped in was <a href="http://plugins.jquery.com/project/jsrepeater" target="_blank">jsRepeater</a>. At first it seemed like a great solution but after a few tests i found all kinds of bugs related to the syntax conflicts with HTML and JavaScript.</p>
<p>After a few days of googling, tests and googling again i found the one and only &#8211;  <a title="jTemplates" href="http://jtemplates.tpython.com/" target="_blank">jTemplates</a>.<br />
jTemplates is a template engine for JavaScript, wich is wraped in a jQuery Plugin.<br />
The syntax is very simple and  intuitive. It&#8217;s support parameters, includes, if/else, loops, JavaScript functions and many other nice and usable  features.</p>
<p>Let&#8217;s say we want to list all our products. What we have to do is to write the template (HTML), pass the data and we have a product list.</p>
<p>
<div><span style="color: #0000ff;">{#foreach $T.Product as P}</span></div>
<div style="padding-left: 30px;"><span style="color: #0000ff;">&lt;</span><span style="color: #0000ff;">div</span> <span style="color: #008000;">style</span>=&#8221;float:left;width:150px;height:150px&#8221;<span style="color: #0000ff;">&gt;</span></div>
<div style="padding-left: 60px;"><span style="color: #0000ff;">&lt;</span><span style="color: #0000ff;">div</span><span style="color: #0000ff;">&gt;</span><strong>{$T.P.Title}</strong><span style="color: #0000ff;">&lt;/div&gt;</span></div>
<div style="padding-left: 60px;"><span style="color: #0000ff;">&lt;</span><span style="color: #0000ff;">img</span> <span style="color: #008000;">src</span>=&#8221;<strong>{$T.P.Url}</strong>&#8221; <span style="color: #008000;">alt</span>=&#8221;<strong>{$T.P.Title}</strong>&#8221; style=&#8221;width:10px;height:10px&#8221; <span style="color: #0000ff;">/&gt;</span></div>
<div style="padding-left: 60px;"><span style="color: #0000ff;">&lt;hr /&gt;</span></div>
<div style="padding-left: 60px;"><span style="color: #0000ff;">&lt;</span><span style="color: #0000ff;">div</span><span style="color: #0000ff;">&gt;</span>Price : <strong>{$T.P.Price}$</strong><span style="color: #0000ff;">&lt;/div&gt;</span></div>
<div style="padding-left: 30px;"><span style="color: #0000ff;">&lt;/</span><span style="color: #0000ff;">div</span><span style="color: #0000ff;">&gt;</span></div>
<div><span style="color: #0000ff;">{#/for}</span></div>
</p>
<p>Look how easy this is. You just write HTML and werever you need to insert some data you put {$.T.P.ColumnName}.</p>
<p>So, how we use it ?<br />
Just add some textarea to your page, give it some id, set it&#8217;s display style to none and write your template inside.</p>
<pre class="html" name="code">
&lt;textarea cols="0" rows ="0" style="display:none;" id="ProductListTemplate"&gt;&lt;!--
{#foreach $T.Product as P}
	&lt;div style=”float:left;width:150px;height:150px”&gt;
		&lt;div>{$T.P.Title}&lt;/div&gt;
		&lt;img src=”{$T.P.Url}” alt=”{$T.P.Title}” style=”width:10px;height:10px” /&gt;
		&lt;hr /&gt;
		&lt;div>Price : {$T.P.Price}$&lt;/div&gt;
	&lt;/div&gt;
{#/for}
--&gt;&lt;/textarea&gt;
</pre>
<p>Add some empty container that will hold the result.</p>
<pre class="html" name="code">
&lt;div id="ProductListContainer"&gt;&lt;/div&gt;
</pre>
<p>Execute setTemplateElement and execute processTemplate while passing the data into it as a parameter</p>
<pre class="javascript" name="code">
$("#ProductListContainer").setTemplateElement("ProductListTemplate");
$("#ProductListContainer").processTemplate(data);
</pre>
<p>Easy, isn&#8217;t it ?<br />
I must say that the above example is a simple one, but I&#8217;ve been using jTemplates to create complicated lists, grids, trees, popups and even an image editing web application. Use it, I&#8217;m sure you will love it.</p>
<div style="margin-top:-15px;margin-bottom:15px;"><script type="text/javascript">
var dzone_url = 'http://kossovsky.net/index.php/2009/10/jtemplates-jquery-template-engine/';
var dzone_style = '1';
</script><br />
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js"></script>
</div>
<br /><div><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx.php?value=4.9" /></div><div>Rating: 4.9/<strong>5</strong> (12 votes cast)</div><br /><a target="_blank" href="http://www.gdstarrating.com/"><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx/powered.png" border="0" width="80" height="15" /></a><br />
<p class="FacebookLikeButton"><fb:like href="http%3A%2F%2Fkossovsky.net%2Findex.php%2F2009%2F10%2Fjtemplates-jquery-template-engine%2F" layout="standard" show_faces="false" width="450" action="like" colorscheme="light"></fb:like></p>
]]></content:encoded>
			<wfw:commentRss>http://kossovsky.net/index.php/2009/10/jtemplates-jquery-template-engine/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Javascript pseudo protocol (is EVIL)</title>
		<link>http://kossovsky.net/index.php/2009/07/javascript-pseudo-protocol-is-evil/</link>
		<comments>http://kossovsky.net/index.php/2009/07/javascript-pseudo-protocol-is-evil/#comments</comments>
		<pubDate>Sun, 12 Jul 2009 18:35:42 +0000</pubDate>
		<dc:creator>Maxim</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[UI]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[href javascript]]></category>
		<category><![CDATA[javascript problems]]></category>
		<category><![CDATA[JS]]></category>
		<category><![CDATA[script type]]></category>
		<category><![CDATA[span style]]></category>
		<category><![CDATA[style color]]></category>
		<category><![CDATA[style text]]></category>
		<category><![CDATA[text decoration]]></category>
		<category><![CDATA[text element]]></category>
		<category><![CDATA[text javascript]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[type javascript]]></category>

		<guid isPermaLink="false">http://kossovsky.net/?p=586</guid>
		<description><![CDATA[This post is somehow related to my previous post about javascript function context.  Recently I helped one of my friends to debug a very funny problem. He told me that his inline event handler doen&#8217;t work, because he could not pass this object to his function. You probably wonder what did I find? &#60;script type="text/javascript"&#62; function [...]<br /><div><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx.php?value=4.6" /></div><div>Rating: 4.6/<strong>5</strong> (5 votes cast)</div><br /><a target="_blank" href="http://www.gdstarrating.com/"><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx/powered.png" border="0" width="80" height="15" /></a><br />]]></description>
			<content:encoded><![CDATA[<p>This post is somehow related to my previous post about <a href="http://kossovsky.net/index.php/2009/07/function-context-and-apply-function/" target="_blank">javascript function context</a>.  Recently I helped one of my friends to debug a very funny problem. He told me that his inline event handler doen&#8217;t work, because he could not pass <strong><em>this</em></strong> object to his function.<br />
You probably wonder what did I find? <img src='http://kossovsky.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /><br />
<span id="more-586"></span></p>
<pre class="javascript" name="code">    &lt;script type="text/javascript"&gt;
        function doSomething(obj) {
            obj.style.color = '#cc0000';
        }
    &lt;/script&gt;
    &lt;a href="javascript:doSomething(this)"&gt;Link&lt;/a&gt;</pre>
<p><strong><em>this</em></strong> keyword in his case was not A object as expected but <strong><em>window</em></strong>.<br />
Having javascript:  in href attribute is like running JavaScript from address bar of your browser. It will run in <strong><em>window</em></strong> context.<br />
Only if my friend was writing his code like this:</p>
<pre class="javascript" name="code">   ...
    &lt;a onclick="doSomething(this)"&gt;Link&lt;/a&gt;</pre>
<p>it would work like charm.</p>
<p>But I never use <strong><em>javascript:</em></strong> at all in my markup. Why?<br />
1. If you need text element that is clickable use span, any visual styling like text-decoration or cursor can be achieved using CSS.<br />
2. If you don&#8217;t have actual link behind you shouldn&#8217;t use A tag. As far as I know it&#8217;s not good for SEO.<br />
3. Javascript problems as i described above can arise<br />
I would write the code above like this:</p>
<pre class="javascript" name="code">    ...
    &lt;span style="text-decoration:underline;cursor:pointer;"
                 onclick="doSomething(this)"&gt;Link&lt;/span&gt;</pre>
<p>The only reason I know to use A for JavaScript  triggers is to achieve hover effect without use of JavaScript.<br />
If you know another reason why you should/shouldn&#8217;t use links as JavaScript triggers you&#8217;re welcome to comment.<br />
After this post you can get an impression that I don&#8217;t like javascript: notation and you will be wrong,  actually there are very usefull tricks I use all the time:<br />
1. Check some JS value on your page. Type javascript:alert(yourvariable) in the address bar and press enter.<br />
<img src="http://kossovsky.net/wp-content/uploads/2009/07/1.jpg" alt="" width="299" height="35" /></p>
<p>You will get :<br />
<img src="http://kossovsky.net/wp-content/uploads/2009/07/2.jpg" alt="" width="187" height="134" /></p>
<p>2. Or let&#8217;s say you have function somewhere on the page and you have to see it quick without searching through all your scripts. Or you wan&#8217;t to <span style="text-decoration: line-through">steal</span> see how someone implemented something <img src='http://kossovsky.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /><br />
Just type  javascript:alert(yourdesiredfunction) and voila:<br />
<img src="http://kossovsky.net/wp-content/uploads/2009/07/3.jpg" alt="" width="283" height="44" /></p>
<p><img src="http://kossovsky.net/wp-content/uploads/2009/07/4.jpg" alt="" width="260" height="140" /></p>
<p>UPD:<br />
Just googled good page with JS best practices, it has Javascript: pseudoprotocol part that says almost exactly the same as my conclusions.<br />
<a href="http://www.javascripttoolbox.com/bestpractices/">http://www.javascripttoolbox.com/bestpractices/</a></p>
<br /><div><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx.php?value=4.6" /></div><div>Rating: 4.6/<strong>5</strong> (5 votes cast)</div><br /><a target="_blank" href="http://www.gdstarrating.com/"><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx/powered.png" border="0" width="80" height="15" /></a><br />
<p class="FacebookLikeButton"><fb:like href="http%3A%2F%2Fkossovsky.net%2Findex.php%2F2009%2F07%2Fjavascript-pseudo-protocol-is-evil%2F" layout="standard" show_faces="false" width="450" action="like" colorscheme="light"></fb:like></p>
]]></content:encoded>
			<wfw:commentRss>http://kossovsky.net/index.php/2009/07/javascript-pseudo-protocol-is-evil/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>CSS Sprite Generator</title>
		<link>http://kossovsky.net/index.php/2009/06/css-sprite-generator/</link>
		<comments>http://kossovsky.net/index.php/2009/06/css-sprite-generator/#comments</comments>
		<pubDate>Sun, 14 Jun 2009 21:29:32 +0000</pubDate>
		<dc:creator>Xander</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Graphics]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[c-sharp]]></category>
		<category><![CDATA[composite image]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[CSS Sprite]]></category>
		<category><![CDATA[css sprites]]></category>
		<category><![CDATA[multiple images]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[positioning]]></category>
		<category><![CDATA[Puzzle]]></category>
		<category><![CDATA[Speed]]></category>
		<category><![CDATA[sprite]]></category>

		<guid isPermaLink="false">http://kossovsky.net/?p=3</guid>
		<description><![CDATA[CSS sprites group multiple images into one composite image and display them using CSS background positioning. Coming soon… Rating: 0.0/5 (0 votes cast)<br /><div><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx.php?value=0.0" /></div><div>Rating: 0.0/<strong>5</strong> (0 votes cast)</div><br /><a target="_blank" href="http://www.gdstarrating.com/"><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx/powered.png" border="0" width="80" height="15" /></a><br />]]></description>
			<content:encoded><![CDATA[<p>CSS sprites group multiple images into one composite image and display them using CSS background positioning.</p>
<p>Coming soon…</p>
<br /><div><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx.php?value=0.0" /></div><div>Rating: 0.0/<strong>5</strong> (0 votes cast)</div><br /><a target="_blank" href="http://www.gdstarrating.com/"><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx/powered.png" border="0" width="80" height="15" /></a><br />
<p class="FacebookLikeButton"><fb:like href="http%3A%2F%2Fkossovsky.net%2Findex.php%2F2009%2F06%2Fcss-sprite-generator%2F" layout="standard" show_faces="false" width="450" action="like" colorscheme="light"></fb:like></p>
]]></content:encoded>
			<wfw:commentRss>http://kossovsky.net/index.php/2009/06/css-sprite-generator/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

