Published in: ASP
URL: http://www.aspemporium.com/aspapps_src.aspx?eid=36
<%@ Language = VBScript%> <% With Response .Buffer=true .Expires=0 .Clear End With %> <HTML> <BODY> <H3>BreadCrumbTrail Object</H3> It turns out that the most requested example also has the most problems, in terms of being easy to customize, that is. Well, that was then and this is now! The new bread crumb trail is a fully featured VBScript Class! Now anyone can customize a dynamic navigation menu by simply setting properties and then calling a method. In seconds you can configure the class and then include the file into any ASP page and voila: an instant navigation menu. The best part is, customization no longer requires you to "get your hands dirty" modifying the breadcrumbtrail procedure. Be sure to view the source code for properties and methods and more detailed information about this new version. This is a 110% improvement, people. <BR> <BR> <% '''''''''''''''''''''''''''''' ' CLASS CODE '''''''''''''''''''''''''''''' Class BreadCrumbTrail '################################# '# BreadCrumbTrail Object # '# Version: 2.0 # '# http://www.aspEmporium.com/ # '# ####################################### '# # '# Summary: # '# - Creates a customized, dynamic navigation menu for any website. # '# - Features newly redesigned class structure to enable better # '# programmer interaction with the BreadCrumbTrail system through # '# the use of customizable properties. # '# # '# # '# Properties: # '# All properties are OPTIONAL and have default values. # '# These properties only affect the display of the nav menu. # '# +----------------+----------------+-------------------------------+ # '# | PROPERTY | DATA TYPE | INFORMATION | # '# +----------------+----------------+-------------------------------+ # '# +----------------+----------------+-------------------------------+ # '# | TrailSeparator | STRING | String indicating what to | # '# | | | separate directories with | # '# | | | in the display. | # '# | | | Defaults to "/" | # '# +----------------+----------------+-------------------------------+ # '# | ShowFileName | BOOLEAN | Boolean indicating whether or | # '# | | | not to show the name of the | # '# | | | current page being accessed. | # '# | | | Defaults to True | # '# +----------------+----------------+-------------------------------+ # '# | SiteName | STRING | String representing the root's| # '# | | | link in the breadcrumbtrail | # '# | | | display. | # '# | | | Defaults to "http://" + host | # '# +----------------+----------------+-------------------------------+ # '# | PathURLs | VARIANT (array)| Array of virtual paths. | # '# +----------------+----------------+-------------------------------+ # '# | PathRealNames | VARIANT (array)| Array of display names for the| # '# | | | paths in the PathURLs property| # '# +----------------+----------------+-------------------------------+ # '# # '# # '# Methods: # '# There is only one method and must be called to display the menu. # '# +----------------+----------------+-------------------------------+ # '# | METHOD | DATA TYPE | INFORMATION | # '# +----------------+----------------+-------------------------------+ # '# +----------------+----------------+-------------------------------+ # '# | DisplayTrail | VOID | Displays the trail using | # '# | | | Response.Write method. | # '# | | | This is a required method | # '# | | | and must be called after | # '# | | | zero or more properties have | # '# | | | been set. | # '# +----------------+----------------+-------------------------------+ # '# # '# # '# Version Information: # '# Version 1.0 - released August, 2000 # '# - Initial release of the simple dynamic navigation menu as a # '# function called BreadCrumbTrail. Customization required a # '# developer to modify the function significantly by hand. # '# # '# Version 2.0 - release January, 2001 # '# - New class structure with easy to use properties and methods. # '# - Major improvements made to the ease of customization by # '# adding user customizable properties. The old BreadCrumbTrail # '# function from version 1.0 was basically re-used as the # '# major private procedure of the class. # '# # '# # '# Usage: # '# sample ASP code: # '# # '# Set a = New BreadCrumbTrail # '# With a # '# .TrailSeparator = "/" # '# .ShowFileName = True # '# .SiteName = "Home" # '# .PathURLs = Array( _ # '# "/path1/", _ # '# "/path2/", _ # '# "/path3/", _ # '# "/path4/" _ # '# ) # '# .PathRealNames = Array( _ # '# "The First Path", _ # '# "The Second Path", _ # '# "The Third Path", _ # '# "The Fourth Path" _ # '# ) # '# .DisplayTrail # '# End With # '# Set a = Nothing # '# # '# The best way to understand the PathURLs and PathRealNames # '# properties is to think of them as two relative arrays. # '# The PathURLs array is a list of any virtual paths that # '# you would like to rename with different names (the # '# BreadCrumbTrail will automatically give each folder or file name # '# it's exact name by default). The PathRealNames array is a list # '# of new names for the directory paths specified in PathURLs. This # '# means that the first element of PathURLs would be replaced by the # '# first element of PathRealNames in the trail display. # '# # '# Include the class into any file you want to call the trail. # '# # '####################################################################### 'public class variables can be set 'by users, just like properties Public TrailSeparator, ShowFileName Public SiteName, PathURLs, PathRealNames Private Sub Class_Initialize() 'default property values TrailSeparator = "/" ShowFileName = True SiteName = "http://" & _ Request.ServerVariables( "HTTP_HOST" ) PathURLs = "" PathRealNames = "" End Sub Public Sub DisplayTrail() Response.Write(BreadCrumbTrail_Old) End Sub Private Function BreadCrumbTrail_Old() 'This function is almost untouched from 'the first version. Most of the changes 'were just to incorporate the property 'settings and convert their values to 'work with the old function. Dim Separator, ShowLastFlag, a Dim strCurrentPath, strCurrentHost Dim i, strOut, j, strLink, arrEachPath Dim sCompareLink, k, bFixed, bFixed2 'get trailseparator property Separator = TrailSeparator 'get showfilename property a = not showFileName a = cint(a) a = abs(a) ShowLastFlag = a 'get sitename property strCurrentHost = SiteName strCurrentPath = _ Request.ServerVariables( "PATH_INFO" ) ' break the path down arrEachPath = Split( strCurrentPath, "/" ) ' create the home (root) link strOut = strOut & "<A HREF=""/"">" strOut = strOut & Replace( strCurrentHost, _ " ", " " ) strOut = strOut & "</A>" & Separator ' loop through the path array ' ignore the first element(0) and start at 1 For i = 1 to UBound( arrEachPath ) - ShowLastFlag j = 0 : strLink = "" : sCompareLink = "" bFixed = false : bFixed2 = false do until j > i ' create a mini-loop for each link ' in the array so we can build the ' path to each directory in the path. ' generate the link string for each ' entry in the array and don't forget to ' urlencode spaces... strLink = strLink & _ Replace( arrEachPath( j ), _ " ", "%20" ) & "/" sCompareLink = sCompareLink & _ arrEachPath( j ) & "/" j = j + 1 loop If i = UBound( arrEachPath ) Then sCompareLink = _ left(sCompareLink, _ Len(sCompareLink) - 1) Else ' generate the html to surround ' the link and name it the same ' as the original directory strOut = strOut & _ "<A HREF=""" & strLink & """>" End If if isarray(pathURLs) and _ isarray(PathRealNames) then for k = 0 to ubound(pathURLs) if lcase(trim(pathURLs(k))) = _ lcase(trim(sCompareLink)) then strOut = strOut & _ Replace( PathRealNames(k), _ " ", " " ) bFixed = true exit for end if next else bFixed = false end if if not bFixed then strOut = strOut & _ Replace( arrEachPath( i ), _ " ", " " ) end if If i <> UBound( arrEachPath ) Then strOut = strOut & _ "</A>" & Separator End If Next If Not ShowFileName Then strOut = _ Left(strOut, Len(strOut) - Len(TrailSeparator)) BreadCrumbTrail_Old = strOut End Function End Class %> <% '''''''''''''''''''''''''''''' ' RUNTIME CODE '''''''''''''''''''''''''''''' response.write "<BIG>Sample Usage 1:</BIG><BR>" response.write "<B>bread crumb trail with default property settings:</B><BR>" Dim a Set a = New BreadCrumbTrail a.DisplayTrail Set a = Nothing response.write "<BR><BR>" response.write "<BIG>Sample Usage 2:</BIG><BR>" response.write "<B>bread crumb trail with all custom property settings:</B><BR>" Set a = New BreadCrumbTrail With a .TrailSeparator = " > " .ShowFileName = True .SiteName = "Home" .PathURLs = Array( _ "/aspapps.asp" _ ) .PathRealNames = Array( _ "Classic ASP Apps" _ ) .DisplayTrail End With Set a = Nothing response.write "<BR><BR>" response.write "<BIG>Sample Usage 3:</BIG><BR>" response.write "<B>bread crumb trail with some different property settings:</B><BR>" Set a = New BreadCrumbTrail With a .TrailSeparator = " | " .ShowFileName = False .SiteName = "My Home Page" .DisplayTrail End With Set a = Nothing %> </BODY> </HTML>
You need to login to post a comment.
