Permalink
Browse files

Merge pull request #3 from renyi/master

Small bug fixes
  • Loading branch information...
2 parents 7bc72b2 + fbd493b commit 38fef71261fef7de372e5e5bc3ab546c71deb452 @paltman paltman committed Jul 1, 2012
Showing with 14 additions and 28 deletions.
  1. +0 −25 agon_ratings/static/agon_ratings/js/ajax_csrf.js
  2. +14 −3 agon_ratings/templates/agon_ratings/_script.html
@@ -1,25 +0,0 @@
-(function($) {
- // from http://docs.djangoproject.com/en/1.3/ref/contrib/csrf/#ajax
- $('html').ajaxSend(
- function(event, xhr, settings) {
- function getCookie(name) {
- var cookieValue = null;
- if (document.cookie && document.cookie != '') {
- var cookies = document.cookie.split(';');
- for (var i = 0; i < cookies.length; i++) {
- var cookie = $.trim(cookies[i]);
- // Does this cookie string begin with the name we want?
- if (cookie.substring(0, name.length + 1) == (name + '=')) {
- cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
- break;
- }
- }
- }
- return cookieValue;
- }
- if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {
- // Only send the token to relative URLs i.e. locally.
- xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
- }
- });
- })(jQuery);
@@ -1,4 +1,13 @@
-<script type="text/javascript" src="{{ STATIC_URL }}agon_ratings/js/ajax_csrf.js"></script>
+<script>
+ (function($) {
+ $('html').ajaxSend(
+ function(event, xhr, settings) {
+ if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {
+ xhr.setRequestHeader("X-CSRFToken", "{{ csrf_token }}");
+ }
+ });
+ })(jQuery);
+</script>
<script type="text/javascript" src="{{ STATIC_URL }}agon_ratings/js/jquery.raty.js"></script>
<script type="text/javascript">
$(function () {
@@ -17,8 +26,10 @@
url: "{{ post_url }}",
type: "POST",
data: {
- "rating": current_rating,
- "category": "{{ category }}"
+ "rating": current_rating
+ {% if category %}
+ ,"category": "{{ category }}"
+ {% endif %}
},
statusCode: {
403: function(jqXHR, textStatus, errorThrown) {

0 comments on commit 38fef71

Please sign in to comment.