|
| 1 | +$(document).ready(function () { |
| 2 | + var quotas = [ |
| 3 | + {id: 1, label: "Platina", rowCss: "platinum", perRow: 2, logo: {w: 250, h: 120}, details: true}, |
| 4 | + {id: 2, label: "Ouro", rowCss: "gold", perRow: 4, logo: {w: 200, h: 100}, details: false}, |
| 5 | + {id: 3, label: "Prata", rowCss: "silver", perRow: 6, logo: {w: 160, h: 80}, details: false}, |
| 6 | + {id: 4, label: "Bronze", rowCss: "brass", perRow: 12, logo: {w: 80, h: 60}, details: false} |
| 7 | + ]; |
| 8 | + |
| 9 | + findSponsors(0); |
| 10 | + |
| 11 | + function findSponsors(i) |
| 12 | + { |
| 13 | + if (i >= quotas.length) { |
| 14 | + $('div.sponsors h4')[0].style.marginTop = 0; |
| 15 | + $('#sponsorsContainer').removeClass('hide'); |
| 16 | + return; |
| 17 | + } |
| 18 | + |
| 19 | + var quota = quotas[i]; |
| 20 | + |
| 21 | + $.ajax( |
| 22 | + { |
| 23 | + url: baseUrl + 'sponsors', |
| 24 | + dataType: 'json', |
| 25 | + data: {'quota': quota.id}, |
| 26 | + type: 'GET', |
| 27 | + success: function (sponsors) { |
| 28 | + renderSponsors(quota, sponsors); |
| 29 | + findSponsors(i + 1); |
| 30 | + } |
| 31 | + } |
| 32 | + ); |
| 33 | + } |
| 34 | + |
| 35 | + function renderSponsors(quota, sponsors) |
| 36 | + { |
| 37 | + if (sponsors.length == 0) { |
| 38 | + return ; |
| 39 | + } |
| 40 | + |
| 41 | + var element = $('<div class="row sponsors ' + quota.rowCss + '"></div>'); |
| 42 | + element.append('<h4 class="label label-default">' + quota.label + '</h4>') |
| 43 | + |
| 44 | + for (var i = 0; i < sponsors.length; ++i) { |
| 45 | + var sponsor = sponsors[i]; |
| 46 | + |
| 47 | + if (i % quota.perRow == 0 && element.children().length > 0) { |
| 48 | + $('#sponsorsContainer').append(element); |
| 49 | + element = $('<div class="row sponsors ' + quota.rowCss + '"></div>'); |
| 50 | + } |
| 51 | + |
| 52 | + element.append( |
| 53 | + '<div class="col-md-' + (12 / quota.perRow) + '">' + getSponsorContent(quota, sponsor) + '</div>' |
| 54 | + ); |
| 55 | + } |
| 56 | + |
| 57 | + if (element.children().length > 0) { |
| 58 | + $('#sponsorsContainer').append(element); |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + function getSponsorContent(quota, sponsor) |
| 63 | + { |
| 64 | + var link = '<a href="' + sponsor.website + '" target="_blank" title="' + sponsor.name + '">' |
| 65 | + + '<img src="' + baseUrl + 'sponsor/' + sponsor.id + '?w=' + quota.logo.w + '&h=' |
| 66 | + + quota.logo.h + '" alt="' + sponsor.name + '">' |
| 67 | + + '</a>'; |
| 68 | + |
| 69 | + if (!quota.details) { |
| 70 | + return link; |
| 71 | + } |
| 72 | + |
| 73 | + return '<div class="col-md-6" style="text-align: center">' + link + '</div>' |
| 74 | + + '<div class="col-md-6"><h5>' + sponsor.name + '</h5><p>' + sponsor.details + '</p></div>'; |
| 75 | + } |
| 76 | +}); |
0 commit comments