<?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>Tigraine &#187; jQuery</title>
	<atom:link href="http://www.tigraine.at/category/programmierung/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tigraine.at</link>
	<description>Daniel Hoelbling talks about programming</description>
	<lastBuildDate>Fri, 03 Feb 2012 00:02:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Execute callback once multiple ajax requests finish with jQuery</title>
		<link>http://www.tigraine.at/2011/09/26/execute-callback-once-multiple-ajax-requests-finish-with-jquery/</link>
		<comments>http://www.tigraine.at/2011/09/26/execute-callback-once-multiple-ajax-requests-finish-with-jquery/#comments</comments>
		<pubDate>Mon, 26 Sep 2011 17:42:51 +0000</pubDate>
		<dc:creator>Daniel Hölbling</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.tigraine.at/?p=1148</guid>
		<description><![CDATA[I just stumbled upon the problem of having to load multiple resources during page initialization. During the initial load I wanted a way to prevent any animations and other fancy stuff from happening but rather only create the page as soon as possible. Since I couldn&#8217;t find any way in jQuery (there are no combined [...]]]></description>
			<content:encoded><![CDATA[<p>I just stumbled upon the problem of having to load multiple resources during page initialization. During the initial load I wanted a way to prevent any animations and other fancy stuff from happening but rather only create the page as soon as possible. </p>
<p>Since I couldn&#8217;t find any way in jQuery (there are no combined callbacks) I decided to implement this using the <a href="http://api.jquery.com/category/deferred-object/">deferred promise</a> concept jQuery 1.5 introduced.</p>
<p>Deferred basically means &#8220;<em>I represent a ajax call that has happened or is happening &#8211; ask me about it and I&#8217;ll tell you when it&#8217;s done or was done already</em>&#8220;.<br />
So implementing my little wait functions was rather trivial:</p>
<p><script src="https://gist.github.com/1242097.js?file=wait.coffee"></script></p>
<p>I used CoffeeScript for this, but <a href="https://gist.github.com/1242097#file_wait.js">the resulting JavaScript</a> is also quite readable and you can use that too.</p>
<p>What this does is provide you with the awkwardly named function <code>waitForAjaxRequestsToComplete</code> that takes one callback parameter and an array of jQuery promises.<br />
Once all promises succeed or fail the callback will be called and the first parameter will contain information about failures.</p>
<p>Sample usage:</p>
<pre class="javascript" name="code">
waitForAjaxRequestsToComplete(function (info) {
  console.log("requests failed " + info.failures)
  console.log("requests succeeded " + info.successes)
  console.log(info.failed) //contains all failed promises
}, [ $.ajax(...), $.ajax(...), $.ajax(...) ]);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.tigraine.at/2011/09/26/execute-callback-once-multiple-ajax-requests-finish-with-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery.validate and multiple forms on one page</title>
		<link>http://www.tigraine.at/2011/08/31/jquery-validate-and-multiple-forms-on-one-page/</link>
		<comments>http://www.tigraine.at/2011/08/31/jquery-validate-and-multiple-forms-on-one-page/#comments</comments>
		<pubDate>Wed, 31 Aug 2011 12:25:44 +0000</pubDate>
		<dc:creator>Daniel Hölbling</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.tigraine.at/?p=1063</guid>
		<description><![CDATA[I like generic, convention based approaches to infrastructure so in most of my projects you&#8217;ll find something like this in the main javascript file: $('form').validate(); There is only one slight problem: jQuery validate doesn&#8217;t work like most jQuery plugins and won&#8217;t operate on the matched set, but rather only on the first element. So if [...]]]></description>
			<content:encoded><![CDATA[<p>I like generic, convention based approaches to infrastructure so in most of my projects you&#8217;ll find something like this in the main javascript file:</p>
<pre class="javascript" name="code">
$('form').validate();
</pre>
<p>There is only one slight problem: jQuery validate doesn&#8217;t work like most jQuery plugins and won&#8217;t operate on the matched set, but rather only on the first element.</p>
<p>So if you want to validate multiple forms you have to call each form individually through <code>each</code></p>
<pre class="javascript" name="code">
$('form').each() {
    $(this).validate();
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.tigraine.at/2011/08/31/jquery-validate-and-multiple-forms-on-one-page/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>jQuery.validate and Microsofts unobtrusive validation don&#8217;t play well together</title>
		<link>http://www.tigraine.at/2011/08/26/jquery-validate-and-microsofts-unobtrusive-validation-dont-play-well-together/</link>
		<comments>http://www.tigraine.at/2011/08/26/jquery-validate-and-microsofts-unobtrusive-validation-dont-play-well-together/#comments</comments>
		<pubDate>Fri, 26 Aug 2011 19:09:40 +0000</pubDate>
		<dc:creator>Daniel Hölbling</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.tigraine.at/?p=1059</guid>
		<description><![CDATA[I was banging my head against the wall for more than three hours, reading jQuery.validate&#8216;s code, trying to figure out why my supplied errorPlacement or highlight callbacks where not called. The code in question looked perfectly fine and came pretty much straight out of the docs: $('form').validate({ debug: true, errorPlacement: function () { console.log("errorPlacement", this, [...]]]></description>
			<content:encoded><![CDATA[<p>I was banging my head against the wall for more than three hours, reading <a href="http://bassistance.de/jquery-plugins/jquery-plugin-validation/">jQuery.validate</a>&#8216;s code, trying to figure out why my supplied <code>errorPlacement</code> or <code>highlight</code> callbacks where not called.</p>
<p>The code in question looked perfectly fine and came pretty much straight out of the docs:</p>
<pre name="code" class="javascript">
$('form').validate({
    debug: true,
    errorPlacement: function () {
        console.log("errorPlacement", this, arguments);
    },
    highlight: function () {
        console.log("highlight", this, arguments);
    },
    success: function () {
        console.log("success", this, arguments);
    }
});
</pre>
<p>As you can see I was still stuck in the &#8220;let&#8217;s see what we can do from these callbacks&#8221; phase of implementing my own automatic validation scheme for a project.<br />
Guess what the above did? <strong>Nothing!</strong> And I mean really nothing. The validation worked as expected with my validation classes,  but none of my callbacks got ever called (meanwhile supplied arguments like messages etc worked like a charm).</p>
<p>After 3 hours I finally came onto something when I couldn&#8217;t find the validation classnames that where put on my elements inside the jQuery.validation code I was looking at.<br />
Turns out: Microsoft&#8217;s jquery.validation.unobtrusive.js cripples jQuery.validation so that most of it&#8217;s configuration options simply don&#8217;t work any more. Neither with the <a href="http://docs.jquery.com/Plugins/Validation/Validator/setDefaults">$.validate.setDefaults()</a> nor with the <a href="http://docs.jquery.com/Plugins/Validation/validate">$(&#8216;#element&#8217;).validate()</a> methods. </p>
<p>Needless to say that I almost broke into tears when my stuff was working fine once I removed the unobtrusive script from the page.</p>
<p>I do like the unobtrusive stuff &#8211; it serves it&#8217;s purpose inside the MS MVC niche. But in this case I was not using unobtrusive on that form at all! So I simply did not expect the library to mess with jQuery.validate in any way as there was no unobtrusive validation stuff going on.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tigraine.at/2011/08/26/jquery-validate-and-microsofts-unobtrusive-validation-dont-play-well-together/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Localized Fullcalendar options</title>
		<link>http://www.tigraine.at/2011/08/23/localized-fullcalendar-options/</link>
		<comments>http://www.tigraine.at/2011/08/23/localized-fullcalendar-options/#comments</comments>
		<pubDate>Tue, 23 Aug 2011 09:04:31 +0000</pubDate>
		<dc:creator>Daniel Hölbling</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.tigraine.at/?p=1056</guid>
		<description><![CDATA[I usually try to avoid using too many jQuery plugins, especially for rather simple stuff like this. But displaying a calendar is pretty tricky (believe me &#8211; I wrote one using GDI+) and Fullcalendar has saved me countless hours so far. One issue that cropped up now is that we needed our Fullcalendar to be [...]]]></description>
			<content:encoded><![CDATA[<p>I usually try to avoid using too many jQuery plugins, especially for rather <a href="http://stackoverflow.com/questions/7099958/possible-to-have-mouseover-for-x-seconds-functionality-using-jquery/7100304#7100304">simple stuff like this</a>. But displaying a calendar is pretty tricky (believe me &#8211; I wrote one using GDI+) and <a href="http://arshaw.com/fullcalendar/">Fullcalendar </a>has saved me countless hours so far. </p>
<p>One issue that cropped up now is that we needed our Fullcalendar to be localized in German. As with most things I came across so far, Fullcalendar already supports it &#8211; but the documentation is a bit cryptic on the issue so here is my localized options hash:</p>
<pre class="javascript" name="code">
var localOptions = {
	buttonText: {
		today: 'Heute',
		month: 'Monat',
		day: 'Tag',
		week: 'Woche'
	},
	monthNames: ['Jänner','Februar','März','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember'],
	monthNamesShort: ['Jän','Feb','Mär','Apr','Mai','Jun','Jul','Aug','Sept','Okt','Nov','Dez'],
	dayNames: ['Sonntag','Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag'],
	dayNamesShort: ['So','Mo','Di','Mi','Do','Fr','Sa']
}

$('#calendar').fullCalendar($.extend({ ... your options ... }, localOptions));
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.tigraine.at/2011/08/23/localized-fullcalendar-options/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery: Execute once animation finished</title>
		<link>http://www.tigraine.at/2011/08/21/jquery-execute-once-animation-finished/</link>
		<comments>http://www.tigraine.at/2011/08/21/jquery-execute-once-animation-finished/#comments</comments>
		<pubDate>Sun, 21 Aug 2011 11:04:47 +0000</pubDate>
		<dc:creator>Daniel Hölbling</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.tigraine.at/?p=1038</guid>
		<description><![CDATA[Good JavaScript almost forces you into learning async programming and jQuery animations is no different. Everything in jQuery supports callbacks because the stuff you do is in most cases done on the background while your script continues to run. But as with most stuff, there are many ways of going about this: Completed Callbacks $('#item').fadeOut('slow', [...]]]></description>
			<content:encoded><![CDATA[<p>Good JavaScript almost forces you into learning async programming and jQuery animations is no different. Everything in jQuery supports callbacks because the stuff you do is in most cases done on the background while your script continues to run.</p>
<p>But as with most stuff, there are many ways of going about this:</p>
<h3>Completed Callbacks</h3>
<pre name="code" class="javascript">
    $('#item').fadeOut('slow', function () {
        console.log('animation finished');
    });
</pre>
<p>The problem with this approach is that it gets rather tedious to queue stuff together if you want to do say three things in order.</p>
<p>Let&#8217;s say you want to a fadeOut animation then add a cssClass, start another animation and once that one is finished remove the cssClass again. Using callbacks this looks rather ugly:</p>
<pre name="code" class="javascript">
    $('#item').fadeOut('slow', function () {
        var foo = $('#foo');
        foo.addClass('myclass');
        $('#item2').fadeIn('slow', function () {
          foo.removeClasS('myclass');
        }
    });
</pre>
<p>As you can see, two nested callbacks is really not that readable and almost confusing.. That&#8217;s why there is a better way to do this:</p>
<h3>The fx Queue</h3>
<p>jQuery uses a queue for all it&#8217;s animations. That&#8217;s the magic behind this nice syntax:</p>
<pre name="code" class="javascript">
    $('#item').fadeIn().fadeOut();
</pre>
<p>If you run this code it will first fade the item in and only once it&#8217;s completely visible it will start the fadeOut animation.</p>
<p>Problem with this is that it looks nice in it&#8217;s syntax, but can&#8217;t be mixed with the regular jQuery methods. Something like </p>
<pre name="code" class="javascript">
$('#item').fadeIn().removeClass('active').fadeOut();</pre>
<p> will not work simply because you removeClass will be executed instantly while fadeIn and fadeOut will be queued for later execution by the effects (fx) queue.</p>
<p>In that case you can hook into the queue yourself by using the <a href="http://api.jquery.com/queue/">.queue() </a> method:</p>
<pre name="code" class="javascript">
    $('#item').fadeIn().queue(function (next) {
        $(this).removeClass('active');
        next(); //Important to continue running the queue
    }).fadeOut();
</pre>
<p>Hope this helps!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tigraine.at/2011/08/21/jquery-execute-once-animation-finished/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery.Stepy select callback</title>
		<link>http://www.tigraine.at/2011/08/02/jquery-stepy-select-callback/</link>
		<comments>http://www.tigraine.at/2011/08/02/jquery-stepy-select-callback/#comments</comments>
		<pubDate>Tue, 02 Aug 2011 10:26:33 +0000</pubDate>
		<dc:creator>Daniel Hölbling</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.tigraine.at/?p=1023</guid>
		<description><![CDATA[I just stumbled upon a little issue while using jQuery.Stepy wizard plugin: There are callbacks for navigating, but there is simply no callback that gets fired when the current step is actually displayed. As it happens there are a number of things you may want to do once a wizard  step is shown like start [...]]]></description>
			<content:encoded><![CDATA[<p>I just stumbled upon a little issue while using <a href="http://www.wbotelhos.com/stepy/">jQuery.Stepy</a> wizard plugin: There are callbacks for navigating, but there is simply no callback that gets fired when the current step is actually displayed.<br />
As it happens there are a number of things you may want to do once a wizard  step is shown like start animations or maybe initialize something. (And next/back get fired before validation happens so they don&#8217;t actually work in case validation fails)</p>
<p>Thank god JavaScript is almost by definition open-source so I fixed this with the <a href="https://github.com/wbotelhos/stepy/pull/10">following pull request</a>.</p>
<p>The select callback works just like the back/next callbacks:</p>
<pre name="code" class="javascript">
$('#wizard').stepy({
  select: function (index) {
     //your code goes here
     //index is 1 based - not zero based
  }
});
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.tigraine.at/2011/08/02/jquery-stepy-select-callback/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The deprecated target attribute and jQuery</title>
		<link>http://www.tigraine.at/2008/09/24/the-deprecated-target-attribute-and-jquery/</link>
		<comments>http://www.tigraine.at/2008/09/24/the-deprecated-target-attribute-and-jquery/#comments</comments>
		<pubDate>Wed, 24 Sep 2008 09:31:03 +0000</pubDate>
		<dc:creator>Daniel Hölbling</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.tigraine.at/2008/09/24/the-deprecated-target-attribute-and-jquery/</guid>
		<description><![CDATA[It&#8217;s usually not considered polite to open new windows whenever somebody clicks one of your external links. Those back and forward buttons are there for a reason, so I strongly encourage people to avoid opening new windows. But, we all know customers. They get this &#34;but I want this&#34; look the second they discover that [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s usually not considered polite to open new windows whenever somebody clicks one of your external links. Those back and forward buttons are there for a reason, so I strongly encourage people to avoid opening new windows.</p>
<p>But, we all know customers. They get this &quot;but I want this&quot; look the second they discover that users <em>may </em>leave their web site too early (can&#8217;t say how much this attitude sucks..).</p>
<p>One popular way to do this is to use jQuery to open all external links on your page in a popup (making code that obviously violates the &quot;don&#8217;t open new windows&quot; rule still validate). </p>
<div class="wlWriterSmartContent" id="scid:2e6d557b-b705-4c34-b5ad-8606cf99c7de:4f930759-7851-4959-90dc-fb594528415d" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px">
<pre name="code" class="jscript">
$(document).ready(function() {
&#160;&#160;&#160;&#160;$("a[rel='external']").click(function(event) {
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;window.open($(this).attr("href"));
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;event.preventDefault();
&#160;&#160;&#160;&#160;});
});
</pre>
</div>
<p>Now all you have to do is, add a <em>rel=&quot;external&quot;</em> attribute to all outgoing links, and this little jQuery function will take care of making them popup.</p>
<p>Still, this is <strong>bad</strong>. It contradicts the whole idea why they removed the target attribute in the first place, so consider this as a quick&#8217;n'dirty hack to satisfy stupid customers.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tigraine.at/2008/09/24/the-deprecated-target-attribute-and-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

