Permalink
Browse files

Merge branch 'non-hash'

  • Loading branch information...
2 parents 69d75ef + 55ce926 commit 088e41ccb15ddd4379bdbfa0d06472ef41d3edb8 @quirkey quirkey committed May 1, 2011
@@ -57,8 +57,9 @@
// call the callback function if it has an access token.
this.helper("requireOAuth", function(cb) {
if (this.app.getAccessToken()) {
- if (cb)
+ if (cb) {
cb.apply(this);
+ }
} else {
this.redirect(this.app.authorize + "?state=" + escape(this.path));
return false;
@@ -96,13 +97,15 @@
// Add OAuth 2.0 access token to all XHR requests.
$(document).ajaxSend(function(evt, xhr) {
var token = app.getAccessToken();
- if (token)
+ if (token) {
xhr.setRequestHeader("Authorization", "OAuth " + token);
+ }
});
// Converts query string parameters in fragment identifier to object.
- function parseParams(hash) {
- var pairs = hash.substring(1).split("&"), params = {};
+ function parseParams(path) {
+ var hash = path.match(/#(.*)$/)[1];
+ var pairs = hash.split("&"), params = {};
for (var i in pairs) {
var splat = pairs[i].split("=");
params[splat[0]] = splat[1].replace(/\+/g, " ");
@@ -115,30 +118,31 @@
// redirection.
this.bind("run", function(evt, params) {
start_url = params.start_url || "#";
- if (this.app.getAccessToken())
+ if (this.app.getAccessToken()) {
this.trigger("oauth.connected");
+ }
});
// Intercept OAuth authorization response with access token, stores it and
// redirects to original URL, or application root.
- this.before(/^#(access_token=|[^\\].*\&access_token=)/, function(context) {
+ this.before(/#(access_token=|[^\\].*\&access_token=)/, function(context) {
var params = parseParams(context.path);
this.app.setAccessToken(params.access_token);
// When the filter redirected the original request, it passed the original
// request's URL in the state parameter, which we get back after
// authorization.
- context.redirect(params.state.length == 0 ? this.app.start_url : unescape(params.state));
+ context.redirect(params.state.length === 0 ? this.app.start_url : unescape(params.state));
return false;
- }).get(/^#(access_token=|[^\\].*\&access_token=)/, function(context) { });
+ }).get(/#(access_token=|[^\\].*\&access_token=)/, function(context) { });
// Intercept OAuth authorization response with error (typically access
// denied).
- this.before(/^#(error=|[^\\].*\&error=)/, function(context) {
+ this.before(/#(error=|[^\\].*\&error=)/, function(context) {
var params = parseParams(context.path);
var message = params.error_description || "Access denined";
context.trigger("oauth.denied", { code: params.error, message: message });
return false;
- }).get(/^#(error=|[^\\].*\&error=)/, function(context) { });
+ }).get(/#(error=|[^\\].*\&error=)/, function(context) { });
}
})(jQuery);
@@ -20,39 +20,37 @@
//
// Clicking on that link would not go to /about, but would set the apps location
// to 'about' and trigger the route.
-
Sammy.PushLocationProxy = function(app) {
this.app = app;
};
Sammy.PushLocationProxy.prototype = {
- bind: function() {
- var proxy = this;
- $(window).bind('popstate', function(e) {
- proxy.app.trigger('location-changed');
- });
- $('a').live('click', function(e) {
- // Do not bind external links
- if (location.hostname == this.hostname)
- {
- e.preventDefault();
- proxy.setLocation($(this).attr('href'));
- proxy.app.trigger('location-changed');
- }
- });
- },
- unbind: function() {
- $('a').unbind('click');
- $(window).unbind('popstate');
- },
+ bind: function() {
+ var proxy = this;
+ $(window).bind('popstate', function(e) {
+ proxy.app.trigger('location-changed');
+ });
+ $('a').live('click', function(e) {
+ // Do not bind external links
+ if (location.hostname == this.hostname) {
+ e.preventDefault();
+ proxy.setLocation($(this).attr('href'));
+ proxy.app.trigger('location-changed');
+ }
+ });
+ },
+ unbind: function() {
+ $('a').unbind('click');
+ $(window).unbind('popstate');
+ },
- getLocation: function() {
- return window.location.pathname;
- },
+ getLocation: function() {
+ return window.location.pathname;
+ },
- setLocation: function(new_location) {
- history.pushState({ path: this.path }, '', new_location)
- }
+ setLocation: function(new_location) {
+ history.pushState({ path: this.path }, '', new_location);
+ }
};
})(jQuery);
Oops, something went wrong.

0 comments on commit 088e41c

Please sign in to comment.