// AJB 28/10/2001 Better Archive Listings
// AJB 1/11/2001, cookie.js
// + blogarc.html
// AJB 1/11/2001, cookie.js
// (very) Simple cookie handling
// Example usage:
// var Xcookie = new obiCookie( "LimitArchive", 365 );
// ( First Param is cookie name, second is desired expirey time in days)
//
// 1. Read Cookie
// var theCookie = Xcookie.GetCookie();
// if ( null == theCookie )
// // Cookie does not exist
// else
// // the cookie value can be taken either
// // from the return value or from the .cookieVal property
// var x = theCookie;
// var x = Xcookie.cookieVal;
//
// 2. Write Cookie (Expiry time as in object initialisation)
// Xcookie.SetCookie( "106" );
//
// 3. Delete Cookie
// Xcookie.KillCookie();
//
// My Type 'obiCookie'
// Constructor
function obiCookie( theCookieName, theExpireTimeInDays ){
this.CookieName = theCookieName;
this.cookieVal = null;
this.expireTimeInMs = theExpireTimeInDays * 1000 * 60 * 60 * 24;
}
// Methods
obiCookie.prototype.GetCookie = function(){
// Look for our named cookie
var i = document.cookie.indexOf( this.CookieName + "=" );
if ( -1 != i ){
var e = document.cookie.slice( i ).indexOf( ";" );
this.cookieVal = document.cookie.slice( i+this.CookieName.length+1, (-1 != e)?e:document.cookie.length );
return this.cookieVal;}
return null;
}
obiCookie.prototype.SetCookie = function( Value ){
var expireDate = new Date();
expireDate.setTime( expireDate.getTime() + this.expireTimeInMs );
var cookietext = this.CookieName + "=" + Value +
"; expires=" + expireDate.toGMTString();
document.cookie = cookietext;
this.cookieVal = Value;
}
obiCookie.prototype.KillCookie = function(){
var expireDate = new Date();
document.cookie = this.CookieName + "=0" +
"; expires=" + expireDate.toGMTString();
this.cookieVal = null;
}
obiCookie.prototype.GetValue = function(){
return this.cookieVal;
}
// AJB 28/10/2001 Better Archive Listings
// Last Update 3/8/2002
// My Type 'BlogArchiveEntry'
function BlogArchiveEntry( theLink, theName )
{
this.Link = theLink;
this.Name = theName;
// Extract Date from Name, Yuk!
// 09/30/2001 - 10/06/2001
this.StartDate = new Date( this.Name.slice(6,10), this.Name.slice(0,2)-1, this.Name.slice(3,5) );
this.EndDate = new Date( this.Name.slice(13+6,13+10), this.Name.slice(13+0,13+2)-1, this.Name.slice(13+3,13+5) );
}
BlogArchiveEntry.prototype.Compare = function( rhs ){
if ( this.StartDate == rhs.StartDate )
return 0;
else if ( this.StartDate > rhs.StartDate )
return 1;
else
return -1;
}
BlogArchiveEntry.prototype.MakeLink_UKShort = function(){
var newName = this.StartDate.getDate()+"/"+(this.StartDate.getMonth()+1)+"/"+this.StartDate.getFullYear();
var outString = "";
if ( -1 != location.href.indexOf( this.Link ) ){
// No Link, this is our page!
outString = "" + newName + "";
} else {
// Link
outString = "" +
newName + "";
}
return outString;
}
BlogArchiveEntry.prototype.MakeLink_Normal = function(){
var outString = "";
if ( -1 != location.href.indexOf( this.Link ) ) {
// No Link, this is our page!
outString = this.Name;
} else {
// Link
outString = "" +
this.Name + "";
}
return outString;
}
// Short/Long listing selection
function ShowAll(){
var cookie = new obiCookie( "LimitArchive", 365 );
cookie.SetCookie( 0 );
location.href = location.href;
}
function ShowSubset( HowMany ){
var cookie = new obiCookie( "LimitArchive", 365 );
cookie.SetCookie( HowMany );
location.href = location.href;
}
// Locate URL in list of archives
function FindIdx( myURL ){
for ( var n=0; n" + AnchorText + "";
}
function MakeNextArchiveLink( myURL, AnchorText )
{
var idx;
if ( -1 == ( idx = FindIdx( myURL )) ) return null;
if ( (BlogInfo.length-1) == idx ) return null;
if (( null == AnchorText ) || ( "" == AnchorText ))
return BlogInfo[idx+1].MakeLink_UKShort();
else
return "" + AnchorText + "";
}
function MakeFirstArchiveLink( AnchorText )
{
if (( null == AnchorText ) || ( "" == AnchorText ))
return BlogInfo[0].MakeLink_UKShort();
else
return "" + AnchorText + "";
}
function WriteArchiveSection()
{
document.write( "" );
var isIndexPage = ( -1 != location.href.indexOf( "index.html" ) ); // todo: fix this test
var isArchivePage = ( -1 != location.href.indexOf( "blogarc" ) );
var thisIndex = FindIdx( location.href );
// Show Link for Home Page, if this is an archive Page
if ( !isIndexPage )
document.write( "- Current Posts
" );
// Next/Previous Links
var navlink="";
var wrotelink=false;
if ( navlink = MakeNextArchiveLink( location.href, "Previous Week" )){
document.write( "- " + navlink + "
" );
wrotelink=true;
}
if ( navlink = MakePreviousArchiveLink( location.href, "Following Week" )){
document.write( "- " + navlink + "
" );
wrotelink=true;
}
if ( true == wrotelink ) document.write( "
" );
// Work out extents of listing
var startindex = 0;
var limit = 0;
var limitArchiveCookie = new obiCookie( "LimitArchive", 365 );
if ( null == limitArchiveCookie.GetCookie() )
limitArchiveCookie.SetCookie( defaultlimit );
limit = Number(limitArchiveCookie.GetValue());
if ( 0 != limit ){ // Showing a subset around the current archive file
if ( -1 == thisIndex )
startindex = 0; // but this is not an archive page, so don't!
else
startindex = Math.round( thisIndex - (limit/2) );
limit += startindex;
}
else // Showing whole lisiting
limit = BlogInfo.length;
// Clamp selected region to ends
if ( startindex < 0 ){
limit -= startindex;
startindex = 0;
}
if ( limit > BlogInfo.length ){
startindex -= (limit-BlogInfo.length);
limit = BlogInfo.length;
}
// The Archives
for ( var n=startindex; n" + BlogInfo[n].MakeLink_UKShort()+"" );
}
// Archive Length Options
if ( 0 == limitArchiveCookie.GetCookie() )
document.write( "- [Show Less]
" );
else
document.write( "- [Show All]
" );
document.write( "
" );
}
function WriteArchiveBottom()
{
// Next/Previous Links
var navlink="";
var wrotelink=false;
if ( navlink = MakeNextArchiveLink( location.href, "[<< Previous Week]" ))
{
document.write( navlink );
wrotelink=true;
}
if ( navlink = MakePreviousArchiveLink( location.href, "[Following Week >>]" ))
{
document.write( (wrotelink?" ":"") + navlink );
wrotelink=true;
}
if ( !wrotelink )
{
document.write( MakeFirstArchiveLink( "[<< Archives]" ) );
}
}
// (c)2002 A J Buchanan. Blogger populated data structure
var count=0;
var BlogInfo = new Array();
BlogInfo[count++] = new BlogArchiveEntry( "<$BlogArchiveLink$>" , "<$BlogArchiveName$>" );
// Other Data
var defaultlimit = 5;
// Limited Processing - Need list sorted
function bi_comp( a, b ){
return -a.Compare( b );
}
BlogInfo.sort( bi_comp );