annotate media/js/shoutbox.js @ 301:ee451ad46af1

Fixing #140; limit topic notification emails to at most 1 per day, or more if the user visits the topic.
author Brian Neal <bgneal@gmail.com>
date Thu, 13 Jan 2011 03:27:42 +0000
parents 0eed8161ca39
children
rev   line source
bgneal@12 1 $(document).ready(function() {
bgneal@272 2
bgneal@272 3 var numShouts = $('#shoutbox-shout-container > p').size();
bgneal@296 4 var sbBox = $('#shoutbox-shout-container');
bgneal@296 5
bgneal@296 6 if (numShouts < 2)
bgneal@296 7 {
bgneal@296 8 sbBox.append('<p>Welcome to SurfGuitar101.com!</p>');
bgneal@296 9 ++numShouts;
bgneal@296 10 }
bgneal@296 11 if (numShouts < 2)
bgneal@296 12 {
bgneal@296 13 sbBox.append('<p>((((( More Reverb )))))</p>');
bgneal@296 14 ++numShouts;
bgneal@296 15 }
bgneal@296 16
bgneal@272 17 var sbCycleOpts = null;
bgneal@296 18 var sbCycle = sbBox.cycle({
bgneal@272 19 fx: 'scrollUp',
bgneal@272 20 timeout: 5000,
bgneal@272 21 pause: 1,
bgneal@272 22 next: '#shoutbox-next',
bgneal@272 23 prev: '#shoutbox-prev',
bgneal@272 24 before: function(curr, next, opts) {
bgneal@272 25 if (!opts.addSlide || sbCycleOpts) return;
bgneal@272 26 sbCycleOpts = opts;
bgneal@272 27 }
bgneal@272 28 });
bgneal@272 29 function addShout(shout) {
bgneal@272 30 ++numShouts;
bgneal@272 31 sbCycleOpts.addSlide(shout);
bgneal@296 32 sbBox.cycle(numShouts - 1);
bgneal@272 33 }
bgneal@272 34
bgneal@12 35 var submit = $('#shoutbox-submit');
bgneal@12 36 submit.click(function () {
bgneal@12 37 var input = $('#shoutbox-smiley-input');
bgneal@27 38 var msg = $.trim(input.val());
bgneal@12 39 if (msg.length == 0) {
bgneal@12 40 return false;
bgneal@12 41 }
bgneal@12 42 submit.attr('disabled', 'disabled');
bgneal@150 43 $.ajax({
bgneal@150 44 url: '/shout/shout/',
bgneal@150 45 type: 'POST',
bgneal@150 46 data: { msg: msg },
bgneal@150 47 dataType: 'html',
bgneal@150 48 success: function (data, textStatus) {
bgneal@12 49 input.val('');
bgneal@12 50 if (data != '') {
bgneal@272 51 addShout(data);
bgneal@12 52 }
bgneal@12 53 submit.removeAttr('disabled');
bgneal@12 54 },
bgneal@150 55 error: function (xhr, textStatus, ex) {
bgneal@150 56 alert('Oops, an error occurred. ' + xhr.statusText + ' - ' +
bgneal@150 57 xhr.responseText);
bgneal@150 58 }
bgneal@150 59 });
bgneal@12 60 return false;
bgneal@12 61 });
bgneal@12 62 var smilies_loaded = false;
bgneal@12 63 var smiley_frame = $('#shoutbox-smiley-frame');
bgneal@12 64 $('#shoutbox-smilies').click(function () {
bgneal@12 65 smiley_frame.toggle();
bgneal@12 66 if (!smilies_loaded) {
bgneal@12 67 smiley_frame.load('/smiley/farm/', function () {
bgneal@12 68 $('#shoutbox-busy-icon').hide();
bgneal@123 69 var txt = $("#shoutbox-smiley-input")[0];
bgneal@123 70 $('#shoutbox-smiley-frame img').click(function() {
bgneal@123 71 txt.value += ' ' + this.alt + ' ';
bgneal@123 72 txt.focus();
bgneal@123 73 });
bgneal@12 74 smilies_loaded = true;
bgneal@12 75 });
bgneal@12 76 }
bgneal@12 77 });
bgneal@12 78 });