FIX: Widgets should support links to foreign hosts

This commit is contained in:
Robin Ward 2016-05-11 12:02:10 -04:00
parent 4d48a1dd79
commit e831203897
No known key found for this signature in database
GPG Key ID: 0E091E2B4ED1B83D
3 changed files with 11 additions and 8 deletions

View File

@ -90,6 +90,15 @@ const DiscourseURL = Ember.Object.extend({
}); });
}, },
routeToTag(a) {
if (a && a.host !== document.location.host) {
document.location = a.href;
return false;
}
return this.routeTo(a.href);
},
/** /**
Our custom routeTo method is used to intelligently overwrite default routing Our custom routeTo method is used to intelligently overwrite default routing
behavior. behavior.

View File

@ -48,15 +48,9 @@ export default createWidget('home-logo', {
click(e) { click(e) {
if (wantsNewWindow(e)) { return false; } if (wantsNewWindow(e)) { return false; }
e.preventDefault(); e.preventDefault();
const a = $(e.target).closest('a')[0];
if (a && a.host !== document.location.host) {
document.location = a.href;
}
DiscourseURL.routeTo(this.href()); DiscourseURL.routeToTag($(e.target).closest('a')[0]);
return false; return false;
} }
}); });

View File

@ -81,6 +81,6 @@ export default createWidget('link', {
this.sendWidgetEvent('linkClicked'); this.sendWidgetEvent('linkClicked');
} }
return DiscourseURL.routeTo(this.href(this.attrs)); return DiscourseURL.routeToTag($(e.target).closest('a')[0]);
} }
}); });