FIX: use CDN for user card/profile background and user avatars

This commit is contained in:
Régis Hanol 2015-01-29 20:15:17 +01:00
parent e42e9bd010
commit 14dc22f288
5 changed files with 15 additions and 11 deletions

View File

@ -24,6 +24,12 @@ window.Discourse = Ember.Application.createWithMixins(Discourse.Ajax, {
return u + url;
},
getURLWithCDN: function(url) {
url = this.getURL(url);
if (Discourse.CDN) { url = Discourse.CDN + url; }
return url;
},
Resolver: DiscourseResolver,
_titleChanged: function() {

View File

@ -1,4 +1,5 @@
var esc = Handlebars.Utils.escapeExpression;
Discourse.BBCode.register('quote', {noWrap: true, singlePara: true}, function(contents, bbParams, options) {
var params = {'class': 'quote'},
username = null;

View File

@ -51,7 +51,7 @@ Discourse.Utilities = {
var classes = "avatar" + (options.extraClasses ? " " + options.extraClasses : "");
var title = (options.title) ? " title='" + Handlebars.Utils.escapeExpression(options.title || "") + "'" : "";
return "<img width='" + size + "' height='" + size + "' src='" + url + "' class='" + classes + "'" + title + ">";
return "<img width='" + size + "' height='" + size + "' src='" + Discourse.getURLWithCDN(url) + "' class='" + classes + "'" + title + ">";
},
tinyAvatar: function(avatarTemplate, options) {

View File

@ -72,10 +72,9 @@ Discourse.User = Discourse.Model.extend({
@type {String}
**/
profileBackground: function() {
var background = this.get('profile_background');
if(Em.isEmpty(background) || !Discourse.SiteSettings.allow_profile_backgrounds) { return; }
return 'background-image: url(' + background + ')';
var url = this.get('profile_background');
if (Em.isEmpty(url) || !Discourse.SiteSettings.allow_profile_backgrounds) { return; }
return 'background-image: url(' + Discourse.getURLWithCDN(url) + ')';
}.property('profile_background'),
/**
@ -442,6 +441,7 @@ Discourse.User.reopenClass(Discourse.Singleton, {
avatarTemplate: function(username, uploadedAvatarId) {
var url;
if (uploadedAvatarId) {
url = "/user_avatar/" +
Discourse.BaseUrl +
@ -456,11 +456,7 @@ Discourse.User.reopenClass(Discourse.Singleton, {
Discourse.LetterAvatarVersion + ".png";
}
url = Discourse.getURL(url);
if (Discourse.CDN) {
url = Discourse.CDN + url;
}
return url;
return Discourse.getURLWithCDN(url);
},
/**

View File

@ -11,6 +11,7 @@ export default Discourse.View.extend(CleansUp, {
addBackground: function() {
var url = this.get('controller.user.card_background');
if (!this.get('allowBackgrounds')) { return; }
var $this = this.$();
@ -19,7 +20,7 @@ export default Discourse.View.extend(CleansUp, {
if (Ember.isEmpty(url)) {
$this.css('background-image', '').addClass('no-bg');
} else {
$this.css('background-image', "url(" + url + ")").removeClass('no-bg');
$this.css('background-image', "url(" + Discourse.getURLWithCDN(url) + ")").removeClass('no-bg');
}
}.observes('controller.user.card_background'),