Skip to content

Commit

Permalink
Added startOpen option to prevent immediate truncation
Browse files Browse the repository at this point in the history
The default behavior is to truncate the text immediately on
initialization.
  • Loading branch information
kmark committed Nov 8, 2013
1 parent b548053 commit 5df32ec
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
13 changes: 9 additions & 4 deletions readmore.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
lessLink: '<a href="#">Close</a>',
embedCSS: true,
sectionCSS: 'display: block; width: 100%;',
startOpen: false,

// callbacks
beforeToggle: function(){},
Expand Down Expand Up @@ -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});
});
},

Expand Down

0 comments on commit 5df32ec

Please sign in to comment.