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 renderResult(data) { var res = ''; var score = data['result']['bestOverlayScore']*100; res += '
Concordia score: '+score.toFixed(0)+'%
'; res += '
phrase search
'; 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 = '