@@ -113,17 +113,45 @@ Github.prototype.displayIcons = function () {
113113 }
114114} ;
115115
116- // Apply results to HTML template
117- Github . prototype . applyTemplate = function ( repo ) {
118- var self = this ,
119- githubRepo = new GithubRepo ( repo ) ,
120- $widget = githubRepo . toHTML ( ) ;
116+ // Request repositories from Github
117+ Github . prototype . requestData = function ( repo ) {
118+ var self = this ;
121119
122- $widget . appendTo ( self . $container ) ;
120+ $ . ajax ( {
121+ url : "https://api.github.com/repos/" + repo ,
122+ dataType : "jsonp" ,
123+ success : function ( results ) {
124+ var result_data = results . data ;
125+
126+ // Handle API failures
127+ if ( results . meta . status >= 400 && result_data . message ) {
128+ self . handleErrorRequest ( result_data ) ;
129+ }
130+ else {
131+ self . handleSuccessfulRequest ( result_data ) ;
132+ }
133+ }
134+ } ) ;
135+ } ;
136+
137+ // Handle Errors requests
138+ Github . prototype . handleErrorRequest = function ( result_data ) {
139+ var self = this ;
140+
141+ console . warn ( result_data . message ) ;
142+ return ;
143+ } ;
144+
145+ // Handle Successful request
146+ Github . prototype . handleSuccessfulRequest = function ( result_data ) {
147+ var self = this ;
148+
149+ self . applyTemplate ( result_data ) ;
150+ self . setCache ( result_data ) ;
123151} ;
124152
125153// Stores repostories in sessionStorage if available
126- Github . prototype . cacheResults = function ( result_data ) {
154+ Github . prototype . setCache = function ( result_data ) {
127155 var self = this ;
128156
129157 // Cache data
@@ -144,42 +172,16 @@ Github.prototype.getCache = function() {
144172 }
145173} ;
146174
147- // Handle Errors requests
148- Github . prototype . handlerErrorRequests = function ( result_data ) {
149- var self = this ;
150-
151- console . warn ( result_data . message ) ;
152- return ;
153- } ;
154-
155- // Handle Successful request
156- Github . prototype . handlerSuccessfulRequest = function ( result_data ) {
157- var self = this ;
175+ // Apply results to HTML template
176+ Github . prototype . applyTemplate = function ( repo ) {
177+ var self = this ,
178+ githubRepo = new GithubRepo ( repo ) ,
179+ $widget = githubRepo . toHTML ( ) ;
158180
159- self . applyTemplate ( result_data ) ;
160- self . cacheResults ( result_data ) ;
181+ $widget . appendTo ( self . $container ) ;
161182} ;
162183
163- // Request repositories from Github
164- Github . prototype . requestData = function ( repo ) {
165- var self = this ;
166-
167- $ . ajax ( {
168- url : "https://api.github.com/repos/" + repo ,
169- dataType : "jsonp" ,
170- success : function ( results ) {
171- var result_data = results . data ;
172-
173- // Handle API failures
174- if ( results . meta . status >= 400 && result_data . message ) {
175- self . handlerErrorRequest ( ) ;
176- }
177- else {
178- self . handlerSuccessfulRequest ( result_data ) ;
179- }
180- }
181- } ) ;
182- } ;
184+ // -- Attach plugin to jQuery's prototype --------------------------------------
183185
184186; ( function ( $ , window , undefined ) {
185187
@@ -191,4 +193,4 @@ Github.prototype.requestData = function ( repo ) {
191193 } ) ;
192194 } ;
193195
194- } ( window . jQuery || window . Zepto , window ) ) ;
196+ } ( window . jQuery || window . Zepto , window ) ) ;
0 commit comments