This is actually pretty simple to do using Prototype/Scriptaculous. (Please note: heavy JavaScript geekery ahead – there are no easy Action-ized methods for doing this, and you have to do some methodical prep work for it to happen at all.)
###Prep work
There is one basic requirement that you have to observe, no matter how you are performing this trick: all content that you plan to load into the page after the initial page load must be page fragments, not entire pages. If you load a complete valid HTML page into another valid HTML page, then they will both become invalid, and further JavaScript manipulation of the combination will become iffy at best.
The first thing to start with is your extra content. If it’s the result of a search, or some other server-side process like that, then you need to figure out how that process is paging its results, and what you need to modify about that query to tell the server to send the next set of results. If it’s just static content, then you need to know all the URLs to the content ahead of time, and your main page needs to know both what has loaded so far and what is next.
###Static pages
Let’s take the simplest possible route to an endless scroll. First, lay out your main page. Make note of the width of your endless element, you’ll need it later. Also, you are strongly recommended to create an inline layout (sometimes referred to by Dan Jasker as a “box model” layout – see http://freewaycast.com for links to one or more screencasts on the topic) because otherwise your page footer will be overlapped by the content you are loading in.
Next, make a new Master page, and set its width to the same dimension as your main content element on your first page. Apply the PHP Make Insert Page Action to the master page. This will strip off the HTML, head, and body tags from the generated code, leaving only the content of the body behind. Pro tip: make sure “Use external stylesheets” is turned on in your Document Setup dialog.
Now make each of your latter pages, taking care when naming them to follow a pattern you can remember, or simply writing down their filenames (not the titles, which won’t show up anyway) for future geekery.
###Loading indicators
Now, back at your starting page, double-click inside your main HTML element, and use the main menu command “Insert/HTML item” to create the loading indicator. This will insert initially as a 100px square. Let’s style it up: first visit http://www.ajaxload.info/ and create a nice loading image. Now set that as the background image of your inline HTML box. Set the background position to center, center, no-repeat. All of this is done using the background segment of the Style tab on the Inspector while the box is selected (handles showing). Now stretch the box out to full width, so it completely fills the main HTML box from left to right. Set its height to just tall enough to show the animated background.
Next, click once on the loading indicator HTML box so its handles are showing and open the Item / Extended dialog. Click the New button, and enter the following Name/Value pair:
- Name: data-load
- Value: filename_of_next_page.html
Obviously, change that filename to match the first filename from your list of latter pages. Okay the dialog, then press New again. Enter this pair of Name/Value:
- Name: class
- Value: loading
Okay out of the teetering stack of sub-sub-sub dialog boxes, and copy the loading indicator box to the clipboard. Now double-click above or below the loading indicator so you have a flashing text cursor, and paste as many times as you have additional latter pages. Click once on each duplicate loading indicator, and use the Item/Extended dialog stack to change the filename to match each of the pages in your list. You should end up with one loading indicator for each page you wish to load, inserted at the bottom of your main HTML box in the order you expect them to appear.
###The Geekery, as promised
Now apply Protaculous to the page, and set the Library picker to prototype-packed. Click once on the top Function Body button, and paste in the following code:
Now publish your site, and preview in a browser. (This might work in Freeway’s Preview, but most likely will not.)
If you see the error message instead of your requested content after you scroll to the bottom of your first page, look carefully at it to see what the URL is it’s trying to load, and make sure that the file is named precisely that and exists alongside your main page in the site folder. If it doesn’t, then you have to figure out why.
Post a link to your page when you’re done, so we can revel in your handiwork!
Walter
freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options