tickets/app/assets/javascripts/search.js

49 lines
1.6 KiB
JavaScript
Raw Permalink Normal View History

2015-08-18 18:28:47 +00:00
(function(){
document.getElementById("search-form").reset();
// $("#serach-btn").on("click",function(){
// var el = $(this);
// if(el.hasClass("opened")){
// $(".search-box input").stop().animate({"width":"0"},function(){
// $(".search-box").hide();
// el.removeClass("opened");
// }).val("");
// }else{
// $(".search-box").show();
// el.addClass("opened");
// $(".search-box input").stop().animate({"width":"200px"}).focus();
// }
// return false;
// })
2015-08-18 18:28:47 +00:00
var regex = new RegExp(/[a-z]+:/);
$("#smart-field-select").on("change",function(){
var el = $(this),
old_value = $(".search-box input").val(),
matches = old_value.match(regex);
if(matches != null){
old_value = old_value.replace(matches[0], el.val());
if(el.val() == ""){
old_value = old_value.trim();
}
}else{
old_value = el.val() + " " + old_value;
}
$(".search-box input").val(old_value).focus();
})
var interval = null;
$(".search-box input").on("keyup",function(){
var el = $(this);
clearTimeout(interval);
interval = setTimeout(function(){
var val = el.val();
if(val == ""){
$("#smart-field-select").find("option:eq(0)").prop("selected","selected");
}else{
var matches = val.match(regex);
if(matches != null){
$("#smart-field-select").find('option[value="' + matches[0] + '"]').prop("selected","selected");
}
}
},500);
})
})()