Skip to content

Commit

Permalink
Don't truncate description in the middle of a word
Browse files Browse the repository at this point in the history
  • Loading branch information
Floris Verloop committed Aug 3, 2016
1 parent 440e75b commit daa910b
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions framer/Components/ShareComponent.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -135,23 +135,18 @@ class ShareComponent

@_startListening()

_truncateCredential: (str, words) ->
_truncateCredential: (str) ->
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})
str = _.truncate(str, {"length": maxLengthWithAvatar})

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

return str

Expand All @@ -163,7 +158,7 @@ class ShareComponent

# Truncate title if too long
if @shareInfo.title
@shareInfo.title = @_truncateCredential(@shareInfo.title, true)
@shareInfo.title = @_truncateCredential(@shareInfo.title)

# Render main sheet
_renderSheet: ->
Expand Down Expand Up @@ -418,8 +413,7 @@ class ShareComponent

# Truncate if description is too long
if @shareInfo.description.length > @options.maxDescriptionLength
truncated = @shareInfo.description.substring(@options.maxDescriptionLength,length).trim()
@options.shortDescription = truncated + ""
@options.shortDescription = _.truncate(@shareInfo.description, {"length": @options.maxDescriptionLength, "separator": " "})

@descriptionTruncatedSize = Utils.textSize(
parseDescription(@options.shortDescription),
Expand Down

0 comments on commit daa910b

Please sign in to comment.