2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
18
* This script, when included in a html file, builds a neat breadcrumb trail
19
* based on its url. That is, if it doesn't contains bugs (I'm relatively
23
* <script type="text/javascript" language="JavaScript" src="breadcrumbs.js"></script>
27
* IE 5 on Mac doesn't know Array.push.
29
* Implement it - courtesy to fritz.
31
var abc = new Array();
33
Array.prototype.push = function(what){this[this.length]=what}
36
/* ========================================================================
38
======================================================================== */
41
* Two-dimensional array containing extra crumbs to place at the front of
42
* the trail. Specify first the name of the crumb, then the URI that belongs
43
* to it. You'll need to modify this for every domain or subdomain where
44
* you use this script (you can leave it as an empty array if you wish)
46
var PREPREND_CRUMBS = new Array();
48
var link1 = "@skinconfig.trail.link1.name@";
49
var link2 = "@skinconfig.trail.link2.name@";
50
var link3 = "@skinconfig.trail.link3.name@";
52
var href1 = "@skinconfig.trail.link1.href@";
53
var href2 = "@skinconfig.trail.link2.href@";
54
var href3 = "@skinconfig.trail.link3.href@";
56
if(!(link1=="")&&!link1.indexOf( "@" ) == 0){
57
PREPREND_CRUMBS.push( new Array( link1, href1 ) );
59
if(!(link2=="")&&!link2.indexOf( "@" ) == 0){
60
PREPREND_CRUMBS.push( new Array( link2, href2 ) );
62
if(!(link3=="")&&!link3.indexOf( "@" ) == 0){
63
PREPREND_CRUMBS.push( new Array( link3, href3 ) );
67
* String to include between crumbs:
69
var DISPLAY_SEPARATOR = " > ";
71
* String to include at the beginning of the trail
73
var DISPLAY_PREPREND = " > ";
75
* String to include at the end of the trail
77
var DISPLAY_POSTPREND = "";
80
* CSS Class to use for a single crumb:
82
var CSS_CLASS_CRUMB = "breadcrumb";
85
* CSS Class to use for the complete trail:
87
var CSS_CLASS_TRAIL = "breadcrumbTrail";
90
* CSS Class to use for crumb separator:
92
var CSS_CLASS_SEPARATOR = "crumbSeparator";
95
* Array of strings containing common file extensions. We use this to
96
* determine what part of the url to ignore (if it contains one of the
97
* string specified here, we ignore it).
99
var FILE_EXTENSIONS = new Array( ".html", ".htm", ".jsp", ".php", ".php3", ".php4" );
102
* String that separates parts of the breadcrumb trail from each other.
103
* When this is no longer a slash, I'm sure I'll be old and grey.
105
var PATH_SEPARATOR = "/";
107
/* ========================================================================
109
======================================================================== */
111
* Capitalize first letter of the provided string and return the modified
114
function sentenceCase( string )
116
//var lower = string.toLowerCase();
117
//return lower.substr(0,1).toUpperCase() + lower.substr(1);
121
* Returns an array containing the names of all the directories in the
122
* current document URL
124
function getDirectoriesInURL()
126
var trail = document.location.pathname.split( PATH_SEPARATOR );
128
// check whether last section is a file or a directory
129
var lastcrumb = trail[trail.length-1];
130
for( var i = 0; i < FILE_EXTENSIONS.length; i++ )
132
if( lastcrumb.indexOf( FILE_EXTENSIONS[i] ) )
134
// it is, remove it and send results
135
return trail.slice( 1, trail.length-1 );
139
// it's not; send the trail unmodified
140
return trail.slice( 1, trail.length );
143
/* ========================================================================
144
BREADCRUMB FUNCTIONALITY
145
======================================================================== */
147
* Return a two-dimensional array describing the breadcrumbs based on the
148
* array of directories passed in.
150
function getBreadcrumbs( dirs )
155
// the array we will return
156
var crumbs = new Array();
160
for( var i = 0; i < dirs.length; i++ )
162
prefix += dirs[i] + postfix;
163
crumbs.push( new Array( dirs[i], prefix ) );
167
// preprend the PREPREND_CRUMBS
168
if(PREPREND_CRUMBS.length > 0 )
170
return PREPREND_CRUMBS.concat( crumbs );
177
* Return a string containing a simple text breadcrumb trail based on the
178
* two-dimensional array passed in.
180
function getCrumbTrail( crumbs )
182
var xhtml = DISPLAY_PREPREND;
184
for( var i = 0; i < crumbs.length; i++ )
186
xhtml += '<a href="' + crumbs[i][1] + '" >';
187
xhtml += unescape( crumbs[i][0] ) + '</a>';
188
if( i != (crumbs.length-1) )
190
xhtml += DISPLAY_SEPARATOR;
194
xhtml += DISPLAY_POSTPREND;
200
* Return a string containing an XHTML breadcrumb trail based on the
201
* two-dimensional array passed in.
203
function getCrumbTrailXHTML( crumbs )
205
var xhtml = '<span class="' + CSS_CLASS_TRAIL + '">';
206
xhtml += DISPLAY_PREPREND;
208
for( var i = 0; i < crumbs.length; i++ )
210
xhtml += '<a href="' + crumbs[i][1] + '" class="' + CSS_CLASS_CRUMB + '">';
211
xhtml += unescape( crumbs[i][0] ) + '</a>';
212
if( i != (crumbs.length-1) )
214
xhtml += '<span class="' + CSS_CLASS_SEPARATOR + '">' + DISPLAY_SEPARATOR + '</span>';
218
xhtml += DISPLAY_POSTPREND;
224
/* ========================================================================
225
PRINT BREADCRUMB TRAIL
226
======================================================================== */
228
// check if we're local; if so, only print the PREPREND_CRUMBS
229
if( document.location.href.toLowerCase().indexOf( "http://" ) == -1 )
231
document.write( getCrumbTrail( getBreadcrumbs() ) );
235
document.write( getCrumbTrail( getBreadcrumbs( getDirectoriesInURL() ) ) );