06.05.2013 Views

Drupal 6 JavaScript and jQuery - Ebook-Cours.com

Drupal 6 JavaScript and jQuery - Ebook-Cours.com

Drupal 6 JavaScript and jQuery - Ebook-Cours.com

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

[ 81 ]<br />

Chapter 3<br />

So in that one corner case, we can avoid adding our effect when $('#node-form').<br />

size() is greater than 0.<br />

In the case where there is only one sticky node on a page, or when the sticky node is<br />

displayed as part of a content editing preview, the function simply returns without<br />

doing anything.<br />

But if neither of those conditions is met, initialization continues. Let's take a look at<br />

what's next:<br />

StickyRotate.init = function() {<br />

var stickies = $(".sticky");<br />

// If we don't have enough, stop immediately.<br />

if (stickies.size() 0) {<br />

return;<br />

}<br />

var highest = 100;<br />

stickies.each(function () {<br />

var stickyHeight = $(this).height();<br />

if(stickyHeight > highest) {<br />

}<br />

});<br />

highest = stickyHeight;<br />

/* The rest of the code... */<br />

};<br />

We are interested in the highlighted portion of the code. The focus of this snippet of<br />

code is the height of the area where our sticky nodes will be displayed.<br />

Looking back at our three sticky nodes, we have two fairly large teasers (the two<br />

Latin Descartes' quotes), but we also have a very short one. The node entitled A<br />

Sticky Node has a one-line teaser: This node should always be displayed near the<br />

top of the home page.<br />

What we don't want is for a short node like this to cause the page layout to shift<br />

significantly. We don't want the content to slide up for the short node, <strong>and</strong> then slide<br />

back down to make room for longer nodes.<br />

What we do want then, is to control the height of the sticky nodes. We want them all<br />

to take up the same amount of screen space.<br />

The code we just saw is designed to find the largest sticky node, get that node's<br />

height, <strong>and</strong> then use that as the height for all of the sticky nodes.<br />

This material is copyright <strong>and</strong> is licensed for the sole use by Richard Ostheimer on 18th June 2009<br />

2205 hilda ave., , missoula, , 59801

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!