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