From 65d7103bdc20d597decaeefa6ae9c782d6d51aaa Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Fri, 26 Feb 2016 16:48:41 -0500 Subject: [PATCH] FIX: Don't stop youtube videos from playing on cloak --- .../discourse/widgets/post-small-action.js.es6 | 1 + .../javascripts/discourse/widgets/post-stream.js.es6 | 9 +++++---- app/assets/javascripts/discourse/widgets/post.js.es6 | 9 +++++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/discourse/widgets/post-small-action.js.es6 b/app/assets/javascripts/discourse/widgets/post-small-action.js.es6 index c0dcea64eba..4940b6446a8 100644 --- a/app/assets/javascripts/discourse/widgets/post-small-action.js.es6 +++ b/app/assets/javascripts/discourse/widgets/post-small-action.js.es6 @@ -24,6 +24,7 @@ const icons = { }; export default createWidget('post-small-action', { + buildKey: attrs => `post-small-act-${attrs.id}`, tagName: 'div.small-action.onscreen-post.clearfix', buildId(attrs) { diff --git a/app/assets/javascripts/discourse/widgets/post-stream.js.es6 b/app/assets/javascripts/discourse/widgets/post-stream.js.es6 index d000aa321d1..404d4fd8601 100644 --- a/app/assets/javascripts/discourse/widgets/post-stream.js.es6 +++ b/app/assets/javascripts/discourse/widgets/post-stream.js.es6 @@ -1,7 +1,6 @@ import { createWidget } from 'discourse/widgets/widget'; import transformPost from 'discourse/lib/transform-post'; import { Placeholder } from 'discourse/lib/posts-with-placeholders'; -import { h } from 'virtual-dom'; import { addWidgetCleanCallback } from 'discourse/components/mount-widget'; const CLOAKING_ENABLED = !window.inTestEnv; @@ -86,9 +85,11 @@ export default createWidget('post-stream', { const height = _cloaked[post.id]; if (height) { - result.push(h('div.cloaked-post', { id: `post_${post.post_number}`, - attributes: { style: `height: ${height}px` } })); - } else if (transformed.isSmallAction) { + transformed.cloaked = true; + transformed.height = height; + } + + if (transformed.isSmallAction) { result.push(this.attach('post-small-action', transformed, { model: post })); } else { result.push(this.attach('post', transformed, { model: post })); diff --git a/app/assets/javascripts/discourse/widgets/post.js.es6 b/app/assets/javascripts/discourse/widgets/post.js.es6 index 2952479d2ba..3c1148f8d4c 100644 --- a/app/assets/javascripts/discourse/widgets/post.js.es6 +++ b/app/assets/javascripts/discourse/widgets/post.js.es6 @@ -378,7 +378,14 @@ export default createWidget('post', { buildKey: attrs => `post-${attrs.id}`, shadowTree: true, + buildAttributes(attrs) { + if (attrs.cloaked) { + return { style: `height: ${attrs.height}px` }; + } + }, + buildClasses(attrs) { + if (attrs.cloaked) { return 'cloaked-post'; } const classNames = ['topic-post', 'clearfix']; if (attrs.selected) { classNames.push('selected'); } @@ -397,6 +404,8 @@ export default createWidget('post', { }, html(attrs) { + if (attrs.cloaked) { return 'cloaked'; } + return this.attach('post-article', attrs); },