Created
May 31, 2014 04:18
-
-
Save liddiard/0b78adaeea11bf309704 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($) { | |
/*! | |
A very simplified version of: | |
Name: Reading Time | |
Dependencies: jQuery | |
Author: Michael Lynch | |
Author URL: http://michaelynch.com | |
Date Created: August 14, 2013 | |
Date Updated: January 24, 2014 | |
Licensed under the MIT license | |
*/ | |
$.fn.readingTime = function(selector) { | |
//return if no element was bound | |
//so chained events can continue | |
if(!this.length) { | |
return this; | |
} | |
//define element | |
var el = $(this); | |
// words per minute | |
var wpm = 270; | |
// calculate the reading time | |
var reading_time = Math.round(el.text().split(' ').length / wpm); | |
// don't display anything if reading time is less that 30 secs | |
if (reading_time < 1) | |
return this; | |
else | |
$(selector).html(reading_time + ' min. read – '); | |
} | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment