@@ -83,10 +83,10 @@ Github.prototype.init = function () {
83
83
84
84
if ( cached !== null ) {
85
85
self . applyTemplate ( JSON . parse ( cached ) ) ;
86
+ return ;
86
87
}
87
- else {
88
- self . requestData ( self . repo ) ;
89
- }
88
+
89
+ self . requestData ( self . repo ) ;
90
90
} ;
91
91
92
92
// Display or hide icons
@@ -109,51 +109,43 @@ Github.prototype.requestData = function ( repo ) {
109
109
url : "https://api.github.com/repos/" + repo ,
110
110
dataType : "jsonp" ,
111
111
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 ) {
116
116
self . handleErrorRequest ( result_data ) ;
117
+ return ;
117
118
}
118
- else {
119
- self . handleSuccessfulRequest ( result_data ) ;
120
- }
119
+
120
+ self . handleSuccessfulRequest ( result_data ) ;
121
121
}
122
122
} ) ;
123
123
} ;
124
124
125
125
// Handle Errors requests
126
126
Github . prototype . handleErrorRequest = function ( result_data ) {
127
- var self = this ;
128
-
129
127
console . warn ( result_data . message ) ;
130
128
return ;
131
129
} ;
132
130
133
131
// Handle Successful request
134
132
Github . 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 ) ;
139
135
} ;
140
136
141
137
// Stores repostories in sessionStorage if available
142
138
Github . prototype . setCache = function ( result_data ) {
143
- var self = this ;
144
-
145
139
// Cache data
146
140
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 ) ) ;
148
142
}
149
143
} ;
150
144
151
145
// Grab cached results
152
146
Github . prototype . getCache = function ( ) {
153
- var self = this ;
154
-
155
147
if ( window . sessionStorage ) {
156
- return window . sessionStorage . getItem ( "gh-repos:" + self . repo ) ;
148
+ return window . sessionStorage . getItem ( "gh-repos:" + this . repo ) ;
157
149
}
158
150
else {
159
151
return false ;
@@ -162,11 +154,10 @@ Github.prototype.getCache = function() {
162
154
163
155
// Apply results to HTML template
164
156
Github . 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 ( ) ;
168
159
169
- $widget . appendTo ( self . $container ) ;
160
+ $widget . appendTo ( this . $container ) ;
170
161
} ;
171
162
172
163
// -- Attach plugin to jQuery's prototype --------------------------------------
0 commit comments