annotate gpp/shoutbox/static/js/shoutbox.js @ 312:88b2b9cb8c1f

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