Merge pull request #611 from anthonymayer/siteurl-in-urls

Fix various url problems by taking siteUrl into account when getting route urls.
This commit is contained in:
Sacha Greif 2014-12-10 09:39:38 +09:00
commit ca78347dce
6 changed files with 28 additions and 21 deletions

View file

@ -152,7 +152,7 @@ Template[getTemplate('comment_item')].events({
'click .not-upvoted .upvote': function(e, instance){
e.preventDefault();
if(!Meteor.user()){
Router.go(getSigninUrl());
Router.go('atSignIn');
flashMessage(i18n.t("please_log_in_first"), "info");
}
Meteor.call('upvoteComment', this, function(error, result){
@ -162,7 +162,7 @@ Template[getTemplate('comment_item')].events({
'click .upvoted .upvote': function(e, instance){
e.preventDefault();
if(!Meteor.user()){
Router.go(getSigninUrl());
Router.go('atSignIn');
flashMessage(i18n.t("please_log_in_first"), "info");
}
Meteor.call('cancelUpvoteComment', this, function(error, result){
@ -172,7 +172,7 @@ Template[getTemplate('comment_item')].events({
'click .not-downvoted .downvote': function(e, instance){
e.preventDefault();
if(!Meteor.user()){
Router.go(getSigninUrl());
Router.go('atSignIn');
flashMessage(i18n.t("please_log_in_first"), "info");
}
Meteor.call('downvoteComment', this, function(error, result){
@ -182,7 +182,7 @@ Template[getTemplate('comment_item')].events({
'click .downvoted .downvote': function(e, instance){
e.preventDefault();
if(!Meteor.user()){
Router.go(getSigninUrl());
Router.go('atSignIn');
flashMessage(i18n.t("please_log_in_first"), "info");
}
Meteor.call('cancelDownvoteComment', this, function(error, result){

View file

@ -6,7 +6,7 @@ Template[getTemplate('userMenu')].helpers({
return getDisplayName(Meteor.user());
},
profileUrl: function () {
return getProfileUrl(Meteor.user());
return Router.routes['user_profile'].path({_idOrSlug: Meteor.user().slug});
},
userEditUrl: function () {
return Router.routes['user_edit'].path(Meteor.user());

View file

@ -1,7 +1,7 @@
Template[getTemplate('postUpvote')].helpers({
upvoted: function(){
var user = Meteor.user();
if(!user) return false;
if(!user) return false;
return _.include(this.upvoters, user._id);
},
oneBasedRank: function(){
@ -15,7 +15,7 @@ Template[getTemplate('postUpvote')].events({
var post = this;
e.preventDefault();
if(!Meteor.user()){
Router.go(getSigninUrl());
Router.go('atSignIn');
flashMessage(i18n.t("please_log_in_first"), "info");
}
Meteor.call('upvotePost', post, function(error, result){

View file

@ -5,9 +5,6 @@ cl = function(something){
getCurrentTemplate = function() {
return Router.current().lookupTemplate();
};
getCurrentRoute = function() {
return Router.current().url;
};
t=function(message){
var d=new Date();
console.log("### "+message+" rendered at "+d.getHours()+":"+d.getMinutes()+":"+d.getSeconds());
@ -46,25 +43,37 @@ goTo = function(url){
Router.go(url);
};
// This function should only ever really be necessary server side
// Client side using .path() is a better option since it's relative
// and shouldn't care about the siteUrl.
getRouteUrl = function (routeName, params, options) {
options = options || {};
options.host = getSiteUrl();
return Router.routes[routeName].url(
params || {},
options
);
};
getSignupUrl = function(){
return Router.routes['atSignUp'].url();
return getRouteUrl('atSignUp');
};
getSigninUrl = function(){
return Router.routes['atSignIn'].url();
return getRouteUrl('atSignIn');
};
getPostUrl = function(id){
return Router.routes['post_page'].url({_id: id});
return getRouteUrl('post_page', {_id: id});
};
getPostEditUrl = function(id){
return Router.routes['post_edit'].url({_id: id});
return getRouteUrl('post_edit', {_id: id});
};
getCommentUrl = function(id){
return Router.routes['comment_reply'].url({_id: id});
return getRouteUrl('comment_reply', {_id: id});
};
getPostCommentUrl = function(postId, commentId){
// get link to a comment on a post page
return Router.routes['post_page_comment'].url({
return getRouteUrl('post_page_comment', {
_id: postId,
commentId: commentId
});
@ -88,9 +97,7 @@ invitesEnabled = function () {
return getSetting("requireViewInvite") || getSetting("requirePostInvite");
};
getOutgoingUrl = function(url){
// we don't use IR's url() function here in case ROOT_URL hasn't been set
var cleanUrl = encodeURIComponent(url);
return getSetting('siteUrl', Meteor.absoluteUrl()) + 'out?url=' + cleanUrl;
return getRouteUrl('out', {}, {query: {url: url}});
};
// ---------------------------------- String Helper Functions ----------------------------------- //
cleanUp = function(s){

View file

@ -47,7 +47,7 @@ getProfileUrl = function(user) {
return getProfileUrlBySlugOrId(user.slug);
};
getProfileUrlBySlugOrId = function(slugOrId) {
return Router.routes['user_profile'].url({_idOrSlug: slugOrId});
return getRouteUrl('user_profile', {_idOrSlug: slugOrId});
};
hasPassword = function(user) {
return !!user.services.password;

View file

@ -1,5 +1,5 @@
getUnsubscribeLink = function(user){
return Router.routes['unsubscribe'].url({hash: user.email_hash});
return getRouteUrl('unsubscribe', {hash: user.email_hash});
};
// given a notification, return the correct subject and html to send an email