Skip to content

Commit daf9360

Browse files
committed
Merge pull request #11 from ndimatteo/master
account for content wrapped in <p> tags & various fixes
2 parents c84a815 + bcae71d commit daf9360

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

src/jquery.shorten.js

+13-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
2-
* jQuery Shorten plugin 1.0.0
2+
* jQuery Shorten plugin 1.1.0
33
*
4-
* Copyright (c) 2013 Viral Patel
4+
* Copyright (c) 2014 Viral Patel
55
* http://viralpatel.net
66
*
77
* Licensed under the MIT license:
@@ -20,11 +20,11 @@
2020
$.fn.shorten = function (settings) {
2121

2222
"use strict";
23-
if ($(this).data('jquery.shorten')){
24-
return false;
25-
}
26-
$(this).data('jquery.shorten', true);
27-
23+
if ($(this).data('jquery.shorten')){
24+
return false;
25+
}
26+
$(this).data('jquery.shorten', true);
27+
2828
var config = {
2929
showChars: 100,
3030
ellipsesText: "...",
@@ -124,15 +124,16 @@
124124
}
125125
}
126126
}
127-
c = bag;
127+
c = $('<div/>').html(bag + '<span class="ellip">' + config.ellipsesText + '</span>').html();
128128
}
129129

130-
var html = '<span class="shortcontent">' + c + '&nbsp;' + config.ellipsesText +
131-
'</span><span class="allcontent">' + content +
132-
'</span>&nbsp;&nbsp;<span><a href="javascript://nop/" class="morelink">' + config.moreText + '</a></span>';
130+
var html = '<div class="shortcontent">' + c +
131+
'</div><div class="allcontent">' + content +
132+
'</div><span><a href="javascript://nop/" class="morelink">' + config.moreText + '</a></span>';
133133

134134
$this.html(html);
135-
$this.find(".allcontent").hide(); // Esconde el contenido completo para todos los textos
135+
$this.find(".allcontent").hide(); // Hide all text
136+
$('.shortcontent p:last', $this).css('margin-bottom',0); //Remove bottom margin on last paragraph as it's likely shortened
136137
}
137138
});
138139

0 commit comments

Comments
 (0)