diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8d87b1d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules/* diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..afb46bf --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,30 @@ +module.exports = function(grunt) +{ + grunt.initConfig({ + pkg: grunt.file.readJSON('package.json'), + jshint: { + foo: { + src: ['src/<%= pkg.name %>.js'] + } + }, + uglify: { + options: { + banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n' + }, + build: { + src: 'src/<%= pkg.name %>.js', + dest: 'build/<%= pkg.name %>.min.js' + } + }, + watch: { + files: ['src/*.js'], + tasks: ['jshint', 'uglify'] + } + }); + + grunt.loadNpmTasks('grunt-contrib-jshint'); + grunt.loadNpmTasks('grunt-contrib-uglify'); + grunt.loadNpmTasks('grunt-contrib-watch'); + + grunt.registerTask('default', ['jshint', 'uglify']); +}; diff --git a/build/jquery.readtime.min.js b/build/jquery.readtime.min.js new file mode 100644 index 0000000..7ebe640 --- /dev/null +++ b/build/jquery.readtime.min.js @@ -0,0 +1,2 @@ +/*! jquery.readtime 2014-09-03 */ +!function(a){a.fn.readtime=function(b){var c={"class":"readtime",format:"# min read",images:12,wpm:275,wrapper:"time"};return b=a.extend(c,b),this.each(function(){var c=this.textContent||this.innerText||"",d=c.replace(/(^\s*)|(\s*$)/gi,"").replace(/[ ]{2,}/gi," ").replace(/\n /,"\n").split(" ").length,e=d/b.wpm*60;b.images&&(e+=a(this).find("img").length*b.images),e=Math.round(e/60),e=b.format.replace(/#/,e);var f=document.createElement(b.wrapper);a(f).addClass(b.class).html(e).prependTo(a(this))})}}(jQuery); \ No newline at end of file diff --git a/example.html b/examples/index.html similarity index 98% rename from example.html rename to examples/index.html index d3898b9..8e743b2 100644 --- a/example.html +++ b/examples/index.html @@ -17,7 +17,7 @@

Sed sodales arcu metus, sed convallis dolor semper sed. Curabitur consectetur aliquet dignissim. Phasellus eu magna enim. Aliquam varius posuere nibh quis ornare. Sed semper vestibulum nibh et tincidunt. Quisque aliquet lorem eu sapien vulputate, ac ultricies tellus elementum. Phasellus velit velit, mollis sit amet sagittis eu, iaculis a sapien. Praesent sed justo in erat viverra faucibus. Integer in porttitor dui, vel consectetur lorem. Donec dapibus sed sem non feugiat. Curabitur egestas augue vel volutpat rutrum. Quisque ut nisl ut lorem fermentum finibus. Donec ut augue mauris.

- + diff --git a/jquery.readtime.min.js b/jquery.readtime.min.js deleted file mode 100644 index 91e0715..0000000 --- a/jquery.readtime.min.js +++ /dev/null @@ -1,5 +0,0 @@ -/* - The MIT License - http://opensource.org/licenses/MIT - @link https://github.com/joshtronic/jquery.readtime -*/ -(function(b){b.e.h=function(c){c=b.extend({a:"readtime",format:"# min read",b:"time"},c);return this.d(function(){var a=(this.textContent||this.innerText||"").replace(/(^\s*)|(\s*$)/gi,"").replace(/[ ]{2,}/gi," ").replace(/\n /,"\n").split(" ").length/275*60,a=a+12*b(this).find("img").length,a=Math.round(a/60),a=c.format.replace(/#/,a),d=document.createElement(c.b);b(d).c(c.a).f(a).g(b(this))})}})(jQuery); diff --git a/package.json b/package.json new file mode 100644 index 0000000..97bffab --- /dev/null +++ b/package.json @@ -0,0 +1,14 @@ +{ + "name": "jquery.readtime", + "version": "0.2.0", + "repository": { + "type": "git", + "url": "git://github.com/joshtronic/jquery.readme.git" + }, + "devDependencies": { + "grunt": "^0.4.5", + "grunt-contrib-jshint": "^0.10.0", + "grunt-contrib-uglify": "^0.5.1", + "grunt-contrib-watch": "^0.6.1" + } +} diff --git a/jquery.readtime.js b/src/jquery.readtime.js similarity index 84% rename from jquery.readtime.js rename to src/jquery.readtime.js index f85f4d3..0e18c4f 100644 --- a/jquery.readtime.js +++ b/src/jquery.readtime.js @@ -9,7 +9,6 @@ * @license The MIT License - http://opensource.org/licenses/MIT * @link https://github.com/joshtronic/jquery.readtime */ - (function($) { $.fn.readtime = function(options) @@ -18,6 +17,8 @@ var defaults = { class: 'readtime', // Class name of the output element format: '# min read', // # == the number of minutes + images: 12, // Seconds per image, false to disable + wpm: 275, // Words per minute, defaults to average wrapper: 'time' // What the output will be wrapped in }; @@ -34,10 +35,13 @@ .split(' ').length; // Calculates the read time for the words (in seconds) - var time = (words / 275) * 60; + var time = (words / options.wpm) * 60; // Counts any images in the element and adds more time - time += ($(this).find('img').length * 12); + if (options.images) + { + time += ($(this).find('img').length * options.images); + } // Gets us back to minutes and rounds to an integer time = Math.round(time / 60);