bgneal@312
|
1 $(document).ready(function() {
|
bgneal@322
|
2 $.ajaxSetup({
|
bgneal@322
|
3 beforeSend: function(xhr, settings) {
|
bgneal@322
|
4 function getCookie(name) {
|
bgneal@322
|
5 var cookieValue = null;
|
bgneal@322
|
6 if (document.cookie && document.cookie != '') {
|
bgneal@322
|
7 var cookies = document.cookie.split(';');
|
bgneal@322
|
8 for (var i = 0; i < cookies.length; i++) {
|
bgneal@322
|
9 var cookie = jQuery.trim(cookies[i]);
|
bgneal@322
|
10 // Does this cookie string begin with the name we want?
|
bgneal@322
|
11 if (cookie.substring(0, name.length + 1) == (name + '=')) {
|
bgneal@322
|
12 cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
|
bgneal@322
|
13 break;
|
bgneal@322
|
14 }
|
bgneal@322
|
15 }
|
bgneal@322
|
16 }
|
bgneal@322
|
17 return cookieValue;
|
bgneal@322
|
18 }
|
bgneal@322
|
19 if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {
|
bgneal@322
|
20 // Only send the token to relative URLs i.e. locally.
|
bgneal@322
|
21 xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
|
bgneal@322
|
22 }
|
bgneal@322
|
23 }
|
bgneal@322
|
24 });
|
bgneal@312
|
25
|
bgneal@672
|
26 // social bookmarking pop-up support
|
bgneal@672
|
27 $('.social-sharing').delegate('a', 'click', function(e) {
|
bgneal@672
|
28 if ($(window).width() > 700)
|
bgneal@672
|
29 {
|
bgneal@672
|
30 e.preventDefault();
|
bgneal@672
|
31 window.open(this.href,'share-this','height=300,width=500,status=no,toolbar=no');
|
bgneal@672
|
32 }
|
bgneal@672
|
33 });
|
bgneal@672
|
34
|
bgneal@427
|
35 $("html").bind("ajaxStart", function() {
|
bgneal@427
|
36 $(this).addClass('busy');
|
bgneal@427
|
37 }).bind("ajaxStop", function() {
|
bgneal@427
|
38 $(this).removeClass('busy');
|
bgneal@427
|
39 });
|
bgneal@427
|
40
|
bgneal@312
|
41 var numShouts = $('#shoutbox-shout-container > p').size();
|
bgneal@312
|
42 var sbBox = $('#shoutbox-shout-container');
|
bgneal@312
|
43
|
bgneal@312
|
44 if (numShouts < 2)
|
bgneal@312
|
45 {
|
bgneal@312
|
46 sbBox.append('<p>Welcome to SurfGuitar101.com!</p>');
|
bgneal@312
|
47 ++numShouts;
|
bgneal@312
|
48 }
|
bgneal@312
|
49 if (numShouts < 2)
|
bgneal@312
|
50 {
|
bgneal@312
|
51 sbBox.append('<p>((((( More Reverb )))))</p>');
|
bgneal@312
|
52 ++numShouts;
|
bgneal@312
|
53 }
|
bgneal@312
|
54
|
bgneal@312
|
55 var sbCycleOpts = null;
|
bgneal@312
|
56 var sbCycle = sbBox.cycle({
|
bgneal@312
|
57 fx: 'scrollUp',
|
bgneal@312
|
58 timeout: 5000,
|
bgneal@312
|
59 pause: 1,
|
bgneal@312
|
60 next: '#shoutbox-next',
|
bgneal@312
|
61 prev: '#shoutbox-prev',
|
bgneal@312
|
62 before: function(curr, next, opts) {
|
bgneal@312
|
63 if (!opts.addSlide || sbCycleOpts) return;
|
bgneal@312
|
64 sbCycleOpts = opts;
|
bgneal@312
|
65 }
|
bgneal@312
|
66 });
|
bgneal@312
|
67 function addShout(shout) {
|
bgneal@312
|
68 ++numShouts;
|
bgneal@312
|
69 sbCycleOpts.addSlide(shout);
|
bgneal@312
|
70 sbBox.cycle(numShouts - 1);
|
bgneal@312
|
71 }
|
bgneal@312
|
72
|
bgneal@312
|
73 var submit = $('#shoutbox-submit');
|
bgneal@312
|
74 submit.click(function () {
|
bgneal@312
|
75 var input = $('#shoutbox-smiley-input');
|
bgneal@312
|
76 var msg = $.trim(input.val());
|
bgneal@312
|
77 if (msg.length == 0) {
|
bgneal@312
|
78 return false;
|
bgneal@312
|
79 }
|
bgneal@312
|
80 submit.attr('disabled', 'disabled');
|
bgneal@312
|
81 $.ajax({
|
bgneal@312
|
82 url: '/shout/shout/',
|
bgneal@312
|
83 type: 'POST',
|
bgneal@312
|
84 data: { msg: msg },
|
bgneal@312
|
85 dataType: 'html',
|
bgneal@312
|
86 success: function (data, textStatus) {
|
bgneal@312
|
87 input.val('');
|
bgneal@312
|
88 if (data != '') {
|
bgneal@312
|
89 addShout(data);
|
bgneal@312
|
90 }
|
bgneal@312
|
91 submit.removeAttr('disabled');
|
bgneal@312
|
92 },
|
bgneal@312
|
93 error: function (xhr, textStatus, ex) {
|
bgneal@312
|
94 alert('Oops, an error occurred. ' + xhr.statusText + ' - ' +
|
bgneal@312
|
95 xhr.responseText);
|
bgneal@312
|
96 }
|
bgneal@312
|
97 });
|
bgneal@312
|
98 return false;
|
bgneal@312
|
99 });
|
bgneal@312
|
100 var smilies_loaded = false;
|
bgneal@312
|
101 var smiley_frame = $('#shoutbox-smiley-frame');
|
bgneal@312
|
102 $('#shoutbox-smilies').click(function () {
|
bgneal@312
|
103 smiley_frame.toggle();
|
bgneal@312
|
104 if (!smilies_loaded) {
|
bgneal@312
|
105 smiley_frame.load('/smiley/farm/', function () {
|
bgneal@312
|
106 $('#shoutbox-busy-icon').hide();
|
bgneal@312
|
107 var txt = $("#shoutbox-smiley-input")[0];
|
bgneal@312
|
108 $('#shoutbox-smiley-frame img').click(function() {
|
bgneal@312
|
109 txt.value += ' ' + this.alt + ' ';
|
bgneal@312
|
110 txt.focus();
|
bgneal@312
|
111 });
|
bgneal@312
|
112 smilies_loaded = true;
|
bgneal@312
|
113 });
|
bgneal@312
|
114 }
|
bgneal@312
|
115 });
|
bgneal@312
|
116 });
|