<?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>(function() { &#187; table</title>
	<atom:link href="http://maxb.net/blog/tag/table/feed/" rel="self" type="application/rss+xml" />
	<link>http://maxb.net/blog</link>
	<description>// MAXB.NET LABS</description>
	<lastBuildDate>Mon, 16 May 2011 19:12:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>comodoclick</title>
		<link>http://maxb.net/blog/2009/05/12/comodoclick/</link>
		<comments>http://maxb.net/blog/2009/05/12/comodoclick/#comments</comments>
		<pubDate>Tue, 12 May 2009 08:48:01 +0000</pubDate>
		<dc:creator>Massimiliano Balestrieri</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[table]]></category>

		<guid isPermaLink="false">http://maxb.net/blog/?p=376</guid>
		<description><![CDATA[LINKS: Demo Js FUNZIONALITA&#8217;: Aggiunge la classe &#8220;hover&#8221; ai td di una certa riga di tabella (tr > td) sull&#8217;evento hover del tr Aggiunge la classe &#8220;selected&#8221; ai td di una certa riga di tabella (tr > td) sull&#8217;evento click &#8230; <a href="http://maxb.net/blog/2009/05/12/comodoclick/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h3>LINKS:</h3>
<ul>
<li><a href="http://maxb.net/scripts/comodoclick/" target="_blank">Demo</a></li>
<li><a href="http://maxb.net/scripts/comodoclick/comodoclick.js" target="_blank">Js</a></li>
</ul>
<h3>FUNZIONALITA&#8217;:</h3>
<ul>
<li>Aggiunge la classe &#8220;hover&#8221; ai td di una certa riga di tabella (tr > td) sull&#8217;evento hover del tr</li>
<li>Aggiunge la classe &#8220;selected&#8221; ai td di una certa riga di tabella (tr > td) sull&#8217;evento click del td</li>
<li>Aggiunge la classe &#8220;selected&#8221; ai td di una certa riga di tabella al click sui controlli form checkbox e radio (di conseguenza anche al click sulle label) presenti sulla riga stessa</li>
<li>Nel caso di input:radio la classe selected viene prima cancellata dalle altre righe e poi applicata alla riga &#8220;selezionata&#8221;</li>
</ul>
<h3>AUTOLOAD</h3>
<p>Per attivarlo basta includere gli scripts (jquery, comodoclick) e aggiungere la classe comodoclick ad una tabella.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;script src=&quot;jquery-1.3.2.min.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;comodoclick.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;

&lt;table class=&quot;comodoclick&quot;&gt;
</pre>
<h3>CSS</h3>
<p>Personalizzare a piacere queste classi css:</p>
<pre class="brush: css; title: ; notranslate">
table.comodoclick tr td.hover {background-color:red;}
table.comodoclick tr td.selected {background-color:green;}
</pre>
<h3>CODE</h3>
<p>Il plugin con qualche nota:</p>
<pre class="brush: jscript; title: ; notranslate">
/*
 * Copyright (c) 2008 Massimiliano Balestrieri
 *
 * @requires jQuery v1.3.2
 *
 * Copyright (c) 2008 Massimiliano Balestrieri
 * Examples and docs at: http://maxb.net/blog/
 * Licensed GPL licenses:
 * http://www.gnu.org/licenses/gpl.html
 */
;
(function($){

    function ComodoClick(){
        return this.each(function(){
            var that = this;

            jQuery(&quot;tr&quot;, this).hover(function(){
                jQuery(&quot;td&quot;, this).addClass(&quot;hover&quot;);
            }, function(){
                jQuery(&quot;td&quot;, this).removeClass(&quot;hover&quot;);
            });

            jQuery(&quot;tr&quot;, this).click(function(e){
                var _target = e.target || e.srcElement;
                var _tag = _target.tagName.toString().toLowerCase();
                //prendo solo il click sul td
                //se ci fossero tag di tipo blocco dentro il td sarebbe un problema
                //se invece clicco su una input o su una label gestisco tutto con l'evento -&gt; VEDI SOTTO
                if (_tag === 'td') {
                    var _tr = jQuery(this);
                    _highlight_row(_tr, true);
                }
                //return false;
            });

            //vedi sotto A
            jQuery(&quot;tr&quot;, this).find(&quot;input:checkbox, input:radio&quot;).bind(&quot;click&quot;, function(){
                var _tr = jQuery(this).parents(&quot;tr&quot;);
                _highlight_row(_tr, true);
            });
            //vedi sotto B
            jQuery(&quot;tr&quot;, this).find(&quot;input:checkbox&quot;).bind(&quot;checked&quot;, function(){
                var _tr = jQuery(this).parents(&quot;tr&quot;);
                _highlight_row(_tr, false);
            });

            var _highlight_row = function(_tr, flag){
                //il flag è per selezionare la checkbox/radio forzatamente
                //checkbox gestisce la &quot;multiselezione&quot;

                var _checkbox = jQuery(&quot;input:checkbox&quot;, _tr).length &gt; 0;

                //nel caso dei radio cancello le altre colorazioni
                if (!_checkbox) {
                    jQuery(&quot;td&quot;, that).removeClass(&quot;selected&quot;);
                    jQuery(&quot;tr&quot;, that).removeClass(&quot;selected&quot;);
                    jQuery(&quot;td&quot;, _tr).addClass(&quot;selected&quot;);
                    _tr.addClass(&quot;selected&quot;);

                    if (flag) {
                        jQuery(&quot;input:radio&quot;, _tr).attr(&quot;checked&quot;, &quot;checked&quot;);
                    }

                }
                else {
                    var _selected = _tr.is(&quot;.selected&quot;);
                    if (_selected) {
                        jQuery(&quot;td&quot;, _tr).removeClass(&quot;selected&quot;);
                        _tr.removeClass(&quot;selected&quot;);
                        jQuery(&quot;input:checkbox&quot;, _tr).attr(&quot;checked&quot;, &quot;&quot;);
                    }
                    else {
                        jQuery(&quot;td&quot;, _tr).addClass(&quot;selected&quot;);
                        _tr.addClass(&quot;selected&quot;);
                        jQuery(&quot;input:checkbox&quot;, _tr).attr(&quot;checked&quot;, &quot;checked&quot;);
                    }
                }

            };

            //A: triggero click per colorare la riga
            jQuery(&quot;input:radio:checked&quot;, that).trigger(&quot;click&quot;);
            //B: triggero checked -&gt; se usassi il click la checkbox si deselezionerebbe
            jQuery(&quot;input:checkbox:checked&quot;, that).trigger(&quot;checked&quot;);

        });
    }
	$.fn.comodoclick = ComodoClick;

	//AUTOLOAD
	$(document).ready(function(){
		$('table.comodoclick').comodoclick();
	});
})(jQuery);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://maxb.net/blog/2009/05/12/comodoclick/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

