@@ -83,10 +83,10 @@ Github.prototype.init = function () {
8383
8484 if ( cached !== null ) {
8585 self . applyTemplate ( JSON . parse ( cached ) ) ;
86+ return ;
8687 }
87- else {
88- self . requestData ( self . repo ) ;
89- }
88+
89+ self . requestData ( self . repo ) ;
9090} ;
9191
9292// Display or hide icons
@@ -109,51 +109,43 @@ Github.prototype.requestData = function ( repo ) {
109109 url : "https://api.github.com/repos/" + repo ,
110110 dataType : "jsonp" ,
111111 success : function ( results ) {
112- var result_data = results . data ;
113-
114- // Handle API failures
115- if ( results . meta . status >= 400 && result_data . message ) {
112+ var result_data = results . data ,
113+ isFailling = results . meta . status >= 400 && result_data . message ;
114+
115+ if ( isFailling ) {
116116 self . handleErrorRequest ( result_data ) ;
117+ return ;
117118 }
118- else {
119- self . handleSuccessfulRequest ( result_data ) ;
120- }
119+
120+ self . handleSuccessfulRequest ( result_data ) ;
121121 }
122122 } ) ;
123123} ;
124124
125125// Handle Errors requests
126126Github . prototype . handleErrorRequest = function ( result_data ) {
127- var self = this ;
128-
129127 console . warn ( result_data . message ) ;
130128 return ;
131129} ;
132130
133131// Handle Successful request
134132Github . prototype . handleSuccessfulRequest = function ( result_data ) {
135- var self = this ;
136-
137- self . applyTemplate ( result_data ) ;
138- self . setCache ( result_data ) ;
133+ this . applyTemplate ( result_data ) ;
134+ this . setCache ( result_data ) ;
139135} ;
140136
141137// Stores repostories in sessionStorage if available
142138Github . prototype . setCache = function ( result_data ) {
143- var self = this ;
144-
145139 // Cache data
146140 if ( window . sessionStorage ) {
147- window . sessionStorage . setItem ( "gh-repos:" + self . repo , JSON . stringify ( result_data ) ) ;
141+ window . sessionStorage . setItem ( "gh-repos:" + this . repo , JSON . stringify ( result_data ) ) ;
148142 }
149143} ;
150144
151145// Grab cached results
152146Github . prototype . getCache = function ( ) {
153- var self = this ;
154-
155147 if ( window . sessionStorage ) {
156- return window . sessionStorage . getItem ( "gh-repos:" + self . repo ) ;
148+ return window . sessionStorage . getItem ( "gh-repos:" + this . repo ) ;
157149 }
158150 else {
159151 return false ;
@@ -162,11 +154,10 @@ Github.prototype.getCache = function() {
162154
163155// Apply results to HTML template
164156Github . prototype . applyTemplate = function ( repo ) {
165- var self = this ,
166- githubRepo = new GithubRepo ( repo ) ,
167- $widget = githubRepo . toHTML ( ) ;
157+ var githubRepo = new GithubRepo ( repo ) ,
158+ $widget = githubRepo . toHTML ( ) ;
168159
169- $widget . appendTo ( self . $container ) ;
160+ $widget . appendTo ( this . $container ) ;
170161} ;
171162
172163// -- Attach plugin to jQuery's prototype --------------------------------------
0 commit comments