@@ -12,81 +12,74 @@ function GithubRepo( repo ) {
12
12
13
13
// Parses HTML template
14
14
GithubRepo . prototype . toHTML = function ( ) {
15
- var self = this ;
16
-
17
- self . pushed_at = self . _parsePushedDate ( self . pushed_at ) ,
18
- self . url = self . _parseURL ( self . url ) ;
15
+ this . pushed_at = this . _parsePushedDate ( this . pushed_at ) ,
16
+ this . url = this . _parseURL ( this . url ) ;
19
17
20
18
return $ (
21
19
"<div class='github-box'>" +
22
20
"<div class='github-box-header'>" +
23
21
"<h3>" +
24
- "<a href='" + self . url + "'>" + self . name + "</a>" +
22
+ "<a href='" + this . url + "'>" + this . name + "</a>" +
25
23
"</h3>" +
26
24
"<div class='github-stats'>" +
27
- "<a class='repo-stars' title='Stars' data-icon='7' href='" + self . url + "/watchers'>" + self . watchers + "</a>" +
28
- "<a class='repo-forks' title='Forks' data-icon='f' href='" + self . url + "/network'>" + self . forks + "</a>" +
29
- "<a class='repo-issues' title='Issues' data-icon='i' href='" + self . url + "/issues'>" + self . open_issues + "</a>" +
25
+ "<a class='repo-stars' title='Stars' data-icon='7' href='" + this . url + "/watchers'>" + this . watchers + "</a>" +
26
+ "<a class='repo-forks' title='Forks' data-icon='f' href='" + this . url + "/network'>" + this . forks + "</a>" +
27
+ "<a class='repo-issues' title='Issues' data-icon='i' href='" + this . url + "/issues'>" + this . open_issues + "</a>" +
30
28
"</div>" +
31
29
"</div>" +
32
30
"<div class='github-box-content'>" +
33
- "<p>" + self . description + " — <a href='" + self . url + "#readme'>Read More</a></p>" +
31
+ "<p>" + this . description + " — <a href='" + this . url + "#readme'>Read More</a></p>" +
34
32
"</div>" +
35
33
"<div class='github-box-download'>" +
36
- "<p class='repo-update'>Latest commit to <strong>master</strong> on " + self . pushed_at + "</p>" +
37
- "<a class='repo-download' title='Download as zip' data-icon='w' href='" + self . url + "/zipball/master'></a>" +
34
+ "<p class='repo-update'>Latest commit to <strong>master</strong> on " + this . pushed_at + "</p>" +
35
+ "<a class='repo-download' title='Download as zip' data-icon='w' href='" + this . url + "/zipball/master'></a>" +
38
36
"</div>" +
39
37
"</div>" ) ;
40
38
} ;
41
39
42
40
// Parses pushed_at with date format
43
41
GithubRepo . prototype . _parsePushedDate = function ( pushed_at ) {
44
- var self = this ,
45
- date = new Date ( pushed_at ) ;
42
+ var date = new Date ( pushed_at ) ;
46
43
47
44
return date . getDate ( ) + "/" + ( date . getMonth ( ) + 1 ) + "/" + date . getFullYear ( ) ;
48
45
} ;
49
46
50
47
// Parses URL to be friendly
51
48
GithubRepo . prototype . _parseURL = function ( url ) {
52
- var self = this ;
53
-
54
49
return url . replace ( "api." , "" ) . replace ( "repos/" , "" ) ;
55
50
} ;
56
51
57
52
// -- Github Plugin ------------------------------------------------------------
58
53
59
54
function Github ( element , options ) {
60
- var self = this ,
61
- defaults = {
55
+ var defaults = {
62
56
iconStars : true ,
63
57
iconForks : true ,
64
58
iconIssues : false
65
59
} ;
66
60
67
- self . element = element ;
68
- self . $container = $ ( element ) ;
69
- self . repo = self . $container . attr ( "data-repo" ) ;
61
+ this . element = element ;
62
+ this . $container = $ ( element ) ;
63
+ this . repo = this . $container . attr ( "data-repo" ) ;
70
64
71
- self . options = $ . extend ( { } , defaults , options ) ;
65
+ this . options = $ . extend ( { } , defaults , options ) ;
72
66
73
- self . _defaults = defaults ;
67
+ this . _defaults = defaults ;
74
68
75
- self . init ( ) ;
76
- self . displayIcons ( ) ;
69
+ this . init ( ) ;
70
+ this . displayIcons ( ) ;
77
71
}
78
72
79
73
// Initializer
80
74
Github . prototype . init = function ( ) {
81
- var self = this ,
82
- cached = self . getCache ( ) ;
75
+ var cached = this . getCache ( ) ;
83
76
84
77
if ( cached !== null ) {
85
- self . applyTemplate ( JSON . parse ( cached ) ) ;
78
+ this . applyTemplate ( JSON . parse ( cached ) ) ;
86
79
return ;
87
80
}
88
81
89
- self . requestData ( self . repo ) ;
82
+ this . requestData ( this . repo ) ;
90
83
} ;
91
84
92
85
// Display or hide icons
@@ -103,7 +96,7 @@ Github.prototype.displayIcons = function () {
103
96
104
97
// Request repositories from Github
105
98
Github . prototype . requestData = function ( repo ) {
106
- var self = this ;
99
+ var that = this ;
107
100
108
101
$ . ajax ( {
109
102
url : "https://api.github.com/repos/" + repo ,
@@ -113,11 +106,11 @@ Github.prototype.requestData = function ( repo ) {
113
106
isFailling = results . meta . status >= 400 && result_data . message ;
114
107
115
108
if ( isFailling ) {
116
- self . handleErrorRequest ( result_data ) ;
109
+ that . handleErrorRequest ( result_data ) ;
117
110
return ;
118
111
}
119
112
120
- self . handleSuccessfulRequest ( result_data ) ;
113
+ that . handleSuccessfulRequest ( result_data ) ;
121
114
}
122
115
} ) ;
123
116
} ;
0 commit comments