about summary refs log tree commit diff
path: root/app/assets/javascripts/components
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2016-09-05 20:59:56 +0200
committerEugen Rochko <eugen@zeonfederated.com>2016-09-05 20:59:56 +0200
commit5f36d8828a08859262a0520a07f103fecbdfc7c3 (patch)
treedb6787cd7977265f9ef9f2d297fe91e73187c401 /app/assets/javascripts/components
parentfc222dfa495a4a05dc1a216bfe4d6b079db4e320 (diff)
Better layout for attachments in <MediaGallery>
Diffstat (limited to 'app/assets/javascripts/components')
-rw-r--r--app/assets/javascripts/components/components/media_gallery.jsx19
1 files changed, 17 insertions, 2 deletions
diff --git a/app/assets/javascripts/components/components/media_gallery.jsx b/app/assets/javascripts/components/components/media_gallery.jsx
index 403c68202..eb2288ae5 100644
--- a/app/assets/javascripts/components/components/media_gallery.jsx
+++ b/app/assets/javascripts/components/components/media_gallery.jsx
@@ -10,8 +10,23 @@ const MediaGallery = React.createClass({
   mixins: [PureRenderMixin],
 
   render () {
-    var children = this.props.media.take(4).map((attachment, i) => {
-      return <a key={attachment.get('id')} href={attachment.get('url')} style={{ float: 'left', marginRight: (i % 2 == 0 ? '5px' : '0'), marginBottom: '5px', textDecoration: 'none', border: 'none', display: 'block', width: '142px', height: '110px', background: `url(${attachment.get('preview_url')}) no-repeat`, backgroundSize: 'cover', cursor: 'zoom-in' }} />;
+    var children = this.props.media.take(4);
+    var size     = children.size;
+
+    children = children.map((attachment, i) => {
+      let width       = 142;
+      let height      = 110;
+      let marginRight = 0;
+
+      if (size == 4 || (size === 3 && i > 0)) {
+        height = 52.5;
+      }
+
+      if ((size === 3 && i === 0) || (size === 4 && i % 2 === 0)) {
+        marginRight = 5;
+      }
+
+      return <a key={attachment.get('id')} href={attachment.get('url')} style={{ position: 'relative', float: 'left', marginRight: `${marginRight}px`, marginBottom: '5px', textDecoration: 'none', border: 'none', display: 'block', width: `${width}px`, height: `${height}px`, background: `url(${attachment.get('preview_url')}) no-repeat`, backgroundSize: 'cover', cursor: 'zoom-in' }} />;
     });
 
     return (