Ver. 1.1
A small but versatile jQuery plugin that allows you to truncate specific sections of your content and then creates a link to toggle the full content.
(c) 2016 David Whitworth (david@whitworth.de)
Released under the GNU General Public License (GPL)
1. Include the advanced-read-more.min.css in the head:
2. Include jQuery followed by advanced-read-more.min.js in the head:
3. Initialize the plugin below the included scripts:
Or with custom options (the options below are used in this ReadMe's Demo):
In order for the plugin to effect any sections, you need to add the class "jrm-truncate" to them:
If you want to define a number of preview lines to any section that differs from the one you set in the options, you can use the data-lines attribute. This will overwrite the value of the showLines option:
See Demo 2.
If you want a certain section's preview to contain it's whole first paragraph (<p>) no matter how many lines it has, you can set the data-lines attribute to "-1". This will ignore the showLines option for that section:
If you want a specific section to have no toggle link, have a toggle link or only have a toggle link until it's clicked, you can use the data-linking attribute. The possibilities match the linking option:
See Demo 2 for data-linking="open only".
If you want a specific section's toggle link to have a different caption, you can use the data-link-caption and data-link-closecaption attributes. This will overwrite the value of the linkCaption and linkCloseCaption options:
See Demo 2.
You can also set the duration of the animation individually for each section by using the data-duration attribute:
See Demo 2.
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
Fixes:
Removed a misplaced placeholder item.
In order for the line-height to be calculated correctly in all browsers (AjRM v1.0.1), a placeholder element was created within each section but wasn't correctly removed afterwards, resulting in a superfluous empty line of text.
New Features:
Added option linking.
It is now possible to control whether the "read more" and/or "read less" links should be created.
Added several data-attributes.
The options linking and animationSpeed can now individually be overwritten by adding the data-linking and data-duration attributes to the sections.
Fixes:
Changed the way the line-height is calculated because it wasn't working in most browsers.
Most browsers didn't return a value for the line-height but 'NaN' if no line-height was specified (i.e. automatic values). Becuase of this, the whole script didn't work in Chrome, Edge, Opera and possibly others.
If you're interested in my other plugins, like the scroll progress tracker used in this ReadMe, feel free to download them from GitHub or JSClasses.org.
If you have any questions, notice any bugs, have issues getting the plugin to work, have an idea for a cool feature to be added, or would like to leave any other kind of feedback, feel free to contact me under David@Whitworth.de
Also, please, feel free to send me links to websites where you used this! ☺