comparison media/js/shoutbox.js @ 272:4557974db0e0

For #114, committing a new shoutbox based on the jquery cycle plugin for user feedback.
author Brian Neal <bgneal@gmail.com>
date Sun, 26 Sep 2010 19:08:31 +0000
parents b43e1288ff80
children 0eed8161ca39
comparison
equal deleted inserted replaced
271:4746df47a538 272:4557974db0e0
1 $(document).ready(function() { 1 $(document).ready(function() {
2
3 var numShouts = $('#shoutbox-shout-container > p').size();
4 var sbCycleOpts = null;
5 var sbCycle = $('#shoutbox-shout-container').cycle({
6 fx: 'scrollUp',
7 timeout: 5000,
8 pause: 1,
9 next: '#shoutbox-next',
10 prev: '#shoutbox-prev',
11 before: function(curr, next, opts) {
12 if (!opts.addSlide || sbCycleOpts) return;
13 sbCycleOpts = opts;
14 }
15 });
16 function addShout(shout) {
17 ++numShouts;
18 sbCycleOpts.addSlide(shout);
19 $('#shoutbox-shout-container').cycle(numShouts - 1);
20 }
21
2 var submit = $('#shoutbox-submit'); 22 var submit = $('#shoutbox-submit');
3 submit.click(function () { 23 submit.click(function () {
4 var input = $('#shoutbox-smiley-input'); 24 var input = $('#shoutbox-smiley-input');
5 var msg = $.trim(input.val()); 25 var msg = $.trim(input.val());
6 if (msg.length == 0) { 26 if (msg.length == 0) {
13 data: { msg: msg }, 33 data: { msg: msg },
14 dataType: 'html', 34 dataType: 'html',
15 success: function (data, textStatus) { 35 success: function (data, textStatus) {
16 input.val(''); 36 input.val('');
17 if (data != '') { 37 if (data != '') {
18 $('#shoutbox-shout-container').prepend(data); 38 addShout(data);
19 $('#shoutbox-shout-container p:first').fadeIn(2500);
20 } 39 }
21 submit.removeAttr('disabled'); 40 submit.removeAttr('disabled');
22 }, 41 },
23 error: function (xhr, textStatus, ex) { 42 error: function (xhr, textStatus, ex) {
24 alert('Oops, an error occurred. ' + xhr.statusText + ' - ' + 43 alert('Oops, an error occurred. ' + xhr.statusText + ' - ' +