You : Predicted Responses
"+p+"
" ); 52 | 53 | }) 54 | $('.prompt').on('mouseover',function(){ 55 | $('.prompt').css('background','none'); 56 | $(this).css('background','#083d53'); 57 | }) 58 | 59 | // $('.prompt')[0].trigger('mouseover'); 60 | const mouseoverEvent = new Event('mouseover'); 61 | document.querySelector('.prompt').dispatchEvent(mouseoverEvent); 62 | var currentSelectedPrompt = 0; 63 | var totalPrompts = prompts.length; 64 | 65 | $('.prompt').on('click',function(){ 66 | document.querySelector('body').removeEventListener('keydown',togglePrompt); 67 | 68 | var currentMessage = $('div[data-tab="6"]').text(); 69 | $('div[data-tab="6"]').text(''); 70 | currentMessage = currentMessage.trim() + ' ' + $(this).text(); 71 | $('div[data-tab="6"]').focus(); 72 | document.execCommand('insertText', false, currentMessage); 73 | $('#predicted-prompts').remove(); 74 | $('div[data-tab="6"]').siblings().hide(); 75 | }) 76 | 77 | function togglePrompt(e){ 78 | console.log($('#predicted-prompts').length); 79 | if($('#predicted-prompts').length){ 80 | e.preventDefault(); 81 | e.stopPropagation(); 82 | 83 | if (e.keyCode===38){ 84 | // console.log('up'); 85 | currentSelectedPrompt-=1; 86 | if (currentSelectedPrompt<0){ 87 | currentSelectedPrompt = totalPrompts-1; 88 | } 89 | console.log('CURRENT_PROMPT_NO(up)',currentSelectedPrompt); 90 | document.querySelectorAll('.prompt')[currentSelectedPrompt].dispatchEvent(mouseoverEvent); 91 | 92 | } 93 | else if(e.keyCode===40){ 94 | // console.log('down'); 95 | currentSelectedPrompt+=1; 96 | if (currentSelectedPrompt>=totalPrompts){ 97 | currentSelectedPrompt = 0; 98 | } 99 | console.log('CURRENT_PROMPT_NO(down)',currentSelectedPrompt); 100 | document.querySelectorAll('.prompt')[currentSelectedPrompt].dispatchEvent(mouseoverEvent); 101 | 102 | } 103 | else if(e.keyCode===27){ 104 | // console.log('escape'); 105 | $('#predicted-prompts').remove(); 106 | document.querySelector('body').removeEventListener('keydown',togglePrompt); 107 | console.log('CURRENT_PROMPT_NO(escape)',currentSelectedPrompt); 108 | 109 | var currentMessage = $('div[data-tab="6"]').text(); 110 | $('div[data-tab="6"]').text(''); 111 | $('div[data-tab="6"]').focus(); 112 | document.execCommand('insertText', false, currentMessage); 113 | 114 | } 115 | else if(e.keyCode===13){ 116 | // console.log('enter'); 117 | document.querySelector('body').removeEventListener('keydown',togglePrompt); 118 | console.log('CURRENT_PROMPT_NO(enter)',currentSelectedPrompt); 119 | document.querySelectorAll('.prompt')[currentSelectedPrompt].click(); 120 | } 121 | } 122 | } 123 | 124 | document.querySelector('body').addEventListener('keydown',togglePrompt); 125 | 126 | 127 | 128 | 129 | document.querySelector('[data-tab="7"]').scrollIntoView(false); 130 | } 131 | 132 | function getPrompts(context){ 133 | $.ajax({ 134 | url: 'http://localhost:5000/autocomplete', 135 | crossDomain: true, 136 | dataType: 'json', 137 | data: {context : context}, 138 | success: (d)=>{ 139 | // console.log(d); 140 | displayPrompts(d.outputs, context); 141 | } 142 | }); 143 | } 144 | 145 | 146 | $(document).ready(function(){ 147 | 148 | console.log("Hello, you!"); 149 | 150 | var icon = 'YOU
active
You
Only you can complete your sentences :)
16 |Usage : Enter tab while typing to see the prompts!
17 |