common.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. var loc_uri = URI.parse(window.location.href);
  2. var loc_qry = URI.parseQuery(loc_uri.query)
  3. var getUrlParameter = function getUrlParameter(sParam) {
  4. var sPageURL = window.location.search.substring(1),
  5. sURLVariables = sPageURL.split('&'),
  6. sParameterName,
  7. i;
  8. for (i = 0; i < sURLVariables.length; i++) {
  9. sParameterName = sURLVariables[i].split('=');
  10. if (sParameterName[0] === sParam) {
  11. return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
  12. }
  13. }
  14. };
  15. function csrfSafeMethod(method) {
  16. // these HTTP methods do not require CSRF protection
  17. return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
  18. }
  19. function getCookie(name) {
  20. var cookieValue = null;
  21. if (document.cookie && document.cookie !== '') {
  22. var cookies = document.cookie.split(';');
  23. for (var i = 0; i < cookies.length; i++) {
  24. var cookie = jQuery.trim(cookies[i]);
  25. // Does this cookie string begin with the name we want?
  26. if (cookie.substring(0, name.length + 1) === (name + '=')) {
  27. cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
  28. break;
  29. }
  30. }
  31. }
  32. return cookieValue;
  33. }
  34. var csrftoken = getCookie('csrftoken');