Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

router improvements

  • Loading branch information...
commit 35ddbadb4144014e601605e0ecdf95dbbdc3f5d2 1 parent b647718
@rhysbrettbowen authored
Showing with 19 additions and 15 deletions.
  1. +1 −0  README.md
  2. +18 −15 router.js
View
1  README.md
@@ -246,6 +246,7 @@ you can then register your object with the mediator and the messages that you ma
- schema is now an object
- mvc.Control events can now be given a priority to order them
- more tests
+- router uses HTML5 where possible and you can pass in parameters to hide the fragment
#### v0.8 ####
View
33 router.js
@@ -10,29 +10,28 @@ goog.provide('mvc.Router');
goog.require('goog.array');
goog.require('goog.events');
goog.require('goog.History');
+goog.require('goog.history.Html5History');
/**
* @constructor
+ *
+ * @param {boolean=} opt_noFragment set to true to hide fragment when using
+ * HTML5 history
+ * @param {string=} opt_blankPage url to a blank page - needed if HTML5 is not
+ * available and you don't want to show the fragment
*/
-mvc.Router = function() {
- this.checkhistorysupport();
+mvc.Router = function(opt_noFragment, opt_blankPage) {
+ this.history_ = goog.history.Html5History.isSupported()?
+ new goog.history.Html5History():
+ new goog.History(opt_noFragment, opt_blankPage);
+ if(this.history_.setUseFragment)
+ this.history_.setUseFragment(!opt_noFragment);
goog.events.listen(this.history_, goog.history.EventType.NAVIGATE,
this.onChange_, false, this);
this.history_.setEnabled(true);
this.routes_ = [];
};
-/**
-*checks if HTML5History is supported
-*/
-mvc.prototype.checkhistorysupport=function (){
- if(goog.history.Html5History.isSupported()){
- this.history_= new goog.history.Html5History();this.history_.setUseFragment(false);
-}
-else
-{
- this.history_=new goog.History();
-}
-};
+
/**
* pass through the fragment for the URL
*
@@ -51,7 +50,11 @@ mvc.Router.prototype.navigate = function(fragment) {
*/
mvc.Router.prototype.route = function(route, fn) {
if(goog.isString(route))
- route = new RegExp('^' + goog.string.regExpEscape(route).replace(/\\:\w+/g, '(\\w+)').replace(/\\\*/g, '(.*)').replace(/\\\[/g,"(").replace(/\\\]/g,")?") + '$');
+ route = new RegExp('^' + goog.string.regExpEscape(route)
+ .replace(/\\:\w+/g, '(\\w+)')
+ .replace(/\\\*/g, '(.*)')
+ .replace(/\\\[/g,"(")
+ .replace(/\\\]/g,")?") + '$');
this.routes_.push({route: route, callback: fn});
};
Please sign in to comment.
Something went wrong with that request. Please try again.