|
1 | 1 | /* |
2 | | - * jQuery Github - v0.2.7 |
| 2 | + * jQuery Github - v0.2.8 |
3 | 3 | * A jQuery plugin to display your Github Repositories. |
4 | 4 | * https://github.com/zenorocha/jquery-github/ |
5 | 5 | * |
|
18 | 18 | var self = this; |
19 | 19 |
|
20 | 20 | self.element = element; |
21 | | - self.$container = $(element); |
22 | | - self.repo = self.$container.attr("data-repo"); |
| 21 | + self.$container = $( element ); |
| 22 | + self.repo = self.$container.attr( "data-repo" ); |
23 | 23 |
|
24 | | - self.options = $.extend( {}, defaults, options) ; |
| 24 | + self.options = $.extend( {}, defaults, options ) ; |
25 | 25 |
|
26 | 26 | self._defaults = defaults; |
27 | 27 | self._name = pluginName; |
|
34 | 34 | var self = this, |
35 | 35 | cached = self.getCache(); |
36 | 36 |
|
37 | | - if (cached !== null) { |
38 | | - self.applyTemplate(JSON.parse(cached)); |
| 37 | + if ( cached !== null ) { |
| 38 | + self.applyTemplate( JSON.parse( cached ) ); |
39 | 39 | } |
40 | 40 | else { |
41 | | - self.requestData(self.repo); |
| 41 | + self.requestData( self.repo ); |
42 | 42 | } |
43 | 43 | }; |
44 | 44 |
|
45 | 45 | // Apply results to HTML template |
46 | | - Plugin.prototype.applyTemplate = function (repo) { |
| 46 | + Plugin.prototype.applyTemplate = function ( repo ) { |
47 | 47 | var self = this, |
48 | | - $widget = self.parseTemplate(repo); |
| 48 | + $widget = self.parseTemplate( repo ); |
49 | 49 |
|
50 | | - $widget.appendTo(self.$container); |
| 50 | + $widget.appendTo( self.$container ); |
51 | 51 | }; |
52 | 52 |
|
53 | 53 | // Stores repostories in sessionStorage if available |
54 | | - Plugin.prototype.cacheResults = function (result_data) { |
| 54 | + Plugin.prototype.cacheResults = function ( result_data ) { |
55 | 55 | var self = this; |
56 | 56 |
|
57 | 57 | // Cache data |
58 | | - if (window.sessionStorage) { |
59 | | - window.sessionStorage.setItem("gh-repos:" + self.repo, JSON.stringify(result_data)); |
| 58 | + if ( window.sessionStorage ) { |
| 59 | + window.sessionStorage.setItem( "gh-repos:" + self.repo, JSON.stringify( result_data ) ); |
60 | 60 | } |
61 | 61 | }; |
62 | 62 |
|
63 | 63 | // Grab cached results |
64 | | - Plugin.prototype.getCache = function () { |
| 64 | + Plugin.prototype.getCache = function() { |
65 | 65 | var self = this; |
66 | 66 |
|
67 | | - if (window.sessionStorage) { |
68 | | - return window.sessionStorage.getItem("gh-repos:" + self.repo); |
| 67 | + if ( window.sessionStorage ) { |
| 68 | + return window.sessionStorage.getItem( "gh-repos:" + self.repo ); |
69 | 69 | } |
70 | 70 | else { |
71 | 71 | return false; |
72 | 72 | } |
73 | 73 | }; |
74 | 74 |
|
75 | 75 | // Handle Errors requests |
76 | | - Plugin.prototype.handlerErrorRequests = function (result_data) { |
| 76 | + Plugin.prototype.handlerErrorRequests = function ( result_data ) { |
77 | 77 | var self = this; |
78 | 78 |
|
79 | | - console.warn(result_data.message); |
| 79 | + console.warn( result_data.message ); |
80 | 80 | return; |
81 | 81 | }; |
82 | 82 |
|
83 | 83 | // Handle Successful request |
84 | | - Plugin.prototype.handlerSuccessfulRequest = function (result_data) { |
| 84 | + Plugin.prototype.handlerSuccessfulRequest = function ( result_data ) { |
85 | 85 | var self = this; |
86 | 86 |
|
87 | | - self.applyTemplate(result_data); |
88 | | - self.cacheResults(result_data); |
| 87 | + self.applyTemplate( result_data ); |
| 88 | + self.cacheResults( result_data ); |
89 | 89 | }; |
90 | 90 |
|
91 | 91 | // Parses Pushed date with date format |
92 | | - Plugin.prototype.parsePushedDate = function (pushed_at) { |
| 92 | + Plugin.prototype.parsePushedDate = function ( pushed_at ) { |
93 | 93 | var self = this, |
94 | | - date = new Date(pushed_at); |
| 94 | + date = new Date( pushed_at ); |
95 | 95 |
|
96 | | - return date.getDate() + "/" + (date.getMonth() + 1) + "/" + date.getFullYear(); |
| 96 | + return date.getDate() + "/" + ( date.getMonth() + 1 ) + "/" + date.getFullYear(); |
97 | 97 | }; |
98 | 98 |
|
99 | 99 | // Parses repository URL to be friendly |
100 | | - Plugin.prototype.parseRepositoryURL = function (url) { |
| 100 | + Plugin.prototype.parseRepositoryURL = function ( url ) { |
101 | 101 | var self = this; |
102 | 102 |
|
103 | | - return url.replace("api.","").replace("repos/",""); |
| 103 | + return url.replace( "api.", "" ).replace( "repos/", "" ); |
104 | 104 | }; |
105 | 105 |
|
106 | 106 | // Parses HTML template |
107 | | - Plugin.prototype.parseTemplate = function (repo) { |
| 107 | + Plugin.prototype.parseTemplate = function ( repo ) { |
108 | 108 | var self = this, |
109 | | - pushed_at = self.parsePushedDate(repo.pushed_at), |
110 | | - repo_url = self.parseRepositoryURL(repo.url); |
| 109 | + pushed_at = self.parsePushedDate( repo.pushed_at ), |
| 110 | + repo_url = self.parseRepositoryURL( repo.url ); |
111 | 111 |
|
112 | | - return $($.parseHTML(" \ |
| 112 | + return $( $.parseHTML(" \ |
113 | 113 | <div class='github-box'> \ |
114 | 114 | <div class='github-box-header'> \ |
115 | 115 | <h3> \ |
|
128 | 128 | <a class='repo-download' href='" + repo_url + "'/zipball/master'>Download as zip</a> \ |
129 | 129 | </div> \ |
130 | 130 | </div> \ |
131 | | - ")); |
| 131 | + ") ); |
132 | 132 | }; |
133 | 133 |
|
134 | 134 | // Request repositories from Github |
135 | | - Plugin.prototype.requestData = function (repo) { |
| 135 | + Plugin.prototype.requestData = function ( repo ) { |
136 | 136 | var self = this; |
137 | 137 |
|
138 | 138 | $.ajax({ |
139 | 139 | url: "https://api.github.com/repos/" + repo, |
140 | 140 | dataType: "jsonp", |
141 | | - success: function(results) { |
| 141 | + success: function( results ) { |
142 | 142 | var result_data = results.data; |
143 | 143 |
|
144 | 144 | // Handle API failures |
145 | | - if (results.meta.status >= 400 && result_data.message) { |
| 145 | + if ( results.meta.status >= 400 && result_data.message ) { |
146 | 146 | self.handlerErrorRequest(); |
147 | 147 | } |
148 | 148 | else { |
149 | | - self.handlerSuccessfulRequest(result_data); |
| 149 | + self.handlerSuccessfulRequest( result_data ); |
150 | 150 | } |
151 | 151 | } |
152 | 152 | }); |
153 | 153 | }; |
154 | 154 |
|
155 | | - $.fn[pluginName] = function ( options ) { |
| 155 | + $.fn[ pluginName ] = function ( options ) { |
156 | 156 | return this.each(function () { |
157 | | - if (!$.data(this, "plugin_" + pluginName)) { |
158 | | - $.data(this, "plugin_" + pluginName, new Plugin( this, options )); |
| 157 | + if ( !$.data( this, "plugin_" + pluginName ) ) { |
| 158 | + $.data( this, "plugin_" + pluginName, new Plugin( this, options ) ); |
159 | 159 | } |
160 | 160 | }); |
161 | 161 | }; |
162 | 162 |
|
163 | | -}(jQuery, window)); |
| 163 | +}( jQuery, window ) ); |
0 commit comments