forked from ricardobeat/github-repos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub-repos.min.js
7 lines (7 loc) · 2.13 KB
/
github-repos.min.js
1
2
3
4
5
6
7
/*
* Project: GitHub Repo Widget
* Description: A widget to display your Github Repositories.
* Author: Ricardo Tomasi
* License: MIT
* Forked from github.com/zenorocha/jquery-github-repos
*/(function(){function f(a,b){this.repo=a,this.callback=e(this,this.ready),this.target=b}function e(a,b){var d="GHWidgetLoaded"+ ++c;window[d]=function(c){b.call(a,c),delete window[d]};return d}function b(a,b){return a.replace(/\{\{(\w+)\}\}/g,function(a,c){return b[c]})}function a(a){return a<10?"0"+a:a}var c=0,d='<div class="github-box-header">\n <h3><a href="{{url}}">{{name}}</a></h3>\n <div class="github-stats">\n <a class="repo-watchers" href="{{url}}/watchers">{{watchers}}</a>\n <a class="repo-forks" href="{{url}}/forks">{{forks}}</a>\n </div>\n</div>\n<div class="github-box-content">\n <p>{{description}} — <a href="{{url}}#readme">Read More</a></p>\n</div>\n<div class="github-box-download">\n <p class="repo-update">Latest commit to <strong>master</strong> on {{pushed_at}}</p>\n <a class="repo-download" href="{{url}}/zipball/master">Download as zip</a>\n</div>';f.prototype.load=function(){var a,b;window.sessionStorage&&(a=sessionStorage["gh-repos:"+this.repo])?window[this.callback](JSON.parse(a)):(b=document.createElement("script"),b.async=!0,b.src="https://api.github.com/repos/"+this.repo+"?callback="+this.callback,document.body.appendChild(b))},f.prototype.ready=function(c){if(c.meta.status>=400&&c.data.message)console.warn(c.data.message);else{window.sessionStorage&&(sessionStorage["gh-repos:"+this.repo]=JSON.stringify(c));var e=c.data,f=new Date(e.pushed_at),g=f.getMonth()+1,h=f.getDate(),i=f.getFullYear();e.pushed_at=a(g)+"/"+a(h)+"/"+i,e.repo_url="//github.com/"+this.repo;var j=document.createElement("div");j.className="github-box",j.innerHTML=b(d,e),this.target&&this.target.parentNode.replaceChild(j,this.target);return j}};var g={create:function(a){var b=document.querySelectorAll(a),c=Array.prototype.slice.call(b,0);c.forEach(function(a){var b=a.dataset&&a.dataset.repo||a.href.split("/").slice(-2).join("/");(new f(b,a)).load()})},Repo:f};typeof exports!="undefined"?exports=g:window.GHRepos=g})()