<?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>bogdan_constantinescu &#187; Javascript</title>
	<atom:link href="http://www.bogdanconstantinescu.com/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bogdanconstantinescu.com</link>
	<description>idei binare</description>
	<lastBuildDate>Wed, 20 Apr 2011 22:09:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>jQuery: traversing</title>
		<link>http://www.bogdanconstantinescu.com/2009/04/06/jquery-traversing/</link>
		<comments>http://www.bogdanconstantinescu.com/2009/04/06/jquery-traversing/#comments</comments>
		<pubDate>Mon, 06 Apr 2009 12:49:16 +0000</pubDate>
		<dc:creator>Bogdan Constantinescu</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[traversing]]></category>

		<guid isPermaLink="false">http://www.bogdanconstantinescu.com/?p=153</guid>
		<description><![CDATA[Având în vedere că scriu foarte rar din cauza timpului limitat pe care îl am, m-am gândit să vă explic puțin despre liste și cum le parcurgem cu jQuery în caz de necesitate. Eu le-am folosit foarte mult în ultima (&#8230;)</p><p><a href="http://www.bogdanconstantinescu.com/2009/04/06/jquery-traversing/">Read the rest of this entry &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>Având în vedere că scriu foarte rar din cauza timpului limitat pe care îl am, m-am gândit să vă explic puțin despre liste și cum le parcurgem cu jQuery în caz de necesitate. Eu le-am folosit foarte mult în ultima perioada pentru versatilitatea de care dau dovada. Exemplul pe care se poate aplica foarte usor este un playlist.</p>
<p>În primul rând o să fac o listă cu necesitățile pentru a face chestia să funcționeze:</p>
<ul>
<li>ultimul <a href="http://jquery.com/" rel="nofollow" title="jQuery"  target="_blank">release jQuery</a> (in acest moment v1.3.2)</li>
<li>vreo 20minute libere</li>
</ul>
<p><span id="more-153"></span></p>
<p>Bun, acum trebuie să facem o simplă listă neordonată. Asta ar arăta în felul următor:</p>
<pre>&nbsp;
&lt;ul id=&quot;unordered_list&quot;&gt;
&lt;li class=&quot;current&quot;&gt;Item 0&lt;/li&gt;
&lt;li&gt;Item 1&lt;/li&gt;
&lt;li&gt;Item 2&lt;/li&gt;
&lt;li&gt;Item 3&lt;/li&gt;
&lt;li&gt;Item 4&lt;/li&gt;
&lt;/ul&gt;
&nbsp;</pre>
<p>ID-ul listei si clasa primului element din listă ne vor folosi puțin mai târziu când ne vom "plimba" prin listă cu Javascript, așa că luați-le "as is". Și dacă tot ne vom juca prin elemente ar fi bine să definim o clasă de CSS pentru elementul curent. Eu am fost puțin mai interesat de subiect decât de felul în care arată așa că am făcut următoarea clasă:</p>
<pre class="css"><span style="color: #6666ff;">.current</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #000000; font-weight: bold;">background</span>: <span style="color: #993333;">yellow</span>; <span style="color: #66cc66;">&#125;</span></pre>
<p>Bun, acum nu ne mai trebuie decât 4 butoane: pentru a adăuga elemente, pentru a șterge elemente, pentru a trece la elementul următor și la cel precedent. Asta s-ar traduce prin:</p>
<pre>&nbsp;
&lt;input id=&quot;add&quot; type=&quot;button&quot; value=&quot;Add new item&quot; /&gt;
&lt;input id=&quot;remove&quot; type=&quot;button&quot; value=&quot;Remove item&quot; /&gt;
&lt;input id=&quot;prev&quot; type=&quot;button&quot; value=&quot;Previous item&quot; /&gt;
&lt;input id=&quot;next&quot; type=&quot;button&quot; value=&quot;Next item&quot; /&gt;</pre>
<p>În acest moment suntem gata să scriem Javascript. Două funcții importante pe care le vom folosi în exemplul de mai jos sunt cele care îmi vor întoarce numarul elementelor din listă și poziția elementului curent.</p>
<pre class="javascript"><span style="color: #003366; font-weight: bold;">function</span> ul_size<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> size = $<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;#unordered_list&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">children</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'li'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">size</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;.size&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">text</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'Size: '</span>+size<span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #000066; font-weight: bold;">return</span> size;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> ul_pos<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> current_pos = $<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;.current&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">prevAll</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">length</span>;
	$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;.current_pos&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">text</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'Current: '</span>+current_pos<span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #000066; font-weight: bold;">return</span> current_pos;
<span style="color: #66cc66;">&#125;</span></pre>
<p>Puteți ignora momentan metoda <em>.text()</em>. Pe scurt, funcția <em>ul_size()</em> numără elementele de tip <em>li</em> din lista noastră, iar funcția <em>ul_pos()</em> numără toate elementele dinaintea celui curent. Acum mai trebuie doar să adăugăm acțiuni pe cele 4 butoane de care vorbeam mai sus.</p>
<pre class="javascript">$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;#add&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">click</span><span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> size = $<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;#unordered_list&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">children</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'li'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">size</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;#unordered_list&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">append</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'
&lt;li&gt;Item '</span>+size+<span style="color: #3366CC;">'&lt;/li&gt;
&nbsp;
'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	ul_size<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;#remove&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">click</span><span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #66cc66;">&#40;</span>ul_size<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> != <span style="color: #CC0000;">1</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;#unordered_list li:last&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">remove</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		ul_size<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;#prev&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">click</span><span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #66cc66;">&#40;</span>ul_pos<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> != <span style="color: #CC0000;">0</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;.current&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">removeClass</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'current'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">prev</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'li'</span><span style="color: #66cc66;">&#41;</span>
                     .<span style="color: #006600;">addClass</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'current'</span><span style="color: #66cc66;">&#41;</span>;
		ul_pos<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;#next&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">click</span><span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #66cc66;">&#40;</span>ul_size<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> &amp;gt; <span style="color: #66cc66;">&#40;</span>$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;.current&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">prevAll</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">length</span><span style="color: #66cc66;">&#41;</span><span style="color: #CC0000;">+1</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;.current&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">removeClass</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'current'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">next</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'li'</span><span style="color: #66cc66;">&#41;</span>
                     .<span style="color: #006600;">addClass</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'current'</span><span style="color: #66cc66;">&#41;</span>;
		ul_pos<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;</pre>
<p>Am pregătit și un exemplu pe care îl puteți vedea <a href="http://bogdanconstantinescu.com/jquery/traversing/index.html" rel="nofollow" title="jQuery Traversing example" >aici</a>.</p>
<p>Dacă aveți întrebări, comentarii sau sugestii, folosiți formularul de mai jos.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bogdanconstantinescu.com/2009/04/06/jquery-traversing/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Tabele cu jQuery</title>
		<link>http://www.bogdanconstantinescu.com/2008/10/02/tabele-cu-jquery/</link>
		<comments>http://www.bogdanconstantinescu.com/2008/10/02/tabele-cu-jquery/#comments</comments>
		<pubDate>Thu, 02 Oct 2008 12:40:06 +0000</pubDate>
		<dc:creator>Bogdan Constantinescu</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.bogdanconstantinescu.com/?p=89</guid>
		<description><![CDATA[Pentru că a trecut ceva vreme de când am scris ultimul post referitor la jQuery, am revenit cu un mic tutorial, dar foarte eficient după părerea mea, despre tabele. Ştiu că nu mai sunt "la modă", dar mi se pare (&#8230;)</p><p><a href="http://www.bogdanconstantinescu.com/2008/10/02/tabele-cu-jquery/">Read the rest of this entry &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>Pentru că a trecut ceva vreme de când am scris ultimul post referitor la jQuery, am revenit cu un mic tutorial, dar foarte eficient după părerea mea, despre tabele. Ştiu că nu mai sunt "la modă", dar mi se pare relativ stupidă folosirea <em>&lt;div&gt;</em>-urilor pentru afişarea informaţiilor care necesită un tabel.</p>
<p>Acestea fiind zise, astăzi o să facem următoarele:</p>
<ul>
<li>o să stilizăm un tabel obişnuit (CSS aplicat cu jQuery)</li>
<li>o să-i dăm o notă mai accentuată rândului pe care ne poziţionăm mouseul</li>
<li>o să-i adăugăm un selector</li>
</ul>
<p>Bun, să începem cu tabelul. Eu am făcut un tabel obişnuit cu nişte valori random. Rezultatul îl puteţi vedea mai jos.<br />
<span id="more-89"></span></p>
<pre class="html4strict">&nbsp;
<span style="color: #009900;"><a href="http://december.com/html/4/element/table.html" rel="nofollow" ><span style="color: #000000; font-weight: bold;">&lt;table&gt;</span></a></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/tbody.html" rel="nofollow" ><span style="color: #000000; font-weight: bold;">&lt;tbody&gt;</span></a></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/tr.html" rel="nofollow" ><span style="color: #000000; font-weight: bold;">&lt;tr&gt;</span></a></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/th.html" rel="nofollow" ><span style="color: #000000; font-weight: bold;">&lt;th&gt;</span></a></span>first name<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/th&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/th.html" rel="nofollow" ><span style="color: #000000; font-weight: bold;">&lt;th&gt;</span></a></span>last name<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/th&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/th.html" rel="nofollow" ><span style="color: #000000; font-weight: bold;">&lt;th&gt;</span></a></span>city<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/th&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tr&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/tr.html" rel="nofollow" ><span style="color: #000000; font-weight: bold;">&lt;tr&gt;</span></a></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/td.html" rel="nofollow" ><span style="color: #000000; font-weight: bold;">&lt;td&gt;</span></a></span>john<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/td.html" rel="nofollow" ><span style="color: #000000; font-weight: bold;">&lt;td&gt;</span></a></span>doe<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/td.html" rel="nofollow" ><span style="color: #000000; font-weight: bold;">&lt;td&gt;</span></a></span>the &quot;big apple&quot;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tr&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/tr.html" rel="nofollow" ><span style="color: #000000; font-weight: bold;">&lt;tr&gt;</span></a></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/td.html" rel="nofollow" ><span style="color: #000000; font-weight: bold;">&lt;td&gt;</span></a></span>anne<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/td.html" rel="nofollow" ><span style="color: #000000; font-weight: bold;">&lt;td&gt;</span></a></span>robinson<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/td.html" rel="nofollow" ><span style="color: #000000; font-weight: bold;">&lt;td&gt;</span></a></span>the city of angels<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tr&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tbody&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/table&gt;</span></span>
&nbsp;</pre>
<p>Bun. Acum o să facem câteva clase CSS pentru tabelul nostru. În primul rând ne trebuie o clasă pentru rândurile pare şi una pentru rândurile impare ca să-i dăm un mic contrast să poată fi citit cu uşurinţă. ( Ca sugestie, încercaţi să faceţi abstracţie de culori pentru că nu prea sunt "pe domeniul meu" <img src='http://www.bogdanconstantinescu.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  )</p>
<pre class="css"><span style="color: #6666ff;">.odd</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #000000; font-weight: bold;">background</span>: <span style="color: #cc00cc;">#D1E6E7</span>; <span style="color: #66cc66;">&#125;</span>
<span style="color: #6666ff;">.even</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #000000; font-weight: bold;">background</span>: <span style="color: #cc00cc;">#94d1e6</span>; <span style="color: #66cc66;">&#125;</span></pre>
<p>Acum să facem ceva ca să dăm o notă mai accentuată rândului peste care ţinem mouseul. Voi denumi această clasă <em>mouseover</em>.</p>
<pre class="css"><span style="color: #6666ff;">.mouseover</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #000000; font-weight: bold;">background</span>: <span style="color: #cc00cc;">#fff395</span>; <span style="color: #66cc66;">&#125;</span></pre>
<p>Şi suntem aproape gata...ne mai trebuie totuşi o ultimă clasă care să ne permită "selectarea" rândului dorit. O să-i spunem <em>click</em>.</p>
<pre class="css"><span style="color: #6666ff;">.click</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #000000; font-weight: bold;">background</span>: <span style="color: #cc00cc;">#feb40c</span>; <span style="color: #000000; font-weight: bold;">font-weight</span>: <span style="color: #993333;">bold</span>; <span style="color: #66cc66;">&#125;</span></pre>
<p>Ok, acum deţinem tot CSS-ul de care avem nevoie, urmează să-l convingem pe jQuery să facă treaba în locul nostru <img src='http://www.bogdanconstantinescu.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  În principiu azi o să folosim funcţiile <em>addClass()</em>, <em>removeClass()</em>, <em>mouseover()</em>, <em>mouseout()</em> şi <em>toggle()</em>. Documentaţie pentru ele găsiţi pe <a href="http://docs.jquery.com/Main_Page" rel="nofollow" title="jQuery documentation"  target="_blank">documentaţia jQuery</a>.</p>
<p>Să ne gândim cam ce ar trebui să facem noi cu jQuery...în primul rând să asociem clasele <strong>odd</strong> şi <strong>even</strong> rândurilor de care aparţin (în speţă, cele impare şi cele pare), să punem clasa <strong>mouseover</strong> pe aceste rânduri când trece mouseul, şi s-o scoatem când nu mai e mouseul deasupra. Acest lucru se face cam aşa:</p>
<pre class="javascript"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;tr:even&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">addClass</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;even&quot;</span><span style="color: #66cc66;">&#41;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">.<span style="color: #006600;">mouseover</span><span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> $<span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">addClass</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;mouseover&quot;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">.<span style="color: #006600;">mouseout</span><span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> $<span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">removeClass</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;mouseover&quot;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;tr:odd&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">addClass</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;odd&quot;</span><span style="color: #66cc66;">&#41;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">.<span style="color: #006600;">mouseover</span><span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> $<span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">addClass</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;mouseover&quot;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">.<span style="color: #006600;">mouseout</span><span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> $<span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">removeClass</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;mouseover&quot;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;</div></li></ol></pre>
<p>Ne mai rămâne să facem "selectorul". Ideea e simplă: când dai click pe un rând îşi schimbă culoarea, iar când faci al doilea click pe acelaşi rând revine la normal. jQuery are implementată o funcţie care se cheamă <em>toggle()</em> şi care face exact ce ne trebuie! <img src='http://www.bogdanconstantinescu.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  Haideţi să vedem cum arată...</p>
<pre class="javascript"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;tr&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">toggle</span><span style="color: #66cc66;">&#40;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	$<span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">addClass</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;click&quot;</span><span style="color: #66cc66;">&#41;</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">	$<span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">removeClass</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;click&quot;</span><span style="color: #66cc66;">&#41;</span>;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#41;</span>;</div></li></ol></pre>
<p>Şi cam asta a fost tot! Nu-mi spuneţi că vă aşteptaţi să fie mai complicat <img src='http://www.bogdanconstantinescu.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   E destul de simplu când foloseşti o librărie care-şi uşurează munca.</p>
<p>Ok, acum haideţi să vă arăt şi <a href="http://www.bogdanconstantinescu.com/jquery/table/"title="jQuery table enchancement"  target="_blank">rezultatul final</a>. Pentru a vedea mai multe detalii nu vă rămâne decât să vă uitaţi peste sursă. Pentru alte detalii, formularul de jos vă aşteaptă să-l folosiţi!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bogdanconstantinescu.com/2008/10/02/tabele-cu-jquery/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Linkuri cu jQuery</title>
		<link>http://www.bogdanconstantinescu.com/2008/09/19/linkuri-cu-jquery/</link>
		<comments>http://www.bogdanconstantinescu.com/2008/09/19/linkuri-cu-jquery/#comments</comments>
		<pubDate>Fri, 19 Sep 2008 09:10:53 +0000</pubDate>
		<dc:creator>Bogdan Constantinescu</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[link]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.bogdanconstantinescu.com/?p=41</guid>
		<description><![CDATA[Aseară a început o mică discuţie pe Twitter referitor la o problemă de validare în cazul linkurilor care conţin `target="_blank"`. Dicuţia a început de la întrebarea lui Radu Ceucă şi au fost sugerate câteva soluţii. Prima dintre ele îi aparţine (&#8230;)</p><p><a href="http://www.bogdanconstantinescu.com/2008/09/19/linkuri-cu-jquery/">Read the rest of this entry &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>Aseară a început o mică discuţie pe Twitter referitor la o problemă de validare în cazul linkurilor care conţin `target="_blank"`. Dicuţia a început de la întrebarea lui <a href="http://www.raduceuca.com/" rel="nofollow" >Radu Ceucă</a> şi au fost sugerate câteva soluţii.</p>
<p>Prima dintre ele îi aparţine lui @<a href="http://www.extraordinaire.me/" rel="nofollow" >extraordinaire</a> care a propus clasicul `window.open`. Din păcate problema e că arată urâţel un <em>onclick</em> care conţine un `window.open` şi presupun că va fi tratat ca pop-up de majoritatea adblock-urilor. O altă soluţie primită am înţeles că a fost <a href="http://www.sitepoint.com/article/standards-compliant-world/3/" rel="nofollow" >clasicul `rel="external"`</a> tratat cu Javascript.</p>
<p>Eu vreau să vă arat cea mai simplă şi curată soluţie folosind <a href="http://www.jquery.com" rel="nofollow" >jQuery</a>. Respectând zicala jQuery, `let's write less and do more` <img src='http://www.bogdanconstantinescu.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<pre class="javascript">$<span style="color: #66cc66;">&#40;</span>document<span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">ready</span><span style="color: #66cc66;">&#40;</span>
   <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
   <span style="color: #66cc66;">&#123;</span>
       $<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;a[@rel*=external]&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">attr</span><span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">&#123;</span> target: <span style="color: #3366CC;">&quot;_blank&quot;</span> <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
   <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#41;</span>;</pre>
<p>Ne mai rămâne doar să includem libraria jQuery şi să punem acest script între &lt;head&gt; şi &lt;/head&gt; şi totul e gata. Orice link care va avea `rel="external"` va fi deschis într-o pagină nouă. Simplu şi curat!</p>
<p>Cu un pas mai aproape de `Javascript Rockstar` <img src='http://www.bogdanconstantinescu.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.bogdanconstantinescu.com/2008/09/19/linkuri-cu-jquery/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>jQuery tooltip &#8211; dezvoltare</title>
		<link>http://www.bogdanconstantinescu.com/2008/09/02/jquery-tooltip-dezvoltare/</link>
		<comments>http://www.bogdanconstantinescu.com/2008/09/02/jquery-tooltip-dezvoltare/#comments</comments>
		<pubDate>Tue, 02 Sep 2008 20:06:44 +0000</pubDate>
		<dc:creator>Bogdan Constantinescu</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[tooltip]]></category>

		<guid isPermaLink="false">http://www.bogdanconstantinescu.com/?p=32</guid>
		<description><![CDATA[În ultimul post am realizat un mic tooltip cu ajutorul jQuery, caruia îi vom aduce nişte modificări în tutorialul de azi. În unul din comentarii Brayn sugera ca tooltip-ul să funcţioneze în felul următor: textul din alt să fie înlocuit (&#8230;)</p><p><a href="http://www.bogdanconstantinescu.com/2008/09/02/jquery-tooltip-dezvoltare/">Read the rest of this entry &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>În ultimul post am realizat un mic tooltip cu ajutorul jQuery, caruia îi vom aduce nişte modificări în tutorialul de azi.</p>
<p>În unul din comentarii <a href="http://www.brayn.ro" rel="nofollow" title="Brayn"  target="_blank">Brayn</a> sugera ca tooltip-ul să funcţioneze în felul următor:</p>
<ul>
<li>textul din <em>alt </em>să fie înlocuit cu un id</li>
<li>tooltip-ul va afişa în final textul dinamic (în cazul nostru îl vom scoate dintr-o bază de date MySQL)</li>
</ul>
<p>În consecinţă am aflat că avem nevoie de câteva lucruri...</p>
<p><span id="more-32"></span></p>
<ul>
<li>o bază de date MySQL</li>
<li>un fişier care interacţionează cu serverul MySQL</li>
<li>o funcţie Javascript care face cererea către acest fişier</li>
</ul>
<p><strong>1. Baza de date</strong></p>
<p>Bun, haideţi să facem o bază de date nouă şi s-o populăm cu nişte informaţii (textele pe care le vom afişa mai apoi în tooltip).</p>
<pre class="sql"> <span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">DATABASE</span> <span style="color: #ff0000;">`tooltip`</span> ;</pre>
<p>Acum vom face şi o tabelă pe care eu am numit-o <em>definition</em>. Pe scurt este vorba de 2 câmpuri: <em>uid</em> - "unique id" (în care se va afla id-ul pe care noi îl vom citi din proprietatea <em>alt</em> a imaginii) şi <em>text </em>- "informaţia ce se va afişa în tooltip".</p>
<pre class="sql"> <span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #ff0000;">`tooltip`</span>.<span style="color: #ff0000;">`definition`</span> <span style="color: #66cc66;">&#40;</span>
<span style="color: #ff0000;">`uid`</span> INT <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span> ,
<span style="color: #ff0000;">`text`</span> TEXT <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> ,
<span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">`uid`</span> <span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span> ENGINE = MYISAM</pre>
<p>Dacă aveţi vreo nelamurire despre SQL puteţi consulta nişte <a href="http://dev.mysql.com/doc/" rel="nofollow" title="MySQL documentation" >manuale online</a>. OK, acum mai trebuie să populăm baza de date proaspăt creată...</p>
<pre class="sql"><span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">`definition`</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`uid`</span>, <span style="color: #ff0000;">`text`</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>, <span style="color: #ff0000;">'First tooltip information coming from a mysql database.'</span><span style="color: #66cc66;">&#41;</span>,
<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span>, <span style="color: #ff0000;">'We also have a second database entry
for showing you the text you were looking for!'</span><span style="color: #66cc66;">&#41;</span>,
<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span>, <span style="color: #ff0000;">'And some more information. You like it, huh? &lt;img src='</span>http://www.bogdanconstantinescu.com/wp-includes/images/smilies/icon_smile.gif<span style="color: #ff0000;">' alt='</span>:-<span style="color: #66cc66;">&#41;</span><span style="color: #ff0000;">' class='</span>wp-smiley<span style="color: #ff0000;">' /&gt; '</span><span style="color: #66cc66;">&#41;</span>,
<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">4</span>, <span style="color: #ff0000;">'Showing possible thanks to jQuery ajax httprequest &lt;img src='</span>http://www.bogdanconstantinescu.com/wp-includes/images/smilies/icon_smile.gif<span style="color: #ff0000;">' alt='</span>:<span style="color: #66cc66;">&#41;</span><span style="color: #ff0000;">' class='</span>wp-smiley<span style="color: #ff0000;">' /&gt; '</span><span style="color: #66cc66;">&#41;</span>;</pre>
<p>Acestea fiind făcute nu ne rămâne decât să trecem la urmatorul pas, realizarea fişierului care va face legătura cu serverul MySQL.</p>
<p><strong>2. Scriptul server-side</strong></p>
<p>Această etapă o puteţi face utilizând orice limbaj de programare server-side care vă place. Personal o să aleg php pentru că pe el îl stăpânesc cel mai bine. Pe scurt ceea ce trebuie să realizăm va arăta cam aşa:</p>
<ul>
<li>aşteptăm sa fie transmis un parametru la chemarea fişierului</li>
<li>ne conectăm la serverul MySQL</li>
<li>facem interogarea şi afişăm rezultatul.</li>
</ul>
<p>Treabă simplă. În consecinţă ajungem la un rezultat asemănător cu cel de mai jos.</p>
<pre class="php"><span style="color: #808080; font-style: italic;">/* ne conectam la serverul mysql si
selectam baza de date pe care vom lucra */</span>
<span style="color: #0000ff;">$dbh</span> = <a href="http://www.php.net/mysql_connect" rel="nofollow" ><span style="color: #000066;">mysql_connect</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;localhost&quot;</span>, <span style="color: #ff0000;">&quot;user&quot;</span>, <span style="color: #ff0000;">&quot;parola&quot;</span><span style="color: #66cc66;">&#41;</span>;
<a href="http://www.php.net/mysql_select_db" rel="nofollow" ><span style="color: #000066;">mysql_select_db</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;tooltip&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">/* verificam sa fie curat inputul si ii
scoatem spatiile goale din jurul sau */</span>
<span style="color: #0000ff;">$request</span> = <a href="http://www.php.net/strip_tags" rel="nofollow" ><span style="color: #000066;">strip_tags</span></a><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/trim" rel="nofollow" ><span style="color: #000066;">trim</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$_POST</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'uid'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">/* facem select-ul in functie de ID */</span>
<span style="color: #0000ff;">$qry</span> = <a href="http://www.php.net/mysql_query" rel="nofollow" ><span style="color: #000066;">mysql_query</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;
		SELECT
			text
		FROM
			`definition`
		WHERE
			uid='&quot;</span>. <span style="color: #0000ff;">$request</span> .<span style="color: #ff0000;">&quot;'&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">/* afisam textul pentru tooltip aferent ID-ului cerut;
daca ID-ul cerut nu exista ii spunem acest lucru*/</span>
<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/mysql_num_rows" rel="nofollow" ><span style="color: #000066;">mysql_num_rows</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$qry</span><span style="color: #66cc66;">&#41;</span> != <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>
	<a href="http://www.php.net/echo" rel="nofollow" ><span style="color: #000066;">echo</span></a> <a href="http://www.php.net/mysql_result" rel="nofollow" ><span style="color: #000066;">mysql_result</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$qry</span>, <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #b1b100;">else</span>
	<a href="http://www.php.net/echo" rel="nofollow" ><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;Sorry, that does not exist!&quot;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">/* si in final inchidem conexiunea la server */</span>
<a href="http://www.php.net/mysql_close" rel="nofollow" ><span style="color: #000066;">mysql_close</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$dbh</span><span style="color: #66cc66;">&#41;</span>;</pre>
<p>Fişierul în cauză eu l-am denumit <em>tooltip.php</em> (ne va fi de folos în ultimul pas) <img src='http://www.bogdanconstantinescu.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>3. Let's do some Javascript magic</strong></p>
<p>Bun, deci avem baza de date, avem fişierul care face output în funcţie de parametrul care îi este trimis (în cazul nostru metoda este POST) şi ne rămâne de făcut doar o funcţie nouă în script şi nişte mici modificări.</p>
<pre class="javascript"><span style="color: #003366; font-weight: bold;">function</span> request<span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #009900; font-style: italic;">/* realizam pachetul de optiuni pentru functie */</span>
	<span style="color: #003366; font-weight: bold;">var</span> data = <span style="color: #66cc66;">&#123;</span>
			type: <span style="color: #3366CC;">&quot;POST&quot;</span>,
			url: <span style="color: #3366CC;">&quot;tooltip.php&quot;</span>,
			data: <span style="color: #3366CC;">&quot;uid=&quot;</span>+id,
			async: <span style="color: #003366; font-weight: bold;">false</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #009900; font-style: italic;">/* chemam functia si ii preluam raspunsul */</span>
	<span style="color: #003366; font-weight: bold;">var</span> response = $.<span style="color: #006600;">ajax</span><span style="color: #66cc66;">&#40;</span>data<span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">responseText</span>;
&nbsp;
	<span style="color: #009900; font-style: italic;">/* si il intoarcem */</span>
	<span style="color: #000066; font-weight: bold;">return</span> response;
<span style="color: #66cc66;">&#125;</span></pre>
<p>Ne mai rămâne ca în funcţia din eventul <em>mouseover</em> să schimbăm valoarea variabilei <em>text</em> cu urmatoarea secvenţă.</p>
<pre class="javascript"><span style="color: #003366; font-weight: bold;">var</span> text = request<span style="color: #66cc66;">&#40;</span>parseInt<span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">alt</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</pre>
<p>În principu dacă am ajuns aici totul ar trebui să fie în regulă. <img src='http://www.bogdanconstantinescu.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Pentru a vă demonstra ceea ce tocmai am realizat puteţi vedea un <a href="http://www.bogdanconstantinescu.com/jquery/ajaxtooltip/"title="tooltip example"  target="_blank">exemplu</a> sau puteţi downloada <a href="http://www.bogdanconstantinescu.com/jquery/ajaxtooltip/tooltip.js"title="tooltip.js"  target="_blank">scriptul Javascript</a> si <a href="http://www.bogdanconstantinescu.com/jquery/ajaxtooltip/tooltip.php.txt"title="tooltip.php"  target="_blank">scriptul php</a>.</p>
<p>Pentru orice nelămurire, sugestie sau "reclamaţie" foloseşte formularul de mai jos!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bogdanconstantinescu.com/2008/09/02/jquery-tooltip-dezvoltare/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>jQuery tooltip</title>
		<link>http://www.bogdanconstantinescu.com/2008/09/01/jquery-tooltip/</link>
		<comments>http://www.bogdanconstantinescu.com/2008/09/01/jquery-tooltip/#comments</comments>
		<pubDate>Mon, 01 Sep 2008 09:16:15 +0000</pubDate>
		<dc:creator>Bogdan Constantinescu</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[tooltip]]></category>

		<guid isPermaLink="false">http://www.bogdanconstantinescu.com/?p=13</guid>
		<description><![CDATA[În acest post o să vă arăt flexibilitatea lui jQuery care vine în ajutorul developerului pentru a simplifica anumite etape ale procesului de dezvoltare. Despre jQuery în câteva cuvinte jQuery este o librarie de Javascript redusă ca mărime ( 15kb (&#8230;)</p><p><a href="http://www.bogdanconstantinescu.com/2008/09/01/jquery-tooltip/">Read the rest of this entry &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>În acest post o să vă arăt flexibilitatea lui <a href="http://jquery.com/" rel="nofollow" title="jQuery"  target="_blank">jQuery</a> care vine în ajutorul developerului pentru a simplifica anumite etape ale procesului de dezvoltare.</p>
<p><strong>Despre jQuery în câteva cuvinte</strong></p>
<ul>
<li>jQuery este o librarie de Javascript redusă ca mărime ( 15kb )</li>
<li>una din primele librării de Javascript crossbrowser (IE 6.0+, FF 2+, Safari 2.0+, Opera 9.0+)</li>
<li>compatibilă cu toate versiunile de <acronym title="Cascading Style Sheet">CSS</acronym></li>
</ul>
<p><strong>Ce fel de tooltip ne dorim?<br />
</strong></p>
<p><span id="more-13"></span></p>
<p>Mi-am propus să realizez un tooltip simplu şi eficient pentru lamuriri adiţionale în completarea unui formular. În principiu am 2 soluţii de a realiza apariţia tooltip-ului:</p>
<ol>
<li>tooltip-ul apare la click (în situaţia în care userul simte nevoia unor explicaţii suplimentare dă un click pe icon-ul de help)</li>
<li>tooltip-ul apare la mouseover</li>
</ol>
<p>Dintre cele 2 opţiuni eu am ales-o pe cea de-a doua pentru ca îmi place să nu pun userul să facă acţiuni în plus pentru a vedea nişte informaţii pe care le doreşte (doar de-asta trăim în vremurile în care cuvântul de ordine în webdevelopment este <strong>uzabilitate</strong>). Ne dorim ca user-ului să-i fie cât mai uşor să utilizeze toate funcţiile site-ului.</p>
<p><strong>Realizarea tooltipului cu ajutorul jQuery</strong></p>
<p>În primul rând trebuie să ne punem scriptul să ruleze după încărcarea completă a paginii.</p>
<pre class="javascript">        $<span style="color: #66cc66;">&#40;</span>document<span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">ready</span><span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span> <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;</pre>
<p>Pentru realizarea apariţiei tooltip-ului la mouseover vom folosi proprietatea obiectului <em>object.mouseover();</em> iar selecţia o vom face după un pattern simplu: "selectează-mi toate imaginile care au clasa 'tooltip' ". În consecinţă codul nostru va arăta în felul următor.</p>
<pre class="javascript"> $<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;img.tooltip&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">mouseover</span><span style="color: #66cc66;">&#40;</span>
<span style="color: #009900; font-style: italic;">/* $(&quot;img.tooltip&quot;) este selectorul nostru care face
selectia imaginilor care au clasa 'tooltip' */</span>
<span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>event<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;</pre>
<p>În pasul următor vom lua de pe imaginea noastră atributul <em>alt</em> a cărui valoare o vom afişa cu ajutorul tooltip-ului. Pentru asta va trebui să facem un <em>&lt;div&gt;</em> în care să afişăm informaţia explicativă. Vom avea nevoie şi de cunoştinţe de CSS pentru a putea stiliza obiectul şi pentru a-l putea duce în poziţia dorită de afişare. În cazul meu, CSS-ul este aşa:</p>
<pre class="css"><span style="color: #cc00cc;">#tooltip</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">position</span>: <span style="color: #993333;">absolute</span>;
	<span style="color: #000000; font-weight: bold;">font-family</span>: Verdana, <span style="color: #993333;">sans-serif</span>;
	<span style="color: #000000; font-weight: bold;">font-size</span>: <span style="color: #933;">10px</span>;
	<span style="color: #000000; font-weight: bold;">max-width</span>: <span style="color: #933;">150px</span>;
	<span style="color: #000000; font-weight: bold;">border</span>: <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#91C2DC</span>;
	<span style="color: #000000; font-weight: bold;">z-index</span>: <span style="color: #933;">10000</span>;
	<span style="color: #000000; font-weight: bold;">color</span>: <span style="color: #cc00cc;">#<span style="color: #933;">333333</span></span>;
	<span style="color: #000000; font-weight: bold;">background</span>:
 <span style="color: #993333;">url</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'information.png'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333;">center</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #993333;">no-repeat</span> <span style="color: #cc00cc;">#FFFFFF</span>;
	<span style="color: #000000; font-weight: bold;">margin</span>: <span style="color: #933;">10px</span> <span style="color: #933;">5px</span> <span style="color: #933;">5px</span> <span style="color: #933;">10px</span>;
	<span style="color: #000000; font-weight: bold;">padding</span>: <span style="color: #933;">20px</span> <span style="color: #933;">3px</span> <span style="color: #933;">3px</span> <span style="color: #933;">3px</span>;
<span style="color: #66cc66;">&#125;</span></pre>
<p>Să vedem cum arată Javascriptul pentru cele descrise mai sus:</p>
<pre class="javascript">$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;img.tooltip&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">mouseover</span><span style="color: #66cc66;">&#40;</span>
<span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>event<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
   <span style="color: #003366; font-weight: bold;">var</span> text = <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">alt</span>;
<span style="color: #009900; font-style: italic;">/* tinem continutul proprietatii
alt in variabila 'text' */</span>
   x = event.<span style="color: #006600;">pageX</span><span style="color: #CC0000;">+10</span>;
<span style="color: #009900; font-style: italic;">/* sa mutam tooltipul putin mai la dreapta
 ca sa nu fie acoperit de cursor */</span>
   y = event.<span style="color: #006600;">pageY</span><span style="color: #CC0000;">+10</span>;
<span style="color: #009900; font-style: italic;">/* si putin mai jos... */</span>
   $<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;body&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">append</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;
&lt;div id='tooltip'&gt;&quot;</span>+text+<span style="color: #3366CC;">&quot;&lt;/div&gt;
&nbsp;
&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #009900; font-style: italic;">/* mai intai facem un div [asta reprezentand
alternativa jQuery la DOM] */</span>
   $<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;#tooltip&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">css</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;left&quot;</span>, x<span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">css</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;top&quot;</span>, y<span style="color: #66cc66;">&#41;</span>;
<span style="color: #009900; font-style: italic;">/* si ne mai ramane doar sa-l mutam langa cursor */</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#41;</span>;</pre>
<p>OK, am făcut tooltip-ul, dar va trebui să-l distrugem la acţiunea <em>object.mouseout();</em> şi cu asta suntem aproape gata.</p>
<pre class="javascript">$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;img.tooltip&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">mouseout</span><span style="color: #66cc66;">&#40;</span>
<span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>event<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
  $<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;#tooltip&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">remove</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #009900; font-style: italic;">/* cand se intampla mouseout distrugem div-ul */</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#41;</span>;</pre>
<p>În funcţie de preferinţe mai rămâne doar să aranjăm totul într-o funcţie şi s-o folosim. Pentru asta eu am făcut un <a href="http://www.bogdanconstantinescu.com/jquery/tooltip/"title="exemplu"  target="_blank">exemplu</a> si de <a href="http://www.bogdanconstantinescu.com/jquery/tooltip/tooltip.js"title="scriptul"  target="_blank">aici</a> puteţi downloada scriptul complet.</p>
<p>Ceea ce tocmai am realizat e o variantă simplă şi nu se vrea în nici un caz o concurenţă la scripturile de tooltip existente, ci o aplicaţie a unor simple cunoştinţe de jQuery.</p>
<p>Orice părere, sugestie sau "reclamaţie" e bine-venită (folosiţi formularul din josul paginii)!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bogdanconstantinescu.com/2008/09/01/jquery-tooltip/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>

