diff options
author | Kevin Mark <kmark937@gmail.com> | 2013-11-08 03:01:22 -0500 |
---|---|---|
committer | Kevin Mark <kmark937@gmail.com> | 2013-11-08 03:01:22 -0500 |
commit | 5df32ecd0351c86410e142bb987218beca5b8b29 (patch) | |
tree | 2f14c64e9238e297a2732589b6d5f236a4f3ba32 | |
parent | b548053d9ab41688a5d559cecf3e9e951be3ba19 (diff) | |
download | Readmore.js-5df32ecd0351c86410e142bb987218beca5b8b29.zip Readmore.js-5df32ecd0351c86410e142bb987218beca5b8b29.tar.gz Readmore.js-5df32ecd0351c86410e142bb987218beca5b8b29.tar.bz2 |
Added startOpen option to prevent immediate truncation
The default behavior is to truncate the text immediately on
initialization.
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | readmore.js | 13 |
2 files changed, 10 insertions, 4 deletions
@@ -26,6 +26,7 @@ Yes, it's that simple. You can change the speed of the animation, the height of * `lessLink: '<a href="#">Close</a>'` * `embedCSS: true` (insert required CSS dynamically, set this to `false` if you include the necessary CSS in a stylesheet) * `sectionCSS: 'display: block; width: 100%;'` (sets the styling of the blocks, ignored if `embedCSS` is `false`) +* `startOpen: false` (do not immediately truncate, start in the fully opened position) * `beforeToggle: function() {}` (called after a more or less link is clicked, but *before* the block is collapsed or expanded) * `afterToggle: function() {}` (called *after* the block is collapsed or expanded) diff --git a/readmore.js b/readmore.js index a6baf9c..3bdb597 100644 --- a/readmore.js +++ b/readmore.js @@ -15,6 +15,7 @@ lessLink: '<a href="#">Close</a>', embedCSS: true, sectionCSS: 'display: block; width: 100%;', + startOpen: false, // callbacks beforeToggle: function(){}, @@ -77,12 +78,16 @@ return true; } else { - current.after($($this.options.moreLink).on('click', function(event) { $this.toggleSlider(this, current, event) }).addClass('readmore-js-toggle')); - } + current.data('sliderHeight', maxHeight); + + var useLink = $this.options.startOpen ? $this.options.lessLink : $this.options.moreLink; + current.after($(useLink).on('click', function(event) { $this.toggleSlider(this, current, event) }).addClass('readmore-js-toggle')); - current.data('sliderHeight', maxHeight); + if(!useLink) { + current.css({height: maxHeight}); + } + } - current.css({height: maxHeight}); }); }, |