Posted By

elightbo on 09/26/08


Tagged

breadcrumb


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

sulfurito
Scooter
nelda751
higrade


ASP breadcrumb


 / Published in: ASP
 

URL: http://www.aspemporium.com/aspapps_src.aspx?eid=36

  1. <%@ Language = VBScript%>
  2. <%
  3. With Response
  4. .Buffer=true
  5. .Expires=0
  6. .Clear
  7. End With
  8. %>
  9. <HTML>
  10. <BODY>
  11.  
  12. <H3>BreadCrumbTrail Object</H3>
  13. It turns out that the most requested example also has the most
  14. problems, in terms of being easy to customize, that is. Well,
  15. that was then and this is now! The new bread crumb trail is a
  16. fully featured VBScript Class! Now anyone can customize a dynamic
  17. navigation menu by simply setting properties and then calling a
  18. method. In seconds you can configure the class and then include the
  19. file into any ASP page and voila: an instant navigation menu. The
  20. best part is, customization no longer requires you to "get your
  21. hands dirty" modifying the breadcrumbtrail procedure. Be sure to
  22. view the source code for properties and methods and more detailed
  23. information about this new version. This is a 110% improvement, people.
  24.  
  25. <BR>
  26. <BR>
  27.  
  28. <%
  29. ''''''''''''''''''''''''''''''
  30. ' CLASS CODE
  31. ''''''''''''''''''''''''''''''
  32. Class BreadCrumbTrail
  33. '#################################
  34. '# BreadCrumbTrail Object #
  35. '# Version: 2.0 #
  36. '# http://www.aspEmporium.com/ #
  37. '# #######################################
  38. '# #
  39. '# Summary: #
  40. '# - Creates a customized, dynamic navigation menu for any website. #
  41. '# - Features newly redesigned class structure to enable better #
  42. '# programmer interaction with the BreadCrumbTrail system through #
  43. '# the use of customizable properties. #
  44. '# #
  45. '# #
  46. '# Properties: #
  47. '# All properties are OPTIONAL and have default values. #
  48. '# These properties only affect the display of the nav menu. #
  49. '# +----------------+----------------+-------------------------------+ #
  50. '# | PROPERTY | DATA TYPE | INFORMATION | #
  51. '# +----------------+----------------+-------------------------------+ #
  52. '# +----------------+----------------+-------------------------------+ #
  53. '# | TrailSeparator | STRING | String indicating what to | #
  54. '# | | | separate directories with | #
  55. '# | | | in the display. | #
  56. '# | | | Defaults to "/" | #
  57. '# +----------------+----------------+-------------------------------+ #
  58. '# | ShowFileName | BOOLEAN | Boolean indicating whether or | #
  59. '# | | | not to show the name of the | #
  60. '# | | | current page being accessed. | #
  61. '# | | | Defaults to True | #
  62. '# +----------------+----------------+-------------------------------+ #
  63. '# | SiteName | STRING | String representing the root's| #
  64. '# | | | link in the breadcrumbtrail | #
  65. '# | | | display. | #
  66. '# | | | Defaults to "http://" + host | #
  67. '# +----------------+----------------+-------------------------------+ #
  68. '# | PathURLs | VARIANT (array)| Array of virtual paths. | #
  69. '# +----------------+----------------+-------------------------------+ #
  70. '# | PathRealNames | VARIANT (array)| Array of display names for the| #
  71. '# | | | paths in the PathURLs property| #
  72. '# +----------------+----------------+-------------------------------+ #
  73. '# #
  74. '# #
  75. '# Methods: #
  76. '# There is only one method and must be called to display the menu. #
  77. '# +----------------+----------------+-------------------------------+ #
  78. '# | METHOD | DATA TYPE | INFORMATION | #
  79. '# +----------------+----------------+-------------------------------+ #
  80. '# +----------------+----------------+-------------------------------+ #
  81. '# | DisplayTrail | VOID | Displays the trail using | #
  82. '# | | | Response.Write method. | #
  83. '# | | | This is a required method | #
  84. '# | | | and must be called after | #
  85. '# | | | zero or more properties have | #
  86. '# | | | been set. | #
  87. '# +----------------+----------------+-------------------------------+ #
  88. '# #
  89. '# #
  90. '# Version Information: #
  91. '# Version 1.0 - released August, 2000 #
  92. '# - Initial release of the simple dynamic navigation menu as a #
  93. '# function called BreadCrumbTrail. Customization required a #
  94. '# developer to modify the function significantly by hand. #
  95. '# #
  96. '# Version 2.0 - release January, 2001 #
  97. '# - New class structure with easy to use properties and methods. #
  98. '# - Major improvements made to the ease of customization by #
  99. '# adding user customizable properties. The old BreadCrumbTrail #
  100. '# function from version 1.0 was basically re-used as the #
  101. '# major private procedure of the class. #
  102. '# #
  103. '# #
  104. '# Usage: #
  105. '# sample ASP code: #
  106. '# #
  107. '# Set a = New BreadCrumbTrail #
  108. '# With a #
  109. '# .TrailSeparator = "/" #
  110. '# .ShowFileName = True #
  111. '# .SiteName = "Home" #
  112. '# .PathURLs = Array( _ #
  113. '# "/path1/", _ #
  114. '# "/path2/", _ #
  115. '# "/path3/", _ #
  116. '# "/path4/" _ #
  117. '# ) #
  118. '# .PathRealNames = Array( _ #
  119. '# "The First Path", _ #
  120. '# "The Second Path", _ #
  121. '# "The Third Path", _ #
  122. '# "The Fourth Path" _ #
  123. '# ) #
  124. '# .DisplayTrail #
  125. '# End With #
  126. '# Set a = Nothing #
  127. '# #
  128. '# The best way to understand the PathURLs and PathRealNames #
  129. '# properties is to think of them as two relative arrays. #
  130. '# The PathURLs array is a list of any virtual paths that #
  131. '# you would like to rename with different names (the #
  132. '# BreadCrumbTrail will automatically give each folder or file name #
  133. '# it's exact name by default). The PathRealNames array is a list #
  134. '# of new names for the directory paths specified in PathURLs. This #
  135. '# means that the first element of PathURLs would be replaced by the #
  136. '# first element of PathRealNames in the trail display. #
  137. '# #
  138. '# Include the class into any file you want to call the trail. #
  139. '# #
  140. '#######################################################################
  141.  
  142. 'public class variables can be set
  143. 'by users, just like properties
  144. Public TrailSeparator, ShowFileName
  145. Public SiteName, PathURLs, PathRealNames
  146.  
  147. Private Sub Class_Initialize()
  148. 'default property values
  149. TrailSeparator = "/"
  150. ShowFileName = True
  151. SiteName = "http://" & _
  152. Request.ServerVariables( "HTTP_HOST" )
  153. PathURLs = ""
  154. PathRealNames = ""
  155. End Sub
  156.  
  157. Public Sub DisplayTrail()
  158. Response.Write(BreadCrumbTrail_Old)
  159. End Sub
  160.  
  161. Private Function BreadCrumbTrail_Old()
  162. 'This function is almost untouched from
  163. 'the first version. Most of the changes
  164. 'were just to incorporate the property
  165. 'settings and convert their values to
  166. 'work with the old function.
  167.  
  168. Dim Separator, ShowLastFlag, a
  169. Dim strCurrentPath, strCurrentHost
  170. Dim i, strOut, j, strLink, arrEachPath
  171. Dim sCompareLink, k, bFixed, bFixed2
  172.  
  173. 'get trailseparator property
  174. Separator = TrailSeparator
  175.  
  176. 'get showfilename property
  177. a = not showFileName
  178. a = cint(a)
  179. a = abs(a)
  180. ShowLastFlag = a
  181.  
  182. 'get sitename property
  183. strCurrentHost = SiteName
  184.  
  185. strCurrentPath = _
  186. Request.ServerVariables( "PATH_INFO" )
  187.  
  188. ' break the path down
  189. arrEachPath = Split( strCurrentPath, "/" )
  190.  
  191. ' create the home (root) link
  192. strOut = strOut & "<A HREF=""/"">"
  193. strOut = strOut & Replace( strCurrentHost, _
  194. " ", "&nbsp;" )
  195. strOut = strOut & "</A>" & Separator
  196.  
  197. ' loop through the path array
  198. ' ignore the first element(0) and start at 1
  199. For i = 1 to UBound( arrEachPath ) - ShowLastFlag
  200. j = 0 : strLink = "" : sCompareLink = ""
  201. bFixed = false : bFixed2 = false
  202. do until j > i
  203. ' create a mini-loop for each link
  204. ' in the array so we can build the
  205. ' path to each directory in the path.
  206.  
  207. ' generate the link string for each
  208. ' entry in the array and don't forget to
  209. ' urlencode spaces...
  210. strLink = strLink & _
  211. Replace( arrEachPath( j ), _
  212. " ", "%20" ) & "/"
  213. sCompareLink = sCompareLink & _
  214. arrEachPath( j ) & "/"
  215. j = j + 1
  216. loop
  217. If i = UBound( arrEachPath ) Then
  218. sCompareLink = _
  219. left(sCompareLink, _
  220. Len(sCompareLink) - 1)
  221. Else
  222. ' generate the html to surround
  223. ' the link and name it the same
  224. ' as the original directory
  225. strOut = strOut & _
  226. "<A HREF=""" & strLink & """>"
  227. End If
  228. if isarray(pathURLs) and _
  229. isarray(PathRealNames) then
  230. for k = 0 to ubound(pathURLs)
  231. if lcase(trim(pathURLs(k))) = _
  232. lcase(trim(sCompareLink)) then
  233. strOut = strOut & _
  234. Replace( PathRealNames(k), _
  235. " ", "&nbsp;" )
  236. bFixed = true
  237. exit for
  238. end if
  239. next
  240. else
  241. bFixed = false
  242. end if
  243. if not bFixed then
  244. strOut = strOut & _
  245. Replace( arrEachPath( i ), _
  246. " ", "&nbsp;" )
  247. end if
  248.  
  249. If i <> UBound( arrEachPath ) Then
  250. strOut = strOut & _
  251. "</A>" & Separator
  252. End If
  253. Next
  254. If Not ShowFileName Then strOut = _
  255. Left(strOut, Len(strOut) - Len(TrailSeparator))
  256. BreadCrumbTrail_Old = strOut
  257. End Function
  258. End Class
  259.  
  260. %>
  261.  
  262.  
  263. <%
  264. ''''''''''''''''''''''''''''''
  265. ' RUNTIME CODE
  266. ''''''''''''''''''''''''''''''
  267. response.write "<BIG>Sample Usage 1:</BIG><BR>"
  268. response.write "<B>bread crumb trail with default property settings:</B><BR>"
  269.  
  270. Dim a
  271.  
  272. Set a = New BreadCrumbTrail
  273. a.DisplayTrail
  274. Set a = Nothing
  275.  
  276.  
  277.  
  278. response.write "<BR><BR>"
  279. response.write "<BIG>Sample Usage 2:</BIG><BR>"
  280. response.write "<B>bread crumb trail with all custom property settings:</B><BR>"
  281.  
  282. Set a = New BreadCrumbTrail
  283. With a
  284. .TrailSeparator = "&nbsp;&gt;&nbsp;"
  285. .ShowFileName = True
  286. .SiteName = "Home"
  287. .PathURLs = Array( _
  288. "/aspapps.asp" _
  289. )
  290. .PathRealNames = Array( _
  291. "Classic ASP Apps" _
  292. )
  293. .DisplayTrail
  294. End With
  295. Set a = Nothing
  296.  
  297.  
  298.  
  299. response.write "<BR><BR>"
  300. response.write "<BIG>Sample Usage 3:</BIG><BR>"
  301. response.write "<B>bread crumb trail with some different property settings:</B><BR>"
  302.  
  303. Set a = New BreadCrumbTrail
  304. With a
  305. .TrailSeparator = "&nbsp;|&nbsp;"
  306. .ShowFileName = False
  307. .SiteName = "My Home Page"
  308. .DisplayTrail
  309. End With
  310. Set a = Nothing
  311.  
  312.  
  313.  
  314. %>
  315.  
  316. </BODY>
  317. </HTML>

Report this snippet  

You need to login to post a comment.