Skip to content

Commit

Permalink
Fix names.
Browse files Browse the repository at this point in the history
  • Loading branch information
JPJPJPOPOP committed Jan 6, 2018
1 parent 9e67f03 commit 02ab612
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 74 deletions.
9 changes: 5 additions & 4 deletions assets/css/translation.css
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ html[dir='rtl'] #srcLanguages {

/* Spell Checker */

#spellcheckerInput {
#spellCheckerInput {
display: block;
height: 131px;
overflow: auto;
resize: both;
}

.spellcheckVisible .spellError {
.spellCheckerVisible .spellError {
border-bottom: 1px solid #f00;
}

Expand All @@ -97,14 +97,15 @@ html[dir='rtl'] #srcLanguages {
width: 110%;
}

.list-group { /* sass-lint:disable-line class-name-format */
.spellCheckerList {
margin-bottom: 0;
}

.list-group-item { /* sass-lint:disable-line class-name-format */
.spellCheckerListItem {
border: 0;
cursor: pointer;
padding: 4px 10px;
display: block;
}

#translatedWebpage {
Expand Down
43 changes: 22 additions & 21 deletions assets/js/persistence.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/* exported persistChoices, restoreChoices, cache, readCache */

/* global config, Store, getURLParam, iso639CodesInverse, pairs, refreshLangList populateSecondaryAnalyzerList,
populateSecondaryGeneratorList, populateSecondarySpellcheckerList, isSubset, handleNewCurrentLang */
populateSecondaryGeneratorList, populateSecondarySpellCheckerList, isSubset, handleNewCurrentLang */
/* global srcLangs, dstLangs, recentSrcLangs, recentDstLangs, setCurDstLang, setCurSrcLang, setRecentDstLangs, setRecentSrcLangs, setLocale,
curSrcLang, curDstLang, locale */

Expand All @@ -13,7 +13,8 @@ var URL_PARAM_Q_LIMIT = 1300,
'#translation': 'q',
'#webpageTranslation': 'qP',
'#analyzation': 'qA',
'#generation': 'qG'
'#generation': 'qG',
'#spellchecker': 'qS'
};

var store = new Store(config.HTML_URL);
Expand Down Expand Up @@ -75,9 +76,9 @@ function persistChoices(mode /*: string */, updatePermalink /*: ?boolean */) {
}
else if(mode === 'spellchecker') {
objects = {
'primarySpellcheckerChoice': $('#primarySpellcheckerMode').val(),
'secondarySpellcheckerChoice': $('#secondarySpellcheckerMode').val(),
'spellcheckerInput': $('#spellcheckerInput').text(),
'primarySpellCheckerChoice': $('#primarySpellCheckerMode').val(),
'secondarySpellCheckerChoice': $('#secondarySpellCheckerMode').val(),
'spellCheckerInput': $('#spellCheckerInput').text(),
'instantChecking': $('#instantChecking').val()
};
}
Expand Down Expand Up @@ -130,10 +131,10 @@ function persistChoices(mode /*: string */, updatePermalink /*: ?boolean */) {
urlParams.push('choice=' + encodeURIComponent($('#secondaryGeneratorMode').val()));
qVal = $('#morphGeneratorInput').val();
}
else if(hash === '#spellchecker' && $('#secondarySpellcheckerMode').val()) {
else if(hash === '#spellchecker' && $('#secondarySpellCheckerMode').val()) {
urlParams = [];
urlParams.push('choice=' + encodeURIComponent($('#secondarySpellcheckerMode').val()));
qVal = $('#spellcheckerInput').text();
urlParams.push('choice=' + encodeURIComponent($('#secondarySpellCheckerMode').val()));
qVal = $('#spellCheckerInput').text();
}

var qName /*: string */ = HASH_URL_MAP[hash];
Expand Down Expand Up @@ -281,28 +282,28 @@ function restoreChoices(mode /*: string */) {
}
else if(mode === 'spellchecker') {
if(store.able()) {
var primarySpellcheckerChoice = store.get('primarySpellcheckerChoice', ''),
secondarySpellcheckerChoice = store.get('secondarySpellcheckerChoice', '');
if(store.has('primarySpellcheckerChoice') && store.has('secondarySpellcheckerChoice')) {
$('#primarySpellcheckerMode option[value="' + primarySpellcheckerChoice + '"]').prop('selected', true);
populateSecondarySpellcheckerList();
$('#secondarySpellcheckerMode option[value="' + secondarySpellcheckerChoice + '"]').prop('selected', true);
var primarySpellCheckerChoice = store.get('primarySpellCheckerChoice', ''),
secondarySpellCheckerChoice = store.get('secondarySpellCheckerChoice', '');
if(store.has('primarySpellCheckerChoice') && store.has('secondarySpellCheckerChoice')) {
$('#primarySpellCheckerMode option[value="' + primarySpellCheckerChoice + '"]').prop('selected', true);
populateSecondarySpellCheckerList();
$('#secondarySpellCheckerMode option[value="' + secondarySpellCheckerChoice + '"]').prop('selected', true);
}
else {
populateSecondarySpellcheckerList();
populateSecondarySpellCheckerList();
}
if(store.has('spellcheckerInput')) {
$('#spellcheckerInput').text(store.get('spellcheckerInput'));
if(store.has('spellCheckerInput')) {
$('#spellCheckerInput').text(store.get('spellCheckerInput'));
$('#instantChecking').prop('checked', store.get('instantChecking', true));
}
}

if(getURLParam('choice')) {
choice = getURLParam('choice').split('-');
$('#primarySpellcheckerMode option[value="' + choice[0] + '"]').prop('selected', true);
populateSecondarySpellcheckerList();
$('#primarySpellCheckerMode option[value="' + choice[0] + '"]').prop('selected', true);
populateSecondarySpellCheckerList();
if(choice.length === 2) {
$('#secondarySpellcheckerMode option[value="' + choice.join('-') + '"]').prop('selected', true);
$('#secondarySpellCheckerMode option[value="' + choice.join('-') + '"]').prop('selected', true);
}
}
}
Expand All @@ -329,6 +330,6 @@ function restoreChoices(mode /*: string */) {
/*:: import {iso639Codes, iso639CodesInverse, locale, setLocale} from "./localization.js" */
/*:: import {populateSecondaryGeneratorList} from "./generator.js" */
/*:: import {populateSecondaryAnalyzerList} from "./analyzer.js" */
/*:: import {populateSecondarySpellcheckerList} from "./spellchecker.js" */
/*:: import {populateSecondarySpellCheckerList} from "./spellchecker.js" */
/*:: import {getURLParam, isSubset} from "./util.js" */
/*:: import {Store} from "./store.js" */
81 changes: 38 additions & 43 deletions assets/js/spellchecker.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var spellers = {}, spellerData = {};
var currentSpellCheckerRequest;

/* exported getSpellers, populateSecondarySpellcheckerList */
/* exported getSpellers, populateSecondarySpellCheckerList */
/* global config, modeEnabled, persistChoices, readCache, ajaxSend, ajaxComplete, filterLangList, allowedLang, analyzers, cache,
localizeInterface, getLangByCode, restoreChoices, callApy */
/* global ENTER_KEY_CODE */
Expand All @@ -11,14 +11,14 @@ function getSpellers() {

if(config.SPELLERS) {
spellerData = config.SPELLERS;
populatePrimarySpellcheckerList(spellerData);
populatePrimarySpellCheckerList(spellerData);
deferred.resolve();
}
else {
var spellers = readCache('spellers', 'LIST_REQUEST');
if(spellers) {
spellerData = spellers;
populatePrimarySpellcheckerList(spellerData);
populatePrimarySpellCheckerList(spellerData);
deferred.resolve();
}
else {
Expand All @@ -28,9 +28,9 @@ function getSpellers() {
beforeSend: ajaxSend,
success: function (data) {
spellerData = data;
populatePrimarySpellcheckerList(spellerData);
populatePrimarySpellCheckerList(spellerData);
cache('spellers', data);
populatePrimarySpellcheckerList(data);
populatePrimarySpellCheckerList(data);
},
error: function () {
console.error('Failed to get available spellers');
Expand All @@ -50,12 +50,12 @@ if(modeEnabled('spellchecker')) {
$(document).ready(function () {
restoreChoices('spellchecker');
var timer, timeout = 2000;
$('#spellChekerForm').submit(function () {
$('#spellCheckerForm').submit(function () {
clearTimeout(timer);
check();
});

$('#spellcheckerInput').on('input propertychange', function () {
$('#spellCheckerInput').on('input propertychange', function () {
if(timer && $('#instantChecking').prop('checked')) {
clearTimeout(timer);
}
Expand All @@ -66,13 +66,13 @@ if(modeEnabled('spellchecker')) {
}, timeout);
});

$('#primarySpellcheckerMode').change(function () {
populateSecondarySpellcheckerList();
$('#primarySpellCheckerMode').change(function () {
populateSecondarySpellCheckerList();
localizeInterface();
persistChoices('spellchecker');
});

$('#secondarySpellcheckerMode').change(function () {
$('#secondarySpellCheckerMode').change(function () {
persistChoices('spellchecker');
});

Expand All @@ -87,20 +87,20 @@ if(modeEnabled('spellchecker')) {
persistChoices('spellchecker');
});

$('#spellcheckerInput').on('input propertychange', function () {
$('#spellcheckerInput').removeClass('spellcheckVisible');
$('#spellCheckerInput').on('input propertychange', function () {
$('#spellCheckerInput').removeClass('spellCheckerVisible');
$('.spellError').each(function () {
$(this).popover('hide');
});
persistChoices('spellchecker');
});

$('#spellcheckerInput').submit(function () {
$('#spellCheckerInput').submit(function () {
clearTimeout(timer);
check();
});

$(document).on('mouseover', '.spellcheckVisible .spellError', function () {
$(document).on('mouseover', '.spellCheckerVisible .spellError', function () {
$('.spellError').each(function () {
$(this).popover('hide');
});
Expand All @@ -123,7 +123,7 @@ if(modeEnabled('spellchecker')) {
});
});

$(document).on('click', '.list-group-item', function () {
$(document).on('click', '.spellCheckerListItem', function () {
var e = $(this).parents('.popover').prev();
e.text($(this).text());
e.removeClass('spellError');
Expand All @@ -133,16 +133,16 @@ if(modeEnabled('spellchecker')) {
});
}

function populateSecondarySpellcheckerList() {
var group = analyzers[$('#primarySpellcheckerMode').val()];
$('#secondarySpellcheckerMode').empty();
function populateSecondarySpellCheckerList() {
var group = analyzers[$('#primarySpellCheckerMode').val()];
$('#secondarySpellCheckerMode').empty();

if(group) {
if(group.length <= 1) {
$('#secondarySpellcheckerMode').fadeOut('fast');
$('#secondarySpellCheckerMode').fadeOut('fast');
}
else {
$('#secondarySpellcheckerMode').fadeIn('fast');
$('#secondarySpellCheckerMode').fadeIn('fast');
}

group.sort(function (a, b) {
Expand All @@ -154,15 +154,15 @@ function populateSecondarySpellcheckerList() {
var langDisplay = lang.indexOf('-') !== -1
? getLangByCode(lang.split('-')[0]) + '-' + getLangByCode(lang.split('-')[1])
: getLangByCode(lang);
$('#secondarySpellcheckerMode').append($('<option></option').val(lang).text(langDisplay));
$('#secondarySpellCheckerMode').append($('<option></option').val(lang).text(langDisplay));
}
}
else {
$('#secondarySpellcheckerMode').fadeOut('fast');
$('#secondarySpellCheckerMode').fadeOut('fast');
}
}
function populatePrimarySpellcheckerList(data) {
$('.spellcheckerMode').empty();
function populatePrimarySpellCheckerList(data) {
$('.spellCheckerMode').empty();

spellers = {};
for(var lang in data) {
Expand All @@ -189,7 +189,7 @@ function populatePrimarySpellcheckerList(data) {

for(var i = 0; i < spellerArray.length; i++) {
lang = spellerArray[i][0];
$('#primarySpellcheckerMode').append($('<option></option>').val(lang).text(getLangByCode(lang)));
$('#primarySpellCheckerMode').append($('<option></option>').val(lang).text(getLangByCode(lang)));
}

restoreChoices('spellerchecker');
Expand All @@ -199,43 +199,38 @@ function check() {
if(currentSpellCheckerRequest) {
currentSpellCheckerRequest.abort();
}
$('#spellcheckerInput').addClass('spellcheckVisible');
$('#spellcheckerInput').html($('#spellcheckerInput').html().replace(/br/g, '\n')
$('#spellCheckerInput').addClass('spellCheckerVisible');
$('#spellCheckerInput').html($('#spellCheckerInput').html().replace(/br/g, '\n')
.replace(/&nbsp;/g, ' '));
var words = $.trim($('#spellcheckerInput').text());
var words = $.trim($('#spellCheckerInput').text());
var splitWords = words.split(' ');
var content = {};
$('#spellcheckerInput').html('');
$('#spellCheckerInput').html('');
currentSpellCheckerRequest = callApy({
data: {
'q': words,
'lang': $('#primarySpellcheckerMode').val()
'lang': $('#primarySpellCheckerMode').val()
},
success: function (data) {
var originalWordsIndex = 0;
for(var tokenIndex = 0; tokenIndex < data.length; tokenIndex++) {
if(data[tokenIndex].known === true) {
if(data[tokenIndex]['known'] === true) { // eslint-disable-line dot-notation
$('#spellcheckerInput').html($('#spellcheckerInput').html() + ' ' + splitWords[originalWordsIndex]);
originalWordsIndex++;
continue;
}
$('#spellcheckerInput').html($('#spellcheckerInput').html() + ' <span class="spellError" id=' +
splitWords[originalWordsIndex] + '>' + splitWords[originalWordsIndex] + '</span>');
content[splitWords[originalWordsIndex]] = '<div class="list-group">';
for(var sugg = 0; sugg < data[tokenIndex].sugg.length; sugg++) {
for(var sugg = 0; sugg < data[tokenIndex]['sugg'].length; sugg++) { // eslint-disable-line dot-notation
content[splitWords[originalWordsIndex]] += '<a href="#" class="list-group-item">' +
data[tokenIndex].sugg[sugg][0] + '</a>';
data[tokenIndex]['sugg'][sugg][0] + '</a>'; // eslint-disable-line dot-notation
content[splitWords[originalWordsIndex]] += '</div>';
}
$('.spellError').each(function () {
var currentTokenId = this.id;
$(this).popover({
animation: false,
placement: 'bottom',
trigger: 'manual',
html: true,
content: content[currentTokenId]
});
$(this).popover({animation: false, placement: 'bottom', trigger: 'manual', html: true,
content: content[currentTokenId]});
});
originalWordsIndex++;
}
Expand All @@ -253,7 +248,7 @@ function handleSpellCheckerErrorResponse(jqXHR) {
}

function spellCheckerNotAvailable(data) {
$('#spellcheckerInput').append($('<div></div>').text(' '));
$('#spellcheckerInput').append($('<div></div>').text(data.message));
$('#spellcheckerInput').append($('<div></div>').text(data.explanation));
$('#spellCheckerInput').append($('<div></div>').text(' '));
$('#spellCheckerInput').append($('<div></div>').text(data.message));
$('#spellCheckerInput').append($('<div></div>').text(data.explanation));
}
12 changes: 6 additions & 6 deletions index.html.in
Original file line number Diff line number Diff line change
Expand Up @@ -331,26 +331,26 @@
</div>
<div class="modeContainer" id="spellcheckerContainer">
<h2 class="visible-xs" data-text="Spell_Checker">Spell Checker</h2>
<form class="form-horizontal" role="form" id="spellChekerForm">
<form class="form-horizontal" role="form" id="spellCheckerForm">
<fieldset>
<legend data-text="Spell_Checker_Help"></legend>
<div class="form-group">
<label for="primarySpellcheckerMode" class="col-sm-2 control-label" data-text="Language">Language</label>
<label for="primarySpellCheckerMode" class="col-sm-2 control-label" data-text="Language">Language</label>
<div class="col-sm-3">
<select class="form-control spellcheckerMode" id="primarySpellcheckerMode" name="primarySpellcheckerMode">
<select class="form-control spellCheckerMode" id="primarySpellCheckerMode" name="primarySpellCheckerMode">
<option> </option>
</select>
</div>
<div class="col-sm-4">
<select class="form-control spellcheckerMode" id="secondarySpellcheckerMode" name="secondarySpellcheckerMode">
<select class="form-control spellCheckerMode" id="secondarySpellCheckerMode" name="secondarySpellCheckerMode">
<option> </option>
</select>
</div>
</div>
<div class="form-group">
<label for="spellcheckerInput" class="col-sm-2 control-label" data-text="Input_Text">Input Text</label>
<label for="spellCheckerInput" class="col-sm-2 control-label" data-text="Input_Text">Input Text</label>
<div class="col-sm-10">
<div class="form-control" id="spellcheckerInput" contenteditable spellcheck="false"></div>
<div class="form-control" id="spellCheckerInput" contenteditable spellcheck="false"></div>
</div>
</div>
<div class="col-sm-offset-2 col-sm-7">
Expand Down

0 comments on commit 02ab612

Please sign in to comment.