mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
1 line
6.8 KiB
JavaScript
1 line
6.8 KiB
JavaScript
|
(function(){var Button,ButtonElement,Config,CountElement,Iframe,QueryString,link,links,_i,_len;if(Config={api:"https://api.github.com",buttonClass:"github-button",iconClass:"octicon",icon:"octicon-mark-github",scriptId:"github-bjs",styles:["default","mega"]},(Config.script=document.getElementById(Config.scriptId))&&(Config.url=Config.script.src.replace(/buttons.js$/,"")),QueryString=function(){function QueryString(){}return QueryString.stringify=function(obj){var key,results,value;results=[];for(key in obj)value=obj[key],null==value&&(value=""),results.push(""+encodeURIComponent(key)+"="+encodeURIComponent(value));return results.join("&")},QueryString.parse=function(str){var obj,pair,_i,_len,_ref;for(obj={},_ref=str.split("&"),_i=0,_len=_ref.length;_len>_i;_i++)pair=_ref[_i],obj[decodeURIComponent(pair.split("=")[0])]=decodeURIComponent(pair.split("=").slice(1).join("="));return obj},QueryString}(),Iframe=function(){function Iframe(callback){var key,value,_ref,_ref1;this.iframe=document.createElement("iframe"),_ref={allowtransparency:!0,scrolling:"no",frameBorder:0};for(key in _ref)value=_ref[key],this.iframe.setAttribute(key,value);_ref1={border:"none",height:"0",width:"1px"};for(key in _ref1)value=_ref1[key],this.iframe.style[key]=value;callback&&callback(this.iframe)}return Iframe.prototype.on=function(event,func){return this.iframe.addEventListener?this.iframe.addEventListener(""+event,func):this.iframe.attachEvent&&this.iframe.attachEvent("on"+event,func),this},Iframe.prototype.once=function(event,func){var once;return once=function(_this){return function(){_this.iframe.removeEventListener?_this.iframe.removeEventListener(""+event,once):_this.iframe.detachEvent&&_this.iframe.detachEvent("on"+event,once),func()}}(this),this.on(event,once)},Iframe}(),Button=function(){function Button(a){a?(this.data=this.parseAnchor(a),this.iframe=new Iframe(function(iframe){a.parentNode.insertBefore(iframe,a)}),this.iframe.once("load",function(_this){return function(){var body,html,iframe,style;iframe=_this.iframe.iframe,html=iframe.contentWindow.document.documentElement,body=iframe.contentWindow.document.body,html.style.overflow=body.style.overflow="visible",style={height:""+body.scrollHeight+"px",width:""+body.scrollWidth+"px"},html.style.overflow=body.style.overflow="",_this.iframe.once("load",function(){var key,value;a.parentNode.removeChild(a),a=null;for(key in style)value=style[key],iframe.style[key]=value}),iframe.src=""+Config.url+"buttons.html"+_this.hash(_this.data)}}(this)),this.iframe.iframe.contentWindow.document.open(),this.iframe.iframe.contentWindow.document.write(this.html()),this.iframe.iframe.contentWindow.document.close()):(this.data=this.parseHash(),document.body.className=this.data.style,document.getElementsByTagName("base")[0].href=this.data.href,new ButtonElement(this.data,function(buttonElement){document.body.appendChild(buttonElement)}),new CountElement(this.data,function(countElement){document.body.appendChild(countElement)}))}return Button.prototype.parseAnchor=function(a){var filter_js,protocolPattern;return protocolPattern=/^([a-z0-9.+-]+:)/i,filter_js=function(href){var protocol;return protocol=protocolPattern.exec(href),protocol&&"javascript:"===protocol[0].toLowerCase()?"":href},{countApi:function(){var api;return api=a.getAttribute("data-count-api"),api?("/"!==api.charAt(0)&&(api="/"+api),api):null}(),countHref:function(){var href;return href=a.getAttribute("data-count-href"),href&&(href=filter_js(href))?href:filter_js(a.href)}(),href:function(){return filter_js(a.href)}(),style:function(){var i,style,_i,_len,_ref;if(style=a.getAttribute("data-style"))for(_ref=Config.styles,_i=0,_len=_ref.length;_len>_i;_i++)if(i=_ref[_i],i===style)return style;return Config.styles[0]}(),text:a.getAttribute("data-text")||a.textContent||a.innerText,icon:a.getAttribute("data-icon")||Config.icon}},Button.prototype.hash=function(data){return"#"+encodeURIComponent(QueryString.stringify(data))},Button.prototype.parseHash=function(){return QueryString.parse(decodeURIComponent(document.location.hash.replace(/^#/,"")))},Butt
|