Download

Concepts

Example

Documentation

Plugins

How to

Contribute

Links

UrlManager

What is this ?

The UrlManager is the class that will help you do deal with URL. That means everything after the anchor (#). In fact it is an abstraction class that plays in the background with RSH (Really Simple History). This is a singleton class. So you will use UrlManager.getInstance() to call it.

How do I change the URL ?

This is pretty simple. You just have to call UrlManager.getInstance().setUrl(myUrl). But don't forget to set useUrl in the framework configuration file to true and to include the RSH script in your page. Example :

In your HTML page :
<head>
	...
	<script type="text/javascript" src="http://localhost/js/WZFwk/libs/prototype/1.6.0.3.js"></script>
	<script type="text/javascript" src="http://localhost/js/WZFwk/libs/prototype/extends.js"></script>

	<script type="text/javascript" src="http://localhost/js/WZFwk/libs/rsh/rsh.js"></script>

	<script type="text/javascript" src="http://localhost/js/WZFwk/compress/compress.js"></script>
	<script type="text/javascript">
		var initializer = new Initializer();
		initializer.init("http://localhost/js/application/conf.xml");
	</script>
	...
</head>

In your Framework configuration file :
<?xml version="1.0" encoding="utf-8"?>
<items>
	<framework>
		<item version="1.0.7" />
		<url>
			...
			<item useUrl="true" />
			...
		</url>
		...
	</framework>
	...
</items>	

And finally in one of your ModelHelper :
var ModuleModel = Class.create(ModelHelper, {
	...
	changeUrl: function() {
		UrlManager.getInstance().setUrl('myUrl'); // --> will add at the end of the current URL #myUrl
	}
});		

How do I know that the URL changed in my ModelHelpers ?

If you remember what we saw in the modelHelper section, you probably remember a method called urlChangeHandler(). This is the method that will inform you that the URL changed. Example that complete the example above :

In an other ModelHelper :
var Module1Model = Class.create(ModelHelper, {
	...
	urlChangeHandler: function(location, data, from) {
		alert(location); // --> myUrl
		alert(data); // --> undefined
		alert(from); // --> fromFramework
	}
});		

If when the user load the page, an anchor is already on place, the same method will be called except the from argument will have the value fromInit.

If the user change the anchor by itself, the argument will be equal to fromUser.

Take also a look to the init method of your model helper.

UrlManager methods

setUrl(newLocation, historyData)

As we just see, the setUrl method helps you to change the URL. It takes two parameters. First the new URL newLocation. And second some data you wish to store in complement of the URL. When you set the URL, all modelHelper that listen to the url will be informed of the modification using the urlChangeHandler() method.

UrlManager.getInstance().setUrl('myUrl'); // --> will add at the end of the current URL #myUrl
UrlManager.getInstance().setUrl('myUrl', {data:42, otherData: [1,2,3]}); 	// --> will add at the end of the current URL #myUrl 
										// and store the second parameter.

getCurrentLocation()

Will return the currentLocation, ie what is after the anchor sign.

getCurrentStorage()

Will return the data you stored with the current location.

getIsUsable()

Will return a boolean that will tell you if you set useUrl to true or false in the framework configuration file.