3
============================================================================
4
The Apache Software License, Version 1.1
5
============================================================================
7
Copyright (C) 2002-2003 The Apache Software Foundation. All rights reserved.
9
Redistribution and use in source and binary forms, with or without modifica-
10
tion, are permitted provided that the following conditions are met:
12
1. Redistributions of source code must retain the above copyright notice,
13
this list of conditions and the following disclaimer.
15
2. Redistributions in binary form must reproduce the above copyright notice,
16
this list of conditions and the following disclaimer in the documentation
17
and/or other materials provided with the distribution.
19
3. The end-user documentation included with the redistribution, if any, must
20
include the following acknowledgment: "This product includes software
21
developed by the Apache Software Foundation (http://www.apache.org/)."
22
Alternately, this acknowledgment may appear in the software itself, if
23
and wherever such third-party acknowledgments normally appear.
25
4. The names "Apache Forrest" and "Apache Software Foundation"
26
must not be used to endorse or promote products derived from this software
27
without prior written permission. For written permission, please contact
30
5. Products derived from this software may not be called "Apache", nor may
31
"Apache" appear in their name, without prior written permission of the
32
Apache Software Foundation.
34
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
35
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
36
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
37
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
38
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
39
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
40
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
41
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
42
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
43
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45
This software consists of voluntary contributions made by many individuals
46
on behalf of the Apache Software Foundation. For more information on the
47
Apache Software Foundation, please see <http://www.apache.org/>.
52
* This script, when included in a html file, builds a neat breadcrumb trail
53
* based on its url. That is, if it doesn't contains bugs (I'm relatively
57
* <script type="text/javascript" language="JavaScript" src="breadcrumbs.js"></script>
59
*@author <a href="mailto:leosimons@apache.org">Leo Simons</a> (main author)
60
*@author <a href="mailto:nicolaken@apache.org">Nicola Ken Barozzi</a> (integration in skin)
61
*@created July 12, 2002
66
* IE 5 on Mac doesn't know Array.push.
68
* Implement it - courtesy to fritz.
70
var abc = new Array();
72
Array.prototype.push = function(what){this[this.length]=what}
75
/* ========================================================================
77
======================================================================== */
80
* Two-dimensional array containing extra crumbs to place at the front of
81
* the trail. Specify first the name of the crumb, then the URI that belongs
82
* to it. You'll need to modify this for every domain or subdomain where
83
* you use this script (you can leave it as an empty array if you wish)
85
var PREPREND_CRUMBS = new Array();
87
PREPREND_CRUMBS.push( new Array( "", "" ) );
90
PREPREND_CRUMBS.push( new Array( "", "" ) );
93
PREPREND_CRUMBS.push( new Array( "", "" ) );
97
* String to include between crumbs:
99
var DISPLAY_SEPARATOR = " > ";
101
* String to include at the beginning of the trail
103
var DISPLAY_PREPREND = "";
105
* String to include at the end of the trail
107
var DISPLAY_POSTPREND = "";
110
* CSS Class to use for a single crumb:
112
var CSS_CLASS_CRUMB = "breadcrumb";
115
* CSS Class to use for the complete trail:
117
var CSS_CLASS_TRAIL = "breadcrumbTrail";
120
* CSS Class to use for crumb separator:
122
var CSS_CLASS_SEPARATOR = "crumbSeparator";
125
* Array of strings containing common file extensions. We use this to
126
* determine what part of the url to ignore (if it contains one of the
127
* string specified here, we ignore it).
129
var FILE_EXTENSIONS = new Array( ".html", ".htm", ".jsp", ".php", ".php3", ".php4" );
132
* String that separates parts of the breadcrumb trail from each other.
133
* When this is no longer a slash, I'm sure I'll be old and grey.
135
var PATH_SEPARATOR = "/";
137
/* ========================================================================
139
======================================================================== */
141
* Capitalize first letter of the provided string and return the modified
144
function sentenceCase( string )
146
//var lower = string.toLowerCase();
147
//return lower.substr(0,1).toUpperCase() + lower.substr(1);
151
* Returns an array containing the names of all the directories in the
152
* current document URL
154
function getDirectoriesInURL()
156
var trail = document.location.pathname.split( PATH_SEPARATOR );
158
// check whether last section is a file or a directory
159
var lastcrumb = trail[trail.length-1];
160
for( var i = 0; i < FILE_EXTENSIONS.length; i++ )
162
if( lastcrumb.indexOf( FILE_EXTENSIONS[i] ) )
164
// it is, remove it and send results
165
return trail.slice( 1, trail.length-1 );
169
// it's not; send the trail unmodified
170
return trail.slice( 1, trail.length );
173
/* ========================================================================
174
BREADCRUMB FUNCTIONALITY
175
======================================================================== */
177
* Return a two-dimensional array describing the breadcrumbs based on the
178
* array of directories passed in.
180
function getBreadcrumbs( dirs )
185
// the array we will return
186
var crumbs = new Array();
190
for( var i = 0; i < dirs.length; i++ )
192
prefix += dirs[i] + postfix;
193
crumbs.push( new Array( dirs[i], prefix ) );
197
// preprend the PREPREND_CRUMBS
198
if(PREPREND_CRUMBS.length > 0 )
200
return PREPREND_CRUMBS.concat( crumbs );
207
* Return a string containing a simple text breadcrumb trail based on the
208
* two-dimensional array passed in.
210
function getCrumbTrail( crumbs )
212
var xhtml = DISPLAY_PREPREND;
214
for( var i = 0; i < crumbs.length; i++ )
216
xhtml += '<a href="' + crumbs[i][1] + '" >';
217
xhtml += unescape( crumbs[i][0] ) + '</a>';
218
if( i != (crumbs.length-1) )
220
xhtml += DISPLAY_SEPARATOR;
224
xhtml += DISPLAY_POSTPREND;
230
* Return a string containing an XHTML breadcrumb trail based on the
231
* two-dimensional array passed in.
233
function getCrumbTrailXHTML( crumbs )
235
var xhtml = '<span class="' + CSS_CLASS_TRAIL + '">';
236
xhtml += DISPLAY_PREPREND;
238
for( var i = 0; i < crumbs.length; i++ )
240
xhtml += '<a href="' + crumbs[i][1] + '" class="' + CSS_CLASS_CRUMB + '">';
241
xhtml += unescape( crumbs[i][0] ) + '</a>';
242
if( i != (crumbs.length-1) )
244
xhtml += '<span class="' + CSS_CLASS_SEPARATOR + '">' + DISPLAY_SEPARATOR + '</span>';
248
xhtml += DISPLAY_POSTPREND;
254
/* ========================================================================
255
PRINT BREADCRUMB TRAIL
256
======================================================================== */
258
// check if we're local; if so, only print the PREPREND_CRUMBS
259
if( document.location.href.toLowerCase().indexOf( "http://" ) == -1 )
261
document.write( getCrumbTrail( getBreadcrumbs() ) );
265
document.write( getCrumbTrail( getBreadcrumbs( getDirectoriesInURL() ) ) );