Skip to content
Permalink
Browse files

Truncate and escape author

  • Loading branch information
Floris Verloop committed Aug 3, 2016
1 parent f11ff0e commit 440e75b10c243a59a76957f7b111601a74f0eefc
Showing with 23 additions and 14 deletions.
  1. +23 −14 framer/Components/ShareComponent.coffee
@@ -135,24 +135,35 @@ class ShareComponent

@_startListening()

_truncateCredential: (str, words) ->
maxLength = 36
maxLengthWithAvatar = 25

str = _.escape(str)

if words
separator = " "
else
separator = ""

# If an avatar is shown
if @shareInfo.twitter isnt undefined and str.length > maxLengthWithAvatar
str = _.truncate(str, {"length": maxLengthWithAvatar, "separator": separator})

else if str.length > maxLength
str = _.truncate(str, {"length": maxLength, "separator": separator})

return str

_checkData: ->
truncate = (str, n) ->
truncatedString = str
truncatedString.substr(0, n-1).trim() + "…"

# Remove leading @ from the Twitter handle
if _.startsWith(@shareInfo.twitter, "@")
@shareInfo.twitter[1..]

# Truncate title if too long
if @shareInfo.title
maxLengthWithAvatar = 26
maxLength = 34

if @shareInfo.twitter and @shareInfo.title.length > maxLengthWithAvatar
@shareInfo.title = truncate(@shareInfo.title, maxLengthWithAvatar)
else if @shareInfo.title.length > maxLength
@shareInfo.title = truncate(@shareInfo.title, maxLength)
@shareInfo.title = @_truncateCredential(@shareInfo.title, true)

# Render main sheet
_renderSheet: ->
@@ -324,6 +335,8 @@ class ShareComponent

# If author name isn't available, fallback to Twitter handle
name = if @shareInfo.author then @shareInfo.author else "@#{@shareInfo.twitter}"
name = @_truncateCredential(name)

showAuthor("<a href='http://twitter.com/#{@shareInfo.twitter}' style='text-decoration: none; -webkit-user-select: auto;' target='_blank'>#{name}</a>")

# If there's no twitter handle, show plain author name
@@ -392,7 +405,6 @@ class ShareComponent
)

showFullDescription = =>
@options.truncated = false
@description.height = @descriptionSize.height
@description.html = parseDescription(@shareInfo.description)

@@ -406,9 +418,6 @@ class ShareComponent

# Truncate if description is too long
if @shareInfo.description.length > @options.maxDescriptionLength

@options.truncated = true

truncated = @shareInfo.description.substring(@options.maxDescriptionLength,length).trim()
@options.shortDescription = truncated + ""

0 comments on commit 440e75b

Please sign in to comment.