From 8b87f095c6f4d8a07a5a2ab1d8563e1ebee1d5d1 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 11 Dec 2014 15:46:08 +1100 Subject: [PATCH] PERF: don't render share dialog until we have a link. --- .../javascripts/discourse/templates/share.hbs | 2 ++ .../javascripts/discourse/views/share.js.es6 | 27 ++++++++++--------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/app/assets/javascripts/discourse/templates/share.hbs b/app/assets/javascripts/discourse/templates/share.hbs index 303ff6ef8e9..a7c850f442d 100644 --- a/app/assets/javascripts/discourse/templates/share.hbs +++ b/app/assets/javascripts/discourse/templates/share.hbs @@ -1,3 +1,4 @@ +{{#if controller.link}}

{{view.title}}

{{#if date}} @@ -14,3 +15,4 @@ +{{/if}} diff --git a/app/assets/javascripts/discourse/views/share.js.es6 b/app/assets/javascripts/discourse/views/share.js.es6 index c6a0b971599..566d5332e8a 100644 --- a/app/assets/javascripts/discourse/views/share.js.es6 +++ b/app/assets/javascripts/discourse/views/share.js.es6 @@ -27,20 +27,23 @@ export default Discourse.View.extend({ }.property('controller.link'), linkChanged: function() { + var self=this; if (this.present('controller.link')) { - if (!this.capabilities.touch) { - var $linkInput = $('#share-link input'); - $linkInput.val(this.get('controller.link')); + Em.run.next(function(){ + if (!self.capabilities.touch) { + var $linkInput = $('#share-link input'); + $linkInput.val(self.get('controller.link')); - // Wait for the fade-in transition to finish before selecting the link: - window.setTimeout(function() { - $linkInput.select().focus(); - }, 160); - } else { - var $linkForTouch = $('#share-link .share-for-touch a'); - $linkForTouch.attr('href', this.get('controller.link')); - $linkForTouch.html(this.get('controller.link')); - } + // Wait for the fade-in transition to finish before selecting the link: + window.setTimeout(function() { + $linkInput.select().focus(); + }, 160); + } else { + var $linkForTouch = $('#share-link .share-for-touch a'); + $linkForTouch.attr('href',self.get('controller.link')); + $linkForTouch.html(self.get('controller.link')); + } + }); } }.observes('controller.link'),