From 5fab45d7bf8d6203fed25d1173e97dd0737787cd Mon Sep 17 00:00:00 2001 From: Zeno Rocha Date: Sun, 13 Jan 2013 22:20:07 -0300 Subject: [PATCH 01/11] moving demo to root --- {demo/css => css}/style.css | 2 +- {demo/font => font}/Museo_Slab_500-webfont.eot | Bin {demo/font => font}/Museo_Slab_500-webfont.svg | 0 {demo/font => font}/Museo_Slab_500-webfont.ttf | Bin {demo/font => font}/Museo_Slab_500-webfont.woff | Bin {demo/img => img}/bg-noise.png | Bin {demo/img => img}/github-cat.png | Bin {demo/img => img}/github-ribbon.png | Bin demo/index.html => index.html | 4 ++-- {assets => js/assets}/base.css | 0 {assets => js/assets}/btn-sprite.png | Bin jquery.github.repos.js => js/jquery.github.repos.js | 0 .../jquery.github.repos.min.js | 0 13 files changed, 3 insertions(+), 3 deletions(-) rename {demo/css => css}/style.css (95%) rename {demo/font => font}/Museo_Slab_500-webfont.eot (100%) rename {demo/font => font}/Museo_Slab_500-webfont.svg (100%) rename {demo/font => font}/Museo_Slab_500-webfont.ttf (100%) rename {demo/font => font}/Museo_Slab_500-webfont.woff (100%) rename {demo/img => img}/bg-noise.png (100%) rename {demo/img => img}/github-cat.png (100%) rename {demo/img => img}/github-ribbon.png (100%) rename demo/index.html => index.html (92%) rename {assets => js/assets}/base.css (100%) rename {assets => js/assets}/btn-sprite.png (100%) rename jquery.github.repos.js => js/jquery.github.repos.js (100%) rename jquery.github.repos.min.js => js/jquery.github.repos.min.js (100%) diff --git a/demo/css/style.css b/css/style.css similarity index 95% rename from demo/css/style.css rename to css/style.css index 8ebc404..d55c9b8 100644 --- a/demo/css/style.css +++ b/css/style.css @@ -1,5 +1,5 @@ body { - background: #Ffffff; + background:#F8F8F8 url('../img/noise.png') top left; } a { diff --git a/demo/font/Museo_Slab_500-webfont.eot b/font/Museo_Slab_500-webfont.eot similarity index 100% rename from demo/font/Museo_Slab_500-webfont.eot rename to font/Museo_Slab_500-webfont.eot diff --git a/demo/font/Museo_Slab_500-webfont.svg b/font/Museo_Slab_500-webfont.svg similarity index 100% rename from demo/font/Museo_Slab_500-webfont.svg rename to font/Museo_Slab_500-webfont.svg diff --git a/demo/font/Museo_Slab_500-webfont.ttf b/font/Museo_Slab_500-webfont.ttf similarity index 100% rename from demo/font/Museo_Slab_500-webfont.ttf rename to font/Museo_Slab_500-webfont.ttf diff --git a/demo/font/Museo_Slab_500-webfont.woff b/font/Museo_Slab_500-webfont.woff similarity index 100% rename from demo/font/Museo_Slab_500-webfont.woff rename to font/Museo_Slab_500-webfont.woff diff --git a/demo/img/bg-noise.png b/img/bg-noise.png similarity index 100% rename from demo/img/bg-noise.png rename to img/bg-noise.png diff --git a/demo/img/github-cat.png b/img/github-cat.png similarity index 100% rename from demo/img/github-cat.png rename to img/github-cat.png diff --git a/demo/img/github-ribbon.png b/img/github-ribbon.png similarity index 100% rename from demo/img/github-ribbon.png rename to img/github-ribbon.png diff --git a/demo/index.html b/index.html similarity index 92% rename from demo/index.html rename to index.html index 074292c..d2b0712 100644 --- a/demo/index.html +++ b/index.html @@ -6,7 +6,7 @@ jQuery Github Repos - + @@ -35,7 +35,7 @@

jQuery Github Repos

- + diff --git a/js/jquery.github.repos.js b/js/jquery.github.repos.js index 7d12194..eec881e 100644 --- a/js/jquery.github.repos.js +++ b/js/jquery.github.repos.js @@ -1,8 +1,10 @@ /* - * Project: jQuery Github Repos - * Description: A jQuery plugin to display your Github Repositories. - * Author: Zeno Rocha - * License: MIT + * jQuery Github Repos v0.2.2 + * A jQuery plugin to display your Github Repositories. + * http://git.io/3A1RMg + * + * Zeno Rocha + * MIT License */ // the semi-colon before function invocation is a safety net against concatenated @@ -30,6 +32,7 @@ this.element = element; this.$container = $(element); this.repo = this.$container.attr("data-repo"); + this.cached; // jQuery has an extend method which merges the contents of two or // more objects, storing the result in the first object. The first object @@ -45,42 +48,80 @@ Plugin.prototype.init = function () { - var self = this; + var self = this; + var cached; + + // Attempt to get cached repo data + if (window.sessionStorage) { + cached = sessionStorage.getItem('gh-repos:' + this.repo); + } + + if (cached != null) { + self.applyTemplate(JSON.parse(cached)); + } + else { $.ajax({ url: 'https://api.github.com/repos/' + this.repo, dataType: 'jsonp', success: function(results){ - var repo = results.data; - var date = new Date(repo.pushed_at); - var pushed_at = date.getMonth() + '/' + date.getDate() + '/' + date.getFullYear(); - var $widget = $(' \ -
\ - \ -
\ -

' + repo.description + ' — Read More

\ -
\ -
\ -

Latest commit to master on ' + pushed_at + '

\ - Download as zip \ -
\ -
\ - '); - - $widget.appendTo(self.$container); + // Handle API failures + if (results.meta.status >= 400 && results.data.message){ + console.warn(results.data.message); + return; + } + else { - } + self.applyTemplate(results.data); + // Cache data + if (window.sessionStorage) { + sessionStorage.setItem('gh-repos:' + self.repo, JSON.stringify(results.data)); + } + + } + } }); + + } + + }; + + Plugin.prototype.applyTemplate = function (repo) { + + var self = this; + var date = new Date(repo.pushed_at); + var pushed_at = date.getDate() + '/' + (date.getMonth() + 1) + '/' + date.getFullYear(); + + var $widget = $(' \ +
\ + \ +
\ +

' + repo.description + ' — Read More

\ +
\ +
\ +

Latest commit to master on ' + pushed_at + '

\ + Download as zip \ +
\ +
\ + '); + + self.appendTemplate($widget); + + }; + + Plugin.prototype.appendTemplate = function ($widget) { + var self = this; + $widget.appendTo(self.$container); }; // A really lightweight plugin wrapper around the constructor, diff --git a/js/jquery.github.repos.min.js b/js/jquery.github.repos.min.js index 27285ab..04bf8e2 100644 --- a/js/jquery.github.repos.min.js +++ b/js/jquery.github.repos.min.js @@ -1,9 +1,10 @@ /* - * jQuery Github Repos v0.3 + * jQuery Github Repos v0.2.2 * A jQuery plugin to display your Github Repositories. + * http://git.io/3A1RMg * * Zeno Rocha * MIT License */ -(function(a,b,c){function g(b,c){this.element=b,this.$container=a(b),this.repo=this.$container.attr("data-repo"),this.options=a.extend({},f,c),this._defaults=f,this._name=d,this.init()}var d="githubRepos",e=b.document,f={propertyName:"value"};g.prototype.init=function(){var b=this;a.ajax({url:"https://api.github.com/repos/"+this.repo,dataType:"jsonp",success:function(c){var d=c.data,e=new Date(d.pushed_at),f=e.getMonth()+"/"+e.getDate()+"/"+e.getFullYear(),g=a('

'+d.description+' — Read More

Latest commit to master on '+f+'

Download as zip
');g.appendTo(b.$container)}})},a.fn[d]=function(b){return this.each(function(){a.data(this,"plugin_"+d)||a.data(this,"plugin_"+d,new g(this,b))})}})(jQuery,window) \ No newline at end of file +(function(a,b){function g(b,c){this.element=b,this.$container=a(b),this.repo=this.$container.attr("data-repo"),this.cached,this.options=a.extend({},f,c),this._defaults=f,this._name=d,this.init()}var d="githubRepos",f=(b.document,{propertyName:"value"});g.prototype.init=function(){var e,d=this;b.sessionStorage&&(e=sessionStorage.getItem("gh-repos:"+this.repo)),null!=e?d.applyTemplate(JSON.parse(e)):a.ajax({url:"https://api.github.com/repos/"+this.repo,dataType:"jsonp",success:function(a){return a.meta.status>=400&&a.data.message?(console.warn(a.data.message),c):(d.applyTemplate(a.data),b.sessionStorage&&sessionStorage.setItem("gh-repos:"+d.repo,JSON.stringify(a.data)),c)}})},g.prototype.applyTemplate=function(b){var c=this,d=new Date(b.pushed_at),e=d.getDate()+"/"+(d.getMonth()+1)+"/"+d.getFullYear(),f=a('

'+b.description+' — Read More

Latest commit to master on '+e+'

Download as zip
');c.appendTemplate(f)},g.prototype.appendTemplate=function(a){var b=this;a.appendTo(b.$container)},a.fn[d]=function(b){return this.each(function(){a.data(this,"plugin_"+d)||a.data(this,"plugin_"+d,new g(this,b))})}})(jQuery,window); \ No newline at end of file From 1ead7b22a87bed68be82e00049c88976488b2629 Mon Sep 17 00:00:00 2001 From: Zeno Rocha Date: Tue, 15 Jan 2013 20:41:42 -0200 Subject: [PATCH 05/11] fixing noise path --- css/style.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/css/style.css b/css/style.css index 2b5e8e1..6789118 100644 --- a/css/style.css +++ b/css/style.css @@ -1,5 +1,5 @@ body { - background:#F8F8F8 url('../img/noise.png') top left; + background:#F8F8F8 url('../img/bg-noise.png') top left; } a { From c44cf71898a6cd4760cc432e26cfbfcfecb16f6a Mon Sep 17 00:00:00 2001 From: Zeno Rocha Date: Thu, 17 Jan 2013 14:11:44 -0200 Subject: [PATCH 06/11] renaming plugin --- README.md | 56 ------------------- index.html | 16 +++--- ...query.github.repos.js => jquery.github.js} | 10 ++-- js/jquery.github.min.js | 10 ++++ js/jquery.github.repos.min.js | 10 ---- 5 files changed, 23 insertions(+), 79 deletions(-) delete mode 100644 README.md rename js/{jquery.github.repos.js => jquery.github.js} (97%) create mode 100644 js/jquery.github.min.js delete mode 100644 js/jquery.github.repos.min.js diff --git a/README.md b/README.md deleted file mode 100644 index 39f5328..0000000 --- a/README.md +++ /dev/null @@ -1,56 +0,0 @@ -# jQuery Github Repos - -![Github Repo Demonstration](http://f.cl.ly/items/0J1y0o0D461A0T1v1328/Screen%20Shot%202013-01-13%20at%207.32.55%20PM.png) - -## Usage - -Use the `github-widget` class and create an attribute called `data-repo`: - -```html -
-``` - -Include jQuery: - -```html - -``` - -Include this jQuery plugin: - -```html - -``` - -Call the plugin: - -```html - -``` - -And that's it \o/ - -## Contributing - -1. Fork it! -2. Create your feature branch: `git checkout -b my-new-feature` -3. Commit your changes: `git commit -am 'Add some feature'` -4. Push to the branch: `git push origin my-new-feature` -5. Submit a pull request :D - -## History - -* v0.3 January 13, 2013 - * Replaced single images for a sprite - * Added minified version -* v0.2 September 11, 2012 - * Code wrapped into a jQuery plugin - * Demonstration page created -* v0.1 September 10, 2012 - * Initial commit - -## License - -[MIT License](http://zenorocha.mit-license.org/) \ No newline at end of file diff --git a/index.html b/index.html index 2aacd3e..32d59d8 100644 --- a/index.html +++ b/index.html @@ -3,7 +3,7 @@ - jQuery Github Repos + jQuery Github @@ -14,19 +14,19 @@ - + Fork me on GitHub
-

jQuery Github Repos

-

A jQuery plugin to display your favorite Github Repositories.
For more informations, visit our repository.

+

jQuery Github

+

A jQuery plugin to display your favorite Github Repositories.
For more informations, visit our repository.

-
+
@@ -34,11 +34,11 @@

jQuery Github Repos

- - + + diff --git a/js/jquery.github.repos.js b/js/jquery.github.js similarity index 97% rename from js/jquery.github.repos.js rename to js/jquery.github.js index eec881e..f80f06d 100644 --- a/js/jquery.github.repos.js +++ b/js/jquery.github.js @@ -1,7 +1,7 @@ /* - * jQuery Github Repos v0.2.2 + * jQuery Github v0.2.2 * A jQuery plugin to display your Github Repositories. - * http://git.io/3A1RMg + * http://git.io/WUV4_Q * * Zeno Rocha * MIT License @@ -21,7 +21,7 @@ // minified (especially when both are regularly referenced in your plugin). // Create the defaults once - var pluginName = 'githubRepos', + var pluginName = 'github', document = window.document, defaults = { propertyName: "value" @@ -94,7 +94,7 @@ var date = new Date(repo.pushed_at); var pushed_at = date.getDate() + '/' + (date.getMonth() + 1) + '/' + date.getFullYear(); - var $widget = $(' \ + var $widget = $($.parseHTML(' \
\
\

\ @@ -113,7 +113,7 @@ Download as zip \

\
\ - '); + ')); self.appendTemplate($widget); diff --git a/js/jquery.github.min.js b/js/jquery.github.min.js new file mode 100644 index 0000000..5e70f34 --- /dev/null +++ b/js/jquery.github.min.js @@ -0,0 +1,10 @@ +/* + * jQuery Github v0.2.2 + * A jQuery plugin to display your Github Repositories. + * http://git.io/WUV4_Q + * + * Zeno Rocha + * MIT License + */ + +(function(a,b){function g(b,c){this.element=b,this.$container=a(b),this.repo=this.$container.attr("data-repo"),this.cached,this.options=a.extend({},f,c),this._defaults=f,this._name=d,this.init()}var d="github",f=(b.document,{propertyName:"value"});g.prototype.init=function(){var e,d=this;b.sessionStorage&&(e=sessionStorage.getItem("gh-repos:"+this.repo)),null!=e?d.applyTemplate(JSON.parse(e)):a.ajax({url:"https://api.github.com/repos/"+this.repo,dataType:"jsonp",success:function(a){return a.meta.status>=400&&a.data.message?(console.warn(a.data.message),c):(d.applyTemplate(a.data),b.sessionStorage&&sessionStorage.setItem("gh-repos:"+d.repo,JSON.stringify(a.data)),c)}})},g.prototype.applyTemplate=function(b){var c=this,d=new Date(b.pushed_at),e=d.getDate()+"/"+(d.getMonth()+1)+"/"+d.getFullYear(),f=a(a.parseHTML('

'+b.description+' — Read More

Latest commit to master on '+e+'

Download as zip
'));c.appendTemplate(f)},g.prototype.appendTemplate=function(a){var b=this;a.appendTo(b.$container)},a.fn[d]=function(b){return this.each(function(){a.data(this,"plugin_"+d)||a.data(this,"plugin_"+d,new g(this,b))})}})(jQuery,window); \ No newline at end of file diff --git a/js/jquery.github.repos.min.js b/js/jquery.github.repos.min.js deleted file mode 100644 index 04bf8e2..0000000 --- a/js/jquery.github.repos.min.js +++ /dev/null @@ -1,10 +0,0 @@ -/* - * jQuery Github Repos v0.2.2 - * A jQuery plugin to display your Github Repositories. - * http://git.io/3A1RMg - * - * Zeno Rocha - * MIT License - */ - -(function(a,b){function g(b,c){this.element=b,this.$container=a(b),this.repo=this.$container.attr("data-repo"),this.cached,this.options=a.extend({},f,c),this._defaults=f,this._name=d,this.init()}var d="githubRepos",f=(b.document,{propertyName:"value"});g.prototype.init=function(){var e,d=this;b.sessionStorage&&(e=sessionStorage.getItem("gh-repos:"+this.repo)),null!=e?d.applyTemplate(JSON.parse(e)):a.ajax({url:"https://api.github.com/repos/"+this.repo,dataType:"jsonp",success:function(a){return a.meta.status>=400&&a.data.message?(console.warn(a.data.message),c):(d.applyTemplate(a.data),b.sessionStorage&&sessionStorage.setItem("gh-repos:"+d.repo,JSON.stringify(a.data)),c)}})},g.prototype.applyTemplate=function(b){var c=this,d=new Date(b.pushed_at),e=d.getDate()+"/"+(d.getMonth()+1)+"/"+d.getFullYear(),f=a('

'+b.description+' — Read More

Latest commit to master on '+e+'

Download as zip
');c.appendTemplate(f)},g.prototype.appendTemplate=function(a){var b=this;a.appendTo(b.$container)},a.fn[d]=function(b){return this.each(function(){a.data(this,"plugin_"+d)||a.data(this,"plugin_"+d,new g(this,b))})}})(jQuery,window); \ No newline at end of file From d5acc38c8a18904e220704bd75ccd4618078b21e Mon Sep 17 00:00:00 2001 From: Zeno Rocha Date: Fri, 1 Mar 2013 10:51:00 -0300 Subject: [PATCH 07/11] updating to v0.2.5 --- js/jquery.github.js | 11 +++++------ js/jquery.github.min.js | 11 +++++------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/js/jquery.github.js b/js/jquery.github.js index f80f06d..5f2ea58 100644 --- a/js/jquery.github.js +++ b/js/jquery.github.js @@ -1,9 +1,9 @@ /* - * jQuery Github v0.2.2 + * jQuery Github - v0.2.5 * A jQuery plugin to display your Github Repositories. - * http://git.io/WUV4_Q - * - * Zeno Rocha + * https://github.com/zenorocha/jquery-github/ + + * Copyright (c) 2013 * MIT License */ @@ -32,7 +32,6 @@ this.element = element; this.$container = $(element); this.repo = this.$container.attr("data-repo"); - this.cached; // jQuery has an extend method which merges the contents of two or // more objects, storing the result in the first object. The first object @@ -56,7 +55,7 @@ cached = sessionStorage.getItem('gh-repos:' + this.repo); } - if (cached != null) { + if (cached !== null) { self.applyTemplate(JSON.parse(cached)); } else { diff --git a/js/jquery.github.min.js b/js/jquery.github.min.js index 5e70f34..9067633 100644 --- a/js/jquery.github.min.js +++ b/js/jquery.github.min.js @@ -1,10 +1,9 @@ /* - * jQuery Github v0.2.2 + * jQuery Github - v0.2.5 * A jQuery plugin to display your Github Repositories. - * http://git.io/WUV4_Q - * - * Zeno Rocha + * https://github.com/zenorocha/jquery-github/ + + * Copyright (c) 2013 * MIT License */ - -(function(a,b){function g(b,c){this.element=b,this.$container=a(b),this.repo=this.$container.attr("data-repo"),this.cached,this.options=a.extend({},f,c),this._defaults=f,this._name=d,this.init()}var d="github",f=(b.document,{propertyName:"value"});g.prototype.init=function(){var e,d=this;b.sessionStorage&&(e=sessionStorage.getItem("gh-repos:"+this.repo)),null!=e?d.applyTemplate(JSON.parse(e)):a.ajax({url:"https://api.github.com/repos/"+this.repo,dataType:"jsonp",success:function(a){return a.meta.status>=400&&a.data.message?(console.warn(a.data.message),c):(d.applyTemplate(a.data),b.sessionStorage&&sessionStorage.setItem("gh-repos:"+d.repo,JSON.stringify(a.data)),c)}})},g.prototype.applyTemplate=function(b){var c=this,d=new Date(b.pushed_at),e=d.getDate()+"/"+(d.getMonth()+1)+"/"+d.getFullYear(),f=a(a.parseHTML('

'+b.description+' — Read More

Latest commit to master on '+e+'

Download as zip
'));c.appendTemplate(f)},g.prototype.appendTemplate=function(a){var b=this;a.appendTo(b.$container)},a.fn[d]=function(b){return this.each(function(){a.data(this,"plugin_"+d)||a.data(this,"plugin_"+d,new g(this,b))})}})(jQuery,window); \ No newline at end of file +(function(e,t,n){function o(t,n){this.element=t,this.$container=e(t),this.repo=this.$container.attr("data-repo"),this.options=e.extend({},s,n),this._defaults=s,this._name=r,this.init()}var r="github",i=t.document,s={propertyName:"value"};o.prototype.init=function(){var n=this,r;t.sessionStorage&&(r=sessionStorage.getItem("gh-repos:"+this.repo)),r!==null?n.applyTemplate(JSON.parse(r)):e.ajax({url:"https://api.github.com/repos/"+this.repo,dataType:"jsonp",success:function(e){if(e.meta.status>=400&&e.data.message){console.warn(e.data.message);return}n.applyTemplate(e.data),t.sessionStorage&&sessionStorage.setItem("gh-repos:"+n.repo,JSON.stringify(e.data))}})},o.prototype.applyTemplate=function(t){var n=this,r=new Date(t.pushed_at),i=r.getDate()+"/"+(r.getMonth()+1)+"/"+r.getFullYear(),s=e(e.parseHTML('

'+t.description+' — Read More

Latest commit to master on '+i+'

Download as zip
'));n.appendTemplate(s)},o.prototype.appendTemplate=function(e){var t=this;e.appendTo(t.$container)},e.fn[r]=function(t){return this.each(function(){e.data(this,"plugin_"+r)||e.data(this,"plugin_"+r,new o(this,t))})}})(jQuery,window); \ No newline at end of file From ae7e5f032d4c3e33876509710ba1089fa3e2e72d Mon Sep 17 00:00:00 2001 From: Zeno Rocha Date: Mon, 5 Aug 2013 15:22:47 -0300 Subject: [PATCH 08/11] Ignore node_modules --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 496ee2c..91dfed8 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.DS_Store \ No newline at end of file +.DS_Store +node_modules \ No newline at end of file From fad7473333a078ee939bf777cf18dd1af8d6b1ba Mon Sep 17 00:00:00 2001 From: Zeno Rocha Date: Mon, 5 Aug 2013 15:22:54 -0300 Subject: [PATCH 09/11] Fix jQuery Boilerplate project url --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 32d59d8..07cc227 100644 --- a/index.html +++ b/index.html @@ -24,7 +24,7 @@

jQuery Github

-
+
From b688e238795d8383d9757c04522af70eb97af8d7 Mon Sep 17 00:00:00 2001 From: Zeno Rocha Date: Tue, 4 Nov 2014 15:04:44 +0100 Subject: [PATCH 10/11] Regenerate --- index.html | 2 +- js/jquery.github.js | 304 +++++++++++++++++++++++----------------- js/jquery.github.min.js | 10 +- 3 files changed, 178 insertions(+), 138 deletions(-) diff --git a/index.html b/index.html index 07cc227..b5bb964 100644 --- a/index.html +++ b/index.html @@ -34,7 +34,7 @@

jQuery Github

- + diff --git a/js/jquery.github.js b/js/jquery.github.js index 5f2ea58..a3e88a1 100644 --- a/js/jquery.github.js +++ b/js/jquery.github.js @@ -1,136 +1,176 @@ /* - * jQuery Github - v0.2.5 + * jquery-github - v0.3.4 * A jQuery plugin to display your Github Repositories. - * https://github.com/zenorocha/jquery-github/ - - * Copyright (c) 2013 + * https://github.com/zenorocha/jquery-github + * + * Copyright (c) 2014 * MIT License */ - -// the semi-colon before function invocation is a safety net against concatenated -// scripts and/or other plugins which may not be closed properly. -;(function ( $, window, undefined ) { - - // undefined is used here as the undefined global variable in ECMAScript 3 is - // mutable (ie. it can be changed by someone else). undefined isn't really being - // passed in so we can ensure the value of it is truly undefined. In ES5, undefined - // can no longer be modified. - - // window is passed through as local variable rather than global - // as this (slightly) quickens the resolution process and can be more efficiently - // minified (especially when both are regularly referenced in your plugin). - - // Create the defaults once - var pluginName = 'github', - document = window.document, - defaults = { - propertyName: "value" - }; - - // The actual plugin constructor - function Plugin( element, options ) { - this.element = element; - this.$container = $(element); - this.repo = this.$container.attr("data-repo"); - - // jQuery has an extend method which merges the contents of two or - // more objects, storing the result in the first object. The first object - // is generally empty as we don't want to alter the default options for - // future instances of the plugin - this.options = $.extend( {}, defaults, options) ; - - this._defaults = defaults; - this._name = pluginName; - - this.init(); - } - - Plugin.prototype.init = function () { - - var self = this; - var cached; - - // Attempt to get cached repo data - if (window.sessionStorage) { - cached = sessionStorage.getItem('gh-repos:' + this.repo); - } - - if (cached !== null) { - self.applyTemplate(JSON.parse(cached)); - } - else { - - $.ajax({ - url: 'https://api.github.com/repos/' + this.repo, - dataType: 'jsonp', - success: function(results){ - - // Handle API failures - if (results.meta.status >= 400 && results.data.message){ - console.warn(results.data.message); - return; - } - else { - - self.applyTemplate(results.data); - - // Cache data - if (window.sessionStorage) { - sessionStorage.setItem('gh-repos:' + self.repo, JSON.stringify(results.data)); - } - - } - } - }); - - } - - }; - - Plugin.prototype.applyTemplate = function (repo) { - - var self = this; - var date = new Date(repo.pushed_at); - var pushed_at = date.getDate() + '/' + (date.getMonth() + 1) + '/' + date.getFullYear(); - - var $widget = $($.parseHTML(' \ -
\ - \ -
\ -

' + repo.description + ' — Read More

\ -
\ -
\ -

Latest commit to master on ' + pushed_at + '

\ - Download as zip \ -
\ -
\ - ')); - - self.appendTemplate($widget); - - }; - - Plugin.prototype.appendTemplate = function ($widget) { - var self = this; - $widget.appendTo(self.$container); - }; - - // A really lightweight plugin wrapper around the constructor, - // preventing against multiple instantiations - $.fn[pluginName] = function ( options ) { - return this.each(function () { - if (!$.data(this, 'plugin_' + pluginName)) { - $.data(this, 'plugin_' + pluginName, new Plugin( this, options )); - } - }); - }; - -}(jQuery, window)); \ No newline at end of file +// -- Github Repository -------------------------------------------------------- + +function GithubRepo( repo ) { + this.description = repo.description; + this.forks = repo.forks_count; + this.name = repo.name; + this.open_issues = repo.open_issues; + this.pushed_at = repo.pushed_at; + this.url = repo.url; + this.stargazers = repo.stargazers_count; +} + +// Parses HTML template +GithubRepo.prototype.toHTML = function () { + this.pushed_at = this._parsePushedDate( this.pushed_at ), + this.url = this._parseURL( this.url ); + + return $( + "
" + + "
" + + "

" + + "" + this.name + "" + + "

" + + "" + + "
" + + "
" + + "

" + this.description + " — Read More

" + + "
" + + "
" + + "

Latest commit to master on " + this.pushed_at + "

" + + "" + + "
" + + "
"); +}; + +// Parses pushed_at with date format +GithubRepo.prototype._parsePushedDate = function ( pushed_at ) { + var date = new Date( pushed_at ); + + return date.getDate() + "/" + ( date.getMonth() + 1 ) + "/" + date.getFullYear(); +}; + +// Parses URL to be friendly +GithubRepo.prototype._parseURL = function ( url ) { + return url.replace( "api.", "" ).replace( "repos/", "" ); +}; + +// -- Github Plugin ------------------------------------------------------------ + +function Github( element, options ) { + var defaults = { + iconStars: true, + iconForks: true, + iconIssues: false + }; + + this.element = element; + this.$container = $( element ); + this.repo = this.$container.attr( "data-repo" ); + + this.options = $.extend( {}, defaults, options ) ; + + this._defaults = defaults; + + this.init(); + this.displayIcons(); +} + +// Initializer +Github.prototype.init = function () { + var cached = this.getCache(); + + if ( cached !== null ) { + this.applyTemplate( JSON.parse( cached ) ); + return; + } + + this.requestData( this.repo ); +}; + +// Display or hide icons +Github.prototype.displayIcons = function () { + var options = this.options, + $iconStars = $( ".repo-stars" ), + $iconForks = $( ".repo-forks" ), + $iconIssues = $( ".repo-issues" ); + + $iconStars.css( "display", options.iconStars ? "inline-block" : "none" ); + $iconForks.css( "display", options.iconForks ? "inline-block" : "none" ); + $iconIssues.css( "display", options.iconIssues ? "inline-block" : "none" ); +}; + +// Request repositories from Github +Github.prototype.requestData = function ( repo ) { + var that = this; + + $.ajax({ + url: "https://api.github.com/repos/" + repo, + dataType: "jsonp", + success: function( results ) { + var result_data = results.data, + isFailling = results.meta.status >= 400 && result_data.message; + + if ( isFailling ) { + that.handleErrorRequest( result_data ); + return; + } + + that.handleSuccessfulRequest( result_data ); + } + }); +}; + +// Handle Errors requests +Github.prototype.handleErrorRequest = function ( result_data ) { + console.warn( result_data.message ); + return; +}; + +// Handle Successful request +Github.prototype.handleSuccessfulRequest = function ( result_data ) { + this.applyTemplate( result_data ); + this.setCache( result_data ); +}; + +// Stores repostories in sessionStorage if available +Github.prototype.setCache = function ( result_data ) { + // Cache data + if ( window.sessionStorage ) { + window.sessionStorage.setItem( "gh-repos:" + this.repo, JSON.stringify( result_data ) ); + } +}; + +// Grab cached results +Github.prototype.getCache = function() { + if ( window.sessionStorage ) { + return window.sessionStorage.getItem( "gh-repos:" + this.repo ); + } + else { + return false; + } +}; + +// Apply results to HTML template +Github.prototype.applyTemplate = function ( repo ) { + var githubRepo = new GithubRepo( repo ), + $widget = githubRepo.toHTML(); + + $widget.appendTo( this.$container ); +}; + +// -- Attach plugin to jQuery's prototype -------------------------------------- + +;( function ( $, window, undefined ) { + + $.fn.github = function ( options ) { + return this.each(function () { + if ( !$( this ).data( "plugin_github" ) ) { + $( this ).data( "plugin_github", new Github( this, options ) ); + } + }); + }; + +}( window.jQuery || window.Zepto, window ) ); diff --git a/js/jquery.github.min.js b/js/jquery.github.min.js index 9067633..3f350b3 100644 --- a/js/jquery.github.min.js +++ b/js/jquery.github.min.js @@ -1,9 +1,9 @@ /* - * jQuery Github - v0.2.5 + * jquery-github - v0.3.4 * A jQuery plugin to display your Github Repositories. - * https://github.com/zenorocha/jquery-github/ - - * Copyright (c) 2013 + * https://github.com/zenorocha/jquery-github + * + * Copyright (c) 2014 * MIT License */ -(function(e,t,n){function o(t,n){this.element=t,this.$container=e(t),this.repo=this.$container.attr("data-repo"),this.options=e.extend({},s,n),this._defaults=s,this._name=r,this.init()}var r="github",i=t.document,s={propertyName:"value"};o.prototype.init=function(){var n=this,r;t.sessionStorage&&(r=sessionStorage.getItem("gh-repos:"+this.repo)),r!==null?n.applyTemplate(JSON.parse(r)):e.ajax({url:"https://api.github.com/repos/"+this.repo,dataType:"jsonp",success:function(e){if(e.meta.status>=400&&e.data.message){console.warn(e.data.message);return}n.applyTemplate(e.data),t.sessionStorage&&sessionStorage.setItem("gh-repos:"+n.repo,JSON.stringify(e.data))}})},o.prototype.applyTemplate=function(t){var n=this,r=new Date(t.pushed_at),i=r.getDate()+"/"+(r.getMonth()+1)+"/"+r.getFullYear(),s=e(e.parseHTML('

'+t.description+' — Read More

Latest commit to master on '+i+'

Download as zip
'));n.appendTemplate(s)},o.prototype.appendTemplate=function(e){var t=this;e.appendTo(t.$container)},e.fn[r]=function(t){return this.each(function(){e.data(this,"plugin_"+r)||e.data(this,"plugin_"+r,new o(this,t))})}})(jQuery,window); \ No newline at end of file +function GithubRepo(a){this.description=a.description,this.forks=a.forks_count,this.name=a.name,this.open_issues=a.open_issues,this.pushed_at=a.pushed_at,this.url=a.url,this.stargazers=a.stargazers_count}function Github(a,b){var c={iconStars:!0,iconForks:!0,iconIssues:!1};this.element=a,this.$container=$(a),this.repo=this.$container.attr("data-repo"),this.options=$.extend({},c,b),this._defaults=c,this.init(),this.displayIcons()}GithubRepo.prototype.toHTML=function(){return this.pushed_at=this._parsePushedDate(this.pushed_at),this.url=this._parseURL(this.url),$("

"+this.description+" — Read More

Latest commit to master on "+this.pushed_at+"

")},GithubRepo.prototype._parsePushedDate=function(a){var b=new Date(a);return b.getDate()+"/"+(b.getMonth()+1)+"/"+b.getFullYear()},GithubRepo.prototype._parseURL=function(a){return a.replace("api.","").replace("repos/","")},Github.prototype.init=function(){var a=this.getCache();return null!==a?void this.applyTemplate(JSON.parse(a)):void this.requestData(this.repo)},Github.prototype.displayIcons=function(){var a=this.options,b=$(".repo-stars"),c=$(".repo-forks"),d=$(".repo-issues");b.css("display",a.iconStars?"inline-block":"none"),c.css("display",a.iconForks?"inline-block":"none"),d.css("display",a.iconIssues?"inline-block":"none")},Github.prototype.requestData=function(a){var b=this;$.ajax({url:"https://api.github.com/repos/"+a,dataType:"jsonp",success:function(a){var c=a.data,d=a.meta.status>=400&&c.message;return d?void b.handleErrorRequest(c):void b.handleSuccessfulRequest(c)}})},Github.prototype.handleErrorRequest=function(a){console.warn(a.message)},Github.prototype.handleSuccessfulRequest=function(a){this.applyTemplate(a),this.setCache(a)},Github.prototype.setCache=function(a){window.sessionStorage&&window.sessionStorage.setItem("gh-repos:"+this.repo,JSON.stringify(a))},Github.prototype.getCache=function(){return window.sessionStorage?window.sessionStorage.getItem("gh-repos:"+this.repo):!1},Github.prototype.applyTemplate=function(a){var b=new GithubRepo(a),c=b.toHTML();c.appendTo(this.$container)},function(a){a.fn.github=function(b){return this.each(function(){a(this).data("plugin_github")||a(this).data("plugin_github",new Github(this,b))})}}(window.jQuery||window.Zepto,window); \ No newline at end of file From 4603cb26f41485e1023a01cc752ca875112b049a Mon Sep 17 00:00:00 2001 From: Ian Ramos Date: Fri, 29 May 2015 16:01:41 -0300 Subject: [PATCH 11/11] Quick fixes to align repo-* icons. --- js/assets/base.css | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/js/assets/base.css b/js/assets/base.css index c992d35..fc9bd83 100644 --- a/js/assets/base.css +++ b/js/assets/base.css @@ -72,9 +72,8 @@ opacity: 1; } -.github-box .github-box-header .github-stats .repo-watchers { - border-right: 1px solid #ddd; - background-position: 3px 4px; +.github-box .github-box-header .github-stats .repo-stars { + background-position: 2px 3px; } .github-box .github-box-header .github-stats .repo-forks { @@ -82,6 +81,10 @@ padding-left: 15px; } +.github-box .github-box-header .github-stats .repo-issues { + background-position: 2px -32px; +} + /* Github Box Content */ .github-box .github-box-content { @@ -153,4 +156,4 @@ border-bottom-color: #9fc7db; filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=100); opacity: 1; -} \ No newline at end of file +}