From c830ffe81cda84478465f3077608e88c6570e2f7 Mon Sep 17 00:00:00 2001 From: Andrew Letson Date: Wed, 15 Mar 2017 16:04:17 -0400 Subject: [PATCH 1/2] add inline support --- src/jquery.shorten.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/jquery.shorten.js b/src/jquery.shorten.js index 5ed0497..62d5f9f 100644 --- a/src/jquery.shorten.js +++ b/src/jquery.shorten.js @@ -26,6 +26,7 @@ ellipsesText: "...", moreText: "more", lessText: "less", + inline: false, onLess: function() {}, onMore: function() {}, errMsg: null, @@ -136,10 +137,15 @@ c+=config.ellipsesText; } - var html = '
' + c + - '
' + content + - '
' + config.moreText + ''; - + if(config.inline) { + var html = '' + c + + '' + content + + ' ' + config.moreText + ''; + } else { + var html = '
' + c + + '
' + content + + '
' + config.moreText + ''; + } $this.html(html); $this.find(".allcontent").hide(); // Hide all text $('.shortcontent p:last', $this).css('margin-bottom', 0); //Remove bottom margin on last paragraph as it's likely shortened From e4acb795522a0161be9620539f13263518e55839 Mon Sep 17 00:00:00 2001 From: Andrew Letson Date: Wed, 15 Mar 2017 16:11:10 -0400 Subject: [PATCH 2/2] Maybe this would be a more correct way of doing it? This way, future config flags can still modify the HTML output directly. --- src/jquery.shorten.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/jquery.shorten.js b/src/jquery.shorten.js index 62d5f9f..2ad8f8e 100644 --- a/src/jquery.shorten.js +++ b/src/jquery.shorten.js @@ -136,16 +136,15 @@ }else{ c+=config.ellipsesText; } - if(config.inline) { - var html = '' + c + - '' + content + - ' ' + config.moreText + ''; - } else { - var html = '
' + c + - '
' + content + - '
' + config.moreText + ''; + var wrapper_tag = 'span'; + } else { + var wrapper_tag = 'div'; } + + var html = '<' + wrapper_tag + ' class="shortcontent">' + c + + '<' + wrapper_tag + ' class="allcontent">' + content + + ' ' + config.moreText + ''; $this.html(html); $this.find(".allcontent").hide(); // Hide all text $('.shortcontent p:last', $this).css('margin-bottom', 0); //Remove bottom margin on last paragraph as it's likely shortened