<?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>giancarlo.dimassa.net &#187; Scriptaculous</title>
	<atom:link href="http://giancarlo.dimassa.net/category/javascript/scriptaculous/feed/" rel="self" type="application/rss+xml" />
	<link>http://giancarlo.dimassa.net</link>
	<description>A web programmer&#039;s blog</description>
	<lastBuildDate>Sun, 01 Feb 2009 20:33:44 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Elastic and bouncing transitions in scriptaculous</title>
		<link>http://giancarlo.dimassa.net/2007/07/11/elastic-and-bouncing-transitions-in-scriptaculous/</link>
		<comments>http://giancarlo.dimassa.net/2007/07/11/elastic-and-bouncing-transitions-in-scriptaculous/#comments</comments>
		<pubDate>Wed, 11 Jul 2007 05:46:09 +0000</pubDate>
		<dc:creator>giancarlo</dc:creator>
				<category><![CDATA[Scriptaculous]]></category>
		<category><![CDATA[elastic]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[prototype]]></category>
		<category><![CDATA[transitions]]></category>

		<guid isPermaLink="false">http://giancarlo.dimassa.net/2007/07/11/elastic-and-bouncing-transitions-in-scriptaculous/</guid>
		<description><![CDATA[Scriptaculous has a lot of transitions, but in some situations, you want to sprinkle up a dull animation, applying a different, custom transition type.
Back in 2003, Robert Penner wrote the easing equations, a set of math formulas in Flash Actionscript released under the BSD license, that simulate various types of physical effects, the most notable [...]]]></description>
			<content:encoded><![CDATA[<p>Scriptaculous has a lot of transitions, but in some situations, you want to sprinkle up a dull animation, applying a different, custom transition type.<br />
Back in 2003, <a target="_blank" href="http://www.robertpenner.com" >Robert Penner</a> wrote the <a target="_blank" href="http://www.robertpenner.com/easing/penner_easing_as2.zip" >easing equations</a>, a set of math formulas in Flash Actionscript released under the BSD license, that simulate various types of physical effects, the most notable are the overshooting elastic and bouncing ones. For an example, <a target="_blank" href="http://www.robertpenner.com/easing/easing_demo.html" >look at the demo here</a>.<br />
Three years later, <a href="mailto:kendsnyderREMOVETHIS@gmail.com">Ken Snyder</a> adapted the equations for scriptaculous, enabling builtin and custom animations to use these new nice effects as transitions. However the Penner easing equations were highly configurable, where instead in the Snyder ones you can only set the duration, because the other parameters are fixed in the source code. Also, not all (indeed, only a few) of the transitions have been ported, and their names have been changed too.</p>
<p><span id="more-29"></span></p>
<p>To use these new transitions, the easiest way is to open the effects.js file inside the src folder of your scriptaculous library, and add these lines at the end:</p>
<blockquote><p>/*<br />
transitions.js</p>
<p>Based on Easing Equations v2.0<br />
(c) 2003 Robert Penner, all rights reserved.<br />
This work is subject to the terms in http://www.robertpenner.com/easing_terms_of_use.html</p>
<p>Adapted for Scriptaculous by Ken Snyder (kendsnyder ~at~ gmail ~dot~ com) June 2006<br />
*/</p>
<p>/*<br />
Overshooting Transitions<br />
*/<br />
// Elastic (adapted from "EaseOutElastic")<br />
Effect.Transitions.Elastic = function(pos) {<br />
return -1*Math.pow(4,-8*pos) * Math.sin((pos*6-1)*(2*Math.PI)/2) + 1;<br />
};<br />
// SwingFromTo (adapted from "BackEaseInOut")<br />
Effect.Transitions.SwingFromTo = function(pos) {<br />
var s = 1.70158;<br />
if ((pos/=0.5) &lt; 1) return 0.5*(pos*pos*(((s*=(1.525))+1)*pos - s));<br />
return 0.5*((pos-=2)*pos*(((s*=(1.525))+1)*pos + s) + 2);<br />
};<br />
// SwingFrom (adapted from "BackEaseIn")<br />
Effect.Transitions.SwingFrom = function(pos) {<br />
var s = 1.70158;<br />
return pos*pos*((s+1)*pos - s);<br />
};<br />
// SwingTo (adapted from "BackEaseOut")<br />
Effect.Transitions.SwingTo = function(pos) {<br />
var s = 1.70158;<br />
return (pos-=1)*pos*((s+1)*pos + s) + 1;<br />
};</p>
<p>/*<br />
Bouncing Transitions<br />
*/<br />
// Bounce (adapted from "EaseOutBounce")<br />
Effect.Transitions.Bounce = function(pos) {<br />
if (pos &lt; (1/2.75)) {<br />
return (7.5625*pos*pos);<br />
} else if (pos &lt; (2/2.75)) {<br />
return (7.5625*(pos-=(1.5/2.75))*pos + .75);<br />
} else if (pos &lt; (2.5/2.75)) {<br />
return (7.5625*(pos-=(2.25/2.75))*pos + .9375);<br />
} else {<br />
return (7.5625*(pos-=(2.625/2.75))*pos + .984375);<br />
}<br />
};<br />
// BouncePast (new creation based on "EaseOutBounce")<br />
Effect.Transitions.BouncePast = function(pos) {<br />
if (pos &lt; (1/2.75)) {<br />
return (7.5625*pos*pos);<br />
} else if (pos &lt; (2/2.75)) {<br />
return 2 - (7.5625*(pos-=(1.5/2.75))*pos + .75);<br />
} else if (pos &lt; (2.5/2.75)) {<br />
return 2 - (7.5625*(pos-=(2.25/2.75))*pos + .9375);<br />
} else {<br />
return 2 - (7.5625*(pos-=(2.625/2.75))*pos + .984375);<br />
}<br />
};</p>
<p>/*<br />
Gradual Transitions<br />
*/<br />
// EaseFromTo (adapted from "Quart.EaseInOut")<br />
Effect.Transitions.EaseFromTo = function(pos) {<br />
if ((pos/=0.5) &lt; 1) return 0.5*Math.pow(pos,4);<br />
return -0.5 * ((pos-=2)*Math.pow(pos,3) - 2);<br />
};<br />
// EaseFrom (adapted from "Quart.EaseIn")<br />
Effect.Transitions.EaseFrom = function(pos) {<br />
return Math.pow(pos,4);<br />
};<br />
// EaseTo (adapted from "Quart.EaseOut")<br />
Effect.Transitions.EaseTo = function(pos) {<br />
return Math.pow(pos,0.25);<br />
};</p></blockquote>
<p>That's all you need to do to add the transitions. To use them, simply add the transition to the effect, for example</p>
<blockquote><p>transition:Effect.Transitions.Bounce</p></blockquote>
<p>like here</p>
<blockquote><p>new Effect.BlindDown(el,{duration:2, transition:Effect.Transitions.Bounce});</p></blockquote>
<p>note that as some time is spent accelerating and decelerating the element, the animation will seem to "endure" less, it will seem to be faster, so it's better to at least double the duration time. Also I suggest tweaking the transitions parameters for further personalization.<br />
As you can see skimming trough the code, the effects name (case sensitive) are: Elastic, SwingFromTo, SwingFrom, SwingTo, Bounce, BouncePast, EaseFromTo, EaseFrom and EaseTo.<br />
Remember that if you upgrade your scriptaculous, you'll need to paste again this code at the end of the effects.js file. You could also consider adding it to your code, as it is not really as important where it is, as soon as the new transitions are loaded after the effects.js code. A third option can be creating a pennier.js file in the scriptaculous folder and change the script tag to add it, as an example</p>
<blockquote><p>&lt;script src="/lib/scriptaculous/src/scriptaculous.js?load=effects,pennier" type="text/javascript"&gt;&lt;/script&gt;</p></blockquote>
<p>but if you prefer to aggregate as much files as possible to reduce network delays during page loads, that's not you'll want to do.<br />
Ah, if you use Flash and plan adding the tweening Pennier equations to your actionscripts, check out his book "Programming Macromedia Flash MX", part III:Dynamic Visuals, chapter 7:Motion, Tweening, and Easing. The book details are available on <a target="_blank" href="http://www.robertpenner.com/" >his website</a>, where the chapter is freely downloadable <a target="_blank" href="http://www.robertpenner.com/easing/penner_chapter7_tweening.pdf" >here</a>.<br />
In a forthcoming article, I'll discuss about an animation library (the technical name is "tween sequencer") for Flash that incorporates the Robert Penner tweens, think of it as the scriptaculous for Flash: <a target="_blank" href="http://www.mosessupposes.com/Fuse/" >The FUSE Kit</a>.</p>
<p class="fbconnect_share"><fb:share-button class="url" href="http://giancarlo.dimassa.net/2007/07/11/elastic-and-bouncing-transitions-in-scriptaculous/" /></p>]]></content:encoded>
			<wfw:commentRss>http://giancarlo.dimassa.net/2007/07/11/elastic-and-bouncing-transitions-in-scriptaculous/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to find the right point in Google Maps (longitude and latitude)</title>
		<link>http://giancarlo.dimassa.net/2007/07/02/how-to-find-the-right-point-in-google-maps-longitude-and-latitude/</link>
		<comments>http://giancarlo.dimassa.net/2007/07/02/how-to-find-the-right-point-in-google-maps-longitude-and-latitude/#comments</comments>
		<pubDate>Mon, 02 Jul 2007 11:40:03 +0000</pubDate>
		<dc:creator>giancarlo</dc:creator>
				<category><![CDATA[Google Maps]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[map]]></category>

		<guid isPermaLink="false">http://giancarlo.dimassa.net/2007/07/02/how-to-find-the-right-point-in-google-maps-longitude-and-latitude/</guid>
		<description><![CDATA[Have you ever used the Google Maps API and found out that you don't really know the right position where to place the markers? As you know, to do so requires entering in javascript the exact marker's coordinates, so you go in a trial-and-error loop to try to correct the numbers until you find the [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever used the Google Maps API and found out that you don't really know the right position where to place the markers? As you know, to do so requires entering in javascript the exact marker's coordinates, so you go in a trial-and-error loop to try to correct the numbers until you find the right spot, browse for various so called google maps builders hoping that one of them actually gives you the coordinates you need to nail the right place, or modify your code so that outputs in some way the coordinates, find the marker's position, jot it down, then restore the old script and add the numbers.</p>
<p><span id="more-10"></span>During this phase the client calls saying the marker isn't in the right place, it's "more to the sea", or "a bit more to the left". You also have the problem that modifying the javascript code makes the map go into the debug mode (outputting coordinates) as long as the right numbers have been found out, even web site readers see them.</p>
<p>Solve the problem one time for all by adding this few lines to your javascript code that uses the Google Maps API (I assume the google map object name is "map", change as needed):</p>
<blockquote><p>if (document.location.href.indexOf('mapsdebug') != -1) {<br />
var markerdebug = new GMarker(map.getCenter()),{draggable:true});<br />
GEvent.addListener(markerdebug, "dragend", function() {<br />
markerdebug.openInfoWindowHtml(</p>
<p>markerdebug.getPoint().toString()</p>
<p>)<br />
});<br />
map.addOverlay(markerdebug);<br />
}</p></blockquote>
<p>This tells the browser that if the URL contains #mapsdebug a new draggable marker appears at the center of the map, that when dropped on a new location outputs in a balloon the point coordinates.</p>
<p>This way you or your client can simply find the marker's coordinates by adding a snippet to the URL.</p>
<p>Here there is a live example in <a target="_blank" href="http://www.zicarmela.com/ischia-dovesiamo.html" >standard</a> and in <a target="_blank" href="http://www.zicarmela.com/ischia-dovesiamo.html#mapsdebug" >debug</a> mode.</p>
<p>Imagine the problem: You approximatively (maybe unintentionally) place a marker in the wrong position, then phone or email the client and say to add #mapsdebug to the map URL, drag the new marker and tell you the numbers.</p>
<p>You place the right coordinates in the javascript and the pinpoint appears into the right position.</p>
<p>Pros of this technique:</p>
<ul>
<li>As you reuse the code, you carry the debug section with you</li>
<li>The website readers doesn't see the map in "debug mode"</li>
<li>The website owner can easily correct the position with a simple drag and drop procedure</li>
<li>It's fun</li>
</ul>
<p>Cons:</p>
<ul>
<li>The google maps code gets longer by a hundred bytes, not very much but you could want to strip out the code when the website finishes building</li>
<li>The website owner still has to correct the position by sending via email the new coordinates. Yes, I could have posted the position via an AJAX call, but the code would get cumbersome and/or more library dependant.</li>
<li>You can't use anymore the word "mapsdebug" when calling the page because it triggers the debug section, but if you want so, simply change the secret token as you wish.</li>
</ul>
<p>There's an alternate technique suggested on a <a target="_blank" href="http://lifehacker.com/software/google-maps/how-to-find-latitude-and-longitude-267361.php" >lifehacker</a> (indeed a <a target="_blank" href="http://www.tech-recipes.com/rx/2403/google_maps_get_latitude_longitude_values" >tech recipes</a> one but this has a screen shot!): Go to the Google Maps website, then center the view on the place you wish to know the latitude and longitude data, then paste this code into the browser bar:</p>
<blockquote><p>javascript:void(prompt('',gApplication.getMap().getCenter()));</p></blockquote>
<p>I prefer mine because it's more accurate and easily to explain to the website owner if he wants to pinpoint the address himself.</p>
<p>Happy mapping!</p>
<p class="fbconnect_share"><fb:share-button class="url" href="http://giancarlo.dimassa.net/2007/07/02/how-to-find-the-right-point-in-google-maps-longitude-and-latitude/" /></p>]]></content:encoded>
			<wfw:commentRss>http://giancarlo.dimassa.net/2007/07/02/how-to-find-the-right-point-in-google-maps-longitude-and-latitude/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>
