From 97eba92a2e2a6a998edf72b3c88c6671f92de939 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 2 Jun 2014 10:30:16 +1000 Subject: [PATCH] BUGFIX: user screen.width cause it will be more correct BUGFIX: fix deprecation and regression in cloaking PERF: cache progressWidth super aggresively to avoid reflows --- .../discourse/initializers/sniff-capabilities.js.es6 | 2 +- app/assets/javascripts/discourse/views/topic_view.js | 7 ++++--- vendor/assets/javascripts/ember-cloaking.js | 10 +++++----- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app/assets/javascripts/discourse/initializers/sniff-capabilities.js.es6 b/app/assets/javascripts/discourse/initializers/sniff-capabilities.js.es6 index a624be6ec..7b5c9be09 100644 --- a/app/assets/javascripts/discourse/initializers/sniff-capabilities.js.es6 +++ b/app/assets/javascripts/discourse/initializers/sniff-capabilities.js.es6 @@ -23,6 +23,6 @@ export default { // We consider high res a device with 1280 horizontal pixels. High DPI tablets like // iPads should report as 1024. - caps.set('highRes', Modernizr.mq("only screen and (min-width: 1280px)")); + caps.set('highRes', window.screen.width >= 1280); } }; diff --git a/app/assets/javascripts/discourse/views/topic_view.js b/app/assets/javascripts/discourse/views/topic_view.js index e09fb663b..1abb09729 100644 --- a/app/assets/javascripts/discourse/views/topic_view.js +++ b/app/assets/javascripts/discourse/views/topic_view.js @@ -38,12 +38,13 @@ Discourse.TopicView = Discourse.View.extend(Discourse.Scrolling, { } this._topicProgress = $topicProgress; // CAREFUL WITH THIS AXE - // offsetWidth will cause a reflow - this._progressWidth = $topicProgress[0].offsetWidth; + // offsetWidth will cause a reflow, this ensures it only happens once + // in future it may make sense to move this offscreen to to the measurement + Discourse.TopicView._progressWidth = Discourse.TopicView._progressWidth || $topicProgress[0].offsetWidth; } // speeds up stuff, bypass jquery slowness and extra checks - var totalWidth = this._progressWidth, + var totalWidth = Discourse.TopicView._progressWidth, progressWidth = this.get('controller.streamPercentage') * totalWidth; $topicProgress.find('.bg') diff --git a/vendor/assets/javascripts/ember-cloaking.js b/vendor/assets/javascripts/ember-cloaking.js index 452ede5f2..ffa1ecd40 100644 --- a/vendor/assets/javascripts/ember-cloaking.js +++ b/vendor/assets/javascripts/ember-cloaking.js @@ -286,7 +286,7 @@ cloak: function() { var self = this; - if (this._containedView && this.get('state') === 'inDOM') { + if (this._containedView && this._state === 'inDOM') { var style = 'height: ' + this.$().height() + 'px;'; this.set('style', style); this.$().prop('style', style); @@ -331,15 +331,15 @@ @method render */ render: function(buffer) { - var containedView = this._containedView; + var containedView = this._containedView, self = this; - if (containedView && containedView.get('state') !== 'inDOM') { + if (containedView && containedView._state !== 'inDOM') { containedView.triggerRecursively('willInsertElement'); containedView.renderToBuffer(buffer); containedView.transitionTo('inDOM'); Em.run.schedule('afterRender', function() { - if(this._containedView) { - this._containedView.triggerRecursively('didInsertElement'); + if(self._containedView) { + self._containedView.triggerRecursively('didInsertElement'); } }); }