<?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>Saddacrackers &#187; code</title>
	<atom:link href="http://www.saddacrackers.com/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.saddacrackers.com</link>
	<description>Family, Art and Codes</description>
	<lastBuildDate>Mon, 01 Aug 2011 22:34:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Add animated thumbnails into your website.</title>
		<link>http://www.saddacrackers.com/web-design/add-animated-thumbnails-into-your-website/</link>
		<comments>http://www.saddacrackers.com/web-design/add-animated-thumbnails-into-your-website/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 23:29:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[web design]]></category>

		<guid isPermaLink="false">http://www.saddacrackers.com/?p=349</guid>
		<description><![CDATA[This code was initially built for the iPhone and employs css3 technologies, but I believe it will work in Safari or Firefox. I&#8217;m not sure about IE (IE-8 will probably be ok). The main class. [...]]]></description>
			<content:encoded><![CDATA[<p>This code was initially built for the iPhone and employs css3 technologies, but I believe it will work in Safari or Firefox. I&#8217;m not sure about IE (IE-8 will probably be ok).</p>
<p><strong>The main class.</strong><br />
Save the code below in a file and name it <em>AnimateThumbs.js</em><strong><br />
</strong></p>
<pre class="brush: javascript;">
var AnimateThumbs = function () {

var _container;
var _totalThumbs;
var x_counter = 0;
var y_counter = 0;
var xArr_counter = 0;
var yArr_counter = 0;
var spacer = 10;
var columns = 4;
var _interval = 100;
var _randomize = false;
//var x = [0,1,2,0,1,2,0,1,2,0,1,2]; // these are how the arrays should look if there are 12 child nodes and 3 columns
//var y = [0,0,0,1,1,1,2,2,2,3,3,3]; // these are how the arrays should look if there are 12 child nodes and 3 columns
var x = new Array();
var y = new Array();

function setup() {
//_container = container;
_totalThumbs = _container.childNodes.length;
hideThumbs();

// populate x and y arrays with the proper row and column positions
// based on the children of the containing div
for (var i=0; i&lt; _totalThumbs; i++) {

if (xArr_counter + 1 &lt; columns) {
xArr_counter++;
x.push(xArr_counter);
y.push(yArr_counter);

} else {
xArr_counter = 0;
x.push(xArr_counter);
y.push(yArr_counter);
yArr_counter++;
}
}

}

// position the thumbs based on
function animateThumbs() {
if (_randomize) {
for (var i=0; i&lt; _totalThumbs; i++) {
setTimeout(randomThumb, _interval * i, i);
}

} else {
for (var i=0; i&lt; _totalThumbs; i++) {
setTimeout(fadeThumb, _interval * i, i);
}
}

}

// remove thumbs one at a time in the same order they were placed
function reverseThumbs() {
for (var i=0; i&lt; _totalThumbs; i++) {
setTimeout(removeThumbs, _interval * i, i);
}
}

// place thumbs on stage in random order
function randomThumb(number) {

var i = number;
var rand = Math.floor(Math.random() * x.length);

_container.childNodes[i].style.top = (103 + spacer) * (y[rand]);
_container.childNodes[i].style.left = (75 + spacer) * (x[rand]);

x.splice(rand,1);
y.splice(rand,1);

}

// place thumbs on stage from top left to bottom right
function fadeThumb(num) {
var i = num;

//alert(num);
_container.childNodes[i].style.top = (103 + spacer) * y_counter;
_container.childNodes[i].style.left = (75 + spacer) * x_counter;

if (x_counter + 1 &lt; columns) {
x_counter++;
} else {
x_counter = 0;
y_counter++;
}

}

// moves thumbs off the viewable area one at a time
function removeThumbs(num) {
var i = num;
var thumbWidth = _container.childNodes[0].offsetWidth;

//alert(num);
_container.childNodes[i].style.top = 0;
_container.childNodes[i].style.left = (-thumbWidth);

}

// moves thumbs off the viewable area all at once
function hideThumbs() {
var thumbWidth = _container.childNodes[0].offsetWidth;

for (var i=0; i&lt; _totalThumbs; i++) {
_container.childNodes[i].style.left = (-thumbWidth);
}
}

/* UTILS */
function changeClass (element, newClass) {
element.setAttribute(&quot;class&quot;, newClass); //For Most Browsers
}

function cleanWhitespace(node)
{
for (var i=0; i&lt;node.childNodes.length; i++)
{
var child = node.childNodes[i];
if(child.nodeType == 3 &amp;&amp; !/\S/.test(child.nodeValue))
{
node.removeChild(child);
i--;
}
if(child.nodeType == 1)
{
cleanWhitespace(child);
}
}
return node;
}

/* PUBLICLY AVAILABLE METHODS */
return {
/* Public methods */
start:function () {
animateThumbs();
},

init:function () {
setup();
},

reverseAnimation:function () {
reverseThumbs();
},

/* Public Properties */
getContainer:function () {
return _container;
},

setContainer:function (obj) {
// remove whitespace so we
// get accurate node counts
cleanWhitespace(obj);
_container = obj;
},

getRandomize:function () {
return _randomize;
},

setRandomize:function (value) {
_randomize = value;
},

setColumns:function (value) {
columns = value;
},

getTotalThumbs:function () {
return _totalThumbs;
}

}

};
</pre>
<p>Now include the code in your html file.</p>
<pre class="brush: html;">

&lt;script type=&quot;text/javascript&quot; src=&quot;js/AnimateThumbs.js&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;
</pre>
<p>And you will need a div setup as a container for your thumbs. I gave my div an id of <em>intro</em></p>
<pre class="brush: html;">

&lt;div id=&quot;intro&quot;&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;/div&gt;
</pre>
<p>Now you need to activate the javascript code.</p>
<pre class="brush: javascript;">

var animatethumbs = new AnimateThumbs();
//set the div that contain the thumbs you wanna animate
animatethumbs.setContainer(document.getElementById('intro'));
//do you want them to animate in randomly?
animatethumbs.setRandomize(false);
//initialize
animatethumbs.init();

setTimeout(animateThumbs, 1500);
setTimeout(killThumbs, 5000);

function animateThumbs() {
//start animation
animatethumbs.start();
}

function killThumbs() {
//remove thumbs
animatethumbs.reverseAnimation();
}
</pre>
<p>Don&#8217;t forget the css so you can actually see the thumbs!!!</p>
<pre class="brush: css;">

#intro { position: relative; }
#intro &gt; div { width: 75px; height: 103px; background-color: #000; -webkit-border-radius: 3px; position: absolute; }
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.saddacrackers.com/web-design/add-animated-thumbnails-into-your-website/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Having Trouble with Lightbox in Safari 3.x?</title>
		<link>http://www.saddacrackers.com/javascript/having-trouble-with-lightbox-in-safari-3x/</link>
		<comments>http://www.saddacrackers.com/javascript/having-trouble-with-lightbox-in-safari-3x/#comments</comments>
		<pubDate>Wed, 13 May 2009 20:38:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.saddacrackers.com/?p=314</guid>
		<description><![CDATA[Well I know I sure was. I came across a bug where images could be displayed smaller or bigger than they should depending on what you clicked on before that image. I&#8217;ve patched the lightbox.js [...]]]></description>
			<content:encoded><![CDATA[<p>Well I know I sure was. I came across a bug where images could be displayed smaller or bigger than they should depending on what you clicked on before that image.</p>
<p>I&#8217;ve patched the lightbox.js to make this bug go away. In lighbox class&#8217; changeImage method I modified the imgPreloader.onload function.</p>
<div id="code">
<pre class="brush: javascript;">&lt;/div&gt;
&lt;div&gt;imgPreloader.onload = (function(){&lt;/div&gt;
&lt;div id=&quot;code&quot;&gt;

this.lightboxImage.src = this.imageArray[this.activeImage][0];

//CrashShop edited at 2009-05-12

//modified unimatrixZxero patch (below) to work with latest lightbox code

//FIXES SAFARI 3.0 Images keeping same height and width attributes as

//previous clicked image

this.lightboxImage.width = imgPreloader.width;

this.lightboxImage.height = imgPreloader.height;

//unimatrixZxero edited fist at 2008-02-20 23:25

//adding these attr setters for bug fix in Safari 3.x

//Element.setWidth('lightboxImage', imgPreloader.width);

//Element.setHeight('lightboxImage', imgPreloader.height);

this.resizeImageContainer(imgPreloader.width, imgPreloader.height);

}).bind(this);

imgPreloader.src = this.imageArray[this.activeImage][0];

&lt;/div&gt;
</pre>
<p>The original fix was by Sam Figueroa found at his <a href="http://unimatrixzxero.macbay.de/dragonsrefuge/posts/view/12">blog</a>. I just had to re-write it to work for the latest version of <a href="http://lokeshdhakar.com/projects/lightbox2/">LightBox</a>.js.</p>
<p>Also, I had to add a timestamp to the javascript include to prevent Safari from using a cached version. Yeah, there&#8217;s a better way, but this was quick and I thought it might help someone like me who ran into this problem. I&#8217;m sure no-one is using this, but if you&#8217;reupdating a legacy website then&#8230; I would sggest jQuery <img src='http://www.saddacrackers.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </div>
]]></content:encoded>
			<wfw:commentRss>http://www.saddacrackers.com/javascript/having-trouble-with-lightbox-in-safari-3x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

