function showNewTmOptions() { showField('tm_name'); hideField('tm_id'); showField('src_lang_id'); showField('trg_lang_id'); } function showExtendTmOptions() { hideField('tm_name'); showField('tm_id'); hideField('src_lang_id'); hideField('trg_lang_id'); } function hideField(fieldId) { $('#'+fieldId).addClass('hidden'); $('label[for='+fieldId+']').addClass('hidden'); } function showField(fieldId) { $('#'+fieldId).removeClass('hidden'); $('label[for='+fieldId+']').removeClass('hidden'); } function toggleHelp() { $('#help').toggleClass('hidden'); } function searchHandle(tmid) { var concordiaRequest = { operation: 'concordiaSearch', tmId: tmid, pattern:$("#search-input").val() } $.ajax({ url: '/cat/concordia_gate.php', type: 'post', dataType: 'json', success: function (data) { $('#result').html(renderResult(data)); }, data: concordiaRequest }); } function phraseSearchHandle(tmid, intervals) { var concordiaRequest = { operation: 'concordiaPhraseSearch', tmId: tmid, pattern:$("#search-input").val(), intervals: intervals } $.ajax({ url: '/cat/concordia_gate.php', type: 'post', dataType: 'json', success: function (data) { if (data['found']) { $('#result').html(renderResult(data)); } else { $('#phrase-prompt').html('Your phrase was not found. Try selecting another phrase: ').fadeOut(200).fadeIn(200); clearTextSelections(); } }, data: concordiaRequest }); } function renderResult(data) { var res = ''; var disablePhraseSearch = true; if (typeof(data['result']['bestOverlayScore']) === 'undefined') { // ignore } else { var score = data['result']['bestOverlayScore']*100; res += '
Concordia score: '+score.toFixed(0)+'%
'; } if (typeof disablePhraseSearch !== 'undefined') { // ignore } else { res += '
Phrase search mode: enter phrase search mode
'; } var inputSentence = $('#search-input').val(); var markedSentence = ''; var fragments = ''; lastInsertedEnd = 0; for(var i = 0; i < data['result']['bestOverlay'].length; i++) { var fragment = data['result']['bestOverlay'][i]; //previous unmarked fragment markedSentence += htmlEncode(inputSentence.slice(lastInsertedEnd, fragment['matchedPatternStart'])); //the marked fragment markedSentence += ''+htmlEncode(inputSentence.slice(fragment['matchedPatternStart'], fragment['matchedPatternEnd']))+''; lastInsertedEnd = fragment['matchedPatternEnd']; fragments += renderFragment(fragment, i); } //remaining unmarked fragment markedSentence += htmlEncode(inputSentence.slice(lastInsertedEnd)); res += '
'+markedSentence+'
'; res += '


'+fragments; return res; } function htmlEncode(value){ // Create a in-memory div, set its inner text (which jQuery automatically encodes) // Then grab the encoded contents back out. The div never exists on the page. return $('
').text(value).html(); } function renderFragment(fragment, number) { var result = '