mirror of
https://github.com/discourse/discourse.git
synced 2025-05-23 22:21:19 +08:00
FIX: Links to images in posts won't go through the Discoruse router
This commit is contained in:
@ -148,21 +148,21 @@ Discourse = Ember.Application.createWithMixins({
|
|||||||
});
|
});
|
||||||
|
|
||||||
$('#main').on('click.discourse', 'a', function(e) {
|
$('#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 $currentTarget = $(e.currentTarget);
|
||||||
var href = $currentTarget.attr('href');
|
var href = $currentTarget.attr('href');
|
||||||
if (!href) return;
|
if (!href) { return; }
|
||||||
if (href === '#') return;
|
if (href === '#') { return; }
|
||||||
if ($currentTarget.attr('target')) return;
|
if ($currentTarget.attr('target')) { return; }
|
||||||
if ($currentTarget.data('auto-route')) return;
|
if ($currentTarget.data('auto-route')) { return; }
|
||||||
|
|
||||||
// If it's an ember #linkTo skip it
|
// 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 ($currentTarget.hasClass('lightbox')) { return; }
|
||||||
if (href.indexOf("mailto:") === 0) return;
|
if (href.indexOf("mailto:") === 0) { return; }
|
||||||
if (href.match(/^http[s]?:\/\//i) && !href.match(new RegExp("^http:\\/\\/" + window.location.hostname, "i"))) return;
|
if (href.match(/^http[s]?:\/\//i) && !href.match(new RegExp("^http:\\/\\/" + window.location.hostname, "i"))) { return; }
|
||||||
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
Discourse.URL.routeTo(href);
|
Discourse.URL.routeTo(href);
|
||||||
|
@ -85,7 +85,7 @@ Discourse.ClickTrack = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If we're on the same site, use the router and track via AJAX
|
// 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", {
|
Discourse.ajax("/clicks/track", {
|
||||||
data: {
|
data: {
|
||||||
url: href,
|
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");
|
Discourse.URL.routeTo = topLevel(Discourse.URL.routeTo, "Discourse.URL.routeTo");
|
||||||
Ember.run.backburner.end = topLevel(Ember.run.backburner.end, "Ember.run.backburner.end");
|
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) {
|
routeTo: function(path) {
|
||||||
var oldPath = window.location.pathname;
|
var oldPath = window.location.pathname;
|
||||||
path = path.replace(/https?\:\/\/[^\/]+/, '');
|
path = path.replace(/https?\:\/\/[^\/]+/, '');
|
||||||
/*
|
|
||||||
If the URL is absolute, remove rootURL
|
// If the URL is absolute, remove rootURL
|
||||||
*/
|
|
||||||
if (path.match(/^\//)) {
|
if (path.match(/^\//)) {
|
||||||
var rootURL = (Discourse.BaseUri === undefined ? "/" : Discourse.BaseUri);
|
var rootURL = (Discourse.BaseUri === undefined ? "/" : Discourse.BaseUri);
|
||||||
rootURL = rootURL.replace(/\/$/, '');
|
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
|
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.
|
same topic, use replaceState and instruct our controller to load more posts.
|
||||||
*/
|
*/
|
||||||
var newMatches = this.TOPIC_REGEXP.exec(path);
|
var newMatches = this.TOPIC_REGEXP.exec(path),
|
||||||
var newTopicId = newMatches ? newMatches[2] : null;
|
newTopicId = newMatches ? newMatches[2] : null;
|
||||||
|
|
||||||
if (newTopicId) {
|
if (newTopicId) {
|
||||||
var oldMatches = this.TOPIC_REGEXP.exec(oldPath);
|
var oldMatches = this.TOPIC_REGEXP.exec(oldPath),
|
||||||
var oldTopicId = oldMatches ? oldMatches[2] : null;
|
oldTopicId = oldMatches ? oldMatches[2] : null;
|
||||||
|
|
||||||
// If the topic_id is the same
|
// If the topic_id is the same
|
||||||
if (oldTopicId === newTopicId) {
|
if (oldTopicId === newTopicId) {
|
||||||
Discourse.URL.replaceState(path);
|
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');
|
var postStream = topicController.get('postStream');
|
||||||
postStream.refresh(opts).then(function() {
|
postStream.refresh(opts).then(function() {
|
||||||
topicController.setProperties({
|
topicController.setProperties({
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
/*global historyState:true */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@module Discourse
|
@module Discourse
|
||||||
*/
|
*/
|
||||||
@ -98,7 +96,6 @@ Ember.DiscourseLocation = Ember.Object.extend({
|
|||||||
@param path {String}
|
@param path {String}
|
||||||
*/
|
*/
|
||||||
setURL: function(path) {
|
setURL: function(path) {
|
||||||
|
|
||||||
path = this.formatURL(path);
|
path = this.formatURL(path);
|
||||||
if (this.getState() && this.getState().path !== path) {
|
if (this.getState() && this.getState().path !== path) {
|
||||||
popstateReady = true;
|
popstateReady = true;
|
||||||
@ -116,7 +113,6 @@ Ember.DiscourseLocation = Ember.Object.extend({
|
|||||||
@param path {String}
|
@param path {String}
|
||||||
*/
|
*/
|
||||||
replaceURL: function(path) {
|
replaceURL: function(path) {
|
||||||
|
|
||||||
path = this.formatURL(path);
|
path = this.formatURL(path);
|
||||||
|
|
||||||
if (this.getState() && this.getState().path !== path) {
|
if (this.getState() && this.getState().path !== path) {
|
||||||
@ -133,7 +129,7 @@ Ember.DiscourseLocation = Ember.Object.extend({
|
|||||||
@method getState
|
@method getState
|
||||||
*/
|
*/
|
||||||
getState: function() {
|
getState: function() {
|
||||||
historyState = get(this, 'history').state;
|
var historyState = get(this, 'history').state;
|
||||||
if (historyState) return historyState;
|
if (historyState) return historyState;
|
||||||
|
|
||||||
return {path: window.location.pathname};
|
return {path: window.location.pathname};
|
||||||
|
Reference in New Issue
Block a user