Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

updates for navigator

  • Loading branch information...
commit f5c43e014eee45b973cd540b9567f44fe34dd12c 1 parent 5892f36
@robrobbins robrobbins authored
Showing with 19 additions and 60 deletions.
  1. +19 −14 extras/navigator/navigator.js
  2. +0 −46 extras/template/README.md
View
33 extras/navigator/navigator.js
@@ -130,7 +130,7 @@ sudo.Navigator.prototype.setData = function setData() {
// Gather the necessary information about the current environment and
// bind to either (push|pop)state or hashchange.
// Also, if given an imcorrect URL for the current environment (hashchange
-// vs pushState) normalize it and set accordingly.
+// vs pushState) normalize it and set accordingly (or don't).
//
// `returns` {object} `this`
sudo.Navigator.prototype.start = function start() {
@@ -152,26 +152,31 @@ sudo.Navigator.prototype.start = function start() {
} else if (this.isHashChange) {
$(window).on('hashchange', this.handleChange.bind(this));
} else return;
- // Does the current URL need to changed? (hashchange vs popstate)
atRoot = window.location.pathname.replace(/[^\/]$/, '$&/') === this.data['root'];
- // somehow a pushstate URL got here (and here is hashchange)
- if(this.isHashChange && !atRoot) {
- window.location.replace(this.data['root'] + window.location.search + '#' +
- this.data.fragment);
- // return early as browser will redirect
- return true;
- // the converse of the above
- } else if(this.isPushState && atRoot && window.location.hash) {
- tmp = this.getHash().replace(this.leadingStripper, '');
- window.history.replaceState({}, document.title, this.data['root'] +
- tmp + window.location.search);
+ // somehow a URL got here not in my 'format', unless explicitly told not too, correct this
+ if(!this.data.stay) {
+ if(this.isHashChange && !atRoot) {
+ window.location.replace(this.data['root'] + window.location.search + '#' +
+ this.data.fragment);
+ // return early as browser will redirect
+ return true;
+ // the converse of the above
+ } else if(this.isPushState && atRoot && window.location.hash) {
+ tmp = this.getHash().replace(this.leadingStripper, '');
+ window.history.replaceState({}, document.title, this.data['root'] +
+ tmp + window.location.search);
+ }
}
// TODO provide option to `go` from inital `start` state?
return this;
};
-// Is a passed in fragment different from the currently set one?
+// ###urlChanged
+// Is a passed in fragment different from the one currently set at `this.get('fragment')`?
+// If so set the fragment to the passed fragment passed in (as well as any 'query' data), else
+// simply return false
//
// `param` {String} `fragment`
+// `returns` {bool}
sudo.Navigator.prototype.urlChanged = function urlChanged(fragment) {
var current = this.getFragment(fragment);
// nothing has changed
View
46 extras/template/README.md
@@ -1,46 +0,0 @@
- # Sudo Micro Templating
-
- This implementaion piggyback's on J.Resig's initial micro templating post
- right along with all the others (Underscore etc...)
-
-## Usage
-
-An example reusable template:
-
- var tmpl = '<ul> \
- {{ for (var i = 0; i < knights.length; i++) { }} \
- {{ var knight = knights[i]; }} \
- <li> \
- <em>{{= knight.name }}</em>. favorite color: {{= knight.favoriteColor }} \
- </li> \
- {{ } }} \
- </ul>';
-
-As opposed to others, sudo micro templating requires that you use a `scope`
-object with your template (thus avoiding the use of `with`), this is reflected in the fact that the above for loop
-iterates over `knights.length`. This mechanism is achieved by passing
-at least 2 `arguments` to the `_.template` method. For example, to retain a `compiled` version of your template
-function you would do this (note the second arg):
-
- var compiled = _.template(tmpl, 'knights');
-
-This returns a function that can be called multiple times with data structures looking like this:
-
- var data = [{
- "name": "Lancelot",
- "favoriteColor": "blue"
- }, {
- "name": "Galahad",
- "favoriteColor": "unsure"
- }];
-
-This Array will then be available in to the template as `knights` (your scope arg) when passed in
-to the `compiled` function:
-
- compiled(data);
-
-### The Source
-
-Can be useful:
-
- compiled.source
Please sign in to comment.
Something went wrong with that request. Please try again.