Spaces:
Runtime error
Runtime error
File size: 2,910 Bytes
d0ed3d4 |
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 |
// ======= INPUT FIELD (FORM CONTROL) VALIDATION =======
var runOnce = false;
var short_summary = '';
var long_summary = '';
(function () {
'use strict'
const forms = document.querySelectorAll('.requires-validation')
Array.from(forms)
.forEach(function (form) {
form.addEventListener('submit', function (event) {
if (!form.checkValidity()) {
event.preventDefault()
event.stopPropagation()
}
form.classList.add('was-validated')
}, false)
})
})()
// ======= RESET INPUT FIELD WHEN USER CLICKED AT IT (HAS RAN ONCE) =======
$(function () {
$('#input_text').on("input", function () {
if (runOnce == true) {
$(".progress-icon").hide();
$("#load-noti").hide();
$(".summarize-button").fadeIn();
}
});
});
$('#short_button').on("click", function () {
var outputField = document.getElementById("output_text");
outputField.innerHTML = short_summary;
});
$('#long_button').on("click", function () {
var outputField = document.getElementById("output_text");
outputField.innerHTML = long_summary;
});
setInterval(function (e) {
var strText = jQuery.trim($('#input_text').val());
var cntChar = strText.replace(/ /g, '').length;
var cntWord = strText.split(/\s+/).length;
var cntPar = strText.split("\n").length;
var postFix = '';
if (strText == '') {
cntWord = 0;
cntLine = 0;
}
//$('#cnt-paras').children('p').text(cntPar + (cntPar > 1 ? " pars" : " par"));
$('#cnt-words').children('p').text(cntWord + (cntWord > 1 ? " words" : " word"));
$('#cnt-chars').children('p').text(cntChar + (cntChar > 1 ? " chars" : " char"));
}, 100);
// ======= COMMUNICATE WITH FLSAK BACK END TO RUN ML TASK =======
$(document).on('submit', '#input_form', function (e) {
var outputField = document.getElementById("output_text");
var data = { "input_text": $("#input_text").val() };
e.preventDefault();
$.ajax({
type: 'POST',
url: '/summarize',
data: JSON.stringify(data),
contentType: "application/json",
dataType: 'json',
beforeSend: function () {
$("#check").attr('checked', false);
$("#input_text").attr("readonly", true);
$(".summarize-button").hide();
$(".progress-icon").fadeIn();
$("#load-noti").fadeIn();
},
success: function (response) {
$("#check").attr('checked', true);
$("#input_text").attr("readonly", false);
$("#load-noti").text("Completed")
short_summary = response.short;
long_summary = response.long;
outputField.innerHTML = short_summary;
},
complete: function () {
runOnce = true;
},
})
}); |