diff --git a/app/assets/javascripts/discourse.js b/app/assets/javascripts/discourse.js index fa09ab10204..ad8f0c54d1a 100644 --- a/app/assets/javascripts/discourse.js +++ b/app/assets/javascripts/discourse.js @@ -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); diff --git a/app/assets/javascripts/discourse/components/click_track.js b/app/assets/javascripts/discourse/components/click_track.js index 99825b947e1..0d98cd68c2e 100644 --- a/app/assets/javascripts/discourse/components/click_track.js +++ b/app/assets/javascripts/discourse/components/click_track.js @@ -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, diff --git a/app/assets/javascripts/discourse/components/development.js b/app/assets/javascripts/discourse/components/development.js index e45aee4cf7b..675010e7b9d 100644 --- a/app/assets/javascripts/discourse/components/development.js +++ b/app/assets/javascripts/discourse/components/development.js @@ -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"); }, diff --git a/app/assets/javascripts/discourse/components/url.js b/app/assets/javascripts/discourse/components/url.js index 0ab91a3264f..2cf9f41d5f7 100644 --- a/app/assets/javascripts/discourse/components/url.js +++ b/app/assets/javascripts/discourse/components/url.js @@ -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({ diff --git a/app/assets/javascripts/discourse/routes/discourse_location.js b/app/assets/javascripts/discourse/routes/discourse_location.js index 5c02aa4120e..8b92cb4a9f1 100644 --- a/app/assets/javascripts/discourse/routes/discourse_location.js +++ b/app/assets/javascripts/discourse/routes/discourse_location.js @@ -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};