Skip to content

Commit

Permalink
Generate v0.2.8
Browse files Browse the repository at this point in the history
  • Loading branch information
zenorocha committed Apr 30, 2013
1 parent 4d96358 commit 55cb984
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 43 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ Also remember to follow [jQuery's Code Style](http://contribute.jquery.org/style

## History

* v0.2.8 April 30, 2013
* Follow jQuery's core style guide
* v0.2.7 April 29, 2013
* Code refactoring
* Follow jQuery's core style guide
* Upgrade Grunt from v0.3 to v0.4
* v0.2.6 March 14, 2013
* Updated to responsive design
Expand Down
78 changes: 39 additions & 39 deletions dist/jquery.github.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* jQuery Github - v0.2.7
* jQuery Github - v0.2.8
* A jQuery plugin to display your Github Repositories.
* https://github.com/zenorocha/jquery-github/
*
Expand All @@ -18,10 +18,10 @@
var self = this;

self.element = element;
self.$container = $(element);
self.repo = self.$container.attr("data-repo");
self.$container = $( element );
self.repo = self.$container.attr( "data-repo" );

self.options = $.extend( {}, defaults, options) ;
self.options = $.extend( {}, defaults, options ) ;

self._defaults = defaults;
self._name = pluginName;
Expand All @@ -34,82 +34,82 @@
var self = this,
cached = self.getCache();

if (cached !== null) {
self.applyTemplate(JSON.parse(cached));
if ( cached !== null ) {
self.applyTemplate( JSON.parse( cached ) );
}
else {
self.requestData(self.repo);
self.requestData( self.repo );
}
};

// Apply results to HTML template
Plugin.prototype.applyTemplate = function (repo) {
Plugin.prototype.applyTemplate = function ( repo ) {
var self = this,
$widget = self.parseTemplate(repo);
$widget = self.parseTemplate( repo );

$widget.appendTo(self.$container);
$widget.appendTo( self.$container );
};

// Stores repostories in sessionStorage if available
Plugin.prototype.cacheResults = function (result_data) {
Plugin.prototype.cacheResults = function ( result_data ) {
var self = this;

// Cache data
if (window.sessionStorage) {
window.sessionStorage.setItem("gh-repos:" + self.repo, JSON.stringify(result_data));
if ( window.sessionStorage ) {
window.sessionStorage.setItem( "gh-repos:" + self.repo, JSON.stringify( result_data ) );
}
};

// Grab cached results
Plugin.prototype.getCache = function () {
Plugin.prototype.getCache = function() {
var self = this;

if (window.sessionStorage) {
return window.sessionStorage.getItem("gh-repos:" + self.repo);
if ( window.sessionStorage ) {
return window.sessionStorage.getItem( "gh-repos:" + self.repo );
}
else {
return false;
}
};

// Handle Errors requests
Plugin.prototype.handlerErrorRequests = function (result_data) {
Plugin.prototype.handlerErrorRequests = function ( result_data ) {
var self = this;

console.warn(result_data.message);
console.warn( result_data.message );
return;
};

// Handle Successful request
Plugin.prototype.handlerSuccessfulRequest = function (result_data) {
Plugin.prototype.handlerSuccessfulRequest = function ( result_data ) {
var self = this;

self.applyTemplate(result_data);
self.cacheResults(result_data);
self.applyTemplate( result_data );
self.cacheResults( result_data );
};

// Parses Pushed date with date format
Plugin.prototype.parsePushedDate = function (pushed_at) {
Plugin.prototype.parsePushedDate = function ( pushed_at ) {
var self = this,
date = new Date(pushed_at);
date = new Date( pushed_at );

return date.getDate() + "/" + (date.getMonth() + 1) + "/" + date.getFullYear();
return date.getDate() + "/" + ( date.getMonth() + 1 ) + "/" + date.getFullYear();
};

// Parses repository URL to be friendly
Plugin.prototype.parseRepositoryURL = function (url) {
Plugin.prototype.parseRepositoryURL = function ( url ) {
var self = this;

return url.replace("api.","").replace("repos/","");
return url.replace( "api.", "" ).replace( "repos/", "" );
};

// Parses HTML template
Plugin.prototype.parseTemplate = function (repo) {
Plugin.prototype.parseTemplate = function ( repo ) {
var self = this,
pushed_at = self.parsePushedDate(repo.pushed_at),
repo_url = self.parseRepositoryURL(repo.url);
pushed_at = self.parsePushedDate( repo.pushed_at ),
repo_url = self.parseRepositoryURL( repo.url );

return $($.parseHTML(" \
return $( $.parseHTML(" \
<div class='github-box'> \
<div class='github-box-header'> \
<h3> \
Expand All @@ -128,36 +128,36 @@
<a class='repo-download' href='" + repo_url + "'/zipball/master'>Download as zip</a> \
</div> \
</div> \
"));
") );
};

// Request repositories from Github
Plugin.prototype.requestData = function (repo) {
Plugin.prototype.requestData = function ( repo ) {
var self = this;

$.ajax({
url: "https://api.github.com/repos/" + repo,
dataType: "jsonp",
success: function(results) {
success: function( results ) {
var result_data = results.data;

// Handle API failures
if (results.meta.status >= 400 && result_data.message) {
if ( results.meta.status >= 400 && result_data.message ) {
self.handlerErrorRequest();
}
else {
self.handlerSuccessfulRequest(result_data);
self.handlerSuccessfulRequest( result_data );
}
}
});
};

$.fn[pluginName] = function ( options ) {
$.fn[ pluginName ] = function ( options ) {
return this.each(function () {
if (!$.data(this, "plugin_" + pluginName)) {
$.data(this, "plugin_" + pluginName, new Plugin( this, options ));
if ( !$.data( this, "plugin_" + pluginName ) ) {
$.data( this, "plugin_" + pluginName, new Plugin( this, options ) );
}
});
};

}(jQuery, window));
}( jQuery, window ) );
2 changes: 1 addition & 1 deletion dist/jquery.github.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion github.jquery.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"repositories",
"git"
],
"version": "0.2.5",
"version": "0.2.8",
"author": {
"name": "Zeno Rocha",
"url": "https://github.com/zenorocha"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "A jQuery plugin to display your Github Repositories.",
"author": "Zeno Rocha",
"homepage": "https://github.com/zenorocha/jquery-github/",
"version": "0.2.7",
"version": "0.2.8",
"devDependencies": {
"grunt": "~0.4.1",
"grunt-cli": "~0.1.7",
Expand Down

0 comments on commit 55cb984

Please sign in to comment.