function toggleHelp() { $('#help').toggleClass('hidden'); } function searchHandle(tmid) { var concordiaRequest = { operation: 'concordiaSearch', tmId: tmid, pattern:$("#search-input").val() } $.ajax({ url: '/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: '/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 = ''; if (typeof(data['result']['bestOverlayScore']) === 'undefined') { // ignore } else { var score = data['result']['bestOverlayScore']*100; res += '
Concordia score: '+score.toFixed(0)+'%
'; } 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 += inputSentence.slice(lastInsertedEnd, fragment['matchedPatternStart']); //the marked fragment markedSentence += ''+inputSentence.slice(fragment['matchedPatternStart'], fragment['matchedPatternEnd'])+''; lastInsertedEnd = fragment['matchedPatternEnd']; fragments += renderFragment(fragment, i); } //remaining unmarked fragment markedSentence += inputSentence.slice(lastInsertedEnd); res += '
'+markedSentence+'
'; res += '


'+fragments; return res; } function renderFragment(fragment, number) { var result = '