226 lines
6.4 KiB
JavaScript
226 lines
6.4 KiB
JavaScript
|
|
var communicates = "Here will be placed other info. Hover to get translation. Click to add for further reference. Insert your text and translate it."
|
|
var translated_words;
|
|
var original_words;
|
|
var message;
|
|
var words_to_be_remembered = new Array();
|
|
|
|
$(document).ready( function() {
|
|
$("#change-text").hide();
|
|
$("#change-language-translate").hide();
|
|
$("#current-translation").hide();
|
|
$("#translation-label").hide();
|
|
$("#show-words").hide();
|
|
$("#show-me-my-words").hide();
|
|
$("#help-block").hide();
|
|
$("#instructions").text("Put your text below:");
|
|
change_communicat(communicates);
|
|
|
|
$("#help-me").click(function() {
|
|
$("#help-block").show();
|
|
$(this).hide();
|
|
});
|
|
|
|
$("#thanks-for-help").click(function() {
|
|
$("#help-block").hide();
|
|
$("#help-me").show();
|
|
});
|
|
$("#send-words").click(function() {
|
|
var address;
|
|
address = $("#email").val();
|
|
console.log(address);
|
|
console.log(message);
|
|
send_mail(address, message);
|
|
var text_for_translation;
|
|
});
|
|
|
|
$("#submit-text").click(function() {
|
|
text_for_translation = $("#input-text").val();
|
|
get_translation(text_for_translation);
|
|
|
|
$("#submit-text").hide();
|
|
$("#change-text").show();
|
|
$("#instructions").text("Enjoy your reading");
|
|
$("#change-language-translate").show();
|
|
$("#input-text").hide();
|
|
});
|
|
|
|
$("#change-language-translate").click(function() {
|
|
|
|
var text_for_translation;
|
|
text_for_translation = $("#input-text").val();
|
|
get_translation(text_for_translation);
|
|
$("#instructions").text("Enjoy your reading");
|
|
$("#submit-text").hide();
|
|
$("#change-text").show();
|
|
$("#input-text").hide();
|
|
$("#show-words").hide();
|
|
$("#show-me-my-words").hide();
|
|
});
|
|
|
|
$("#change-text").click(function() {
|
|
|
|
$("#translated-text").html("");
|
|
$("#input-text").show().html("");
|
|
$("#submit-text").show();
|
|
$("#change-text").hide();
|
|
$("#change-language-translate").hide();
|
|
$("#instructions").text("Put some text below:");
|
|
change_communicat("Insert some text!" );
|
|
$("#current-translation").hide();
|
|
$("#translation-label").hide();
|
|
$("#show-words").hide();
|
|
$("#show-me-my-words").hide();
|
|
});
|
|
|
|
$("#lifren").click(function() {
|
|
$DEST_LANGUAGE = "eng";
|
|
$FROM_LANGUAGE = "fra";
|
|
$(this).addClass("active");
|
|
$("#liiten").removeClass("active");
|
|
$("#lienit").removeClass("active");
|
|
$("#lideen").removeClass("active");
|
|
$("#liende").removeClass("active");
|
|
$("#lienfr").removeClass("active");
|
|
});
|
|
|
|
$("#lienfr").click(function() {
|
|
$DEST_LANGUAGE = "fra";
|
|
$FROM_LANGUAGE = "eng";
|
|
$(this).addClass("active");
|
|
$("#lideen").removeClass("active");
|
|
$("#liende").removeClass("active");
|
|
$("#lifren").removeClass("active");
|
|
|
|
$("#liiten").removeClass("active");
|
|
$("#lienit").removeClass("active");
|
|
});
|
|
|
|
$("#lideen").click(function() {
|
|
$DEST_LANGUAGE = "eng";
|
|
$FROM_LANGUAGE = "deu";
|
|
$(this).addClass("active");
|
|
$("#liiten").removeClass("active");
|
|
$("#lienit").removeClass("active");
|
|
$("#lienfr").removeClass("active");
|
|
$("#liende").removeClass("active");
|
|
$("#lifren").removeClass("active");
|
|
});
|
|
|
|
$("#liende").click(function() {
|
|
$DEST_LANGUAGE = "deu";
|
|
$FROM_LANGUAGE = "eng";
|
|
$(this).addClass("active");
|
|
$("#liiten").removeClass("active");
|
|
$("#lienit").removeClass("active");
|
|
$("#lideen").removeClass("active");
|
|
$("#lienfr").removeClass("active");
|
|
$("#lifren").removeClass("active");
|
|
});
|
|
|
|
|
|
$("#liiten").click(function() {
|
|
$DEST_LANGUAGE = "eng";
|
|
$FROM_LANGUAGE = "ita";
|
|
$(this).addClass("active");
|
|
$("#lideen").removeClass("active");
|
|
$("#liende").removeClass("active");
|
|
$("#lifren").removeClass("active");
|
|
$("#lienfr").removeClass("active");
|
|
$("#lienit").removeClass("active");
|
|
});
|
|
|
|
$("#lienit").click(function() {
|
|
$DEST_LANGUAGE = "ita";
|
|
$FROM_LANGUAGE = "eng";
|
|
$(this).addClass("active");
|
|
$("#lideen").removeClass("active");
|
|
$("#liende").removeClass("active");
|
|
$("#lienfr").removeClass("active");
|
|
$("#lifren").removeClass("active");
|
|
$("#liiten").removeClass("active");
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
$("#show-me-my-words").click( function() {
|
|
show_added_words();
|
|
$(this).hide();
|
|
|
|
});
|
|
|
|
function show_added_words() {
|
|
$("#show-words").show();
|
|
var words = "My words are:\n";
|
|
var i = 0;
|
|
console.log(words_to_be_remembered);
|
|
var local_message = "Words for you from Lanre:\n";
|
|
words_to_be_remembered.forEach(function(word, index){
|
|
words += "<p>" +index + ": " + word + "</p>";
|
|
local_message += index + ": " + word + "\n";
|
|
});
|
|
message = local_message;
|
|
$("#my-words").html(words)
|
|
}
|
|
|
|
function change_communicat(communicat) {
|
|
communicates = communicat;
|
|
$("#communicates").text(communicates);
|
|
}
|
|
|
|
function get_translation(text_for_translation) {
|
|
|
|
$(function() {
|
|
change_communicat("It may take some time..." );
|
|
$.getJSON( $SCRIPT_ROOT + '/_find_translations', {
|
|
text:text_for_translation,
|
|
from_language:$FROM_LANGUAGE,
|
|
dest_language:$DEST_LANGUAGE
|
|
}, function(data) {
|
|
$("#translated-text").html(data.html_output);
|
|
translated_words = data.result;
|
|
original_words = data.words;
|
|
change_communicat("Done! Now you can hover on words or click them, for further reference." );
|
|
$(".word").click(function() {
|
|
var which_one = this.id;
|
|
var word_pair = original_words[which_one] +": " +translated_words[which_one];
|
|
words_to_be_remembered.push(word_pair);
|
|
$("#show-me-my-words").show();
|
|
change_communicat("You've just added a " + word_pair + " for further reference" );
|
|
|
|
$("#current-translation").show();
|
|
$("#translation-label").show();
|
|
$("#current-translation").text(translated_words[which_one]);
|
|
});
|
|
|
|
$(".word").hover(function() {
|
|
var which_one = this.id;
|
|
$("#current-translation").show();
|
|
$("#translation-label").show();
|
|
$("#instructions").text("Enjoy your reading");
|
|
$("#current-translation").text(translated_words[which_one]);
|
|
});
|
|
|
|
});
|
|
return false;
|
|
});
|
|
|
|
}
|
|
|
|
function send_mail(address, message) {
|
|
change_communicat("I'm sending you mail..." );
|
|
$.getJSON( $SCRIPT_ROOT + '/_send_mail', {
|
|
mail_address:address,
|
|
message:message
|
|
}, function(data) {
|
|
change_communicat("Mail should be sent by now." );
|
|
$("#show-words").hide();
|
|
$("#show-me-my-words").hide();
|
|
}
|
|
);
|
|
|
|
|
|
}
|