Permalink
Browse files

some Bugfixes in JS code.

  • Loading branch information...
1 parent a50a8a9 commit b2401b07f39f1b618113e854502ec82136cac84e @jedie committed Mar 20, 2012
Showing with 17 additions and 5 deletions.
  1. +17 −5 pylucid_project/media/PyLucid/pylucid_js_tools.js
@@ -2,13 +2,19 @@
// helper function for console logging
// set debug to true to enable debug logging
function log() {
- try {debug} catch (e) {debug=false};
+ if (typeof debug === 'undefined') {
+ // debug variable is undefined -> no debugging.
+ debug=false;
+ }
if (debug && window.console && window.console.log)
window.console.log(Array.prototype.join.call(arguments,''));
}
log("pylucid_js_tools.js loaded.");
+var load_normal_link=false; // global return value
+
+
function OpenInWindow(link) {
/*************************************************************************
Open link in a new JavaScript window.
@@ -385,7 +391,9 @@ function get_pylucid_comments_form() {
* code from: http://docs.djangoproject.com/en/dev/ref/contrib/csrf/#ajax
* see also: http://docs.djangoproject.com/en/dev/releases/1.3/#csrf-exception-for-ajax-requests
*/
-$(document).ajaxSend(function(event, xhr, settings) {
+jQuery(document).ajaxSend(function(event, xhr, settings) {
+ log("ajax send...");
+
function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie != '') {
@@ -416,8 +424,8 @@ $(document).ajaxSend(function(event, xhr, settings) {
function safeMethod(method) {
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
}
-
if (!safeMethod(settings.type) && sameOrigin(settings.url)) {
+ log("set X-CSRFToken to:"+ getCookie('csrftoken'));
xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
}
});
@@ -484,13 +492,17 @@ jQuery(document).ready(function($) {
* resize input fields */
$(".pylucid_form input").each(function() {
maxlength = $(this).attr("maxlength");
- if (maxlength<=0) {
+ if (maxlength == undefined || maxlength<=0) {
return;
}
if (maxlength > MAX_LENGTH) {
maxlength = MAX_LENGTH;
}
- this.size=maxlength;
+ try {
+ this.size=maxlength;
+ } catch (e) {
+ log("Can't resize input field to '"+maxlength+"':" + e);
+ }
});
/************************************************************************

0 comments on commit b2401b0

Please sign in to comment.