bgneal@312: $(document).ready(function() { bgneal@322: $.ajaxSetup({ bgneal@322: beforeSend: function(xhr, settings) { bgneal@322: function getCookie(name) { bgneal@322: var cookieValue = null; bgneal@322: if (document.cookie && document.cookie != '') { bgneal@322: var cookies = document.cookie.split(';'); bgneal@322: for (var i = 0; i < cookies.length; i++) { bgneal@322: var cookie = jQuery.trim(cookies[i]); bgneal@322: // Does this cookie string begin with the name we want? bgneal@322: if (cookie.substring(0, name.length + 1) == (name + '=')) { bgneal@322: cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); bgneal@322: break; bgneal@322: } bgneal@322: } bgneal@322: } bgneal@322: return cookieValue; bgneal@322: } bgneal@322: if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) { bgneal@322: // Only send the token to relative URLs i.e. locally. bgneal@322: xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken')); bgneal@322: } bgneal@322: } bgneal@322: }); bgneal@312: bgneal@312: var numShouts = $('#shoutbox-shout-container > p').size(); bgneal@312: var sbBox = $('#shoutbox-shout-container'); bgneal@312: bgneal@312: if (numShouts < 2) bgneal@312: { bgneal@312: sbBox.append('
Welcome to SurfGuitar101.com!
'); bgneal@312: ++numShouts; bgneal@312: } bgneal@312: if (numShouts < 2) bgneal@312: { bgneal@312: sbBox.append('((((( More Reverb )))))
'); bgneal@312: ++numShouts; bgneal@312: } bgneal@312: bgneal@312: var sbCycleOpts = null; bgneal@312: var sbCycle = sbBox.cycle({ bgneal@312: fx: 'scrollUp', bgneal@312: timeout: 5000, bgneal@312: pause: 1, bgneal@312: next: '#shoutbox-next', bgneal@312: prev: '#shoutbox-prev', bgneal@312: before: function(curr, next, opts) { bgneal@312: if (!opts.addSlide || sbCycleOpts) return; bgneal@312: sbCycleOpts = opts; bgneal@312: } bgneal@312: }); bgneal@312: function addShout(shout) { bgneal@312: ++numShouts; bgneal@312: sbCycleOpts.addSlide(shout); bgneal@312: sbBox.cycle(numShouts - 1); bgneal@312: } bgneal@312: bgneal@312: var submit = $('#shoutbox-submit'); bgneal@312: submit.click(function () { bgneal@312: var input = $('#shoutbox-smiley-input'); bgneal@312: var msg = $.trim(input.val()); bgneal@312: if (msg.length == 0) { bgneal@312: return false; bgneal@312: } bgneal@312: submit.attr('disabled', 'disabled'); bgneal@312: $.ajax({ bgneal@312: url: '/shout/shout/', bgneal@312: type: 'POST', bgneal@312: data: { msg: msg }, bgneal@312: dataType: 'html', bgneal@312: success: function (data, textStatus) { bgneal@312: input.val(''); bgneal@312: if (data != '') { bgneal@312: addShout(data); bgneal@312: } bgneal@312: submit.removeAttr('disabled'); bgneal@312: }, bgneal@312: error: function (xhr, textStatus, ex) { bgneal@312: alert('Oops, an error occurred. ' + xhr.statusText + ' - ' + bgneal@312: xhr.responseText); bgneal@312: } bgneal@312: }); bgneal@312: return false; bgneal@312: }); bgneal@312: var smilies_loaded = false; bgneal@312: var smiley_frame = $('#shoutbox-smiley-frame'); bgneal@312: $('#shoutbox-smilies').click(function () { bgneal@312: smiley_frame.toggle(); bgneal@312: if (!smilies_loaded) { bgneal@312: smiley_frame.load('/smiley/farm/', function () { bgneal@312: $('#shoutbox-busy-icon').hide(); bgneal@312: var txt = $("#shoutbox-smiley-input")[0]; bgneal@312: $('#shoutbox-smiley-frame img').click(function() { bgneal@312: txt.value += ' ' + this.alt + ' '; bgneal@312: txt.focus(); bgneal@312: }); bgneal@312: smilies_loaded = true; bgneal@312: }); bgneal@312: } bgneal@312: }); bgneal@312: });