Skip to content
This repository has been archived by the owner on Aug 16, 2019. It is now read-only.

Commit

Permalink
add min version
Browse files Browse the repository at this point in the history
  • Loading branch information
maple3142 committed Feb 3, 2018
1 parent 2bc9c88 commit 0136e19
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 26 deletions.
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
root = true

[*]
end_of_line = lf
indent_style = tab
indent_size = 4
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "theme-next-reading-progress",
"version": "1.0.0",
"description": "<h1 align=\"center\">Reading Progress for <a href=\"https://github.com/theme-next\">NexT</a></h1>",
"main": "reading_progress.js",
"scripts": {
"uglify": "uglifyjs --compress --mangle -o reading_progress.min.js -- reading_progress.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/theme-next/theme-next-reading-progress.git"
},
"author": "theme-next",
"license": "MIT",
"bugs": {
"url": "https://github.com/theme-next/theme-next-reading-progress/issues"
},
"homepage": "https://github.com/theme-next/theme-next-reading-progress#readme",
"dependencies": {
"uglify-js": "^3.3.9"
}
}
56 changes: 30 additions & 26 deletions reading_progress.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
(function () {
if (!$('.reading-progress-bar').length) return //no progress bar found
var supportsPassive = false
try {
var opts = Object.defineProperty({}, 'passive', {
get: function () {
supportsPassive = true
}
})
window.addEventListener('test', $.noop, opts)
window.removeEventListener('test', $.noop)
} catch (e) { }
(function() {
if (!$(".reading-progress-bar").length) return; //no progress bar found
var supportsPassive = false;
try {
var opts = Object.defineProperty({}, "passive", {
get: function() {
supportsPassive = true;
}
});
window.addEventListener("test", $.noop, opts);
window.removeEventListener("test", $.noop);
} catch (e) {}

$(document).ready(function () {
var $bar = $('.reading-progress-bar')
window.addEventListener('scroll', function () {
var $win = $(window)
var $post = $('.post-block')
var winmid = $win.scrollTop() + $win.height() / 2 //assume reader will focus on middle of screen(vertical)
var h = winmid - $post.position().top
var percent = Math.round(h / $post.height() * 100)
if (percent < 0) percent = 0
if (percent > 100) percent = 100
$bar.css('width', percent + '%')
}, supportsPassive ? { passive: true } : false)
})
})()
$(document).ready(function() {
var $bar = $(".reading-progress-bar");
window.addEventListener(
"scroll",
function() {
var $win = $(window);
var $post = $(".post-block");
var winmid = $win.scrollTop() + $win.height() / 2; //assume reader will focus on middle of screen(vertical)
var h = winmid - $post.position().top;
var percent = Math.round(h / $post.height() * 100);
if (percent < 0) percent = 0;
if (percent > 100) percent = 100;
$bar.css("width", percent + "%");
},
supportsPassive ? { passive: true } : false
);
});
})();
1 change: 1 addition & 0 deletions reading_progress.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0136e19

Please sign in to comment.