|
| 1 | +(function() { |
| 2 | + var Stars; |
| 3 | + $(function() { |
| 4 | + var _a, countdown, d, h, i, m, ms, s, tick, y; |
| 5 | + $('a.resend').click(function() { |
| 6 | + var a; |
| 7 | + a = $(this); |
| 8 | + a.hide().after('<span>Resending…</span>'); |
| 9 | + $.get(this.href, function() { |
| 10 | + return a.next('span').html('Sent!').fadeOut('slow', function() { |
| 11 | + a.next('span').remove(); |
| 12 | + return a.fadeIn(); |
| 13 | + }); |
| 14 | + }); |
| 15 | + return false; |
| 16 | + }); |
| 17 | + $('a.delete').click(function() { |
| 18 | + return confirm('Are you sure?'); |
| 19 | + }); |
| 20 | + $('a.reveal').click(function() { |
| 21 | + $(this).hide().next('.hidden').slideDown(function() { |
| 22 | + return $(this).find('input').select(); |
| 23 | + }); |
| 24 | + return false; |
| 25 | + }); |
| 26 | + $(':input:visible:first:not([rel=nofollow])').focus(); |
| 27 | + $('input.url').click(function() { |
| 28 | + if (this.value === this.defaultValue) { |
| 29 | + return this.select(); |
| 30 | + } |
| 31 | + }); |
| 32 | + $('form.reset_password').submit(function() { |
| 33 | + var email, form; |
| 34 | + form = $(this); |
| 35 | + email = form.find('input.email').val(); |
| 36 | + $.ajax({ |
| 37 | + type: form.attr('method'), |
| 38 | + url: form.attr('action'), |
| 39 | + data: form.serialize(), |
| 40 | + success: function(data) { |
| 41 | + return form.replaceWith("<h2>" + email + " has been sent a new password</h2>\n<p>It should arrive shortly.</p>"); |
| 42 | + }, |
| 43 | + error: function(xhr) { |
| 44 | + return $('#errors').append("<li>" + xhr.responseText + "</li>"); |
| 45 | + } |
| 46 | + }); |
| 47 | + return false; |
| 48 | + }); |
| 49 | + $('form').submit(function(evt) { |
| 50 | + var errors, form, hasError, highlightError; |
| 51 | + form = $(this).closest('form'); |
| 52 | + errors = $('#errors').html(''); |
| 53 | + form.find('input').removeClass('error'); |
| 54 | + hasError = false; |
| 55 | + highlightError = function(selector, message, fn) { |
| 56 | + var invalid; |
| 57 | + invalid = form.find(selector).filter(fn); |
| 58 | + if (invalid.length) { |
| 59 | + errors.append(("<li>" + (message) + "</li>")); |
| 60 | + invalid.addClass('error'); |
| 61 | + invalid.blur(); |
| 62 | + return (hasError = true); |
| 63 | + } |
| 64 | + }; |
| 65 | + highlightError('input.email', 'Invalid email address', function() { |
| 66 | + var val; |
| 67 | + val = $(this).val(); |
| 68 | + return val && !/^[a-zA-Z0-9+._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/.test(val); |
| 69 | + }); |
| 70 | + highlightError('input[name=name]', 'Name is required', function() { |
| 71 | + return !$(this).val(); |
| 72 | + }); |
| 73 | + highlightError('input#github', 'GitHub username is required', function() { |
| 74 | + return !$(this).val(); |
| 75 | + }); |
| 76 | + highlightError('input.email:first', 'Email is required', function() { |
| 77 | + return !$(this).val(); |
| 78 | + }); |
| 79 | + highlightError('input[type=password]:visible', 'Password required', function() { |
| 80 | + return !$(this).val(); |
| 81 | + }); |
| 82 | + highlightError('input.url', 'Invalid link', function() { |
| 83 | + var val; |
| 84 | + val = $(this).val(); |
| 85 | + return val && val !== this.defaultValue && !/^https?:\/\/.*\./.test(val); |
| 86 | + }); |
| 87 | + !(hasError) ? $('input.url').each(function() { |
| 88 | + if (this.value === this.defaultValue) { |
| 89 | + return (this.value = ''); |
| 90 | + } |
| 91 | + }) : null; |
| 92 | + return !hasError; |
| 93 | + }); |
| 94 | + if ($('.body.index time').length > 0) { |
| 95 | + _a = $('time').attr('datetime').split(/[-:TZ]/); |
| 96 | + y = _a[0]; |
| 97 | + m = _a[1]; |
| 98 | + d = _a[2]; |
| 99 | + h = _a[3]; |
| 100 | + i = _a[4]; |
| 101 | + s = _a[5]; |
| 102 | + ms = Date.UTC(y, m - 1, d, h, i, s); |
| 103 | + countdown = $('#date .about'); |
| 104 | + tick = function() { |
| 105 | + var days, diff, hours, minutes, secs; |
| 106 | + diff = (ms - new Date().getTime()) / 1000; |
| 107 | + days = Math.floor(diff % 604800 / 86400); |
| 108 | + hours = Math.floor(diff % 86400 / 3600); |
| 109 | + minutes = Math.floor(diff % 3600 / 60); |
| 110 | + secs = Math.floor(diff % 60); |
| 111 | + countdown.html(days + ' days ' + hours + ' hours ' + minutes + ' minutes ' + secs + ' seconds'); |
| 112 | + return setTimeout(tick, 1000); |
| 113 | + }; |
| 114 | + tick(); |
| 115 | + } |
| 116 | + return $('time').live('hover', function(e) { |
| 117 | + var $this, _b, dt; |
| 118 | + if (e.type === 'mouseout') { |
| 119 | + return $('.localtime').remove(); |
| 120 | + } |
| 121 | + $this = $(this); |
| 122 | + _b = $this.attr('datetime').split(/[-:TZ]/); |
| 123 | + y = _b[0]; |
| 124 | + m = _b[1]; |
| 125 | + d = _b[2]; |
| 126 | + h = _b[3]; |
| 127 | + i = _b[4]; |
| 128 | + s = _b[5]; |
| 129 | + ms = Date.UTC(y, m - 1, d, h, i, s); |
| 130 | + dt = new Date(ms); |
| 131 | + return $('<div class="localtime blue">').css({ |
| 132 | + left: e.pageX, |
| 133 | + top: $(this).position().top + 25 |
| 134 | + }).html((" \ |
| 135 | +" + (dt.strftime('%a %b %d, %I:%M%P %Z').replace(/\b0/, '')) + " \ |
| 136 | +")).appendTo(document.body); |
| 137 | + }); |
| 138 | + }); |
| 139 | + $('.judge img').each(function() { |
| 140 | + var r; |
| 141 | + r = 'rotate(' + new String(Math.random() * 6 - 3) + 'deg)'; |
| 142 | + return $(this).css('-webkit-transform', r).css('-moz-transform', r); |
| 143 | + }); |
| 144 | + Stars = { |
| 145 | + value: function(elem) { |
| 146 | + return elem.attr('data-value'); |
| 147 | + }, |
| 148 | + input: function(elem) { |
| 149 | + return elem.closest('.stars').prev('input[type=hidden]'); |
| 150 | + }, |
| 151 | + set: function(elem) { |
| 152 | + var newVal, oldVal; |
| 153 | + newVal = this.value(elem); |
| 154 | + oldVal = this.input(elem).val(); |
| 155 | + return this.input(elem).val(newVal === oldVal ? 0 : newVal); |
| 156 | + }, |
| 157 | + highlight: function(elem, hover) { |
| 158 | + var score; |
| 159 | + score = parseInt(hover ? this.value(elem) : this.input(elem).val()); |
| 160 | + return elem.closest('.stars').children().each(function(i, star) { |
| 161 | + var $star, fill; |
| 162 | + $star = $(star); |
| 163 | + fill = $star.attr('data-value') <= score; |
| 164 | + $star.find('.filled').toggle(fill); |
| 165 | + return $star.find('.empty').toggle(!fill); |
| 166 | + }); |
| 167 | + } |
| 168 | + }; |
| 169 | + $('.votes-new, #your_vote').delegate('.star', 'hover', function(e) { |
| 170 | + return Stars.highlight($(this), e.type === 'mouseover'); |
| 171 | + }).delegate('.star', 'click', function(e) { |
| 172 | + return Stars.set($(this)); |
| 173 | + }); |
| 174 | + (function() { |
| 175 | + $('.votes time').each(function() { |
| 176 | + var _a, d, h, i, m, ms, s, y; |
| 177 | + _a = $(this).attr('datetime').split(/[-:TZ]/); |
| 178 | + y = _a[0]; |
| 179 | + m = _a[1]; |
| 180 | + d = _a[2]; |
| 181 | + h = _a[3]; |
| 182 | + i = _a[4]; |
| 183 | + s = _a[5]; |
| 184 | + ms = Date.UTC(y, m - 1, d, h, i, s); |
| 185 | + return $(this).text(prettyDate(new Date(ms))); |
| 186 | + }); |
| 187 | + return setTimeout(arguments.callee, 10 * 1000); |
| 188 | + })(); |
| 189 | + $('.votes .more').each(function() { |
| 190 | + var $more, loadMoreNow, page; |
| 191 | + $more = $(this); |
| 192 | + loadMoreNow = $more.position().top - $(window).height() + 10; |
| 193 | + page = 1; |
| 194 | + return $(window).scroll(function(e) { |
| 195 | + if (loadMoreNow && this.scrollY > loadMoreNow) { |
| 196 | + loadMoreNow = null; |
| 197 | + return $.get(window.location.pathname + ("/votes.js?page=" + (++page)), function(html) { |
| 198 | + var moreVotes; |
| 199 | + moreVotes = $('<div class="page">').html(html); |
| 200 | + $more.remove(); |
| 201 | + $('.votes').append(moreVotes); |
| 202 | + if (moreVotes.find('li').length === 51) { |
| 203 | + $('.votes').append($more); |
| 204 | + return (loadMoreNow = $more.position().top - $(window).height() + 10); |
| 205 | + } |
| 206 | + }); |
| 207 | + } |
| 208 | + }); |
| 209 | + }); |
| 210 | + $('#your_vote a[href$=draft]').click(function() { |
| 211 | + var _a; |
| 212 | + return (typeof (_a = window.localStorage) !== "undefined" && _a !== null) ? (localStorage['draft'] = JSON.stringify($(this).closest('form').serializeArray())) : null; |
| 213 | + }); |
| 214 | + $('.teams-show #your_vote').each(function() { |
| 215 | + var _a, _b, _c, _d, _e, el; |
| 216 | + if (!((typeof (_a = window.localStorage == undefined ? undefined : window.localStorage.draft) !== "undefined" && _a !== null) && window.location.hash === '#draft')) { |
| 217 | + return null; |
| 218 | + } |
| 219 | + try { |
| 220 | + _b = []; _d = JSON.parse(localStorage.draft); |
| 221 | + for (_c = 0, _e = _d.length; _c < _e; _c++) { |
| 222 | + el = _d[_c]; |
| 223 | + _b.push($(this[el.name]).val(el.value)); |
| 224 | + } |
| 225 | + return _b; |
| 226 | + } finally { |
| 227 | + delete localStorage.draft; |
| 228 | + } |
| 229 | + }); |
| 230 | + $('.votes-new .stars, #your_vote .stars').each(function() { |
| 231 | + return Stars.highlight($(this)); |
| 232 | + }); |
| 233 | +})(); |
0 commit comments