about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--app/assets/javascripts/components/components/status_content.jsx27
-rw-r--r--app/assets/stylesheets/components.scss11
-rw-r--r--app/lib/formatter.rb7
-rw-r--r--spec/lib/formatter_spec.rb2
4 files changed, 42 insertions, 5 deletions
diff --git a/app/assets/javascripts/components/components/status_content.jsx b/app/assets/javascripts/components/components/status_content.jsx
index f2c88cee0..68224b7ba 100644
--- a/app/assets/javascripts/components/components/status_content.jsx
+++ b/app/assets/javascripts/components/components/status_content.jsx
@@ -56,12 +56,35 @@ const StatusContent = React.createClass({
     e.stopPropagation();
   },
 
+  handleMouseDown (e) {
+    this.startXY = [e.clientX, e.clientY];
+  },
+
+  handleMouseUp (e) {
+    const [ startX, startY ] = this.startXY;
+    const [ deltaX, deltaY ] = [Math.abs(e.clientX - startX), Math.abs(e.clientY - startY)];
+
+    if (deltaX + deltaY < 5) {
+      this.props.onClick();
+    }
+
+    this.startXY = null;
+  },
+
   render () {
-    const { status, onClick } = this.props;
+    const { status } = this.props;
 
     const content = { __html: emojify(status.get('content')) };
 
-    return <div className='status__content' style={{ cursor: 'pointer' }} dangerouslySetInnerHTML={content} onClick={onClick} />;
+    return (
+      <div
+        className='status__content'
+        style={{ cursor: 'pointer' }}
+        dangerouslySetInnerHTML={content}
+        onMouseDown={this.handleMouseDown}
+        onMouseUp={this.handleMouseUp}
+      />
+    );
   },
 
 });
diff --git a/app/assets/stylesheets/components.scss b/app/assets/stylesheets/components.scss
index e1710580c..4a3a7df5f 100644
--- a/app/assets/stylesheets/components.scss
+++ b/app/assets/stylesheets/components.scss
@@ -60,6 +60,17 @@
   }
 }
 
+.invisible {
+  font-size: 0;
+  line-height: 0;
+}
+
+.ellipsis {
+  &:after {
+    content: "…";
+  }
+}
+
 .lightbox .icon-button {
   color: $color1;
 }
diff --git a/app/lib/formatter.rb b/app/lib/formatter.rb
index 3565611bc..1fa5b83fb 100644
--- a/app/lib/formatter.rb
+++ b/app/lib/formatter.rb
@@ -65,8 +65,11 @@ class Formatter
   end
 
   def link_html(url)
-    link_text = truncate(url.gsub(/\Ahttps?:\/\/(www\.)?/, ''), length: 30)
-    "<a rel=\"nofollow noopener\" target=\"_blank\" href=\"#{url}\">#{link_text}</a>"
+    prefix = url.match(/\Ahttps?:\/\/(www\.)?/).to_s
+    text   = url[prefix.length, 30]
+    suffix = url[prefix.length + 30..-1]
+
+    "<a rel=\"nofollow noopener\" target=\"_blank\" href=\"#{url}\"><span class=\"invisible\">#{prefix}</span><span class=\"ellipsis\">#{text}</span><span class=\"invisible\">#{suffix}</span></a>"
   end
 
   def hashtag_html(match)
diff --git a/spec/lib/formatter_spec.rb b/spec/lib/formatter_spec.rb
index 7b8259fa6..6ec28f5d8 100644
--- a/spec/lib/formatter_spec.rb
+++ b/spec/lib/formatter_spec.rb
@@ -17,7 +17,7 @@ RSpec.describe Formatter do
     end
 
     it 'contains a link' do
-      expect(subject).to match('<a rel="nofollow noopener" target="_blank" href="http://google.com">google.com</a>')
+      expect(subject).to match('<a rel="nofollow noopener" target="_blank" href="http://google.com"><span class="invisible">http://</span><span class="ellipsis">google.com</span><span class="invisible"></span></a>')
     end
   end