Skip to content

Commit

Permalink
Merge branch 'hotfix/2.6.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerome Bonini committed May 30, 2018
2 parents c8a6a0c + 97138d9 commit ed36bf6
Showing 1 changed file with 49 additions and 63 deletions.
112 changes: 49 additions & 63 deletions views/front/preview.jade
Expand Up @@ -803,73 +803,59 @@ block custom_js
/////////
// Autocomplete
/////////
$(document).on("keyup", "input#instruction", function(e){
if (e.ctrlKey)
return;
var newstr = $("#instruction").val();

function split( val ) {
return val.split( /,\s*/ );
}
function extractLast( term ) {
return split( term ).pop();
}

$("#instruction").autocomplete({
autoFocus: true,
delay: 200,
source: function(request, response) {
$.getJSON('/default/completion', {
"str": newstr
}, response);
},
search: function() {
return true;
},
focus: function() {
// prevent value inserted on focus
return false;
},
select: function(event, ui) {

var ENTERKEY = 13;
if (event.keyCode != ENTERKEY) {
var completeVal = ui.item.value;
// If complete value have already typed string in it, dont concat with current value
if (completeVal.indexOf(this.value) == 0) {
this.value = completeVal.split("[variable]").join("").trim();
} else {
// Remove the last word of already typed instruction because it is also in the completed value
var parts = this.value.split(' ');
if (parts[parts.length - 1] == " ")
parts.pop();
else {
compareNum = 0;
l = Math.min(completeVal.length, parts[parts.length - 1].length);
for (i = 0; i < l; i++) {
if (completeVal.charAt(i) == parts[parts.length - 1].charAt(i)) compareNum++;
}
if (compareNum <= completeVal.length && completeVal.substring(0, compareNum) == parts[parts.length - 1])
parts.pop();
$("#instruction").autocomplete({
autoFocus: true,
delay: 200,
source: function(request, response) {
$.getJSON('/default/completion', {
"str": request.term
}, response);
},
search: function() {
return true;
},
focus: function() {
// prevent value inserted on focus
return false;
},
select: function(event, ui) {

var ENTERKEY = 13;
if (event.keyCode != ENTERKEY) {
var completeVal = ui.item.value;
// If complete value have already typed string in it, dont concat with current value
if (completeVal.indexOf(this.value) == 0) {
this.value = completeVal.split("[variable]").join("").trim();
} else {
// Remove the last word of already typed instruction because it is also in the completed value
var parts = this.value.split(' ');
if (parts[parts.length - 1] == " ")
parts.pop();
else {
compareNum = 0;
l = Math.min(completeVal.length, parts[parts.length - 1].length);
for (i = 0; i < l; i++) {
if (completeVal.charAt(i) == parts[parts.length - 1].charAt(i)) compareNum++;
}
this.value = parts.join(' ') + ' ' + completeVal.split("[variable]").join("").trim();
if (compareNum <= completeVal.length && completeVal.substring(0, compareNum) == parts[parts.length - 1])
parts.pop();
}
this.value = parts.join(' ') + ' ' + completeVal.split("[variable]").join("").trim();
}

var TABKEY = 9;
if (event.keyCode == TABKEY) {
event.preventDefault();
this.value = this.value+" ";
$('#instruction').focus();
}
return false;
} else {
event.preventDefault();
$('#execute_instruction').click();
return false;
var TABKEY = 9;
if (event.keyCode == TABKEY) {
event.preventDefault();
this.value = this.value+" ";
$('#instruction').focus();
}
}
});
// }
return false;
} else {
event.preventDefault();
$('#execute_instruction').click();
return false;
}
}
});

/////////
Expand Down

0 comments on commit ed36bf6

Please sign in to comment.