2019-11-28 11:01:09 +00:00
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
2016-06-19 09:07:56 +00:00
|
|
|
var metatags = ['order:id', 'order:width', 'order:height', 'order:filesize', 'order:filename'];
|
|
|
|
|
2018-07-25 23:27:56 +00:00
|
|
|
$('[name="search"]').tagit({
|
2016-06-18 10:58:41 +00:00
|
|
|
singleFieldDelimiter: ' ',
|
|
|
|
beforeTagAdded: function(event, ui) {
|
2016-06-19 09:07:56 +00:00
|
|
|
if(metatags.indexOf(ui.tagLabel) !== -1) {
|
|
|
|
ui.tag.addClass('tag-metatag');
|
|
|
|
} else {
|
|
|
|
console.log(ui.tagLabel);
|
|
|
|
// give special class to negative tags
|
|
|
|
if(ui.tagLabel[0] === '-') {
|
|
|
|
ui.tag.addClass('tag-negative');
|
|
|
|
}else{
|
|
|
|
ui.tag.addClass('tag-positive');
|
|
|
|
}
|
2016-06-18 10:58:41 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
autocomplete : ({
|
|
|
|
source: function (request, response) {
|
2016-06-19 09:07:56 +00:00
|
|
|
var ac_metatags = $.map(
|
|
|
|
$.grep(metatags, function(s) {
|
|
|
|
// Only show metatags for strings longer than one character
|
|
|
|
return (request.term.length > 1 && s.indexOf(request.term) === 0);
|
|
|
|
}),
|
|
|
|
function(item) {
|
|
|
|
return {
|
|
|
|
label : item + ' [metatag]',
|
|
|
|
value : item
|
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2016-06-18 10:58:41 +00:00
|
|
|
var isNegative = (request.term[0] === '-');
|
|
|
|
$.ajax({
|
|
|
|
url: base_href + '/api/internal/autocomplete',
|
|
|
|
data: {'s': (isNegative ? request.term.substring(1) : request.term)},
|
|
|
|
dataType : 'json',
|
|
|
|
type : 'GET',
|
|
|
|
success : function (data) {
|
2016-06-19 09:07:56 +00:00
|
|
|
response(
|
|
|
|
$.merge(ac_metatags,
|
|
|
|
$.map(data, function (count, item) {
|
|
|
|
item = (isNegative ? '-'+item : item);
|
|
|
|
return {
|
|
|
|
label : item + ' ('+count+')',
|
|
|
|
value : item
|
|
|
|
};
|
|
|
|
})
|
|
|
|
)
|
|
|
|
);
|
2016-06-18 10:58:41 +00:00
|
|
|
},
|
|
|
|
error : function (request, status, error) {
|
2018-07-19 23:48:03 +00:00
|
|
|
console.log(error);
|
2016-06-18 10:58:41 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
minLength: 1
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.ui-autocomplete-input').keydown(function(e) {
|
|
|
|
var keyCode = e.keyCode || e.which;
|
|
|
|
|
|
|
|
//Stop tags containing space.
|
2021-03-14 23:43:50 +00:00
|
|
|
if(keyCode === 32) {
|
2016-06-18 10:58:41 +00:00
|
|
|
e.preventDefault();
|
|
|
|
|
2018-07-19 23:32:49 +00:00
|
|
|
$('.autocomplete_tags').tagit('createTag', $(this).val());
|
2016-06-18 10:58:41 +00:00
|
|
|
$(this).autocomplete('close');
|
2021-03-14 23:43:50 +00:00
|
|
|
} else if (keyCode === 9) {
|
2016-06-18 10:58:41 +00:00
|
|
|
e.preventDefault();
|
|
|
|
|
2016-06-19 08:49:55 +00:00
|
|
|
var tag = $('.tagit-autocomplete[style*=\"display: block\"] > li:focus, .tagit-autocomplete[style*=\"display: block\"] > li:first').first();
|
|
|
|
if(tag.length){
|
|
|
|
$(tag).click();
|
2016-06-18 10:58:41 +00:00
|
|
|
$('.ui-autocomplete-input').val(''); //If tag already exists, make sure to remove duplicate.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2016-06-18 18:00:26 +00:00
|
|
|
});
|