<?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>Elzo Valugi &#187; jQuery</title>
	<atom:link href="http://blog.valugi.ro/category/programming/javascript/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.valugi.ro</link>
	<description>$professional_web_surfing tail -f /dev/things/that/happen &#62; blog</description>
	<lastBuildDate>Sat, 03 Dec 2011 02:05:58 +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>NS_ERROR_XPC_BAD_CONVERT_JS jQuery Error on FF3.5</title>
		<link>http://blog.valugi.ro/2009/09/30/ns_error_xpc_bad_convert_js-jquery-error-on-ff3-5/</link>
		<comments>http://blog.valugi.ro/2009/09/30/ns_error_xpc_bad_convert_js-jquery-error-on-ff3-5/#comments</comments>
		<pubDate>Wed, 30 Sep 2009 11:48:13 +0000</pubDate>
		<dc:creator>elzo valugi</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[bug]]></category>

		<guid isPermaLink="false">http://blog.valugi.ro/?p=498</guid>
		<description><![CDATA[Non freakish people should ignore this post. It is a solution for a JavaScript bug that doesn&#8217;t make a clear signature. A colleague got this error when trying to implement a jQuery slider plugin called S3 Slider. uncaught exception: [Exception... "Could not convert JavaScript argument arg 0" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location: "JS frame :: http://dev.valugi.ro/lib/jquery/jquery-1.3.2.min.js [...]]]></description>
			<content:encoded><![CDATA[<p>Non freakish people should ignore this post. It is a solution for a JavaScript bug that doesn&#8217;t make a clear signature.</p>
<p>A colleague got this error when trying to implement a jQuery slider plugin called <a href="http://www.serie3.info/s3slider/" target="_blank">S3 Slider</a>.<br />
<code><br />
uncaught exception: [Exception... "Could not convert JavaScript argument arg 0" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location: "JS frame :: http://dev.valugi.ro/lib/jquery/jquery-1.3.2.min.js :: anonymous :: line 12" data: no]<br />
</code></p>
<p>This error is not obvious and not very well documented on other places on web. I saw that is mainly related with various CSS properties. By debugging the plugin I saw that in his case was thrown when he was not passing some spans that the plugin creators take for granted in the HTML code. So I made a <a href="http://dev.valugi.ro/jquery/bug-css-property-missing-property/" target="_blank">demo</a> to simulate the problem. Check the firebug console for the error.</p>
<p>The code to reproduce the error in your Firebug Console:<br />
<code class="javascript"><br />
var itemsSpan = $('span'); // but no spans in page<br />
var currNo = 0;<br />
var x = $(itemsSpan[currNo]); // x defaults to document<br />
console.log(x);<br />
console.log(x.css('bottom')); // throws error in jQuery curCSS function<br />
</code></p>
<p>It seems that at line 808 in curCSS function, jQuery throws this error as is unable to output the computed style for the document.<br />
Fast solutions: either add the missing elements, either modify the plugin to check for elements before doing any CSS property retrival.</p>
<p>Update from the <a href="http://dev.jquery.com/ticket/5309" target="_blank">bug report</a> that I opened.<br />
<em>In jQuery 1.3.3, $(undefined) will return an empty collection. That will either fix the problem or push it somewhere else. :) You could try the nightly where the patch is already implemented and see how it behaves.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.valugi.ro/2009/09/30/ns_error_xpc_bad_convert_js-jquery-error-on-ff3-5/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Subcookies in jQuery</title>
		<link>http://blog.valugi.ro/2009/09/13/subcookies-in-jquery/</link>
		<comments>http://blog.valugi.ro/2009/09/13/subcookies-in-jquery/#comments</comments>
		<pubDate>Sun, 13 Sep 2009 19:37:10 +0000</pubDate>
		<dc:creator>elzo valugi</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[cookie]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[subcookie]]></category>
		<category><![CDATA[YUI]]></category>

		<guid isPermaLink="false">http://blog.valugi.ro/?p=459</guid>
		<description><![CDATA[I was looking at YUI Api and I thought I find a new concept : subcookies.  But by reading the docs I realized that the concept is not new, as I&#8217;ve used it before. The idea comes from the limit that the browsers are puting to the cookie number, 20 per domain. This usually makes [...]]]></description>
			<content:encoded><![CDATA[<p>I was looking at YUI Api and I thought I find a new concept : <a href="http://developer.yahoo.com/yui/examples/cookie/cookie-subcookie-example.html" target="_blank">subcookies</a>.  But by reading the docs I realized that the concept is not new, as I&#8217;ve used it before. The idea comes from the limit that the browsers are puting to the cookie number, 20 per domain. This usually makes you try to push as much information on the cookie, instead of creating new cookies for each variable that you may want on the clients side. What you do is basically store serialized data in the cookie string.</p>
<p>A server side solution of this problem is to keep only a cookie with a hash on the client side and read/save all the variables associated with that hash on server side or database. Downside to this approach is that you have to make an extra call server/db call each time you wanna know the values.</p>
<p>The interesting thing is that YUI implements a mechanism to read/write this subcookie data. I&#8217;ve tried to do the same in jQuery starting from <a href="http://plugins.jquery.com/project/cookie" target="_blank">$.cookie</a> plugin and I&#8217;ve come up with this usage.</p>
<p><code class="javascript"><br />
/**<br />
 * Create a cookie with the given name, part and value and other optional parameters.<br />
 * If the part parameter is passed the value will be asigned to the part key<br />
 *<br />
 *<br />
 * @example $.cookie('the_cookie', 'part', 'the_value');<br />
 * @desc Set the value of a cookie. If part parameter is present it will create the value in serialized form<br />
 * @example: $.cookie('the_cookie', null, 'the_value') // creates a cookie with value "the_value"<br />
 * @example: $.cookie('the_cookie, 'name', 'the_name') // creates a cookie with value "name=the_name"<br />
 * @example: $.cookie('the_cookie, 'prename','second_name') // will add info to the cookie value "name=the_name&#038;prename=second_name"<br />
 * @example $.cookie('the_cookie', null, 'the_value', {expires: 7, path: '/', domain: 'jquery.com', secure: true});<br />
 * @desc Create a cookie with all available options.<br />
 * @example $.cookie('the_cookie', null, 'the_value');<br />
 * @desc Create a session cookie.<br />
 * @example $.cookie('the_cookie','name', null);<br />
 * @desc Delete the name value<br />
 * @example $.cookie('the_cookie',null, null);<br />
 * @desc Delete a cookie by passing null as value.<br />
 *<br />
 * @param String name The name of the cookie.<br />
 * @param String part The key for the array.<br />
 * @param String value The value of the cookie or of the element.<br />
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.<br />
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.<br />
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.<br />
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained<br />
 *                             when the the browser exits.<br />
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).<br />
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).<br />
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will<br />
 *                        require a secure protocol (like HTTPS).<br />
 *<br />
 *<br />
 */<br />
$.cookie('TheCookie', 'first_key', 'value1', options); // will write the cookie<br />
$.cookie('TheCookie', 'second_key', 'value2', options); // will add the second_key info<br />
alert($.cookie('TheCookie', 'second_key')); // will alert value2<br />
console.log( $.cookie('TheCookie')); // "first_key=value1&#038;second_key=value2<br />
}</code></p>
<p><a href="http://dev.valugi.ro/jquery/subcookie/" target="_blank">You can see a demo of jQuery Subcookie here.</a> This is only a draft but I could rewrite it in a serious plugin if any interes is shown and you think this is could be useful.</p>
<p><code class="javascript"> </code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.valugi.ro/2009/09/13/subcookies-in-jquery/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Callback for image loading with jQuery</title>
		<link>http://blog.valugi.ro/2009/09/11/callback-for-image-loading-with-jquery/</link>
		<comments>http://blog.valugi.ro/2009/09/11/callback-for-image-loading-with-jquery/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 20:33:42 +0000</pubDate>
		<dc:creator>elzo valugi</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[callback]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[loading]]></category>
		<category><![CDATA[preloading]]></category>

		<guid isPermaLink="false">http://blog.valugi.ro/?p=439</guid>
		<description><![CDATA[How to check when a dynamically loaded image has loaded using jQuery. Useful when loading big images as a result of AJAX request and we you need to do extra actions at the end of image loading.]]></description>
			<content:encoded><![CDATA[<p>While I was doing the demo for my previous post about &#8220;<a href="http://blog.valugi.ro/2009/07/31/simulating-a-pan-image-jquery-plugin/">simulating image pan jQuery plugin</a>&#8221; I&#8217;ve noticed that the first time that I was loading the script the actions were executed before even loading the image and resulting in failure. This days at my job I was doing a gallery plugin in jQuery and notice the same problem.</p>
<p>Sometimes you have to load dynamic images as a result of a AJAX request, and you want to be able to do things only after the image has finish loading. In this case the ready() function, which is a wrapper for the window.onload() function is not usefull, because it applies to the elements present at the beginning.</p>
<p>In this scenario you make a request and receive as a string a path for a new image you have to load.	This is usefull if you have big images and want to wait until the images are loaded before doing anything else.</p>
<p><code class="javascript"><br />
	$(document).ready( function (){<br />
		$.get(<br />
			'test.php',<br />
			function( data ){<br />
				//console.log(data); // ["test.jpg"]<br />
				var _image = new Image();<br />
				_image.src = data;<br />
				_image.id = 'newImageId';<br />
				$(_image).load( function(){<br />
					//once image is loaded add it to the div and remove the preloading<br />
					$("#imageContainer").append( _image ).removeClass('loading');<br />
					// do other stuff<br />
					_image.alt = "test image";<br />
				});<br />
			}<br />
		);<br />
	});<br />
</code></p>
<p>I&#8217;ve tested it in IE, FF, Chrome and works with cache enabled/disabled. The secret, not a big one, is the usage of AJAX <a href="http://docs.jquery.com/Ajax/load">load()</a> function which does a GET request in the background and allows a callback. The purpose of the load function is to inject some html code in the current page. If you want to change the src value for a current image and do a callback it will be a good idea to pass a random string to the GET request as your browser could cache the image name and content. </p>
<p><a href="http://dev.valugi.ro/jquery/check-dynamic-loaded-image/" target="_blank">Demo here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.valugi.ro/2009/09/11/callback-for-image-loading-with-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Easiest &#8220;check all&#8221; ever with jQuery made even more &#8230; easy</title>
		<link>http://blog.valugi.ro/2009/08/17/easiest-check-all-ever-with-jquery-made-even-more-easy/</link>
		<comments>http://blog.valugi.ro/2009/08/17/easiest-check-all-ever-with-jquery-made-even-more-easy/#comments</comments>
		<pubDate>Mon, 17 Aug 2009 10:09:54 +0000</pubDate>
		<dc:creator>elzo valugi</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[selectors]]></category>
		<category><![CDATA[semantics]]></category>

		<guid isPermaLink="false">http://blog.valugi.ro/?p=352</guid>
		<description><![CDATA[How to improve some JavaScript. Check full post.]]></description>
			<content:encoded><![CDATA[<p>I was reading some tweets and I got to this <a href="http://briancray.com/2009/08/06/check-all-jquery-javascript/">post</a>, which can be improved.</p>
<p>First the html. Don&#8217;t use divs for layout purposes.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;fieldset&gt;
	// these will be affected by check all
&lt;div&gt;
&lt;input id=&quot;checkall&quot; type=&quot;checkbox&quot; /&gt; Check all&lt;/div&gt;
&lt;div&gt;
&lt;input type=&quot;checkbox&quot; /&gt; Checkbox&lt;/div&gt;
&lt;div&gt;
&lt;input type=&quot;checkbox&quot; /&gt; Checkbox&lt;/div&gt;
&lt;div&gt;
&lt;input type=&quot;checkbox&quot; /&gt; Checkbox&lt;/div&gt;
&lt;/fieldset&gt;
&lt;fieldset&gt;
	// these won't be affected by check all; different fieldset
&lt;div&gt;
&lt;input type=&quot;checkbox&quot; /&gt; Checkbox&lt;/div&gt;
&lt;div&gt;
&lt;input type=&quot;checkbox&quot; /&gt; Checkbox&lt;/div&gt;
&lt;div&gt;
&lt;input type=&quot;checkbox&quot; /&gt; Checkbox&lt;/div&gt;
&lt;/fieldset&gt;</pre></div></div>

<p>The original post divs are nonsense in terms of usability and semantics. Loose them as the original author just needed some BR tags.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;fieldset&gt;
&lt;input id=&quot;checkall&quot; type=&quot;checkbox&quot; /&gt; Check all 
&lt;input type=&quot;checkbox&quot; /&gt; Checkbox
&lt;input type=&quot;checkbox&quot; /&gt; Checkbox
&lt;input type=&quot;checkbox&quot; /&gt; Checkbox
&lt;/fieldset&gt;
&lt;fieldset&gt;
	// these won't be affected by check all; different fieldset
&lt;input type=&quot;checkbox&quot; /&gt; Checkbox
&nbsp;
&lt;input type=&quot;checkbox&quot; /&gt; Checkbox
&nbsp;
&lt;input type=&quot;checkbox&quot; /&gt; Checkbox
&lt;/fieldset&gt;</pre></div></div>

<p>This is the original javascript:<br />
<code class="javascript"><br />
$(function () { // this line makes sure this code runs on page load<br />
$('#checkall').click(function () {<br />
$checkall = $(this); OK<br />
$close = $checkall.parents('fieldset:eq(0)').find('input'); // this is called $close but it should be $elements or something<br />
$checkall.attr('checked') !== true ? $close.removeAttr('checked') : $close.attr('checked', 'checked'); // see my version down<br />
});<br />
});<br />
</code><br />
The javascript can be shortened and I preffer using native functions like <strong>is()</strong>, pseudoselectors like <strong>:checked</strong>, and <strong>boolean</strong> values when accepted instead of strings.</p>
<p><code class="javascript"><br />
$('#checkall').click( function () {<br />
var all= $(this).siblings();<br />
$(this).is(':checked') ? all.attr('checked', true) : all.attr('checked', false);<br />
});<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.valugi.ro/2009/08/17/easiest-check-all-ever-with-jquery-made-even-more-easy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simulating a Pan Image jQuery plugin</title>
		<link>http://blog.valugi.ro/2009/07/31/simulating-a-pan-image-jquery-plugin/</link>
		<comments>http://blog.valugi.ro/2009/07/31/simulating-a-pan-image-jquery-plugin/#comments</comments>
		<pubDate>Fri, 31 Jul 2009 11:16:04 +0000</pubDate>
		<dc:creator>elzo valugi</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[pan]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://blog.valugi.ro/?p=319</guid>
		<description><![CDATA[Fact: jQuery has plugins for everything. Fact: you don&#8217;t have to use plugins for everything. Working on a custom javaScript intensive CMS I get the task of displaying a big image inside a controlled environment. I could have used a plugin like MbImgNavigator or ImageZoom. I implemented both but I wasn&#8217;t particularly satisfied with neither. [...]]]></description>
			<content:encoded><![CDATA[<p>Fact: jQuery has plugins for everything.</p>
<p>Fact: you don&#8217;t have to use plugins for everything.</p>
<p>Working on a custom javaScript intensive CMS I get the task of displaying a big image inside a controlled environment. I could have used a plugin like <a href="http://pupunzi.wordpress.com/2009/01/20/mbimgnavigator/">MbImgNavigator</a> or <a href="http://www.visual-blast.com/source/jqzoom/">ImageZoom</a>. I implemented both but I wasn&#8217;t particularly satisfied with neither.</p>
<p>So I created my own simulation that is just a couple of lines without even the need for something complex.<br />
What it does:</p>
<ul>
<li>checking if the image is bigger than then the restrictive container</li>
<li>modifies a envelope container to allow movement only between the calculated permitted limits</li>
<li>activates the drag (jQueryUI) by globally or by axis if only one of the dimensions is overlapping the limits</li>
</ul>
<p>If the image is smaller that the limits nothing happens.<br />
<code class="javascript"><br />
	$(document).ready( function (){<br />
		var overflow_x = 0;<br />
		var overflow_y = 0;<br />
		var _image_x = $('#imageTest').width();<br />
		var _image_y = $('#imageTest').height();<br />
		if( _image_x > 300 ){<br />
			overflow_x = _image_x;<br />
		}<br />
		if( _image_y > 300 ){<br />
			overflow_y = _image_y;<br />
		}<br />
		if( overflow_x &#038;&#038; overflow_y ){<br />
			$('#bckContainerImg').css(<br />
				{<br />
					height: (overflow_y * 2 - 300),<br />
					width: ( overflow_x * 2 - 300 ),<br />
					'margin-top' : -( overflow_y - 300),<br />
					'margin-left': -( overflow_x - 300)<br />
				}<br />
			);<br />
			$("#bigImg img").draggable({containment: '#bckContainerImg'}).css({ cursor: 'all-scroll'});<br />
		} else{<br />
			if( overflow_x ){<br />
				$('#bckContainerImg').css({width: ( overflow_x*2 -300 ), 'margin-left': -(overflow_x - 300) });<br />
				$("#bigImg img").draggable({ axis: 'x', containment: '#bckContainerImg' }).css({ cursor: 'e-resize'});<br />
			}<br />
			if( overflow_y ){<br />
				$('#bckContainerImg').css({ height: (overflow_y * 2 - 300),  'margin-top': -(overflow_y - 300),});<br />
				$("#bigImg img").draggable({ axis: 'y', containment: '#bckContainerImg' }).css({ cursor: 'n-resize'});<br />
			}<br />
		}<br />
	});<br />
</code></p>
<p>You can see a <a href="http://dev.valugi.ro/jquery/pan-image/">full demo here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.valugi.ro/2009/07/31/simulating-a-pan-image-jquery-plugin/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>how to scroll down a div with overflow</title>
		<link>http://blog.valugi.ro/2009/07/28/how-to-scroll-down-a-div-with-overflow/</link>
		<comments>http://blog.valugi.ro/2009/07/28/how-to-scroll-down-a-div-with-overflow/#comments</comments>
		<pubDate>Tue, 28 Jul 2009 15:00:42 +0000</pubDate>
		<dc:creator>elzo valugi</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[overflow]]></category>
		<category><![CDATA[scrollDown]]></category>

		<guid isPermaLink="false">http://blog.valugi.ro/?p=292</guid>
		<description><![CDATA[I was doing a javascript chat application and I got this css/javascript problem of keeping the last entry in the box visible. How nice is to find that your favourite jS library already thought of that. Docs: https://developer.mozilla.org/en/DOM/element.scrollTop http://docs.jquery.com/CSS/scrollTop $(document).ready( function (){ // it will scroll down the double of the div's height // you [...]]]></description>
			<content:encoded><![CDATA[<p>I was doing a javascript chat application and I got this css/javascript problem of keeping the last entry in the box visible.<br />
How nice is to find that your favourite jS library already thought of that.</p>
<p>Docs:<br />
<a href="https://developer.mozilla.org/en/DOM/element.scrollTop">https://developer.mozilla.org/en/DOM/element.scrollTop</a><br />
<a href="http://docs.jquery.com/CSS/scrollTop">http://docs.jquery.com/CSS/scrollTop</a></p>
<p><code class='javascript'><br />
    $(document).ready( function (){<br />
        // it will scroll down the double of the div's height<br />
        // you can change it with any value<br />
        $("#scroller").scrollTop( $("#scroller").height() * 2 );<br />
    });<br />
</code></p>
<p>Demo:<br />
<a href="http://dev.valugi.ro/jquery/scroll-down/">http://dev.valugi.ro/jquery/scroll-down/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.valugi.ro/2009/07/28/how-to-scroll-down-a-div-with-overflow/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

