|
1 |
| -var App = (function( window, document, $ ) { |
| 1 | +var App = (function (window, document, $) { |
2 | 2 |
|
3 | 3 | 'use strict';
|
4 | 4 |
|
5 | 5 | var users = [
|
6 |
| - 'BrendanEich', |
7 |
| - 'isaacs', |
8 |
| - 'rdworth', |
9 |
| - 'fat', |
10 |
| - 'michalbe', |
11 |
| - 'afabbro', |
12 |
| - 'addyosmani', |
13 |
| - 'joezimjs', |
14 |
| - 'douglascrockford', |
15 |
| - 'paulirish', |
16 |
| - 'tj', |
17 |
| - 'guille', |
18 |
| - 'nzakas', |
19 |
| - 'jeresig', |
20 |
| - 'substack', |
21 |
| - 'dherman', |
22 |
| - 'creationix', |
23 |
| - 'mrdoob', |
24 |
| - 'codepo8', |
25 |
| - 'rwaldron', |
26 |
| - 'darkwing', |
27 |
| - 'bevacqua', |
28 |
| - 'sindresorhus', |
29 |
| - 'getify', |
30 |
| - 'ericelliott', |
31 |
| - 'aaronfrost', |
32 |
| - 'jhusain', |
33 |
| - 'ryanflorence', |
34 |
| - 'gaearon', |
35 |
| - 'rauschma' |
36 |
| - ], |
37 |
| - userIsDone, |
38 |
| - URL = 'https://api.github.com/'; |
| 6 | + 'BrendanEich', |
| 7 | + 'isaacs', |
| 8 | + 'rdworth', |
| 9 | + 'fat', |
| 10 | + 'michalbe', |
| 11 | + 'afabbro', |
| 12 | + 'addyosmani', |
| 13 | + 'joezimjs', |
| 14 | + 'douglascrockford', |
| 15 | + 'paulirish', |
| 16 | + 'tj', |
| 17 | + 'guille', |
| 18 | + 'nzakas', |
| 19 | + 'jeresig', |
| 20 | + 'substack', |
| 21 | + 'dherman', |
| 22 | + 'creationix', |
| 23 | + 'mrdoob', |
| 24 | + 'codepo8', |
| 25 | + 'rwaldron', |
| 26 | + 'darkwing', |
| 27 | + 'bevacqua', |
| 28 | + 'sindresorhus', |
| 29 | + 'getify', |
| 30 | + 'ericelliott', |
| 31 | + 'aaronfrost', |
| 32 | + 'jhusain', |
| 33 | + 'ryanflorence', |
| 34 | + 'gaearon', |
| 35 | + 'rauschma' |
| 36 | + ], |
| 37 | + userIsDone, |
| 38 | + URL = 'https://api.github.com/'; |
39 | 39 |
|
40 | 40 | return {
|
41 | 41 | // Init function
|
42 |
| - init: function() { |
| 42 | + init: function () { |
43 | 43 | this.getGithubUsers();
|
44 | 44 | this.getGithubContrib();
|
| 45 | + $('img.lazy').lazyload(); |
45 | 46 | },
|
46 | 47 | // Getting and appending users of github
|
47 |
| - getGithubUsers: function() { |
48 |
| - var i=0, length = userIsDone = users.length, |
49 |
| - str=''; |
| 48 | + getGithubUsers: function () { |
| 49 | + var i = 0, |
| 50 | + length = userIsDone = users.length, |
| 51 | + str = '', |
| 52 | + $whoto; |
50 | 53 |
|
51 | 54 | // Callback function
|
52 |
| - function cb( result ) { |
53 |
| - userIsDone-=1; |
54 |
| - str += '<div class="user"><a href="' + result.html_url + '"><img height="80" width="80" src="' + result.avatar_url + '"><span>' + result.name + '</span></a></div>'; |
| 55 | + function cb(result) { |
| 56 | + userIsDone -= 1; |
| 57 | + str += '<div class="user"><a href="' + result.html_url + |
| 58 | + '"><img height="80" width="80" class="lazy" data-original="' + |
| 59 | + result.avatar_url + '"><span>' + result.name + |
| 60 | + '</span></a></div>'; |
55 | 61 | // Checking if all callbacks were called
|
56 |
| - if( userIsDone === 0 ) { |
57 |
| - $('#whotofollow .users').append( str ); |
| 62 | + if (userIsDone === 0) { |
| 63 | + $whoto = $('#whotofollow .users'); |
| 64 | + $whoto.append(str); |
| 65 | + $whoto.find('img.lazy').lazyload(); |
58 | 66 | }
|
59 | 67 | }
|
60 | 68 |
|
61 | 69 | // Doing the requests for each user
|
62 |
| - for( ; i < length; i+=1 ) { |
63 |
| - $.get( URL + 'users/' + users[ i ] + '?client_id=5feee647eb6cc3d1f984&client_secret=9ed0c553e278d047a264c3abd26f385144d51ac4', cb ); |
| 70 | + for (; i < length; i += 1) { |
| 71 | + $.get(URL + 'users/' + users[i] + |
| 72 | + '?client_id=5feee647eb6cc3d1f984&client_secret=9ed0c553e278d047a264c3abd26f385144d51ac4', |
| 73 | + cb); |
64 | 74 | }
|
65 | 75 | },
|
66 | 76 | // Getting the project's contributors
|
67 |
| - getGithubContrib: function() { |
| 77 | + getGithubContrib: function () { |
| 78 | + var $footer; |
68 | 79 |
|
69 | 80 | // Callback function
|
70 |
| - function cb( result ) { |
71 |
| - var i=0, |
| 81 | + function cb(result) { |
| 82 | + var i = 0, |
72 | 83 | length = result.length,
|
73 |
| - str='', |
| 84 | + str = '', |
74 | 85 | obj;
|
75 | 86 |
|
76 |
| - for ( ; i < length; i+=1 ) { |
77 |
| - obj = result[ i ]; |
| 87 | + for (; i < length; i += 1) { |
| 88 | + obj = result[i]; |
78 | 89 |
|
79 |
| - str += '<div class="user"><a href="' + obj.html_url + '"><img width="80" height="80" src="' + obj.avatar_url + '"><span>' + obj.login + '</span></a></div>'; |
| 90 | + str += '<div class="user"><a href="' + obj.html_url + |
| 91 | + '"><img width="80" height="80" class="lazy" data-original="' + obj |
| 92 | + .avatar_url + '"><span>' + obj.login + |
| 93 | + '</span></a></div>'; |
80 | 94 | }
|
81 | 95 |
|
82 |
| - $('#footer .users').append( str ); |
| 96 | + $footer = $('#footer .users'); |
| 97 | + $footer.append(str); |
| 98 | + $footer.find('img.lazy').lazyload(); |
83 | 99 | }
|
84 | 100 |
|
85 | 101 | // Doing the request
|
86 |
| - $.get( URL + 'repos/braziljs/js-the-right-way/contributors?client_id=5feee647eb6cc3d1f984&client_secret=9ed0c553e278d047a264c3abd26f385144d51ac4', cb ) |
| 102 | + $.get(URL + |
| 103 | + 'repos/braziljs/js-the-right-way/contributors?client_id=5feee647eb6cc3d1f984&client_secret=9ed0c553e278d047a264c3abd26f385144d51ac4', |
| 104 | + cb) |
87 | 105 | }
|
88 | 106 | }
|
89 | 107 |
|
90 |
| -}( window, document, jQuery )); |
| 108 | +}(window, document, jQuery)); |
91 | 109 |
|
92 | 110 | // Starting the Application
|
93 | 111 | App.init();
|
0 commit comments