FIX: Links to images in posts won't go through the Discoruse router

This commit is contained in:
Robin Ward
2013-07-03 14:06:34 -04:00
parent b0e10673a2
commit ba0bd934ba
5 changed files with 22 additions and 26 deletions
@@ -85,7 +85,7 @@ Discourse.ClickTrack = {
}
// If we're on the same site, use the router and track via AJAX
if (href.indexOf(Discourse.URL.origin()) === 0) {
if ((href.indexOf(Discourse.URL.origin()) === 0) && (!href.match(/\.(png|gif|jpg|jpeg)$/i))) {
Discourse.ajax("/clicks/track", {
data: {
url: href,
@@ -74,7 +74,6 @@ Discourse.Development = {
});
};
//Ember.CoreView.prototype._renderToBuffer = window.probes.measure(Ember.CoreView.prototype._renderToBuffer, "renderToBuffer");
Discourse.URL.routeTo = topLevel(Discourse.URL.routeTo, "Discourse.URL.routeTo");
Ember.run.backburner.end = topLevel(Ember.run.backburner.end, "Ember.run.backburner.end");
},
@@ -62,9 +62,8 @@ Discourse.URL = Em.Object.createWithMixins({
routeTo: function(path) {
var oldPath = window.location.pathname;
path = path.replace(/https?\:\/\/[^\/]+/, '');
/*
If the URL is absolute, remove rootURL
*/
// If the URL is absolute, remove rootURL
if (path.match(/^\//)) {
var rootURL = (Discourse.BaseUri === undefined ? "/" : Discourse.BaseUri);
rootURL = rootURL.replace(/\/$/, '');
@@ -76,19 +75,21 @@ Discourse.URL = Em.Object.createWithMixins({
then we want to apply some special logic. If the post_number changes within the
same topic, use replaceState and instruct our controller to load more posts.
*/
var newMatches = this.TOPIC_REGEXP.exec(path);
var newTopicId = newMatches ? newMatches[2] : null;
var newMatches = this.TOPIC_REGEXP.exec(path),
newTopicId = newMatches ? newMatches[2] : null;
if (newTopicId) {
var oldMatches = this.TOPIC_REGEXP.exec(oldPath);
var oldTopicId = oldMatches ? oldMatches[2] : null;
var oldMatches = this.TOPIC_REGEXP.exec(oldPath),
oldTopicId = oldMatches ? oldMatches[2] : null;
// If the topic_id is the same
if (oldTopicId === newTopicId) {
Discourse.URL.replaceState(path);
var topicController = Discourse.__container__.lookup('controller:topic');
var opts = { };
if (newMatches[3]) opts.nearPost = newMatches[3];
var topicController = Discourse.__container__.lookup('controller:topic'),
opts = {};
if (newMatches[3]) opts.nearPost = newMatches[3];
var postStream = topicController.get('postStream');
postStream.refresh(opts).then(function() {
topicController.setProperties({