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