Skip to content
Snippets Groups Projects
url-title.vtl 1.23 KiB
Newer Older
Brad's avatar
Brad committed
#set($cusFieldVarName="title")
<script>
	function updateDisplayURLTitle(){
		// get the title entered by the user
		var plainTitle = dojo.byId("$cusFieldVarName");	
		
		if(plainTitle == undefined || plainTitle.value.length ==0){
			dojo.byId("displayURLTitle").innerHTML = "";
			dojo.byId("urlTitle").value="";
			return;
		}
		
		// make a friendly url
		var urlTitle = plainTitle.value.toLowerCase();
		urlTitle= urlTitle.replace(/^\s+|\s+$/g,"");
		urlTitle = urlTitle.replace(/[^a-zA-Z 0-9]+/g,' ');	
		urlTitle = urlTitle.replace(/\s/g, "-");
		while(urlTitle.indexOf("--") > -1){
			urlTitle = urlTitle.replace("--",'-');	
		}
		while(urlTitle.lastIndexOf("-") == urlTitle.length -1 ){
			urlTitle=urlTitle.substring(0,urlTitle.length -1);
		}
		// set the values of the display place holder and the custom field
		// the   is to hold the div open
		dojo.byId("displayURLTitle").innerHTML = urlTitle;
		dojo.byId("urlTitle").value=urlTitle;
	}


	// attach this the text1 field onchange
	dojo.addOnLoad(function(){
			dojo.connect(dojo.byId("$cusFieldVarName"), "onchange", null, "updateDisplayURLTitle");
		}
	);
	// populate the field on load
	dojo.addOnLoad(updateDisplayURLTitle);

</script>
<div id="displayURLTitle" style="height:20px"> </div>