reading-position-indicator
Advanced tools
Comparing version
@@ -0,0 +0,0 @@ module.exports = { |
## Changelog | ||
### 1.0.2 | ||
* Add displayBeforeScroll to configuration | ||
### 1.0.1 | ||
@@ -9,2 +13,1 @@ | ||
* No changes, first version | ||
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.ReadingPositionIndicator=t():e.ReadingPositionIndicator=t()}(this,function(){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var r={};return t.m=e,t.c=r,t.i=function(e){return e},t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=3)}([function(e,t,r){"use strict";e.exports=r(1).default},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(){var e=document.createElement("div"),t={transform:"transform",WebkitTransition:"webkitTransform",MsTransform:"msTransform"};for(var r in t)if(void 0!==e.style[r])return t[r];return"transform"}function i(){return window.pageYOffset||document.documentElement.scrollTop||0}function s(){return Math.max(document.documentElement.clientHeight,document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight)}function c(){return Math.max(window.innerHeight,0)}function a(e,t,r){var n;return function(){var o=this,i=arguments,s=function(){n=null,r||e.apply(o,i)},c=r&&!n;clearTimeout(n),n=setTimeout(s,t||200),c&&e.apply(o,i)}}Object.defineProperty(t,"__esModule",{value:!0});var l=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();r(2);var u=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{color:null,percentage:{show:!1,color:null,opacity:null}};n(this,e),this.props=t,this.scroll={maxHeight:1,last_known_scroll_position:0,ticking:!1}}return l(e,[{key:"init",value:function(){var e=this;return this._transformName=o(),this.progressBarContainerEl=document.getElementById("rpi-progress-bar-container"),this.progressBarEl=this.progressBarContainerEl.querySelector(".rpi-progress-bar-container__position"),this.progressBarPercentageEl=this.progressBarContainerEl.querySelector(".rpi-progress-bar-container__percentage"),this.props.color&&(this.progressBarEl.style.background=this.props.color),this.props.percentage&&(this.props.percentage.color&&(this.progressBarPercentageEl.style.color=this.props.percentage.color),this.props.percentage.opacity&&(this.progressBarPercentageEl.style.opacity=this.props.percentage.opacity)),this._onResize=a(function(){e._update()},200),this._update(),this._onScroll=this._onScroll.bind(this),this._onResize=this._onResize.bind(this),window.addEventListener("scroll",this._onScroll),window.addEventListener("resize",this._onResize),this}},{key:"destroy",value:function(){return window.removeEventListener("scroll",this._onScroll),window.removeEventListener("resize",this._onResize),this}},{key:"_update",value:function(){this.scroll.documentHeight=s(),this.scroll.viewHeight=c(),this.scroll.maxHeight=this.scroll.documentHeight-this.scroll.viewHeight,this._updateProgressBar(i())}},{key:"_onScroll",value:function(){var e=this;this.scroll.last_known_scroll_position=i(),this.scroll.ticking||window.requestAnimationFrame(function(){e._updateProgressBar(e.scroll.last_known_scroll_position),e.scroll.ticking=!1}),this.scroll.ticking=!0}},{key:"_updateProgressBar",value:function(e){var t=Math.min(e||0,this.scroll.maxHeight),r=Math.round(100*t/Math.max(this.scroll.maxHeight,1));this.progressBarContainerEl.setAttribute("aria-valuenow",r),this.progressBarEl.style[this._transformName]="scaleX("+r/100+")",this.props.percentage&&this.props.percentage.show&&(this.scroll.viewHeight>=this.scroll.documentHeight?this.progressBarPercentageEl.textContent="":this.progressBarPercentageEl.textContent=r+"%")}}]),e}();t.default=u},function(e,t){},function(e,t,r){e.exports=r(0)}])}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.ReadingPositionIndicator=t():e.ReadingPositionIndicator=t()}(this,function(){return function(e){function t(o){if(r[o])return r[o].exports;var n=r[o]={i:o,l:!1,exports:{}};return e[o].call(n.exports,n,n.exports,t),n.l=!0,n.exports}var r={};return t.m=e,t.c=r,t.i=function(e){return e},t.d=function(e,r,o){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:o})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=3)}([function(e,t,r){"use strict";e.exports=r(1).default},function(e,t,r){"use strict";function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(){var e=document.createElement("div"),t={transform:"transform",WebkitTransition:"webkitTransform",MsTransform:"msTransform"};for(var r in t)if(void 0!==e.style[r])return t[r];return"transform"}function i(){return window.pageYOffset||document.documentElement.scrollTop||0}function s(){return Math.max(document.documentElement.clientHeight,document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight)}function a(){return Math.max(window.innerHeight,0)}function l(e,t,r){var o;return function(){var n=this,i=arguments,s=function(){o=null,r||e.apply(n,i)},a=r&&!o;clearTimeout(o),o=setTimeout(s,t||200),a&&e.apply(n,i)}}Object.defineProperty(t,"__esModule",{value:!0});var c=function(){function e(e,t){for(var r=0;r<t.length;r++){var o=t[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,r,o){return r&&e(t.prototype,r),o&&e(t,o),t}}();r(2);var u=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{color:null,percentage:{show:!1,displayBeforeScroll:!1,color:null,opacity:null}};o(this,e),this.props=t,this.scroll={maxHeight:1,last_known_scroll_position:0,ticking:!1}}return c(e,[{key:"init",value:function(){var e=this;return this._transformName=n(),this.progressBarContainerEl=document.getElementById("rpi-progress-bar-container"),this.progressBarEl=this.progressBarContainerEl.querySelector(".rpi-progress-bar-container__position"),this.progressBarPercentageEl=this.progressBarContainerEl.querySelector(".rpi-progress-bar-container__percentage"),this.props.color&&(this.progressBarEl.style.background=this.props.color),this.props.percentage&&(this.props.percentage.color&&(this.progressBarPercentageEl.style.color=this.props.percentage.color),this.props.percentage.opacity&&(this.progressBarPercentageEl.style.opacity=this.props.percentage.opacity)),this._onResize=l(function(){e._update(),e._updateProgressBar(i())},200),this._update(),this.props.percentage&&this.props.percentage.displayBeforeScroll&&this._updateProgressBar(i()),this._onScroll=this._onScroll.bind(this),this._onResize=this._onResize.bind(this),window.addEventListener("scroll",this._onScroll),window.addEventListener("resize",this._onResize),this}},{key:"destroy",value:function(){return window.removeEventListener("scroll",this._onScroll),window.removeEventListener("resize",this._onResize),this}},{key:"_update",value:function(){this.scroll.documentHeight=s(),this.scroll.viewHeight=a(),this.scroll.maxHeight=this.scroll.documentHeight-this.scroll.viewHeight}},{key:"_onScroll",value:function(){var e=this;this.scroll.last_known_scroll_position=i(),this.scroll.ticking||window.requestAnimationFrame(function(){e._updateProgressBar(e.scroll.last_known_scroll_position),e.scroll.ticking=!1}),this.scroll.ticking=!0}},{key:"_updateProgressBar",value:function(e){var t=Math.min(e||0,this.scroll.maxHeight),r=Math.round(100*t/Math.max(this.scroll.maxHeight,1));this.progressBarContainerEl.setAttribute("aria-valuenow",r),this.progressBarEl.style[this._transformName]="scaleX("+r/100+")",this.props.percentage&&this.props.percentage.show&&(this.scroll.viewHeight>=this.scroll.documentHeight?this.progressBarPercentageEl.textContent="":this.progressBarPercentageEl.textContent=r+"%")}}]),e}();t.default=u},function(e,t){},function(e,t,r){e.exports=r(0)}])}); |
{ | ||
"name": "reading-position-indicator", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Reading position indicator on a webpage", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -0,0 +0,0 @@ # reading position indicator |
@@ -71,2 +71,3 @@ // apply library styling | ||
show: false, | ||
displayBeforeScroll: false, | ||
color: null, | ||
@@ -105,5 +106,9 @@ opacity: null, | ||
this._update(); | ||
this._updateProgressBar(getScrollPosition()); | ||
}, 200); | ||
this._update(); | ||
if (this.props.percentage && this.props.percentage.displayBeforeScroll) { | ||
this._updateProgressBar(getScrollPosition()); | ||
} | ||
@@ -129,3 +134,2 @@ this._onScroll = this._onScroll.bind(this); | ||
this.scroll.maxHeight = this.scroll.documentHeight - this.scroll.viewHeight; | ||
this._updateProgressBar(getScrollPosition()); | ||
} | ||
@@ -132,0 +136,0 @@ |
module.exports = require('./assets/ReadingPositionIndicator').default; |
@@ -0,0 +0,0 @@ /* eslint-disable */ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
309
1.31%2154839
-0.02%