summaryrefslogtreecommitdiffstats
path: root/readmore.js
diff options
context:
space:
mode:
authorJed Foster <jed@jedfoster.com>2013-07-24 20:54:29 -0700
committerJed Foster <jed@jedfoster.com>2013-07-24 20:54:29 -0700
commitd2d0cd9b03f8217fdf451d2d7f7d5df25b73853e (patch)
tree9407de9160d089c88d1a51dfcf4226aa013becb1 /readmore.js
parentf7dfa6a9450ff9f9ddffdd41aa900dbbb93400aa (diff)
downloadReadmore.js-d2d0cd9b03f8217fdf451d2d7f7d5df25b73853e.zip
Readmore.js-d2d0cd9b03f8217fdf451d2d7f7d5df25b73853e.tar.gz
Readmore.js-d2d0cd9b03f8217fdf451d2d7f7d5df25b73853e.tar.bz2
Add readmore-js CSS to set overflow and display properties; tweak calculation of heights. Should close #3
Diffstat (limited to 'readmore.js')
-rw-r--r--readmore.js24
1 files changed, 20 insertions, 4 deletions
diff --git a/readmore.js b/readmore.js
index 173a615..590d43e 100644
--- a/readmore.js
+++ b/readmore.js
@@ -13,7 +13,21 @@
maxHeight: 200,
moreLink: '<a href="#">Read More</a>',
lessLink: '<a href="#">Close</a>'
- };
+ },
+
+ styles = '.readmore-js-section { overflow: hidden; display: block; width: 100%; }\
+.readmore-js-toggle { }';
+
+ (function(d,u) {
+ if(d.createStyleSheet) {
+ d.createStyleSheet( u );
+ }
+ else {
+ var css=d.createElement('style');
+ css.appendChild(document.createTextNode(u));
+ d.getElementsByTagName("head")[0].appendChild(css);
+ }
+ }(document, styles));
function Readmore( element, options ) {
this.element = element;
@@ -35,13 +49,15 @@
var current = $(this),
maxHeight = (current.css('max-height').replace(/[^-\d\.]/g, '') > $this.options.maxHeight) ? current.css('max-height').replace(/[^-\d\.]/g, '') : $this.options.maxHeight;
+ current.addClass('readmore-js-section');
+
if(current.css('max-height') != "none") {
current.css("max-height", "none");
}
- current.data("boxHeight", current.height());
+ current.data("boxHeight", current.outerHeight(true));
- if(current.innerHeight() < maxHeight) {
+ if(current.outerHeight(true) < maxHeight) {
// The block is shorter than the limit, so there's no need to truncate it.
return true;
}
@@ -51,7 +67,7 @@
sliderHeight = maxHeight;
- current.css("height", sliderHeight).css("overflow", 'hidden');
+ current.css({height: sliderHeight});
});
},