bzr add media

This commit is contained in:
Sanj 2012-02-23 18:18:11 +05:30
parent 955bf189c4
commit 6ffecd56fd
3 changed files with 99 additions and 0 deletions

View File

@ -0,0 +1,67 @@
// اطارات
$(function() {
/* slightly strange, to be able to do ajax with csrf protection, taken from http://stackoverflow.com/questions/5100539/django-csrf-check-failing-with-an-ajax-post-request */
//
// $.ajaxSetup({
// beforeSend: function(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 = jQuery.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'));
// }
// }
// });
setTimeout(autoTranslate, 5000);
$('#doTranslate').click(function() {
var data = [];
var $this = $(this);
$this.attr("disabled", "disabled");
$('#transTable tr').each(function() {
var $this = $(this);
var $val = $this.find('td').eq(0);
var ord = $val.attr("data-ord").split(",");
// var ord = $ord.text().split(",");
var val = $val.text();
$this.removeAttr("disabled");
data.push({
'ord': ord,
'val': val
});
});
var baseUrl = "/googletranslate/" + model + "/" + field + "/";
var url = "/dotranslate/" + model + "/" + field + "/";
$.post(url, {'data': JSON.stringify(data)}, function(response) {
var newStart = start + 100;
var newEnd = end + 100;
location.href = baseUrl + "?start=" + newStart + "&end=" + newEnd;
}, "json");
});
});
function autoTranslate() {
var controlValue = $.trim($('#controlValue').text());
if (controlValue == "Tires") {
$('#doTranslate').click();
} else {
setTimeout(autoTranslate, 5000);
}
}

4
manifests/media/js/jquery.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,28 @@
$(function() {
// alert("foo");
$('.transInput').blur(function() {
// alert("foo");
var val = $(this).val();
var string = $(this).parents('tr').children().eq(0).text();
// console.log($(this).data("original"));
var oldVal = $(this).data("original");
if (val != oldVal) {
var data = {
'id': $(this).data("id"),
'model': trans.model,
'field': trans.field,
'string': string,
'translation': val
};
$(this).data("original", val);
var url = trans.model == 'Translation' ? '/stringtranslate/' : '/dotrans/';
$.post(url, data, function(response) {
console.log(response);
}, "json");
// console.log(data);
}
});
});