kdj_singlish
Version:
KDJ Singlish is an app which created to help people to type in sinhala without making any mistakes. This will save your time and fix all the issues you are getting when you type. Just use it and let me know the issues.
696 lines (644 loc) • 36.5 kB
JavaScript
function changeFont(a) {
switch (a) {
case 0:
if ("undefined" == typeof fonObjMap[0] ? (fontObj = new getPropertyFont0, vowels = fontObj.vowels, pureConsonant = fontObj.pureConsonant, allPossibleChars = fontObj.getAllPossibleChars(), fonObjMap[0] = fontObj) : (fontObj = fonObjMap[0], vowels = fontObj.vowels, pureConsonant = fontObj.pureConsonant, allPossibleChars = fontObj.allPossibleChars), 0 == $("#english_era").length) return;
$("#singhala_era").css("font-family", "monospace"), $(".currentWord").css("font-family", "monospace"), $("#suggestions").css("font-family", "monospace"), convert();
break;
case 1:
"undefined" == typeof fonObjMap[1] ? (fontObj = new getPropertyFont1, vowels = fontObj.vowels, pureConsonant = fontObj.pureConsonant, allPossibleChars = fontObj.getAllPossibleChars(), fonObjMap[1] = fontObj) : (fontObj = fonObjMap[1], vowels = fontObj.vowels, pureConsonant = fontObj.pureConsonant, allPossibleChars = fontObj.allPossibleChars), $("#singhala_era").css("font-family", "FM ARJUN, FM ARJUN_IE"), $(".currentWord").css("font-family", "FM ARJUN, FM ARJUN_IE"), $("#suggestions").css("font-family", "FM ARJUN, FM ARJUN_IE"), convert();
break;
case 2:
"undefined" == typeof fonObjMap[1] ? (fontObj = new getPropertyFont1, vowels = fontObj.vowels, pureConsonant = fontObj.pureConsonant, allPossibleChars = fontObj.getAllPossibleChars(), fonObjMap[1] = fontObj) : (fontObj = fonObjMap[1], vowels = fontObj.vowels, pureConsonant = fontObj.pureConsonant, allPossibleChars = fontObj.allPossibleChars), $("#singhala_era").css("font-family", "FM Ababld-Bold, FM Ababld-Bold_IE"), $(".currentWord").css("font-family", "FM Ababld-Bold, FM Ababld-Bold_IE"), $("#suggestions").css("font-family", "FM Ababld-Bold, FM Ababld-Bold_IE"), convert();
break;
case 3:
"undefined" == typeof fonObjMap[1] ? (fontObj = new getPropertyFont1, vowels = fontObj.vowels, pureConsonant = fontObj.pureConsonant, allPossibleChars = fontObj.getAllPossibleChars(), fonObjMap[1] = fontObj) : (fontObj = fonObjMap[1], vowels = fontObj.vowels, pureConsonant = fontObj.pureConsonant, allPossibleChars = fontObj.allPossibleChars), $("#singhala_era").css("font-family", "FM Gemunu, FM Gemunu_IE"), $(".currentWord").css("font-family", "FM Gemunu, FM Gemunu_IE"), $("#suggestions").css("font-family", "FM Gemunu, FM Gemunu_IE"), convert();
break;
case 4:
"undefined" == typeof fonObjMap[1] ? (fontObj = new getPropertyFont1, vowels = fontObj.vowels, pureConsonant = fontObj.pureConsonant, allPossibleChars = fontObj.getAllPossibleChars(), fonObjMap[1] = fontObj) : (fontObj = fonObjMap[1], vowels = fontObj.vowels, pureConsonant = fontObj.pureConsonant, allPossibleChars = fontObj.allPossibleChars), $("#singhala_era").css("font-family", "FM Derana, FM Derana_IE"), $(".currentWord").css("font-family", "FM Derana, FM Derana_IE"), $("#suggestions").css("font-family", "FM Derana, FM Derana_IE"), convert();
break;
case 5:
"undefined" == typeof fonObjMap[5] ? (fontObj = new getPropertyFont5, vowels = fontObj.vowels, pureConsonant = fontObj.pureConsonant, allPossibleChars = fontObj.getAllPossibleChars(), fonObjMap[5] = fontObj) : (fontObj = fonObjMap[5], vowels = fontObj.vowels, pureConsonant = fontObj.pureConsonant, allPossibleChars = fontObj.allPossibleChars), $("#singhala_era").css("font-family", "DL Araliya, DL Araliya_IE"), $(".currentWord").css("font-family", "DL Araliya, DL Araliya_IE"), $("#suggestions").css("font-family", "DL Araliya, DL Araliya_IE"), convert();
break;
case 6:
"undefined" == typeof fonObjMap[1] ? (fontObj = new getPropertyFont1, vowels = fontObj.vowels, pureConsonant = fontObj.pureConsonant, allPossibleChars = fontObj.getAllPossibleChars(), fonObjMap[1] = fontObj) : (fontObj = fonObjMap[1], vowels = fontObj.vowels, pureConsonant = fontObj.pureConsonant, allPossibleChars = fontObj.allPossibleChars), $("#singhala_era").css("font-family", "FM Rajantha, FM Rajantha_IE"), $(".currentWord").css("font-family", "FM Rajantha, FM Rajantha_IE"), $("#suggestions").css("font-family", "FM Rajantha, FM Rajantha_IE"), convert();
break;
case 7:
"undefined" == typeof fonObjMap[1] ? (fontObj = new getPropertyFont1, vowels = fontObj.vowels, pureConsonant = fontObj.pureConsonant, allPossibleChars = fontObj.getAllPossibleChars(), fonObjMap[1] = fontObj) : (fontObj = fonObjMap[1], vowels = fontObj.vowels, pureConsonant = fontObj.pureConsonant, allPossibleChars = fontObj.allPossibleChars), $("#singhala_era").css("font-family", "FM Samantha, FM Samantha_IE"), $(".currentWord").css("font-family", "FM Samantha, FM Samantha_IE"), $("#suggestions").css("font-family", "FM Samantha, FM Samantha_IE"), convert();
break;
case 8:
"undefined" == typeof fonObjMap[8] ? (fontObj = new getPropertyFont8, vowels = fontObj.vowels, pureConsonant = fontObj.pureConsonant, allPossibleChars = fontObj.getAllPossibleChars(), fonObjMap[8] = fontObj) : (fontObj = fonObjMap[8], vowels = fontObj.vowels, pureConsonant = fontObj.pureConsonant, allPossibleChars = fontObj.allPossibleChars), $("#singhala_era").css("font-family", "MADHURA, MADHURA_IE"), $(".currentWord").css("font-family", "MADHURA, MADHURA_IE"), $("#suggestions").css("font-family", "MADHURA, MADHURA_IE"), convert()
}
}
function showOverflowItems(a) {
a ? $("#modifiresContent").scrollTop($("#modifiresContent").scrollTop() + 20) : $("#modifiresContent").scrollTop($("#modifiresContent").scrollTop() - 20)
}
function showToolBar() {
clearTimeout(toolBarTimer), $("#tool_bar").is("visible") || $("#tool_bar").slideDown()
}
function hideToolBar() {
toolBarTimer = setTimeout(function () {
$("#tool_bar").slideUp()
}, 2e3)
}
function chageFontSize(a) {
$("#english_era").css("font-size", $(a).val()), $("#dummy_content").css("font-size", $(a).val()), setDummyEleWidth(), hideToolBar()
}
function saveSession(a) {
$("#tool_bar").hide(), $.ajax({
method: "POST",
url: "php/AddRetriveRecords.php?action=save_session",
data: {
session_data: $("#english_era").val(),
mode: viewMode,
fontId: $("#selectedFont").attr("font_id")
}
}).done(function (b) {
a && ("" != b && null != b && "s" == b.trim() ? ($("#mail_success_cont").text("Saved data successfully"), $("#mail_success").show(), setTimeout(function () {
$("#mail_success").hide()
}, 2e3)) : ($("#mail_fail_cont").text("Save data failed! try again later!"), $("#mail_fail").show(), setTimeout(function () {
$("#mail_fail").hide()
}, 2e3)))
}).fail(function (b) {
a && ($("#mail_fail_cont").text("Save data failed! try again later!"), $("#mail_fail").show(), setTimeout(function () {
$("#mail_fail").hide()
}, 2e3))
})
}
function showHelp() {
$.ajax("php/AddRetriveRecords.php?action=remove_past_data"), window.open("help.html", "_blank")
}
function showFontHelp() {
$.ajax("php/AddRetriveRecords.php?action=remove_past_data"), window.open("help.html#differentFont", "_blank")
}
function showCommentBox() {
$("#comment_win").show(), $("#comment_name").focus()
}
function cancelCommentBox() {
$("#comment_win").hide()
}
function sendComment() {
var a = $("#comment_name").val(),
b = $("#comment_mail").val(),
c = $("#comment_comment").val();
return 0 == c.trim().length ? void alert("Plase insert your comment before sending!") : ($.ajax({
method: "POST",
url: "php/AddRetriveRecords.php?action=send_comment",
data: {
name: a,
mail: b,
comment: c
}
}).done(function (a) {
$("#mail_success_cont").text("Thank you for your valuable comment!"), $("#mail_success").show(), setTimeout(function () {
$("#mail_success").hide()
}, 2e3)
}).fail(function () {
$("#mail_fail_cont").text("Sorry, your comment sending fail, please try again later"), $("#mail_fail").show(), setTimeout(function () {
$("#mail_fail").hide()
}, 2e3)
}), void $("#comment_win").hide())
}
function addModifire(a) {
$("#english_era").focus();
var b = $("#english_era").prop("selectionStart"),
c = $("#english_era").val();
if (0 != c.length) {
for (var e = c.substr(0, b), f = "", g = b - 1; g >= 0 && (" " != c[g] && "\n" != c[g] && "\t" != c[g]); g--) f += c[g];
var h = getWordToken(f.split("").reverse().join(""));
h = h.slice(0, h.length - 1);
var i = h.split("_"),
j = 0;
if (i.length > 0 && i[i.length - 1].length > 0) {
j = i[i.length - 1].length;
var k = i[i.length - 1];
if ("undefined" != typeof vowels[k]) {
var l = getModifireForVowel(k, a);
e += l, e += c.substr(b, c.length), $("#english_era").val(e), $("#english_era").prop("selectionStart", b + l.length), $("#english_era").prop("selectionEnd", b + l.length)
} else "undefined" != typeof pureConsonant[k] ? (e += a, e += c.substr(b, c.length), $("#english_era").val(e), $("#english_era").prop("selectionStart", b + a.length), $("#english_era").prop("selectionEnd", b + a.length)) : "a" == k[k.length - 1] ? (e = e.slice(0, e.length - 1), e += a, e += c.substr(b, c.length), $("#english_era").val(e), $("#english_era").prop("selectionStart", b + a.length - 1), $("#english_era").prop("selectionEnd", b + a.length - 1)) : alert("First, please insert any base character to modify! like 'k' of 'ka' ")
}
} else alert("First, please insert any base character to modify! like 'k' of 'ka' ");
convert()
}
function myAlert(a, b, c) {
$("#my_alert_cont").html(a), $("#my_alert_body").css("height", b), c ? $("#my_alert_cancel").show() : $("#my_alert_cancel").hide(), $("#my_alert").show()
}
function closeMyAlert() {
$("#my_alert").hide()
}
function getModifireForVowel(a, b) {
if ("a" == a) {
if ("aa" == b) return "a";
if ("ae" == b) return "e";
if ("aee" == b) return "ee";
alert("First, please insert any base character to modify! like 'k' of 'ka' ")
} else alert("First, please insert any base character to modify! like 'k' of 'ka' ");
return ""
}
function changeSugSelection(a) {
var b = $("#suggestions ul li.selected_suggesion");
$("#suggestions ul li").removeClass("selected_suggesion");
var c = $("#suggestions ul li"),
d = b.length - 1;
a || (d = 0), c.length > 0 && b.length > 0 && (d = $("#suggestions ul li").index(b[0]), a ? d-- : d++), d < 0 ? d = c.length - 1 : d >= c.length && (d = 0), $($("#suggestions ul li")[d]).addClass("selected_suggesion")
}
function getCaret(a) {
if (!noTextSelection) return a.selectionStart;
if (document.selection) {
a.focus();
var b = document.selection.createRange();
if (null == b) return 0;
var c = a.createTextRange(),
d = c.duplicate();
return c.moveToBookmark(b.getBookmark()), d.setEndPoint("EndToStart", c), d.text.length
}
return 0
}
function addChar(a) {
$("#english_era").focus();
var b = $("#english_era").prop("selectionStart"),
c = $("#english_era").val();
noTextSelection && isIE && (b = getCaret($("#english_era")[0]));
var e = c.substr(0, b);
e += a, e += c.substr(b, c.length), $("#english_era").val(e), $("#english_era").prop("selectionStart", b + a.length), $("#english_era").prop("selectionEnd", b + a.length), convert()
}
function addSuggetion(a) {
if ("undefined" != typeof a && null != a) {
var b = $(a).attr("code");
if ("undefined" != typeof b && 0 != b.length) {
$("#english_era").focus();
var c = $("#english_era").val(),
d = $("#english_era").prop("selectionStart"),
e = "",
f = c.substr(0, d);
f = f.split("");
var g = -1;
if (f.length > 0 && "\n" != f[f.length - 1])
for (var h = f.length - 1; h >= 0 && (" " != f[h] && "\n" != f[h] && "\t" != f[h]); h--) g = h;
if (g >= 0 && g < parseInt(d)) {
e += c.substr(0, g), e += b;
c.split("");
"undefined" != typeof b[d] && " " == b[d] && "\t" == b[d] || (e += " "), c.length > parseInt(d) && (e += c.substr(d, c.length - 1)), $("#english_era").val(e), $("#english_era").prop("selectionStart", g + b.length + 1), $("#english_era").prop("selectionEnd", g + b.length + 1)
}
3 == viewMode ? processSingleMode(!0, "M") : convert()
}
}
}
function isMobileMode() {
return !$($(".toolBar")[0]).is(":visible")
}
function setDocSize() {
$("#mid_row").hide();
var a = 100;
isMobileMode() ? (chageView(2, $("#view2")), a = $(document).innerHeight() - 100 - parseInt($("body").css("margin-top")) - parseInt($("body").css("margin-bottom"))) : (chageView(viewMode, $("#view" + viewMode)), a = $(document).innerHeight() - 210 - parseInt($("body").css("margin-top")) - parseInt($("body").css("margin-bottom"))), $("#mid_row").height(a + "px"), $("#mid_row").show(), setDummyEleWidth()
}
function setDummyEleWidth() {
$("#english_era")[0].scrollHeight - $("#english_era").innerHeight() > 2 && $("#dummy_content").width($("#english_era")[0].clientWidth)
}
function isWordBreaker(a) {
return "\n" == a || "\t" == a || " " == a
}
function processSingleMode(a, b) {
var c = $("#english_era").val(),
d = !1,
e = c.length;
if (3 == viewMode && 0 != c.length) {
$("#english_era").focus();
for (var f = $("#english_era").prop("selectionStart"), g = $("#english_era").prop("selectionStart"), h = f, i = f, j = f - 1; j >= 0; j--)
if (isWordBreaker(c[j]) || 0 == j) {
h = j;
break
} for (var j = f; j <= c.length; j++)
if (j == c.length || isWordBreaker(c[j])) {
i = j;
break
} var k = "";
if (h > 0) {
var l = c.substr(0, h + 1);
k = getUnicodeTextSingleView(l)
}
var m = 0 == h ? 0 : h + 1;
if (m < i) {
var n = c.substring(m, i);
if (isEnglishWord(n) || "undefined" == typeof singleModeWordsMap[n]) a = !1;
else {
n = singleModeWordsMap[n], d = !0;
var o = Math.floor(n.length / 2);
"L" == b ? o = 0 : "R" == b && (o = n.length), e = k.length + o
}
k += n
} else g = k.length;
if (i < c.length) {
var p = c.substr(i, c.length);
k += getUnicodeTextSingleView(p)
}
if ($("#english_era").val(k), d) $("#english_era").prop("selectionStart", e), $("#english_era").prop("selectionEnd", e);
else if (a) {
for (var q = $("#english_era").val().length, r = $("#english_era").val(), j = f; j <= r.length; j++)
if (j == r.length || isWordBreaker(r[j])) {
q = j;
break
} $("#english_era").prop("selectionStart", q + 1), $("#english_era").prop("selectionEnd", q + 1)
} else $("#english_era").prop("selectionStart", g), $("#english_era").prop("selectionEnd", g);
if ("undefined" != typeof singleModeEngText && singleModeEngText.length > 0)
for (var s = singleModeEngText.split(/\s/g), t = 0; t < s.length - 1; t++) localWordList[s[t]] = !0
}
}
function getUnicodeTextSingleView(a) {
singleModeEngText = "";
for (var b = "", c = "", d = 0; d < a.length; d++)
if (isWordBreaker(a[d])) {
var e = toSinghalaWord(b);
isEnglishWord(b) || "undefined" == typeof singleModeWordsMap[e] ? (singleModeEngText += b + a[d], singleModeWordsMap[e] = b) : singleModeEngText += singleModeWordsMap[e] + a[d], c += e + a[d], b = ""
} else b += a[d];
var e = toSinghalaWord(b);
return isEnglishWord(b) || "undefined" == typeof singleModeWordsMap[e] ? (singleModeEngText += b, singleModeWordsMap[e] = b) : singleModeEngText += singleModeWordsMap[e], c += e
}
function isEnglishWord(a) {
for (var b = !0, c = 0; c < a.length; c++)
if (a.charCodeAt(c) > 127) {
b = !1;
break
} return b
}
function getPosition(a) {
var b = "M";
return 37 == a || 8 == a ? b = "R" : 39 != a && 46 != a || (b = "L"), b
}
function convert(a) {
if (setCurrentWordText(), 3 == viewMode) return void("undefined" != typeof a && 0 == a.keyCode ? processSingleMode(!1, "M") : "undefined" == typeof a || 32 != a.keyCode && 13 != a.keyCode && 9 != a.keyCode ? "undefined" == typeof a || $("#suggestions").is(":visible") || 37 != a.keyCode && 38 != a.keyCode && 39 != a.keyCode && 40 != a.keyCode && 46 != a.keyCode && 8 != a.keyCode || processSingleMode(!1, getPosition(a.keyCode)) : processSingleMode(!0, "M"));
var b = $("#english_era").val();
b = b.replace(/(?:\t)/g, " ");
var c = b.split(" "),
d = "",
e = !1,
f = $("#english_era").prop("selectionStart"),
g = !1;
b.length != f && (g = !0);
for (var h = 0; h < c.length; h++)
if ("<--" != c[h])
if ("-->" != c[h])
if (e) d += c[h] + " ";
else {
if (h != c.length - 1 && !g)
for (var i = c[h].split(/\s/g), j = 0; j < i.length; j++) localWordList[i[j]] = !0;
d += toSinghalaWord(c[h]) + " "
}
else e = !1;
else e = !0;
$("#singhala_era").val(d), isIE && $("#singhala_era").val().length > 0 && $("#singhala_era").val($("#singhala_era").val()), $("#english_era").val().length - $("#english_era").prop("selectionStart") < 10 && $("#singhala_era").animate({
scrollTop: $("#singhala_era")[0].scrollHeight
}, "slow")
}
function setCurrentWordText() {
for (var a = $("#english_era").val(), b = $("#english_era").prop("selectionStart"), d = ($("#english_era").prop("selectionStart"), b), e = b, f = b - 1; f >= 0; f--)
if (isWordBreaker(a[f]) || 0 == f) {
d = f;
break
} for (var f = b; f <= a.length; f++)
if (f == a.length || isWordBreaker(a[f])) {
e = f;
break
} var g = 0 == d ? 0 : d + 1;
if (g < e) {
var h = a.substring(g, e);
isEnglishWord(h) && $("#currentWordInput").html(toSinghalaWord(h))
} else $("#currentWordInput").html("");
if (isWordBreaker(a[b - 1]) && b - 2 >= 0) {
for (var f = b - 2; f >= 0; f--) {
if (isWordBreaker(a[f])) {
d = f + 1;
break
}
if (0 == f) {
d = f;
break
}
}
if (d >= 0 && b - d >= 2) {
var i = a.substring(d, b - 1);
showNextWords(i)
}
} else $(".currentWord").find("span").remove()
}
function showNextWords(a) {
if (3 != viewMode || isEnglishWord(a)) {
$(".currentWord").find("span").remove();
var b = new Array;
if ("undefined" != typeof nextWordMap[a]) b = nextWordMap[a], addDOMNextWords(b);
else {
if (null != nextXHR) try {
nextXHR.abort(), nextXHR = null
} catch (a) {}
nextXHR = $.ajax("php/AddRetriveRecords.php?action=get_next_word¤t_word=" + a).done(function (c) {
if (null != c && c.length > 0) {
try {
b = JSON.parse(c)
} catch (a) {}
$(".currentWord").find("span").remove(), "object" == typeof b && Object.keys(b).length > 0 && (addDOMNextWords(b), nextWordMap[a] = b)
}
}).fail(function () {})
}
}
}
function addDOMNextWords(a) {
var b = $("#selectedFont").attr("font_id"),
c = "undefined" == typeof $("#fontSizeSelector").val() ? 16 : $("#fontSizeSelector").val();
0 == b ? $(".currentWord").append("<span class='nextWord' >Ctrl+</span>") : $(".currentWord").append("<span class='nextWord' ></span>"), $.each(a, function (a, b) {
var d = parseInt(a) + 1,
e = "undefined" == typeof allPossibleChars["."] ? "." : allPossibleChars["."],
f = $("<span style='font-size:" + c + "px' onclick='addNextWord(this)' eng_word='" + b + "' class='nextWord' >" + d + e + toSinghalaWord(b) + "</span>");
$(".currentWord").append(f)
})
}
function addNextWord(a) {
var b = $(a).attr("eng_word");
"undefined" != typeof b && b.length > 0 && addChar(b + " "), 3 == viewMode && processSingleMode(!0, "M")
}
function toSinghalaWord(a) {
for (var b = "", c = "", f = 0; f < a.length; f++) {
var g = a[f];
"undefined" == typeof allPossibleChars[c + g] ? (b += "undefined" != typeof allPossibleChars[c] ? allPossibleChars[c] : c, c = g) : c += g
}
return b += "undefined" != typeof allPossibleChars[c] ? allPossibleChars[c] : c, fontObj.postProcessingWord(b)
}
function switchLan() {
if (3 == viewMode) return void alert("Sorry, currently this function is not available for the single mode view");
if (0 != parseInt($("#selectedFont").attr("font_id"))) return void alert("Sorry, currently this function is available only for sinhala unicode font!");
var a = $("#english_era").val();
inputTextArr = a.split(/\s/g);
for (var b = new Array, c = 0; c < inputTextArr.length; c++) "<--" == inputTextArr[c].trim() ? b.push("open") : "-->" == inputTextArr[c].trim() && (0 == b.length ? b.push("close") : "open" == b[b.length - 1] ? 1 == b.length ? b = new Array : b.slice(0, b.length - 1) : b.push("close"));
openEnglish = 0 != b.length && "open" == b[b.length - 1], $("#english_era").focus();
var d = $("#english_era").prop("selectionStart"),
a = $("#english_era").val(),
e = "--> ";
openEnglish ? ($("#lanSwitcher").html("සිංහල (Ctrl+e)"), a.length > 0 && " " != a[d - 1] && (e = " " + e)) : ($("#lanSwitcher").html("Eng. (Ctrl+e)"), e = "<-- ", a.length > 0 && " " != a[d - 1] && (e = " " + e)), openEnglish = !openEnglish;
var g = a.substr(0, d);
g += e, g += a.substr(d, a.length), $("#english_era").val(g), $("#english_era").prop("selectionStart", d + e.length), $("#english_era").prop("selectionEnd", d + e.length)
}
function showSuggestions(a) {
if (null != suggestXHR) try {
suggestXHR.abort(), suggestXHR = null
} catch (a) {}
37 == a.keyCode || 38 == a.keyCode || 39 == a.keyCode || 40 == a.keyCode || 13 == a.keyCode || 27 == a.keyCode || openEnglish || ($("#suggestions").hide(), clearTimeout(suggesionsTimer), suggesionsTimer = setTimeout(function () {
showSuggestionsOntimeOut()
}, 300))
}
function showSuggestionsOntimeOut() {
$("#english_era").focus();
var a = $("#english_era").val(),
b = $("#english_era").prop("selectionStart"),
c = a.substr(0, b),
d = "";
if (c.length > 0 && "\n" != c[c.length - 1])
for (var e = c.length - 1; e >= 0 && (" " != c[e] && "\n" != c[e] && "\t" != c[e]); e--) d += c[e];
if (0 == d.length) return void $("#suggestions").hide();
var f = d.split("").reverse().join("");
getServerSuggestionList(f, c)
}
function updateSuggesionList(a, b) {
if (0 == a.length) return void $("#suggestions").hide();
var c = "";
$.each(a, function (a, b) {
c += "<li onclick='addSuggetion(this)' code='" + b + "' >" + toSinghalaWord(b) + "</li>"
}), $("#suggestions ul").html(c), $($("#suggestions ul").children()[0]).addClass("selected_suggesion");
var d = b.replace(/(?:\r\n|\r|\n)/g, "<br />");
$("#dummy_content span").html(d), setDummyEleWidth();
var e = $("#dummy_content").offset().top,
f = $("#dummy_content").height() - $("#english_era").scrollTop(),
g = $("#dummy_content span")[0].getClientRects(),
h = g[g.length - 1],
i = h.left + h.width;
if (!isMobileMode() && $("body").height() < parseFloat(e + f) + $("#suggestions").height()) {
var j = $("#suggestions").height();
$("#suggestions").css("top", parseFloat(e + f - j - 13) + "px")
} else $("#suggestions").css("top", parseFloat(e + f) + "px");
$("#suggestions").css("left", parseFloat(i) + "px"), $("#suggestions").show()
}
function getServerSuggestionList(a, b) {
var c = new Array;
if ($.each(localWordList, function (b, d) {
b.substr(0, a.length) == a && c.push(b)
}), $("#offline_sugg").is(":checked")) updateSuggesionList(c, b);
else {
if (null != suggestXHR) try {
suggestXHR.abort(), suggestXHR = null
} catch (a) {}
suggestXHR = $.ajax("php/AddRetriveRecords.php?action=get_suggestions&token=" + getWordToken(a)).done(function (a) {
if (null != a && a.length > 0) {
try {
$.extend(c, JSON.parse(a))
} catch (a) {}
updateSuggesionList(c, b)
} else updateSuggesionList(c, b)
}).fail(function (a, d, e) {
"abort" != d && updateSuggesionList(c, b)
})
}
}
function getWordToken(a) {
for (var b = "", c = "", f = 0; f < a.length; f++) {
var g = a[f];
"undefined" == typeof allPossibleChars[c + g] ? (b += "undefined" != typeof allPossibleChars[c] ? c + "_" : c + "_", c = g) : c += g
}
return b += c + "_"
}
function resetText() {
$("#english_era").html(""), $("#english_era").val(""), $("#singhala_era").html(""), $("#singhala_era").val("")
}
function copyEnglish() {
$("#english_era").prop("selectionStart", 0), $("#english_era").prop("selectionEnd", $("#english_era").val().length)
}
function copySinghala() {
$("#singhala_era").prop("selectionStart", 0), $("#singhala_era").prop("selectionEnd", $("#english_era").val().length)
}
function chageView(a, b) {
if (1 == a) setPortrait(viewMode);
else if (2 == a) setlandScape(viewMode);
else if (3 == a) {
var c = /(<--).+(-->)/;
if (c.test($("#english_era").val())) return void alert("Your script contains pure english text, currently this view is not supporting the switch language feature. Please remove text between '<--' and '-->' and try again!");
if (0 != parseInt($("#selectedFont").attr("font_id"))) return void alert("Sorry, currently this view is available only for sinhala unicode font!");
setSingleView(viewMode)
}
$(".view_handler").css("border-bottom", "none"), $(b).css("border-bottom", "3px red solid")
}
function setlandScape(a) {
$(".right_row").show(), $("#midPaneBreaker").show(), $(".mid_mid_row").css("float", "right"), $(".left_row").css({
height: "48%",
width: "90%"
}), $(".right_row").css({
height: "48%",
width: "90%",
"margin-left": "1%"
}), isMobileMode() && ($(".left_row").css({
width: "98%"
}), $(".right_row").css({
width: "98%"
})), viewMode = 2, 3 == a && singleModeEngText && ($("#english_era").val(singleModeEngText), convert())
}
function setPortrait(a) {
$(".right_row").show(), $("#midPaneBreaker").hide(), $(".mid_mid_row").css("float", "left"), $(".left_row").css({
height: "100%",
width: "45%"
}), $(".right_row").css({
height: "100%",
width: "45%",
"margin-left": "0px"
}), viewMode = 1, 3 == a && singleModeEngText && ($("#english_era").val(singleModeEngText), convert())
}
function setSingleView(a) {
$("#midPaneBreaker").hide(), $(".mid_mid_row").css("float", "right"), $(".right_row").hide(), $(".left_row").css({
height: "100%",
width: "90%"
}), viewMode = 3, processSingleMode(!0, "M")
}
function changedFont(a) {
var b = $(a).attr("fontId");
if (3 == viewMode) return void alert("Sorry, currently this view is available only for sinhala unicode font!");
if (0 != b) {
var c = /(<--).+(-->)/;
if (c.test($("#english_era").val())) return void alert("Your script contains pure english text, currently this view is supporting only for sinhala unicode font. Please remove text between '<--' and '-->' and try again!")
}
var d = $(a).attr("font_file");
$("#fontLink").attr("href", "fonts/" + d);
var e = $(a).attr("font_size");
$("#selectedFont").html($(a).html()), $("#selectedFont").attr("font_id", b), $("#fontSizeSelector").val(parseInt(e)), changeSinhalaFontSize($("#fontSizeSelector")), changeFont(parseInt(b))
}
function changeSinhalaFontSize(a) {
var b = $(a).val();
$("#singhala_era").css("font-size", b + "px")
}
function removeFontFace() {
$("#fontSelecter").css({
"font-family": "monospace"
})
}
function showFontList() {
$("#fontSelector").show(), $(".selectedFont").css({
"border-bottom-width": "0px",
"-webkit-border-bottom-right-radius": "0px",
"-webkit-border-bottom-left-radius": "0px",
"-moz-border-radius-bottomright": "0px",
"-moz-border-radius-bottomleft": "0px",
"border-bottom-right-radius": "0px",
"border-bottom-left-radius": "0px"
})
}
function hideFontList() {
$("#fontSelector").hide(), $(".selectedFont").css({
"border-bottom-width": "1px",
"-webkit-border-bottom-right-radius": "4px",
"-webkit-border-bottom-left-radius": "4px",
"-moz-border-radius-bottomright": "4px",
"-moz-border-radius-bottomleft": "4px",
"border-bottom-right-radius": "4px",
"border-bottom-left-radius": "4px"
})
}
function boldSinhalaArea(a) {
"0" == $(a).attr("bold") ? ($(a).attr("bold", "1"), $(a).css("background-color", "yellow"), $("#singhala_era").css("font-weight", "bold")) : ($(a).attr("bold", "0"), $(a).css("background-color", ""), $("#singhala_era").css("font-weight", "normal"))
}
function likeUs() {
liked || $.ajax({
method: "POST",
url: "php/AddRetriveRecords.php?action=like_us"
}).done(function (a) {
"" != a && null != a && "s" == a.trim() ? ($("#likeCount").text(parseInt($("#likeCount").text()) + 1), $("#likeUsBtn").css("border", "1px rgb(244, 134, 134) solid")) : $("#likeUsBtn").css("border", "1px rgb(244, 134, 134) solid"), liked = !0
}).fail(function (a) {})
}
var openEnglish = !1,
localWordList = {},
vowels = {},
pureConsonant = {},
lastSentIndex = 0,
lastSentNextIndex = 0,
noTextSelection = !1,
liked = !1,
toolBarTimer, suggesionsTimer = null,
viewMode = 1,
singleModeEngText = "",
singleModeWordsMap = {},
fontObj = null,
numFonts = 9,
fonObjMap = new Array(numFonts),
allPossibleChars = {},
isIE = !1,
nextWordMap = {},
suggestXHR = null,
nextXHR = null;
try {
isIE = !!document.documentMode
} catch (a) {}
"function" != typeof String.prototype.trim && (String.prototype.trim = function () {
return this.replace(/^\s+|\s+$/g, "")
}), $(document).ready(function () {
changeFont(0), 0 != $("#english_era").length && ($("#english_era").focus(), "undefined" == typeof $("#english_era").prop("selectionStart") && (noTextSelection = !0), setDocSize(), $("#english_era").attr("placeholder", "Waiting..."), $.ajax({
method: "POST",
url: "php/AddRetriveRecords.php?action=update_hits"
}).done(function (a) {
try {
var b = JSON.parse(a);
if (b.likeCount.trim() == parseInt(b.likeCount.trim()) && $("#likeCount").text(parseInt(b.likeCount.trim())), "undefined" != typeof b.history && "" != b.history.trim() && confirm("We have your last session hitory data, do you want to restore them? ")) {
$("#english_era").val(b.history), convert();
var c = 0,
d = 1;
"undefined" != typeof b.fontId && "" != b.fontId.trim() && (c = parseInt(b.fontId) >= 0 && parseInt(b.fontId) <= numFonts ? parseInt(b.fontId) : 0), "undefined" != typeof b.mode && "" != b.mode.trim() && (d = parseInt(b.mode) > 0 ? parseInt(b.mode) : 1), c > 0 && $("[fontId=" + c + "]").click(), chageView(d, $("#view" + d))
}
} catch (a) {}
$("#english_era").attr("placeholder", "Insert Your Sinhala Text by Singlish (Phonetic Notation) Here")
}).fail(function () {
$("#english_era").attr("placeholder", "Insert Your Sinhala Text by Singlish (Phonetic Notation) Here")
}), $(window).resize(function () {
setDocSize()
}), $("#tool_handler").mouseenter(function () {
showToolBar()
}), $("#tool_bar").mouseleave(function (a) {
"change_font" != a.target.id && hideToolBar()
}), $("#tool_bar").mouseenter(function (a) {
showToolBar()
}), setInterval(function () {
var a = 0,
b = Object.keys(localWordList);
if (lastSentIndex != b.length) {
lastSentIndex > b.length && (lastSentIndex = 0), a = b.length;
var c = $("#auto_save").is(":checked") ? $("#english_era").val() : "";
3 == viewMode && (c = $("#auto_save").is(":checked") ? singleModeEngText : ""), $.ajax({
method: "POST",
url: "php/AddRetriveRecords.php?action=add_words",
data: {
wordList: JSON.stringify(b.slice(lastSentIndex, b.length)),
fullText: c,
save_session: $("#auto_save").is(":checked"),
mode: viewMode,
fontId: $("#selectedFont").attr("font_id")
}
}).done(function (b) {
try {
1 == parseInt(b) && (lastSentIndex = a)
} catch (a) {}
})
}
}, 15e3), setInterval(function () {
var a = $("#english_era").val(),
b = a.split(/\s+/);
b.length > 1 && b.length - lastSentNextIndex > 2 && $.ajax({
method: "POST",
url: "php/AddRetriveRecords.php?action=add_next_list",
data: {
wordList: JSON.stringify(b.slice(lastSentNextIndex, b.length - 1))
}
}).done(function (a) {
try {
1 == parseInt(a) && (lastSentNextIndex = b.length - 2)
} catch (a) {}
})
}, 2e4), $("#english_era").bind("paste", null, function (a) {
3 == viewMode && setTimeout(function () {
processSingleMode(!0, "M")
}, 100)
}))
}), $(document).click(function (a) {
$("#suggestions").hide(), 0 == $(a.target).closest(".selectedFontCont").length && hideFontList()
}), $(document).keydown(function (a) {
39 == a.keyCode ? $("#suggestions").hide() : 37 == a.keyCode ? $("#suggestions").hide() : 38 == a.keyCode ? $("#suggestions").is(":visible") && (changeSugSelection(!0), a.preventDefault()) : 40 == a.keyCode ? $("#suggestions").is(":visible") && (changeSugSelection(!1), a.preventDefault()) : 13 == a.keyCode ? $("#suggestions").is(":visible") && ($("#suggestions").hide(), addSuggetion($("#suggestions ul li.selected_suggesion")), a.preventDefault()) : a.ctrlKey && 69 == a.keyCode ? (switchLan(), a.preventDefault()) : a.ctrlKey && 83 == a.keyCode ? (saveSession(!1), a.preventDefault()) : a.ctrlKey && a.keyCode >= 49 && a.keyCode <= 57 ? ($(".currentWord").children("span").length >= a.keyCode - 47 && addNextWord($(".currentWord").children("span")[a.keyCode - 48]), a.preventDefault()) : 27 == a.keyCode && $("#suggestions").hide()
});