You are not logged in Log in Join
You are here: Home » Members » aaltepet's Home » SilvaRandomContent Code Source » readme » View Document

Log in
Name

Password

 

readme

# Copyright (c) 2007 Andy Altepeter. All rights reserved.
# See also gpl.txt

Meta::
Valid for: Silva 1.5+, Silva Random Content Source 1.0+
Author: Andy Altepeter
Email: aaltepet at altepeter dot net
Prerequesites: prototype JS library (http://www.prototypejs.org)

Silva Random Content Source 1.0

This product provides a 'Random Content Code Source'. This code source
chooses a random item from a specified container and displays it. The
allowed meta_types are Silva Documents and Silva Images. Only one meta_type
is allowed per instance of the code source.

This code source can get random items from the specified folder and subfolders
by adjusting the 'depth' property. A depth of '-1' indicates an umlimited depth,
'0' is the current folder only (default), and '1' or more indicates the number
of levels deep to traverse.

There are two types of randomness: on page load, and on interval. If using
"on page load", a random content item will be selected when the Silva Document
is rendered. If "on interval", a random content item will be selected when
the Silva Document is rendered, and every X seconds it will be replaced
with a new random content item from the specified folder. This interval
content replacement is done using prototype's Ajax.Request object.

The javascript that controls the "on interval" also caches the random content.
So, only one request per random content item will be made to server per
load of the page containing the code source.

The random content has a few options to control how it is displayed. Regardless
of whether the type is Silva Document or Silva Image, you can choose to display
the content types Title as well as the Description. These are both located
on the properties tab, as silva-content:title and silva-extra:description.

This code source is completely customizable via css. You need to specify a unique
ID of the code source, and can include any css styles to be placed in the containing
<div>'s "style" attribute. This div has a class of "random-cs". The title of the code
source is a level 3 heading. The random content either has a class of "random-image" or
"random-doc". The random content's title is a level 4 heading. The description
is a paragraph with class "content-desc".

A sample of the code sources output may look like:

<div style="border: 1px solid black;" id="random-id" class="random-cs">
<h3>Random Content Test</h3>
<script type="text/javascript"> <!-- controls the interval content replacement -->
<div class="random-content">
<div class="random-image">
<h4 class="random-content-title">Pear</h4>
<p class="random-content-desc">Description of item</p>
<img src="http://www.bethel.edu/test/empty_tables_pear.gif" alt="Pear" height="48" width="48">
</div>
</div>
</div>

Expect these styles to be present in the next release of SilvaStylesheets (1.2):
http://zope.org/Members/aaltepet/SilvaStylesheets

Notes about Javascript:

Prototype is a fairly large javascript framework (~40k). I had reservations about
including it in our standard template. However, when gzip transfer encoding is activated,
only ~10k is send across the wire. So, using gzip transfer encoding is highly recommended.
We use apache 2.0 in from of Zope. To activate gzip transfer encoding for _just_ the
javascript area, I did the following (http://httpd.apache.org/docs/2.0/mod/mod_deflate.html):

<Location /globals/js/>
SetOutputFilter DEFLATE
# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html
# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip
# MSIE masquerades as Netscape, but it is fine
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# Don't compress images
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</Location>


All of the "standard" javascript I am using across all of Bethel University's Silva sites
is stored in the Silva product's globals directory. I created a 'js' directory within
'globals', where prototype, vivo (http://altepeter.net/tech/vivo, scriptaculous, etc) are
located. [ So, Products/Silva/globals/js ] When these are pulled into the layout, I use
absolute urls to the files, so they can be properly cached by the browser. E.g.
tal:define="prototype here/globals/js/prototype.js/absolute_url"

If prototype is not found and "random interval" is being used, the after the first interval
and alert box is displayed informing the client that prototype is not found, and that
the interval will be cancelled.