|
19 | 19 | // minified (especially when both are regularly referenced in your plugin).
|
20 | 20 |
|
21 | 21 | // Create the defaults once
|
22 |
| - var pluginName = 'defaultPluginName', |
| 22 | + var pluginName = 'githubWidget', |
23 | 23 | document = window.document,
|
24 | 24 | defaults = {
|
25 | 25 | propertyName: "value"
|
|
28 | 28 | // The actual plugin constructor
|
29 | 29 | function Plugin( element, options ) {
|
30 | 30 | this.element = element;
|
| 31 | + this.$container = $(element); |
| 32 | + this.repo = this.$container.attr("data-repo"); |
31 | 33 |
|
32 | 34 | // jQuery has an extend method which merges the contents of two or
|
33 | 35 | // more objects, storing the result in the first object. The first object
|
|
42 | 44 | }
|
43 | 45 |
|
44 | 46 | Plugin.prototype.init = function () {
|
45 |
| - // Place initialization logic here |
46 |
| - // You already have access to the DOM element and the options via the instance, |
47 |
| - // e.g., this.element and this.options |
| 47 | + |
| 48 | + var self = this; |
| 49 | + |
| 50 | + $.ajax({ |
| 51 | + url: 'https://api.github.com/repos/' + this.repo, |
| 52 | + dataType: 'jsonp', |
| 53 | + success: function(results){ |
| 54 | + |
| 55 | + var repo = results.data; |
| 56 | + var date = new Date(repo.pushed_at); |
| 57 | + var pushed_at = date.getMonth() + '/' + date.getDate() + '/' + date.getFullYear(); |
| 58 | + var $widget = $(' \ |
| 59 | + <div class="github-box repo"> \ |
| 60 | + <div class="github-box-title"> \ |
| 61 | + <h3> \ |
| 62 | + <a class="repo" href="' + repo.url.replace('api.','').replace('repos/','') + '">' + repo.name + '</a> \ |
| 63 | + </h3> \ |
| 64 | + <div class="github-stats"> \ |
| 65 | + <a class="watchers" href="' + repo.url.replace('api.','').replace('repos/','') + '/watchers">' + repo.watchers + '</a> \ |
| 66 | + <a class="forks" href="' + repo.url.replace('api.','').replace('repos/','') + '/forks">' + repo.forks + '</a> \ |
| 67 | + </div> \ |
| 68 | + </div> \ |
| 69 | + <div class="github-box-content"> \ |
| 70 | + <p class="description">' + repo.description + ' — <a href="' + repo.url.replace('api.','').replace('repos/','') + '#readme">Read More</a></p> \ |
| 71 | + <p class="link"><a href="' + repo.homepage + '">' + repo.homepage + '</a></p> \ |
| 72 | + </div> \ |
| 73 | + <div class="github-box-download"> \ |
| 74 | + <p class="updated">Latest commit to <strong>master</strong> on ' + pushed_at + '</p> \ |
| 75 | + <a class="download" href="' + repo.url.replace('api.','').replace('repos/','') + '/zipball/master">Download as zip</a> \ |
| 76 | + </div> \ |
| 77 | + </div> \ |
| 78 | + '); |
| 79 | + |
| 80 | + $widget.appendTo(self.$container); |
| 81 | + |
| 82 | + } |
| 83 | + |
| 84 | + }); |
48 | 85 | };
|
49 | 86 |
|
50 | 87 | // A really lightweight plugin wrapper around the constructor,
|
|
0 commit comments