Skip to content

Commit

Permalink
example of embedding JavaScript in Velocity format
Browse files Browse the repository at this point in the history
  • Loading branch information
barrington committed Aug 13, 2010
1 parent 6bbfd91 commit ec54719
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions UsingJavaScriptInVelocityFormats/filter-by-expert-area.vm
@@ -0,0 +1,58 @@
#*
This format generates a drop-menu which, upon selection, will jump to a pre-defined Cascade page aggregating
articles based on the selected expert area. The menu itself will be generated by a Content Type index block, referencing
all pages of type 'ArticlesByExpertArea.' Each of these page will have a dynamic-metadata value named 'expert-area' specifying
the exact expert area to aggregate. It is this value which will be displayed in the "Browse by Expert Area" drop-menu generated
in this format.
*#

## use a macro to set the selected expert area
#macro ( setExpertArea $asset )

## reset to baseline
#set ( $expertArea = "NONE" )
## use $_XPathTool to extract the specified expert-area value from the given $asset
#set ( $expertArea = $_XPathTool.selectSingleNode($asset,"dynamic-metadata[name = 'expert-area']/value").text )

#end

## baseline
#set ( $expertArea = "NONE" )

## get a list of all "Expert Area" index pages (i.e. all pages of Content Type 'ArticlesByExpertArea')
#set ( $expertIndexes = $_XPathTool.selectNodes(${contentRoot},"//system-page[dynamic-metadata[name = 'expert-area']]") )

## sort the results alphabetically by 'expert-area'
$_SortTool.addSortCriterion("dynamic-metadata[name = 'expert-area']/value", "", "text", "ascending", "")
$_SortTool.sort($expertIndexes)

## use JavaScript function to jump to specified aggregate page
<script language="JavaScript">

function browseExpertise(menu)
{
var gotoURL = menu.options[menu.selectedIndex].value;
if (gotoURL != "NONE")
{
top.location.href = gotoURL;
}
}

</script>

## output menu in an <h4>
<h4>Expert Area:

<select onChange="browseExpertise(this);">
<option value="NONE" selected="true">Browse by Expert Area...</option>

## loop through all 'ArticleByExpertArea' pages & output their respective 'expert-areas' in the "Browse by..." menu
#foreach ( $expertIndex in $expertIndexes )
#set ( $url = $expertIndex.getChild("path").text )
## execute the macro to set the $expertArea variable
#setExpertArea ( $expertIndex )
<option value="[system-asset]${url}[/system-asset]"><a href="${url}" target="_parent" title="${expertArea}">${expertArea}</a></option>
#end

</select>
</h4>

0 comments on commit ec54719

Please sign in to comment.