{"_id":"readmore.js","_rev":"3-d0e39c78f495ef6916e0773a43bd3b7a","name":"readmore.js","description":"A lightweight jQuery plugin for collapsing and expanding long blocks of text with \"Read more\" and \"Close\" links.","dist-tags":{"latest":"2.0.4"},"versions":{"2.0.4":{"name":"readmore.js","version":"2.0.4","description":"A lightweight jQuery plugin for collapsing and expanding long blocks of text with \"Read more\" and \"Close\" links.","main":"readmore.min.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git+https://github.com/jedfoster/Readmore.js.git"},"keywords":["css","jquery","readmore","expand","collapse"],"author":{"name":"Jed Foster","email":"jed@jedfoster.com"},"license":"MIT","bugs":{"url":"https://github.com/jedfoster/Readmore.js/issues"},"homepage":"https://github.com/jedfoster/Readmore.js","devDependencies":{"gulp":"^3.8.10","gulp-rename":"^1.2.0","gulp-uglify":"^1.0.2"},"gitHead":"993189a59999dffe810a7b812ed209f41126a0cf","_id":"readmore.js@2.0.4","_shasum":"2c7ab3e05602dfe14c16dc8ace7ee1b5b9fb3e24","_from":".","_npmVersion":"3.3.6","_nodeVersion":"5.0.0","_npmUser":{"name":"jedfoster","email":"jed@jedfoster.com"},"dist":{"shasum":"2c7ab3e05602dfe14c16dc8ace7ee1b5b9fb3e24","tarball":"https://registry.npmjs.org/readmore.js/-/readmore.js-2.0.4.tgz","integrity":"sha512-ZmvHhd7D1LldCziWK771vddpCP2ovwAXOBP9aG4HRPZAzbSZepBYYw4IPD5wtpezQp7dtDCNF3EjKioIBZUj7w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCdIz42tiNVdFyjZuKY0hHieuLVOEBzbny3/taG5P4OPwIhAP9UiEZ5i8wI7wy3aXbxp3L68pXaapnIJdN5nX2OXCP4"}]},"maintainers":[{"name":"jedfoster","email":"jed@jedfoster.com"}]}},"readme":"# Readmore.js\n\nA smooth, responsive jQuery plugin for collapsing and expanding long blocks of text with \"Read more\" and \"Close\" links.\n\nThe markup Readmore.js requires is so simple, you can probably use it with your existing HTML—there's no need for complicated sets of `div`'s or hardcoded classes, just call `.readmore()` on the element containing your block of text and Readmore.js takes care of the rest. Readmore.js plays well in a responsive environment, too.\n\nReadmore.js is tested with—and supported on—all versions of jQuery greater than 1.9.1. All the \"good\" browsers are supported, as well as IE10+; IE8 & 9 _should_ work, but are not supported and the experience will not be ideal.\n\n\n## Install\n\nInstall Readmore.js with Bower:\n\n```\n$ bower install readmore\n```\n\nThen include it in your HTML:\n\n```html\n<script src=\"/bower_components/readmore/readmore.min.js\"></script>\n```\n\n\n## Use\n\n```javascript\n$('article').readmore();\n```\n\nIt's that simple. You can change the speed of the animation, the height of the collapsed block, and the open and close elements.\n\n```javascript\n$('article').readmore({\n  speed: 75,\n  lessLink: '<a href=\"#\">Read less</a>'\n});\n```\n\n### The options:\n\n* `speed: 100` in milliseconds\n* `collapsedHeight: 200` in pixels\n* `heightMargin: 16` in pixels, avoids collapsing blocks that are only slightly larger than `collapsedHeight`\n* `moreLink: '<a href=\"#\">Read more</a>'`\n* `lessLink: '<a href=\"#\">Close</a>'`\n* `embedCSS: true` insert required CSS dynamically, set this to `false` if you include the necessary CSS in a stylesheet\n* `blockCSS: 'display: block; width: 100%;'` sets the styling of the blocks, ignored if `embedCSS` is `false`\n* `startOpen: false` do not immediately truncate, start in the fully opened position\n* `beforeToggle: function() {}` called after a more or less link is clicked, but *before* the block is collapsed or expanded\n* `afterToggle: function() {}` called *after* the block is collapsed or expanded\n\nIf the element has a `max-height` CSS property, Readmore.js will use that value rather than the value of the `collapsedHeight` option.\n\n### The callbacks:\n\nThe callback functions, `beforeToggle` and `afterToggle`, both receive the same arguments: `trigger`, `element`, and `expanded`.\n\n* `trigger`: the \"Read more\" or \"Close\" element that was clicked\n* `element`: the block that is being collapsed or expanded\n* `expanded`: Boolean; `true` means the block is expanded\n\n#### Callback example:\n\nHere's an example of how you could use the `afterToggle` callback to scroll back to the top of a block when the \"Close\" link is clicked.\n\n```javascript\n$('article').readmore({\n  afterToggle: function(trigger, element, expanded) {\n    if(! expanded) { // The \"Close\" link was clicked\n      $('html, body').animate( { scrollTop: element.offset().top }, {duration: 100 } );\n    }\n  }\n});\n```\n\n### Removing Readmore:\n\nYou can remove the Readmore.js functionality like so:\n\n```javascript\n$('article').readmore('destroy');\n```\n\nOr, you can be more surgical by specifying a particular element:\n\n```javascript\n$('article:first').readmore('destroy');\n```\n\n### Toggling blocks programmatically:\n\nYou can toggle a block from code:\n\n```javascript\n$('article:nth-of-type(3)').readmore('toggle');\n```\n\n\n## CSS:\n\nReadmore.js is designed to use CSS for as much functionality as possible: collapsed height can be set in CSS with the `max-height` property; \"collapsing\" is achieved by setting `overflow: hidden` on the containing block and changing the `height` property; and, finally, the expanding/collapsing animation is done with CSS3 transitions.\n\nBy default, Readmore.js inserts the following CSS, in addition to some transition-related rules:\n\n```css\nselector + [data-readmore-toggle], selector[data-readmore] {\n  display: block;\n  width: 100%;\n}\n```\n\n_`selector` would be the element you invoked `readmore()` on, e.g.: `$('selector').readmore()`_\n\nYou can override the base rules when you set up Readmore.js like so:\n\n```javascript\n$('article').readmore({blockCSS: 'display: inline-block; width: 50%;'});\n```\n\nIf you want to include the necessary styling in your site's stylesheet, you can disable the dynamic embedding by setting `embedCSS` to `false`:\n\n```javascript\n$('article').readmore({embedCSS: false});\n```\n\n### Media queries and other CSS tricks:\n\nIf you wanted to set a `maxHeight` based on lines, you could do so in CSS with something like:\n\n```css\nbody {\n  font: 16px/1.5 sans-serif;\n}\n\n/* Show only 4 lines in smaller screens */\narticle {\n  max-height: 6em; /* (4 * 1.5 = 6) */\n}\n```\n\nThen, with a media query you could change the number of lines shown, like so:\n\n```css\n/* Show 8 lines on larger screens */\n@media screen and (min-width: 640px) {\n  article {\n    max-height: 12em;\n  }\n}\n```\n\n\n## Contributing\n\nPull requests are always welcome, but not all suggested features will get merged. Feel free to contact me if you have an idea for a feature.\n\nPull requests should include the minified script and this readme and the demo HTML should be updated with descriptions of your new feature. \n\nYou'll need NPM:\n\n```\n$ npm install\n```\n\nWhich will install the necessary development dependencies. Then, to build the minified script:\n\n```\n$ gulp compress\n```\n\n","maintainers":[{"name":"jedfoster","email":"jed@jedfoster.com"}],"time":{"modified":"2022-06-26T09:19:41.580Z","created":"2015-11-01T02:22:32.879Z","2.0.4":"2015-11-01T02:22:32.879Z"},"homepage":"https://github.com/jedfoster/Readmore.js","keywords":["css","jquery","readmore","expand","collapse"],"repository":{"type":"git","url":"git+https://github.com/jedfoster/Readmore.js.git"},"author":{"name":"Jed Foster","email":"jed@jedfoster.com"},"bugs":{"url":"https://github.com/jedfoster/Readmore.js/issues"},"license":"MIT","readmeFilename":"README.md"}