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

View File

@ -148,21 +148,21 @@ Discourse = Ember.Application.createWithMixins({
});
$('#main').on('click.discourse', 'a', function(e) {
if (e.isDefaultPrevented() || e.shiftKey || e.metaKey || e.ctrlKey) return;
if (e.isDefaultPrevented() || e.shiftKey || e.metaKey || e.ctrlKey) { return; }
var $currentTarget = $(e.currentTarget);
var href = $currentTarget.attr('href');
if (!href) return;
if (href === '#') return;
if ($currentTarget.attr('target')) return;
if ($currentTarget.data('auto-route')) return;
if (!href) { return; }
if (href === '#') { return; }
if ($currentTarget.attr('target')) { return; }
if ($currentTarget.data('auto-route')) { return; }
// If it's an ember #linkTo skip it
if ($currentTarget.hasClass('ember-view')) return;
if ($currentTarget.hasClass('ember-view')) { return; }
if ($currentTarget.hasClass('lightbox')) return;
if (href.indexOf("mailto:") === 0) return;
if (href.match(/^http[s]?:\/\//i) && !href.match(new RegExp("^http:\\/\\/" + window.location.hostname, "i"))) return;
if ($currentTarget.hasClass('lightbox')) { return; }
if (href.indexOf("mailto:") === 0) { return; }
if (href.match(/^http[s]?:\/\//i) && !href.match(new RegExp("^http:\\/\\/" + window.location.hostname, "i"))) { return; }
e.preventDefault();
Discourse.URL.routeTo(href);

View File

@ -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,

View File

@ -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");
},

View File

@ -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({

View File

@ -1,5 +1,3 @@
/*global historyState:true */
/**
@module Discourse
*/
@ -98,7 +96,6 @@ Ember.DiscourseLocation = Ember.Object.extend({
@param path {String}
*/
setURL: function(path) {
path = this.formatURL(path);
if (this.getState() && this.getState().path !== path) {
popstateReady = true;
@ -116,7 +113,6 @@ Ember.DiscourseLocation = Ember.Object.extend({
@param path {String}
*/
replaceURL: function(path) {
path = this.formatURL(path);
if (this.getState() && this.getState().path !== path) {
@ -133,7 +129,7 @@ Ember.DiscourseLocation = Ember.Object.extend({
@method getState
*/
getState: function() {
historyState = get(this, 'history').state;
var historyState = get(this, 'history').state;
if (historyState) return historyState;
return {path: window.location.pathname};