/**
 * The MIT License (MIT)
 * 
 * Copyright (c) 2017 Johannes Runkel (www.jrunkel.de)
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
!function(t,e){function i(e,i){if(this.element=e,this.options=t.extend({},s,i),!this.options.target){var a=t('<div style="position: fixed; top: 0; left: 0; right: 0; height: 2px; background: transparent;"></div>').append('<div style="position: absolute; width: 0%; height: 100%; left: 0; top: 0; background: green;"></div>');t("body").append(a),this.options.target=a.children()}this._default=s,this._name=n,this.lastValue=-1,this.init()}var n="articleProgress",s={target:null,mode:"width",advance:30,circleBg:"#fff",circleFg:"green"};i.prototype.init=function(){var i=this;t(e).on("resize scroll",function(){i.update()}),this.update()},i.prototype.update=function(){var i=t(this.element).eq(0),n=i.offset(),s=t(e).scrollTop(),a=i.height(),o=t(e).height()*this.options.advance/100,r=s-n.top+o<0,c=n.top+a-s-o<0,h=0;c?h=100:r||(h=(s-n.top+o)/a*100)<0&&(h=0),h!==this.lastValue&&(this.lastValue=h,this.change(h))},i.prototype.change=function(e){var i=this.options.mode.split(" "),n=t(this.options.target);for(var s in i){switch(i[s]){case"width":n.css("width",e+"%");break;case"text":n.text(Math.round(e)+"%");break;case"circle":if(100===e)n.css("background-image","none");else{var a=90+360*e/100,o=e<50?"transparent":this.options.circleFg,r=e<50?this.options.circleBg:"transparent";n.css("background-image","linear-gradient("+a+"deg, "+o+" 50%, "+r+" 50%), linear-gradient(90deg, "+this.options.circleBg+" 50%, transparent 50%)")}break;case"progress":n.attr("aria-valuenow",e),n.find("div").css("width",e+"%")}}},t.fn[n]=function(t){return this.each(function(){new i(this,t)})}}(jQuery,window);