summaryrefslogtreecommitdiffstats
path: root/lanre_py/templates/layout.html
blob: 73005b972d528ef947981c0cd5f7cfa08b81f1f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<!doctype html>
<title>Lanre</title>
<link rel=stylesheet type=text/css href="{{ url_for('static', filename='bootstrap.css') }}">

<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<style type="text/css">
      body {
        padding-top: 40px;
        padding-bottom: 40px;
      }
    </style>

<div class="container">
 
    <div class="hero-unit">
      <h1>Designed for your pleasure of reading foreign texts</h1>
    </div>
       

  <div class="row-fluid">
    
    <div class="span8">
      {% for message in get_flashed_messages() %}
      <div class=flash>{{ message }}</div>
        {% endfor %}
        
    </div>

  </div>
  
<div class="row-fluid">
    {% block body %}{% endblock %}
</div><div class="row-fluid">
 

<div class=" well-small">
  <button class="btn btn-info" id="show-me-my-words">I added words. Now what?</button>
  </br>

  <div id="show-words" class="well-large well">
    <div class="alert alert-info" id="my-words">
    </div>

    <textarea  cols="20" rows="1" placeholder="me@email.com" id="email"></textarea>
  <button class="btn btn-info btn-large" id="send-words">Send them to me!</button>  
    
  </div>
  </div>
  </div>
  
  
</div>
  
<script type=text/javascript>
  $SCRIPT_ROOT = {{ request.script_root|tojson|safe }};
  $LANGUAGE = "fren";
</script>

<script type="text/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();
$("#show-words").hide();
$("#show-me-my-words").hide();
change_communicat(communicates);


  $("#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();

     //some magic
     get_translation(text_for_translation);

     //var translated_text = text_for_translation;
     //$("#translated-text").html(translated_text);
     $("#submit-text").hide();
     $("#change-text").show();
     $("#change-language-translate").show();
     $("#input-text").hide();
   });

    $("#change-language-translate").click(function() {
     
     var text_for_translation;
     text_for_translation = $("#input-text").val();
     

     //some magic
     get_translation(text_for_translation);

     //var translated_text = text_for_translation;
     //$("#translated-text").html(translated_text);
     $("#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();
     change_communicat("Insert some text!" );
     $("#current-translation").hide();
     $("#show-words").hide();
      $("#show-me-my-words").hide();
   });

  $("#lifren").click(function() {
    $LANGUAGE = "fren";
    $(this).addClass("active");
    $("#liiten").removeClass("active");
    $("#lienit").removeClass("active");
  });

  $("#liiten").click(function() {
    $LANGUAGE = "iten";
    $(this).addClass("active");
    $("#lifren").removeClass("active");
    $("#lienit").removeClass("active");
  });

  $("#lienit").click(function() {
    $LANGUAGE = "enit";
    $(this).addClass("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,
        language:$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();
          $("#current-translation").text(translated_words[which_one]);
        });

        $(".word").hover(function() {
          var which_one = this.id;
          $("#current-translation").show();
          $("#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." );
      }
    );

  
}
</script>