<?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>Victor Stanciu &#187; JavaScript</title>
	<atom:link href="http://www.victorstanciu.ro/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.victorstanciu.ro</link>
	<description>Web Developer, Geek</description>
	<lastBuildDate>Tue, 17 Jan 2012 11:18:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Dynamically resizing the Shadowbox.js modal window</title>
		<link>http://www.victorstanciu.ro/dynamically-resizing-the-shadowbox-js-modal-window/</link>
		<comments>http://www.victorstanciu.ro/dynamically-resizing-the-shadowbox-js-modal-window/#comments</comments>
		<pubDate>Fri, 01 Apr 2011 13:21:18 +0000</pubDate>
		<dc:creator>Victor Stanciu</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[shadowbox]]></category>

		<guid isPermaLink="false">http://www.victorstanciu.ro/?p=713</guid>
		<description><![CDATA[Shadowbox.js is an excellent modal window component capable of handling everything from iFrames to Flash videos to image galleries. However, and odd as it seems, the out-of-the-box solution doesn&#8217;t have a resize() method with which to resize the modal window via JavaScript. The reason you might want to manually resize the modal window is in [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.shadowbox-js.com/index.html">Shadowbox.js</a> is an excellent modal window component capable of handling everything from iFrames to Flash videos to image galleries. However, and odd as it seems, the out-of-the-box solution doesn&#8217;t have a <strong>resize()</strong> method with which to resize the modal window via JavaScript. The reason you might want to manually resize the modal window is in case the content inside changes, for example in the case of IFrames. Fortunately, implementing such a method is quite easy.</p>
<p>First, download <a href="http://www.shadowbox-js.com/download.html" target="_blank">Shadowbox</a>. As of this version, the downloaded files are automatically <strong>minified</strong>, so in order to be able to properly add the needed code you will have to prettify the code, using a tool such as <a href="http://jsbeautifier.org/" target="_blank">http://jsbeautifier.org/</a>.</p>
<p>After you have prettified the code, scroll down right after the <strong>onWindowResize</strong> method, which should look something like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">k.<span style="color: #660066;">onWindowResize</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>P<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">return</span>
    <span style="color: #009900;">&#125;</span>
    I<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> K <span style="color: #339933;">=</span> g.<span style="color: #660066;">player</span><span style="color: #339933;">,</span>
        S <span style="color: #339933;">=</span> R<span style="color: #009900;">&#40;</span>K.<span style="color: #660066;">height</span><span style="color: #339933;">,</span> K.<span style="color: #660066;">width</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    t<span style="color: #009900;">&#40;</span>S.<span style="color: #660066;">width</span><span style="color: #339933;">,</span> S.<span style="color: #660066;">left</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    E<span style="color: #009900;">&#40;</span>S.<span style="color: #660066;">innerHeight</span><span style="color: #339933;">,</span> S.<span style="color: #660066;">top</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>K.<span style="color: #660066;">onWindowResize</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        K.<span style="color: #660066;">onWindowResize</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>The reason I am including the <strong>onWindowResize</strong> method is because, the code being packed, the variable names might change in subsequent versions of Shadowbox, so you will have to take a look at an existing function. Now, right below the <strong>onWindowResize</strong> method, add the following code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">k.<span style="color: #660066;">dynamicResize</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>w<span style="color: #339933;">,</span> h<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>P<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">return</span>
    <span style="color: #009900;">&#125;</span>
    I<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    g.<span style="color: #660066;">player</span>.<span style="color: #660066;">width</span> <span style="color: #339933;">=</span> w<span style="color: #339933;">;</span>
    g.<span style="color: #660066;">player</span>.<span style="color: #660066;">height</span> <span style="color: #339933;">=</span> h<span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> K <span style="color: #339933;">=</span> g.<span style="color: #660066;">player</span><span style="color: #339933;">,</span>
        S <span style="color: #339933;">=</span> R<span style="color: #009900;">&#40;</span>K.<span style="color: #660066;">height</span><span style="color: #339933;">,</span> K.<span style="color: #660066;">width</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    t<span style="color: #009900;">&#40;</span>S.<span style="color: #660066;">width</span><span style="color: #339933;">,</span> S.<span style="color: #660066;">left</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    E<span style="color: #009900;">&#40;</span>S.<span style="color: #660066;">innerHeight</span><span style="color: #339933;">,</span> S.<span style="color: #660066;">top</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>K.<span style="color: #660066;">onWindowResize</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        K.<span style="color: #660066;">onWindowResize</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Notice that there are only three lines that differ between the two methods. After adding this method (and perhaps minifying the code again), you can easily resize the modal like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">Shadowbox.<span style="color: #660066;">skin</span>.<span style="color: #660066;">dynamicResize</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">600</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">400</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Or, if you want to do it from inside the iframe loaded within the modal:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">window.<span style="color: #660066;">parent</span>.<span style="color: #660066;">Shadowbox</span>.<span style="color: #660066;">skin</span>.<span style="color: #660066;">dynamicResize</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">600</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">400</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Note that this method <strong>does not</strong> resize the window beyond the viewport dimensions. It will still be scaled down if it exceeds the viewport&#8217;s width or height.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.victorstanciu.ro/dynamically-resizing-the-shadowbox-js-modal-window/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Closure: Extend ui.DatePicker to highlight events</title>
		<link>http://www.victorstanciu.ro/closure-extend-ui-datepicker-to-highlight-events/</link>
		<comments>http://www.victorstanciu.ro/closure-extend-ui-datepicker-to-highlight-events/#comments</comments>
		<pubDate>Sun, 08 Nov 2009 16:49:24 +0000</pubDate>
		<dc:creator>Victor Stanciu</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Closure]]></category>
		<category><![CDATA[DatePicker]]></category>
		<category><![CDATA[google]]></category>

		<guid isPermaLink="false">http://www.victorstanciu.ro/?p=378</guid>
		<description><![CDATA[I got a change to play with the new Google Closure Library a bit, and since the DatePicker component is pretty nice, i figured i could enhance it a bit to suit a need i had some time ago: overlay data from a database, highlight the dates that correspond to events, and jump to the event&#8217;s page [...]]]></description>
			<content:encoded><![CDATA[<p>I got a change to play with the new <a href="http://code.google.com/closure/library/">Google Closure Library</a> a bit, and since the <a href="http://closure-library.googlecode.com/svn/trunk/closure/goog/docs/class_goog_ui_DatePicker.html">DatePicker</a> component is pretty nice, i figured i could enhance it a bit to suit a need i had some time ago: overlay data from a database, highlight the dates that correspond to events, and jump to the event&#8217;s page when clicking on a highlighted cell.</p>
<p><a href="http://dev.victorstanciu.ro/google-closure/examples/events-date-picker/"><strong>Example page</strong></a><br />
<a href="http://dev.victorstanciu.ro/google-closure/examples/events-date-picker/eventsdatepicker.js"><strong>Example script</strong></a></p>
<h2>Step 1: provide the JSON events in HTML:</h2>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> events <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>
    <span style="color: #009900;">&#123;</span>date<span style="color: #339933;">:</span> <span style="color: #3366CC;">'2009-11-05'</span><span style="color: #339933;">,</span> url<span style="color: #339933;">:</span> <span style="color: #3366CC;">'http://www.example.com'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#123;</span>date<span style="color: #339933;">:</span> <span style="color: #3366CC;">'2009-11-07'</span><span style="color: #339933;">,</span> url<span style="color: #339933;">:</span> <span style="color: #3366CC;">'http://www.example.com'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#123;</span>date<span style="color: #339933;">:</span> <span style="color: #3366CC;">'2009-11-10'</span><span style="color: #339933;">,</span> url<span style="color: #339933;">:</span> <span style="color: #3366CC;">'http://www.example.com'</span><span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h2>Step 2: extend goog.ui.DatePicker:</h2>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">goog.<span style="color: #660066;">provide</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'goog.ui.EventsDatePicker'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
goog.<span style="color: #660066;">require</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'goog.ui.DatePicker'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
goog.<span style="color: #660066;">ui</span>.<span style="color: #660066;">EventsDatePicker</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>opt_events<span style="color: #339933;">,</span> opt_date<span style="color: #339933;">,</span> opt_dateTimeSymbols<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    goog.<span style="color: #660066;">ui</span>.<span style="color: #660066;">DatePicker</span>.<span style="color: #660066;">call</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> opt_date<span style="color: #339933;">,</span> opt_dateTimeSymbols<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">events</span> <span style="color: #339933;">=</span> opt_events<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
goog.<span style="color: #660066;">inherits</span><span style="color: #009900;">&#40;</span>goog.<span style="color: #660066;">ui</span>.<span style="color: #660066;">EventsDatePicker</span><span style="color: #339933;">,</span> goog.<span style="color: #660066;">ui</span>.<span style="color: #660066;">DatePicker</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Notice how inheritance is handled with Closure. Even though we call <b>goog.inherits()</b>, we <b>must</b> also call the superclass constructor for it to work.</p>
<h2>Step 3: highlight events:</h2>
<p>goog.ui.DatePicker has a <b>setDecorator()</b> method, that accepts a function as it&#8217;s parameter. The function should take a Date object and return a CSS class name to decorate the corresponding cell with.</p>
<p>It&#8217;s basically called once for every cell in the picker, and we are going to use this by checking whether an event exists for the date and return &#8220;goog-date-picker-event&#8221; if so:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">goog.<span style="color: #660066;">ui</span>.<span style="color: #660066;">EventsDatePicker</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>opt_events<span style="color: #339933;">,</span> opt_date<span style="color: #339933;">,</span> opt_dateTimeSymbols<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    goog.<span style="color: #660066;">ui</span>.<span style="color: #660066;">DatePicker</span>.<span style="color: #660066;">call</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> opt_date<span style="color: #339933;">,</span> opt_dateTimeSymbols<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">events</span> <span style="color: #339933;">=</span> opt_events<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// new line:</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">setDecorator</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">eventDecorator</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
goog.<span style="color: #660066;">inherits</span><span style="color: #009900;">&#40;</span>goog.<span style="color: #660066;">ui</span>.<span style="color: #660066;">EventsDatePicker</span><span style="color: #339933;">,</span> goog.<span style="color: #660066;">ui</span>.<span style="color: #660066;">DatePicker</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">/**
 * Searches the events array and returns the event corresponding to passed date
 */</span>
goog.<span style="color: #660066;">ui</span>.<span style="color: #660066;">EventsDatePicker</span>.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">findEventByDate</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>date<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> dateString <span style="color: #339933;">=</span> date.<span style="color: #660066;">toIsoString</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> event      <span style="color: #339933;">=</span> goog.<span style="color: #660066;">array</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">events</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">return</span> event.<span style="color: #660066;">date</span> <span style="color: #339933;">==</span> dateString<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">return</span> event<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">/**
 * Returns a CSS class name to use for cells that have events
 */</span>
goog.<span style="color: #660066;">ui</span>.<span style="color: #660066;">EventsDatePicker</span>.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">eventDecorator</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>date<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> event <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">findEventByDate</span><span style="color: #009900;">&#40;</span>date<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>    
&nbsp;
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>event <span style="color: #339933;">!==</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">'goog-date-picker-event'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Notice the use of <a href="http://closure-library.googlecode.com/svn/trunk/closure/goog/docs/closure_goog_array_array.js.html">goog.array.find()</a> to find the event that matches the date.</p>
<h2>Step 4: click events:</h2>
<p>We will use the findEventByDate function defined above and DatePicker&#8217;s SELECT event to jump to an event&#8217;s URL when clicking on it&#8217;s date:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">goog.<span style="color: #660066;">ui</span>.<span style="color: #660066;">EventsDatePicker</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>opt_events<span style="color: #339933;">,</span> opt_date<span style="color: #339933;">,</span> opt_dateTimeSymbols<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    goog.<span style="color: #660066;">ui</span>.<span style="color: #660066;">DatePicker</span>.<span style="color: #660066;">call</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> opt_date<span style="color: #339933;">,</span> opt_dateTimeSymbols<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">events</span> <span style="color: #339933;">=</span> opt_events<span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">setDecorator</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">eventDecorator</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// new line:</span>
    goog.<span style="color: #660066;">events</span>.<span style="color: #660066;">listen</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> goog.<span style="color: #660066;">ui</span>.<span style="color: #660066;">DatePicker</span>.<span style="color: #660066;">Events</span>.<span style="color: #660066;">SELECT</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">dateClicked</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">/**
 * Checks if an event cell was clicked, and jumps to the event's URL if true
 */</span>
goog.<span style="color: #660066;">ui</span>.<span style="color: #660066;">EventsDatePicker</span>.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">dateClicked</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> date  <span style="color: #339933;">=</span> event.<span style="color: #660066;">date</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> event <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">findEventByDate</span><span style="color: #009900;">&#40;</span>date<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>event <span style="color: #339933;">!==</span> <span style="color: #003366; font-weight: bold;">null</span> <span style="color: #339933;">&amp;&amp;</span> event.<span style="color: #660066;">url</span> <span style="color: #339933;">!=</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        document.<span style="color: #660066;">location</span>.<span style="color: #660066;">href</span> <span style="color: #339933;">=</span> event.<span style="color: #660066;">url</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>That&#8217;s it :). It&#8217;s a short example, but it covers some of the basic aspects of inheritance, event listeners, and some of the utility methods. Closure looks nice :)</p>
<p><a href="http://dev.victorstanciu.ro/google-closure/examples/events-date-picker/"><strong>Example page</strong></a><br />
<a href="http://dev.victorstanciu.ro/google-closure/examples/events-date-picker/eventsdatepicker.js"><strong>Example script</strong></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.victorstanciu.ro/closure-extend-ui-datepicker-to-highlight-events/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Prototype: Hotkeys</title>
		<link>http://www.victorstanciu.ro/prototype-hotkeys/</link>
		<comments>http://www.victorstanciu.ro/prototype-hotkeys/#comments</comments>
		<pubDate>Tue, 26 May 2009 12:42:11 +0000</pubDate>
		<dc:creator>Victor Stanciu</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[hotkeys]]></category>
		<category><![CDATA[prototype]]></category>
		<category><![CDATA[shortcuts]]></category>

		<guid isPermaLink="false">http://www.victorstanciu.ro/?p=342</guid>
		<description><![CDATA[Am scris un mic plugin pentru Prototype ce permite inregistrarea oricator hotkeys si combinatii de taste (poate inclusiv sa &#8220;suprascrie&#8221; combinatii de taste ale browserului, in genul CTRL+S). Documentatia si codul sunt pe pagina de la Google Code, o sa redau si aici exemplul: Presupunem ca vrem sa rulam functia add cu doi parametri la [...]]]></description>
			<content:encoded><![CDATA[<p>Am scris un mic plugin pentru Prototype ce permite inregistrarea oricator hotkeys si combinatii de taste (poate inclusiv sa &#8220;suprascrie&#8221; combinatii de taste ale browserului, in genul <b>CTRL+S</b>).</p>
<p>Documentatia si codul sunt pe pagina de la <a href="http://code.google.com/p/prototype-hotkeys/" title="Prototype: Hotkeys"><b>Google Code</b></a>, o sa redau si aici exemplul: Presupunem ca vrem sa rulam functia <b>add</b> cu doi parametri la apasarea tastelor ALT+A:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> add<span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span> b<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>parseInt<span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> parseInt<span style="color: #009900;">&#40;</span>b<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
Hotkeys.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;alt+a&quot;</span><span style="color: #339933;">,</span> add<span style="color: #339933;">,</span> <span style="color: #CC0000;">3</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Pentru mai multe feature-uri, precum si lista de alias-uri pentru taste, consultati <a href="http://code.google.com/p/prototype-hotkeys/" title="Prototype: Hotkeys">pagina proiectului</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.victorstanciu.ro/prototype-hotkeys/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>FTL jump &#8230; now!</title>
		<link>http://www.victorstanciu.ro/ftl-jump/</link>
		<comments>http://www.victorstanciu.ro/ftl-jump/#comments</comments>
		<pubDate>Tue, 19 May 2009 17:23:12 +0000</pubDate>
		<dc:creator>Victor Stanciu</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://www.victorstanciu.ro/?p=284</guid>
		<description><![CDATA[Fiecare fisier JavaScript, CSS, imagine, Flash, etc. afisat utilizatorului reprezinta un request catre server. Pentru fiecare asemenea fisier browserul trimite cererea, serverul o preia, proceseaza, serveste fisierul cerut, si tot asa. La site-urile &#8220;mari&#8221; se simte. In load-ul serverului, in latimea de banda consumata, in experienta utilizatorilor. Urmand recomandarile echipei de la Yahoo!, o sa [...]]]></description>
			<content:encoded><![CDATA[<p>Fiecare fisier JavaScript, CSS, imagine, Flash, etc. afisat utilizatorului reprezinta un request catre server. Pentru fiecare asemenea fisier browserul trimite cererea, serverul o preia, proceseaza, serveste fisierul cerut, si tot asa. La site-urile &#8220;mari&#8221; se simte. In load-ul serverului, in latimea de banda consumata, in experienta utilizatorilor.</p>
<p>Urmand <a href="http://developer.yahoo.com/performance/rules.html" title="<br />
Best Practices for Speeding Up Your Web Site" target="_blank">recomandarile</a> echipei de la Yahoo!, o sa va arat la ce solutie am ajuns.</p>
<p>Dar mai intai &#8230; cifre. Am ales <a href="http://www.okazii.ro/" title="Okazii" target="_blank"><b>Okazii.ro</b></a> drept studiu de caz (toate masuratorile sunt facute cu <a href="http://developer.yahoo.com/yslow/" title="YSlow" target="_blank">YSlow</a>, folosind o versiune salvata a primei pagini):</p>
<h2>Fara <a href="http://en.wikipedia.org/wiki/FTL_(Battlestar_Galactica)" title="FTL" target="_blank">FTL</a> (pagina <a href="http://dev.victorstanciu.ro/experimente/okazii/old/" title="Okazii.ro - prima pagina">salvata aici</a>)</h2>
<ul>
<li>Nota generala in YSlow: <b>E</b></li>
<li>Numar request-uri pe prima pagina: <b>62</b></li>
<li>Dimensiune prima pagina: <b>406.4KB</b></li>
</ul>
<h2>Cu FTL  (pagina <a href="http://dev.victorstanciu.ro/experimente/okazii/" title="Okazii.ro - prima pagina">salvata aici</a>)</h2>
<ul>
<li>Nota generala in YSlow: <b>C</b></li>
<li>Numar request-uri pe prima pagina: <b>51</b></li>
<li>Dimensiune prima pagina: <b>226.0KB</b></li>
</ul>
<p>Calculat la traficul lor (aprox. <b>82.000</b> vizitatori unici <b>pe zi</b>), netinand cont de cache in nici unul din cazuri, asta se traduce in o diferenta de <b>902.000</b> de request-uri si <b>14.1 GB</b> trafic <b>lunar</b>.</p>
<h2>Cum se foloseste</h2>
<p>Presupunand urmatoarea structura de directoare:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">/public
    /css
    /js
index.php</pre></div></div>

<p><a href="http://dev.victorstanciu.ro/ftl/ftl.zip" title="Download"><b>Descarcati arhiva</b></a> si extrageti fisierele in root asa incat noua structura va fi:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">/ftl
    /cache
    /lib
    CSS.php
    File.php
    JS.php
    config.php
    index_css.php
    index_js.php
/public
    /css
    /js
index.php</pre></div></div>

<p>Mutati fisierele index_css.php si index_js.php din directorul /ftl in directorul /public/css, respectiv /public/js, si redenumiti-le in index.php:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">/ftl
    /cache
    /lib
    CSS.php
    File.php
    JS.php
    config.php
/public
    /css
        index.php
    /js
        index.php
index.php</pre></div></div>

<p>Adaugati liniile urmatoare in .htaccess:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="text" style="font-family:monospace;">&lt;IfModule mod_expires.c&gt;
    ExpiresActive On
    ExpiresByType application/x-javascript A315360000
    ExpiresByType text/css A315360000
&lt;/IfModule&gt;
&nbsp;
RewriteEngine On
RewriteRule ^public/(js|css)/([a-z0-9\.]+)\.(js|css)$    public/$1/index.php?hash=$2</pre></td></tr></table></div>

<p>Includeti fisierele necesare in index.php:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
    <span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ftl/JS.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ftl/CSS.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Totul e pregatit, tot ce mai trebuie sa facem e sa incarcam in pagina fisierele. Spre exemplu, ca sa incarc in &lt;head&gt; cateva fisiere CSS si JS:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
    <span style="color: #000088;">$css</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> FTL_CSS<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$js</span>  <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> FTL_JS<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$css</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'reset'</span><span style="color: #009900;">&#41;</span>
        <span style="color: #339933;">-&gt;</span><span style="color: #004000;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'typo'</span><span style="color: #009900;">&#41;</span>
        <span style="color: #339933;">-&gt;</span><span style="color: #004000;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'layout'</span><span style="color: #009900;">&#41;</span>
        <span style="color: #339933;">-&gt;</span><span style="color: #004000;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'error'</span><span style="color: #009900;">&#41;</span>
        <span style="color: #339933;">-&gt;</span><span style="color: #004000;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ie'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'lte IE 7'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$js</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'prototype'</span><span style="color: #009900;">&#41;</span>
       <span style="color: #339933;">-&gt;</span><span style="color: #004000;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sizzle'</span><span style="color: #009900;">&#41;</span>
       <span style="color: #339933;">-&gt;</span><span style="color: #004000;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'effects'</span><span style="color: #009900;">&#41;</span>
       <span style="color: #339933;">-&gt;</span><span style="color: #004000;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'lightbox'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$css</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">render</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$js</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">render</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Nu uitati sa setati drepturi de scriere pe subdirectoarele din directorul /ftl/cache.</p>
<p>Codul HTML generat va arata in felul urmator:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">link</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #000066;">media</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;screen&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;public/css/1e9dd525d1fbe94f7b8aede22cc141f5.1242750618.css&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!--[if lte IE 7]&gt;&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; media=&quot;screen&quot; href=&quot;public/css/25400724d7370b0b29c9369d9af3dd21.1242750626.css&quot; /&gt;&lt;![endif]--&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;public/js/56c728a5a7689ab1663359a7edff160a.1242751025.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span></pre></td></tr></table></div>

<p>Doua fisiere .css (unul pentru cele standard, unul incarcat doar pentru IE), si un fisier .js. <b>3 request</b>-uri in loc de <b>9</b>, si o dimensiune totala de aprox. <b>6.5 ori mai mica</b>. Fisierele sunt atat <b>minified</b> cat si <b>gzipped</b>, folosind librariile <a href="http://csstidy.sourceforge.net/" title="CSSTidy">CSSTidy</a>, respectiv <a href="http://dean.edwards.name/packer/" title="Packer">Packer</a></p>
<h2>Suna bine, dar ce se intampla cand &#8230;</h2>
<ul>
<li>
Modific sau sterg un fisier .css sau .js ? Trebuie sa schimb ceva de fiecare data ?</p>
<p><i>Nu. De fiecare data cand un fisier este modificat sau sters, fisierul rezultat este regenerat <b>automat</b>, fara nevoie de interventie.</i></p>
</li>
<li>
Un utilizator foloseste un browser ce nu suporta Gzip (stone-age style) ?</p>
<p><i>Respectivului utilizator ii este servita <b>automat</b> o versiune doar <b>minified</b>. Putin mai mare, evident, dar functionala.</i></p>
</li>
<li>
Structura directoarelor mele nu corespunde cu cea din exemplul de mai sus ?<br />
<i>In directorul /ftl este un fisier config.php unde puteti schimba caile catre fisiere / directoare. Aveti grija numai ca include-urile sa functioneze.</i>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.victorstanciu.ro/ftl-jump/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Prototype: Carousel &#8211; Update</title>
		<link>http://www.victorstanciu.ro/prototype-carousel-update/</link>
		<comments>http://www.victorstanciu.ro/prototype-carousel-update/#comments</comments>
		<pubDate>Fri, 24 Apr 2009 19:15:46 +0000</pubDate>
		<dc:creator>Victor Stanciu</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[carousel]]></category>
		<category><![CDATA[google-code]]></category>
		<category><![CDATA[opensource]]></category>
		<category><![CDATA[prototype]]></category>

		<guid isPermaLink="false">http://www.victorstanciu.ro/?p=280</guid>
		<description><![CDATA[A venit vremea ca si Carousel.js sa primeasca un binemeritat update, si sa fie mutat in noua lui casa, Google Code. Asadar, update-urile si bug-tracking-ul vor fi de acum aici. PS: Cateva din noilea feature-uri sunt in exemple.]]></description>
			<content:encoded><![CDATA[<p>A venit vremea ca si <a href="http://www.victorstanciu.ro/prototype-plugin-carousel/" title="Carousel">Carousel.js</a> sa primeasca un binemeritat update, si sa fie mutat in noua lui casa, <a href="http://code.google.com/p/prototype-carousel/" title="prototype-carousel">Google Code</a>.</p>
<p>Asadar, update-urile si bug-tracking-ul vor fi de acum <a href="http://code.google.com/p/prototype-carousel/" title="prototype-carousel"><b>aici</b></a>.</p>
<p>PS: Cateva din noilea feature-uri sunt in <a href="http://dev.victorstanciu.ro/prototype/carousel/" title="Exemple"><b>exemple</b></a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.victorstanciu.ro/prototype-carousel-update/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Prototype: Zoomer</title>
		<link>http://www.victorstanciu.ro/prototype-zoomer/</link>
		<comments>http://www.victorstanciu.ro/prototype-zoomer/#comments</comments>
		<pubDate>Tue, 14 Apr 2009 19:12:28 +0000</pubDate>
		<dc:creator>Victor Stanciu</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[prototype]]></category>
		<category><![CDATA[zoom]]></category>

		<guid isPermaLink="false">http://www.victorstanciu.ro/?p=276</guid>
		<description><![CDATA[M-a rugat cineva acum cateva zile sa recreez un inedit mod de a face zoom pe o imagine. Mi s-a parut foarte interesant, asa ca am scris o mica si rapida extensie de Prototype pentru asta. Cu ocazia asta am creat si primul proiect pe Google Code, loc in care le voi muta si pe [...]]]></description>
			<content:encoded><![CDATA[<p>M-a rugat cineva acum cateva zile sa recreez un inedit mod de a face zoom pe o imagine. Mi s-a parut foarte interesant, asa ca am scris o mica si rapida extensie de Prototype pentru asta.</p>
<p>Cu ocazia asta am creat si primul proiect pe Google Code, loc in care le voi muta si pe cele anterioare.</p>
<p>Un demo este <a href="http://dev.victorstanciu.ro/prototype/zoomer/" title="Prototype: Zoomer" target="_blank"><strong>aici</strong></a>, iar pagina proiectului pe Google Code este <a href="http://code.google.com/p/prototype-zoomer/" title="Google Code" target="_blank"><strong>asta</strong></a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.victorstanciu.ro/prototype-zoomer/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Sizzle si Prototype</title>
		<link>http://www.victorstanciu.ro/sizzle-prototype/</link>
		<comments>http://www.victorstanciu.ro/sizzle-prototype/#comments</comments>
		<pubDate>Fri, 27 Mar 2009 10:23:59 +0000</pubDate>
		<dc:creator>Victor Stanciu</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[prototype]]></category>
		<category><![CDATA[sizzle]]></category>
		<category><![CDATA[speed]]></category>

		<guid isPermaLink="false">http://www.victorstanciu.ro/?p=257</guid>
		<description><![CDATA[Framework-ul JS jQuery foloseste mai nou un selector engine foarte rapid numit Sizzle. Cum jQuery intotdeauna a stat mai bine la capitolul viteza a selectorilor, inlocuirea selector engine-ului Prototype cu Sizzle ar trebui sa aduca un binevenit boost de performanta. Urmarind instructiunile din acest articol, este suficient sa incarcam Sizzle (4KB minified si gzipped) si [...]]]></description>
			<content:encoded><![CDATA[<p>Framework-ul JS <a href="http://jquery.com/" title="jQuery" target="_blank">jQuery</a> foloseste mai nou un selector engine foarte rapid numit <a href="http://sizzlejs.com/" title="Sizzle" target="_blank">Sizzle</a>.</p>
<p>Cum jQuery intotdeauna a stat mai bine la capitolul viteza a selectorilor, inlocuirea selector engine-ului Prototype cu Sizzle ar trebui sa aduca un binevenit boost de performanta.</p>
<p>Urmarind instructiunile din <a href="http://briancrescimanno.com/2009/03/24/using-sizzle-with-prototype/" title="Using Sizzle with Prototype">acest articol</a>, este suficient sa incarcam Sizzle (4KB minified si gzipped) si sa adaugam urmatorul cod dupa Prototype:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">//Overwrite findChildElements to use Sizzle http://sizzlejs.com</span>
Selector.<span style="color: #660066;">findChildElements</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>element<span style="color: #339933;">,</span> expression<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    expression <span style="color: #339933;">=</span> expression.<span style="color: #660066;">join</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;, &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> results <span style="color: #339933;">=</span> Sizzle<span style="color: #009900;">&#40;</span>expression<span style="color: #339933;">,</span> element<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>results.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> results.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            results<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> Element.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span>results<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066; font-weight: bold;">return</span> results<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Acum atat $$ cat si Element#select vor folosit Sizzle. Unul din avantajele majore (pe langa viteza mult imbunatatita) este acela ca in afara de schimbarea de mai sus, nu implica nici o alta modificare in codul nostru, fiind deci posibila trecerea la Sizzle in mijlocul procesului de dezvoltare a proiectului.</p>
<h2>Teste</h2>
<p><a href="http://dev.victorstanciu.ro/experimente/selector-test/" title="SlickSpeed selectors test" class="fullimg" target="_blank"><img src="http://www.victorstanciu.ro/wp-content/uploads/2009/03/slickspeed.png" alt="SlickSpeed" title="SlickSpeed" width="474" height="318" class="size-full wp-image-65" /></a></p>
<p><a href="http://dev.victorstanciu.ro/experimente/selector-test/" title="SlickSpeed selectors test" target="_blank"><b>SlickSpeed Selectors Test</b></a></p>
<p>Puteti rula un test comparativ intre Prototype, Prototype cu Sizzle, si jQuery accesand link-ul de mai sus.</p>
<p>Scorurile din imagine reprezinta medii ale rularilor multiple (scorul mai mic e mai bun). Toate au fost rulate sub Windows. Din ele reies cateva concluzii:</p>
<ul>
<li>In majoritatea browserelor recente, combinatia Prototype+Sizzle a obtinut scoruri aproape identice de jQuery (rezultat de asteptat de altfel).</li>
<li>Selector-engine-ul default in Prototype a iesit castigator in cazul versiunilor &#8220;pe cale de disparitie&#8221; ale browserelor (Firefox 2, Safari 3) precum si in Opera.</li>
<li>jQuery se detaseaza clar cand vine vorba de ambele versiuni de Internet Explorer</li>
<li>Cea mai importanta concluzie: Sizzle aduce un bonus de viteza in browserele ce reprezinta viitorul, precum si in Internet Explorer (chiar daca tot nu se apropie de jQuery), prin urmare eu unul voi apela la aceasta solutie de acum incolo.</li>
</ul>
<p><i>PS: voi sterge orice comentariu care se rezuma la &#8220;[insert framework name] sucks! Mine is bigger and better.&#8221; :)</i></p>
]]></content:encoded>
			<wfw:commentRss>http://www.victorstanciu.ro/sizzle-prototype/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Prototype plugin: Showcase</title>
		<link>http://www.victorstanciu.ro/prototype-plugin-showcase/</link>
		<comments>http://www.victorstanciu.ro/prototype-plugin-showcase/#comments</comments>
		<pubDate>Sat, 04 Oct 2008 11:22:19 +0000</pubDate>
		<dc:creator>Victor Stanciu</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[effects]]></category>
		<category><![CDATA[prototype]]></category>
		<category><![CDATA[scriptaculous]]></category>
		<category><![CDATA[showcase]]></category>

		<guid isPermaLink="false">http://www.victorstanciu.ro/?p=139</guid>
		<description><![CDATA[Am dezvoltat acest plugin ca pe o jucarie personala, asa ca il prezint aici in speranta ca ii va fi de folos cuiva. Ca de obicei, inainte de detaliile tehnice, vizitati paginile cu exemple: Orizontal Vertical Diagonal 1. Cerinte Pentru functionarea acestui plugin veti avea nevoie de: Prototype 1.6 Libraria Effects din cadrul Script.aculo.us 1.8 [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://dev.victorstanciu.ro/experimente/prototype-showcase/examples/horizontal.html" target="_blank" class="fullimg"><img src="http://www.victorstanciu.ro/wp-content/uploads/2008/10/screenshot.png" alt="Showcase" title="Showcase" /></a></p>
<p>Am dezvoltat acest plugin ca pe o jucarie personala, asa ca il prezint aici in speranta ca ii va fi de folos cuiva.</p>
<p>Ca de obicei, inainte de detaliile tehnice, vizitati paginile cu exemple:</p>
<ul>
<li><a href="http://dev.victorstanciu.ro/experimente/prototype-showcase/examples/horizontal.html" title="Orizontal" target="_blank">Orizontal</a></li>
<li><a href="http://dev.victorstanciu.ro/experimente/prototype-showcase/examples/vertical.html" title="Vertical" target="_blank">Vertical</a></li>
<li><a href="http://dev.victorstanciu.ro/experimente/prototype-showcase/examples/diagonal.html" title="Diagonal" target="_blank">Diagonal</a></li>
</ul>
<h2>1. Cerinte</h2>
<p>Pentru functionarea acestui plugin veti avea nevoie de:</p>
<ul>
<li><a href="http://prototypejs.org/" title="Prototype" target="_blank">Prototype 1.6</a></li>
<li><a href="http://script.aculo.us/" title="Effects" target="_blank">Libraria Effects din cadrul Script.aculo.us 1.8</a></li>
</ul>
<p>Acestea vor trebui incarcate in pagina inaintea Showcase.js:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;prototype.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;effects.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;showcase.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span></pre></td></tr></table></div>

<h2>2. Markup</h2>
<p>Minimul de markup si stilizare necesare pentru functionare este urmatorul:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#next&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;controls&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;next&quot;</span>&gt;</span>Next<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#previous&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;controls&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;previous&quot;</span>&gt;</span>Previous<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>	
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;showcase&quot;</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;images/1.jpg&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;images/2.jpg&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;2&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;images/3.jpg&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;3&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>		
	...
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;images/n.jpg&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;n&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#showcase</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">700px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">170px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#showcase</span> li <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">170px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">170px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>	
	<span style="color: #000000; font-weight: bold;">list-style-type</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>	
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#showcase</span> li img <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100%</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100%</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>Codul de mai sus corespunde unui Showcase orizontal de 700x170px. Orientarea (orizontala / verticala / diagonala) este selectata la initializare:</p>
<h2>3. Initializare</h2>
<p>Initializarea plugin-ului se face printr-o singura linie de cod:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">new</span> Showcase.<span style="color: #660066;">Horizontal</span><span style="color: #009900;">&#40;</span>$$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#showcase li'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> $$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a.controls'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>optiune<span style="color: #339933;">:</span> valoare<span style="color: #339933;">,</span> optiune<span style="color: #339933;">:</span> valoare<span style="color: #339933;">,</span> etc<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Orientarea este aleasa prin initializarea clasei respective din cele 3 disponibile:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">new</span> Showcase.<span style="color: #660066;">Horizontal</span><span style="color: #009900;">&#40;</span>slides<span style="color: #339933;">,</span> controls<span style="color: #009900;">&#91;</span><span style="color: #339933;">,</span> options<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">new</span> Showcase.<span style="color: #660066;">Vertical</span><span style="color: #009900;">&#40;</span>slides<span style="color: #339933;">,</span> controls<span style="color: #009900;">&#91;</span><span style="color: #339933;">,</span> options<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">new</span> Showcase.<span style="color: #660066;">Diagonal</span><span style="color: #009900;">&#40;</span>slides<span style="color: #339933;">,</span> controls<span style="color: #009900;">&#91;</span><span style="color: #339933;">,</span> options<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h4>4. Parametri optionali</h4>
<p>Parametrii sunt selectati la initializare, in format JSON: {parametru: valoare, parametru: valoare}:</p>
<ul>
<li><b>ratio</b>: Reprezinta raportul dintre slide-ul din centru si cele din lateral, si controleaza pasul incrementarii graduale a dimensiunii slide-urilor. Spre exemplu, un <b>ratio</b> de 0.3 inseamna ca slide-urile din lateral vor avea dimensiunea unei treimi a aceluia din centru (care nu este redimensionat), iar slide-urile cuprinse intre centru si lateral vor scadea treptat si proportional cu acest raport. <b>Default</b>: 0.5 (50%).</li>
<li><b>size</b>: Numarul total de slide-uri vizibile la un moment dat. Sa presupunem ca avem 20 de slide-uri, dar vrem sa afisam doar 7 simultan. Setam valoarea acestui parametru egala cu 7, iar plugin-ul va &#8220;rula&#8221; pe ecran doar cate 7 slide-uri simultan. <b>Default</b>: numarul total de slide-uri. <b>Atentie</b>: trebuie sa fie un numar <b>impar</b>.</li>
<li><b>duration</b>: Durata unei miscari (viteza). <b>Default</b>: 0.5 secunde.</li>
<li><b>initialDelay</b>: Timpul care trece din momentul initializarii pana la expansiunea initiala a Showcase-ului, creand acel efect la pornire. <b>Default</b>: 1 secunda.</li>
</ul>
<h4>5. Download</h4>
<p>Puteti descarca atat Showcase.js, cat si exemplele de mai sus:</p>
<p><a href="http://dev.victorstanciu.ro/experimente/prototype-showcase/examples/showcase.js" title="Showcase.js" class="highlight" target="_blank">Download Showcase.js (9.4 KB)</a><br />
<a href="http://dev.victorstanciu.ro/experimente/prototype-showcase/examples/showcase-packed.js" title="Showcase.js - Packed" class="highlight" target="_blank">Download Showcase.js &#8211; Packed (3.5 KB)</a><br />
<a href="http://dev.victorstanciu.ro/experimente/prototype-showcase/examples.zip" title="Exemple Showcase.js" class="highlight" target="_blank">Download Exemple</a></p>
<p><i>Lansez Showcase.js sub <a href="http://en.wikipedia.org/wiki/MIT_License" title="Licenta MIT" target="_blank">licenta MIT</a>, care in principiu spune ca oricine poate face ce vrea cu codul :)</i></p>
]]></content:encoded>
			<wfw:commentRss>http://www.victorstanciu.ro/prototype-plugin-showcase/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Update Carousel</title>
		<link>http://www.victorstanciu.ro/update-carousel/</link>
		<comments>http://www.victorstanciu.ro/update-carousel/#comments</comments>
		<pubDate>Thu, 05 Jun 2008 21:48:03 +0000</pubDate>
		<dc:creator>Victor Stanciu</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[prototype]]></category>

		<guid isPermaLink="false">http://www.victorstanciu.ro/?p=30</guid>
		<description><![CDATA[Deoarece am primit mai multe mail-uri care solicitau acest lucru, pun online ultima versiune a plugin-ului Carousel, ce include, printre mici optimizari, si functionalitate pause / resume, in cazul in care se foloseste optiunea de auto-start. Acestea se declanseaza la mouseover / mouseout pe slide-uri, dar desigur pot fi atasate oricarui event. Download Carousel]]></description>
			<content:encoded><![CDATA[<p>Deoarece am primit mai multe mail-uri care solicitau acest lucru, pun online ultima versiune a plugin-ului <a href="http://www.victorstanciu.ro/prototype-plugin-carousel/" title="Carousel">Carousel</a>, ce include, printre mici optimizari, si functionalitate <i>pause</i> / <i>resume</i>, in cazul in care se foloseste optiunea de auto-start. Acestea se declanseaza la <i>mouseover</i> / <i>mouseout</i> pe slide-uri, dar desigur pot fi atasate oricarui event.</p>
<p><a href="http://dev.victorstanciu.ro/experimente/prototype-carousel/js/carousel.js" title="Download Carousel" class="highlight">Download Carousel</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.victorstanciu.ro/update-carousel/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>AJAJ Autocompleter</title>
		<link>http://www.victorstanciu.ro/ajaj-autocompleter/</link>
		<comments>http://www.victorstanciu.ro/ajaj-autocompleter/#comments</comments>
		<pubDate>Mon, 21 Apr 2008 05:39:05 +0000</pubDate>
		<dc:creator>Victor Stanciu</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[autocomplete]]></category>
		<category><![CDATA[json]]></category>

		<guid isPermaLink="false">http://www.victorstanciu.ro/?p=27</guid>
		<description><![CDATA[In incercarile de a reduce cat de mult posibil cantitatea de date transportata intre server si client in mod asincron, am renuntat la a mai folosi XML ca standard, facand trecerea catre JSON (puteti incepe de aici). Majoritatea solutiilor au devenit astfel &#8220;AJAJ based&#8221;. Cu siguranta fiecare dintre voi a folosit sau cel putin testat [...]]]></description>
			<content:encoded><![CDATA[<p>In incercarile de a reduce cat de mult posibil cantitatea de date transportata intre server si client in mod asincron, am renuntat la a mai folosi XML ca standard, facand trecerea catre <a href="http://www.json.org/">JSON</a> (puteti incepe de <a href="http://www.idevelop.ro/introducere-in-json-javascript-object-notation.htm">aici</a>). Majoritatea solutiilor au devenit astfel &#8220;<em title="Asynchronous Javascript and JSON">AJAJ</em> based&#8221;.</p>
<p>Cu siguranta fiecare dintre voi a folosit sau cel putin testat la un moment dat <a href="http://scriptaculous.stikipad.com/scriptaculous/show/Ajax.Autocompleter">Autocompleter-ul Script.aculo.us</a>. Ei bine, aceasta modalitate de autocomplete este buna, mai putin faptul ca trebuie generat server-side intreg UL-ul corespunzator rezultatelor. Aceasta metoda are doua dezavantaje:</p>
<ul>
<li>Cantitatea mai mare de date. <i>Fac o mica paranteza aici. Sunt perfect constient de faptul ca exemplul autocompleter-ului nu este tocmai relevant din acest punct de vedere. Orice solutie de autocomplete va trebui oricum sa intoarca un numar relativ mic de rezultate, altfel avantajul utilizatorului  devine nul, el trebuind sa scaneze atent sugestiile ce ar trebui sa ii scurteze munca. Ma folosesc totusi de  acest exemplu pentru ca vreau sa pregatesc terenul pentru un articol viitor care va ilustra perfect avantajul unei solutii mai &#8220;light&#8221;.</i></li>
<li>Amestecul markup-ului pe partea server. <i>Si aici simt nevoia de justificari suplimentare. Atunci cand e vorba de o singura persoana implicata intr-un proiect / parte a unui proiect, legatura intre back-end si front-end este mult mai stransa. Dar, cand este vorba de echipe in cadrul carora fiecare persoana este responsabila doar de una din aceste parti, atunci separarea cat mai clara intre acesta este indicata.</i></li>
</ul>
<p>Revenind la exemplul Autocompleter-ului Script.aculo.us, acesta poate fi rapid ajustat pentru lucrul cu date in format JSON, prin simpla &#8220;suprascriere&#8221; a functiei ce se ocupa de inserarea in pagina a rezultatelor transferului in felul urmator:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">Ajax.<span style="color: #660066;">Autocompleter</span>.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">updateChoices</span> <span style="color: #339933;">=</span>  <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>choices<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">changed</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">hasFocus</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">update</span>.<span style="color: #660066;">update</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;ul&gt;&lt;/ul&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		response <span style="color: #339933;">=</span> choices.<span style="color: #660066;">evalJSON</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			response.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>suggestion<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">update</span>.<span style="color: #660066;">down</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'ul'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">insert</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> Template<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&lt;li&gt;#{text}&lt;/li&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">evaluate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>text<span style="color: #339933;">:</span> suggestion<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
		Element.<span style="color: #660066;">cleanWhitespace</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">update</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		Element.<span style="color: #660066;">cleanWhitespace</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">update</span>.<span style="color: #660066;">down</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">update</span>.<span style="color: #660066;">firstChild</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">update</span>.<span style="color: #660066;">down</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">childNodes</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">entryCount</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">update</span>.<span style="color: #660066;">down</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">childNodes</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">entryCount</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #003366; font-weight: bold;">var</span> entry <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">getEntry</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				entry.<span style="color: #660066;">autocompleteIndex</span> <span style="color: #339933;">=</span> i<span style="color: #339933;">;</span>
				<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">addObservers</span><span style="color: #009900;">&#40;</span>entry<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span> 
				<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">entryCount</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">stopIndicator</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">index</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">entryCount</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">1</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">options</span>.<span style="color: #660066;">autoSelect</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">selectEntry</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">render</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Doar liniile 4-11 sunt cele modificate, restul reprezinta functia initiala. Sfatul meu este sa nu editati direct libraria <i>controls.js</i> din Script.aculo.us, pentru ca orice modificare direct pe fisierele librariei va duce la ingreunarea unui viitor update, trebuind operate de fiecare data schimbarile pe noua versiune. Mult mai simplu este sa includeti pur si simplu codul de mai sus intr-un fisier ce va fi incarcat <b>dupa</b> Script.aculo.us.</p>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.victorstanciu.ro/ajaj-autocompleter/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

