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 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/assets/base.css b/assets/base.css deleted file mode 100644 index c7f2641..0000000 --- a/assets/base.css +++ /dev/null @@ -1,159 +0,0 @@ -.github-repos:nth-child(even) .github-box{ - margin-right:0 !important -} - -.github-box{ - font-family:"proxima-nova-1","proxima-nova-2","Helvetica Neue",Arial,sans-serif; - background:#fafafa; - border:1px solid #ddd; - color:#666; - -moz-border-radius:5px; - -webkit-border-radius:5px; - -o-border-radius:5px; - -ms-border-radius:5px; - -khtml-border-radius:5px; - border-radius:5px; - float:left; - margin-right:1.2em; - margin-bottom:2em; - width:46% -} - -.github-box a{ - color:#4183C4; - border:none -} - -.github-box .github-box-title{ - position:relative; - border-bottom:1px solid #ddd; - -moz-border-radius:5px 5px 0 0; - -webkit-border-radius:5px 5px 0 0; - -o-border-radius:5px 5px 0 0; - -ms-border-radius:5px 5px 0 0; - -khtml-border-radius:5px 5px 0 0; - border-radius:5px 5px 0 0; - background:#fcfcfc; - background:-moz-linear-gradient(#fcfcfc, #ebebeb); - background:-webkit-linear-gradient(#fcfcfc, #ebebeb); - -ms-filter:"progid:DXImageTransform.Microsoft.gradient(startColorstr='#fcfcfc',endColorstr='#ebebeb')" -} - -.github-box .github-box-title h3{ - font-family:helvetica,arial,sans-serif;font-weight:normal; - font-size:16px; - color:gray; - margin:0; - padding:10px 10px 10px 10px -} - -.github-box .github-box-title h3 .repo{ - font-weight:bold -} - -.github-box .github-box-title .github-stats{ - position:absolute; - top:10px; - right:10px; - background:white; - border:1px solid #ddd; - border-radius:3px; - font-size:11px; - font-weight:bold; - line-height:21px; - height:21px -} - -.github-box .github-box-title .github-stats a{ - display:inline-block; - height:21px; - color:#666; - padding:0 5px 0 18px; - background:url('btn-sprite.png') no-repeat; - filter:progid:DXImageTransform.Microsoft.Alpha(Opacity=70); - opacity:0.7 -} - -.github-box .github-box-title .github-stats a:hover{ - filter:progid:DXImageTransform.Microsoft.Alpha(Opacity=100); - opacity:1 -} - -.github-box .github-box-title .github-stats .watchers{ - border-right:1px solid #ddd; - background-position:3px 4px -} - -.github-box .github-box-title .github-stats .forks{ - background-position: 2px -14px; - padding-left:15px -} - -.github-box .github-box-content{ - padding:10px; - font-weight:300; - font-size:0.7em -} - -.github-box .github-box-content p{ - margin:0 -} - -.github-box .github-box-content .link{ - font-weight:bold -} - -.github-box .github-box-download{ - position:relative; - border-top:1px solid #ddd; - background:white; - border-radius:0 0 3px 3px; - padding:10px; - height:24px -} - -.github-box .github-box-download .updated{ - margin:0; - font-size:11px; - color:#666; - line-height:24px -} - -.github-box .github-box-download .updated strong{ - font-size:12px; - font-weight:bold; - color:#000 -} - -.github-box .github-box-download .download{ - position:absolute; - display:block; - top:10px; - right:10px; - height:24px; - line-height:24px; - font-size:12px; - color:#666; - font-weight:bold; - text-shadow:0 1px 0 rgba(255,255,255,0.9); - padding:0 10px; - border:1px solid #ddd; - border-bottom-color:#bbb; - border-radius:3px; - display:block; - text-indent:-9999px; - width:24px; - padding:0; - background: url('btn-sprite.png') no-repeat 4px -31px,-webkit-linear-gradient(whiteSmoke, #E5E5E5); - background:url('btn-sprite.png') no-repeat 4px -31px,-moz-linear-gradient(#f1f7fa, #dbeaf1); - filter:progid:DXImageTransform.Microsoft.Alpha(Opacity=70); - opacity:0.7 -} - -.github-box .github-box-download .download:hover{ - color:#527894; - border-color:#cfe3ed; - border-bottom-color:#9fc7db; - filter:progid:DXImageTransform.Microsoft.Alpha(Opacity=100); - opacity:1 -} \ No newline at end of file diff --git a/demo/css/style.css b/css/style.css similarity index 94% rename from demo/css/style.css rename to css/style.css index 8ebc404..6789118 100644 --- a/demo/css/style.css +++ b/css/style.css @@ -1,5 +1,5 @@ body { - background: #Ffffff; + background:#F8F8F8 url('../img/bg-noise.png') top left; } a { @@ -36,6 +36,7 @@ h1 { margin: 0 auto; width: 700px; text-align: center; + clear: both; } #github-logo { @@ -60,10 +61,6 @@ h1 { padding: 30px; } -.link { - display: none; -} - /* Font-face */ @font-face { diff --git a/demo/index.html b/demo/index.html deleted file mode 100644 index 074292c..0000000 --- a/demo/index.html +++ /dev/null @@ -1,45 +0,0 @@ - - - - - - jQuery Github Repos - - - - - - - - - - - - Fork me on GitHub - - -
-

jQuery Github Repos

-

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

-
- -
-
-
-
-
-
- -

Made with love by Zeno Rocha.

- - - - - - - - - - \ No newline at end of file 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/index.html b/index.html new file mode 100644 index 0000000..b5bb964 --- /dev/null +++ b/index.html @@ -0,0 +1,45 @@ + + + + + + jQuery Github + + + + + + + + + + + + Fork me on GitHub + + +
+

jQuery Github

+

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

+
+ +
+
+
+
+
+
+ +

Made with love by Zeno Rocha.

+ + + + + + + + + + \ No newline at end of file diff --git a/jquery.github.repos.js b/jquery.github.repos.js deleted file mode 100644 index 2fbdd92..0000000 --- a/jquery.github.repos.js +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Project: jQuery Github Repos - * Description: A jQuery plugin to display your Github Repositories. - * Author: Zeno Rocha - * License: MIT - */ - -// 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 = 'githubRepos', - 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; - - $.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.name + ' \ -

\ - \ -
\ -
\ -

' + repo.description + ' — Read More

\ - \ -
\ -
\ -

Latest commit to master on ' + pushed_at + '

\ - Download as zip \ -
\ -
\ - '); - - $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 diff --git a/jquery.github.repos.min.js b/jquery.github.repos.min.js deleted file mode 100644 index 9400b36..0000000 --- a/jquery.github.repos.min.js +++ /dev/null @@ -1,9 +0,0 @@ -/* - * jQuery Github Repos v0.3 - * A jQuery plugin to display your Github Repositories. - * - * 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.name+'

'+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 diff --git a/js/assets/base.css b/js/assets/base.css new file mode 100644 index 0000000..fc9bd83 --- /dev/null +++ b/js/assets/base.css @@ -0,0 +1,159 @@ +/* Github Box */ + +.github-box { + font-family: "Helvetica Neue", Arial, sans-serif; + background: #fafafa; + border: 1px solid #ddd; + color: #666; + border-radius: 5px; + float: left; + margin-right: 1.2em; + margin-bottom: 2em; + width: 46%; +} + +.github-box a { + color: #4183C4; + border: none; +} + +/* Github Box Header */ + +.github-box .github-box-header { + position: relative; + border-bottom: 1px solid #ddd; + border-radius: 5px 5px 0 0; + background: #fcfcfc; + background: -moz-linear-gradient(#fcfcfc, #ebebeb); + background: -webkit-linear-gradient(#fcfcfc, #ebebeb); + -ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr='#fcfcfc',endColorstr='#ebebeb')"; +} + +.github-box .github-box-header h3 { + font-family: Helvetica, Arial, sans-serif; + font-weight: normal; + font-size: 16px; + color: gray; + margin: 0; + padding: 10px 10px 10px 10px; +} + +.github-box .github-box-header h3 a { + font-weight: bold +} + +/* Github Box Header - Stats */ + +.github-box .github-box-header .github-stats { + position: absolute; + top: 10px; + right: 10px; + background: white; + border: 1px solid #ddd; + border-radius: 3px; + font-size: 11px; + font-weight: bold; + line-height: 21px; + height: 21px; +} + +.github-box .github-box-header .github-stats a { + display: inline-block; + height: 21px; + color: #666; + padding: 0 5px 0 18px; + background: url('btn-sprite.png') no-repeat; + filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=70); + opacity: 0.7; +} + +.github-box .github-box-header .github-stats a:hover { + filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=100); + opacity: 1; +} + +.github-box .github-box-header .github-stats .repo-stars { + background-position: 2px 3px; +} + +.github-box .github-box-header .github-stats .repo-forks { + background-position: 2px -14px; + padding-left: 15px; +} + +.github-box .github-box-header .github-stats .repo-issues { + background-position: 2px -32px; +} + +/* Github Box Content */ + +.github-box .github-box-content { + padding: 10px; + font-weight: 300; + font-size: 0.7em; +} + +.github-box .github-box-content p { + margin: 0; +} + +.github-box .github-box-content .repo-link { + font-weight: bold; +} + +/* Github Box Download */ + +.github-box .github-box-download { + position: relative; + border-top: 1px solid #ddd; + background: white; + border-radius: 0 0 3px 3px; + padding: 10px; + height: 24px; +} + +.github-box .github-box-download .repo-update { + margin: 0; + font-size: 11px; + color: #666; + line-height: 24px; +} + +.github-box .github-box-download .repo-update strong { + font-size: 12px; + font-weight: bold; + color: #000; +} + +.github-box .github-box-download .repo-download { + position: absolute; + display: block; + top: 10px; + right: 10px; + height: 24px; + line-height: 24px; + font-size: 12px; + color: #666; + font-weight: bold; + text-shadow: 0 1px 0 rgba(255,255,255,0.9); + padding: 0 10px; + border: 1px solid #ddd; + border-bottom-color: #bbb; + border-radius: 3px; + display: block; + text-indent: -9999px; + width: 24px; + padding: 0; + background: url('btn-sprite.png') no-repeat 4px -31px,-webkit-linear-gradient(whiteSmoke, #E5E5E5); + background: url('btn-sprite.png') no-repeat 4px -31px,-moz-linear-gradient(#f1f7fa, #dbeaf1); + filter:progid:DXImageTransform.Microsoft.Alpha(Opacity=70); + opacity: 0.7; +} + +.github-box .github-box-download .repo-download:hover { + color: #527894; + border-color: #cfe3ed; + border-bottom-color: #9fc7db; + filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=100); + opacity: 1; +} diff --git a/assets/btn-sprite.png b/js/assets/btn-sprite.png similarity index 100% rename from assets/btn-sprite.png rename to js/assets/btn-sprite.png diff --git a/js/jquery.github.js b/js/jquery.github.js new file mode 100644 index 0000000..a3e88a1 --- /dev/null +++ b/js/jquery.github.js @@ -0,0 +1,176 @@ +/* + * jquery-github - v0.3.4 + * A jQuery plugin to display your Github Repositories. + * https://github.com/zenorocha/jquery-github + * + * Copyright (c) 2014 + * MIT License + */ +// -- 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 new file mode 100644 index 0000000..3f350b3 --- /dev/null +++ b/js/jquery.github.min.js @@ -0,0 +1,9 @@ +/* + * jquery-github - v0.3.4 + * A jQuery plugin to display your Github Repositories. + * https://github.com/zenorocha/jquery-github + * + * Copyright (c) 2014 + * MIT License + */ +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.name+"

"+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