100
| <![CDATA[<script type="text/javascript">
var jQ = jQuery.noConflict();
jQ(document).ready(function () {
// jQ("div.t3").on('click',function () {
// // console.log(jQ(this).html().length);
// var reducedHeight = jQ(this).height();
// jQ(this).css('height', 'auto');
// var fullHeight = jQ(this).height();
// jQ(this).height(reducedHeight);
// jQ(this).animate({height: fullHeight}, 500);
// });
jQ('.ui.multiple.dropdown').dropdown();
// $('.dropdown').dropdown();
jQ('[data-toggle="tooltip"]').tooltip();
filterSearchIcon();
searchDropdownMenu();
formataIdiomas();
readMore();
jQ("form div.ui.input.focus input#query").on('input' , function () {
var queryParam = jQ("form div.ui.input.focus input#query").val();
if (queryParam.length >= 3 && !isEmptyOrSpaces(queryParam)) {
// GetSearchFunction(queryParam);
}
if(queryParam.length == 0){
jQ('li#RestSearchSolr').each(function(index, item){
// item.remove();
});
// jQ('#RestSearchSolr').each(index, item){
}
function GetSearchFunction (queryParam) {
var restApi = 'https://educapes.des.capes.gov.br/rest/items/search';
jQ.ajax({
dataType: 'json',
headers: {
Accept: "application/json",
"Access-Control-Allow-Origin": "*"
},
contentType:'application/json',
type: 'GET',
url: restApi,
data: {"q":queryParam,
"limit": 20,
"expand":"metadata"},
success: function (data) {
console.log(data);
jQ('li#RestSearchSolr').each(function(index, item){
item.remove();
});
var thumb = "<div class=\"thumbnail-wrapper\"><div class=\"artifact-preview\">\n" +
"<a href=\"#\"><span class=\"item-list conteudo-texto\"></span></a>\n" +
"</div></div>";
jQ(data.item).each(function(index, item){
var requestContextPath = "" + "/handle/";
var html ="<li id=\"RestSearchSolr\">"+thumb +
"<div class=\"artifact-description\">"+
"<div class=\"evenRowOddCol\"><a target='_blank' href="+ requestContextPath + item.handle + ">"+ item.name +"</a></div>"+
"<div class=\"evenRowEvenCol\">"+ item.handle +"</div>"+
"<div class=\"evenRowEvenCol\">"+ item.metadata.value +"</div>"+
"</li>";
jQ('ul.itemList').prepend(html);
})
},
error: function (data) {
console.log(data.error);
}
});
}
});
jQ("#spellCheckQuery").click(function () {
jQ("#query").val(jQ(this).attr('data-spell'));
jQ("#main-query-submit").click();
});
jQ("#filterquery")
.autocomplete({
source: function (request, response) {
jQ.ajax({
url: "/json/discovery/autocomplete?query=",
dataType: "json",
cache: false,
data: {
auto_idx: jQ("#filtername").val(),
auto_query: request.term,
auto_sort: 'count',
auto_type: jQ("#filtertype").val(),
location: ''
},
success: function (data) {
response(jQ.map(data.autocomplete, function (item) {
var tmp_val = item.authorityKey;
if (tmp_val == null || tmp_val == '') {
tmp_val = item.displayedValue;
}
return {
label: item.displayedValue + " (" + item.count + ")",
value: tmp_val
};
}))
}
})
}
});
});
function isEmptyOrSpaces(str){
return str === null || str.match(/^ *$/) !== null;
}
//Icon animation logic
function filterSearchIcon(){
var filter = jQ("#filterquery").val();
if(isEmptyOrSpaces(filter)){
jQ(".search.icon").hide();
}else {
jQ(".search.icon").show();
}
jQ("#filterquery").on('input',function(e){
filter = jQ("#filterquery").val();
if(isEmptyOrSpaces(filter)){
jQ(".search.icon").hide();
}else {
jQ(".search.icon").show();
}
});
}
function formataIdiomas() {
var idiomas = [
{"id":"pt","value": "Português (pt)"},
{"id":"pt-br","value": "Português (pt-br)"},
{"id":"pt_BR","value": "Português (pt-br)"},
{"id":"por_br","value": "Português (pt-br)"},
{"id":"por","value":"Português (por)"},
{"id":"spa","value":"Espanhol (spa)"},
{"id":"es","value":"Espanhol (es)"},
{"id":"ita","value":"Italiano (ita)"},
{"id":"it","value":"Italiano (ita)"},
{"id":"eng","value":"Inglês (eng)"},
{"id":"en","value":"Inglês (en)"},
{"id":"en_us","value":"Inglês (en_us)"},
{"id":"na","value":"Inglês (en)"},
{"id":"deu","value":"Alemão (deu)"},
{"id":"de","value":"Alemão (de)"},
{"id":"fra","value":"Francês (fr)"},
{"id":"fr","value":"Francês (fr)"},
{"id":"cat","value":"Catalão (cat)"},
{"id":"pol","value":"Polonês (pol)"},
{"id":"pl","value":"Polonês (pl)"},
{"id":"abk","value":"Abecásio (abk)"},
{"id":"zho","value":"Chinês (zho)"},
{"id":"zh","value":"Chinês (zh)"},
{"id":"jpn","value":"Japonês (jpn)"},
{"id":"jp","value":"Japonês (jpn)"},
{"id":"nau","value":"Nauruano (nau)"},
{"id":"lat","value":"Latim (lat)"},
{"id":"glg","value":"Galego (glg)"}
];
jQ('p#language').each(function(spanIndex, spanItem) {
var optionsObject = jQ(this);
jQ.each(idiomas, function(i) {
// console.log(idiomas[i].id.toLowerCase() === optionsObject.text().toLowerCase(), idiomas[i].id.toLowerCase(),optionsObject.text().toLowerCase());
if (optionsObject.text().toLowerCase().replace(" ","") === idiomas[i].id.toLowerCase()){
optionsObject.text(idiomas[i].value);
}
});
});
}
//Validate Filters apply
function validateFilters() {
return document.getElementById("filterquery").value.length > 0;
}
//Menu logic dropdown Semantic UI
function searchDropdownMenu(){
jQ('.ui.search.dropdown').dropdown();
jQ('div#dropdownBuscador a.text div.item div.text').html(jQ("select#tlocation option").filter(":selected").attr('name'));
jQ('div#dropdownBuscador.ui.search.selection.dropdown a.text').html(jQ("select#tlocation option").filter(":selected").attr('name'));
jQ("div#dropdownBuscador input").bind("enterKey",function(e){
var out = jQ('div.item.active.selected div.item').attr('value');
if(out === undefined){
out = jQ('div.item.active.selected').attr('value');
jQ("select#tlocation option").filter(":selected").val(out);
// console.log(out);
}else{
jQ("select#tlocation option").filter(":selected").val(out);
// console.log(out);
}
});
jQ("div#dropdownBuscador input").keyup(function(e){
if(e.keyCode == 13)
{
jQ(this).trigger("enterKey");
}
});
jQ('.ui.search.dropdown, #dropdownBuscador').dropdown({
allowCategorySelection: true,
message: {
count : '{count} selecionados',
maxSelections : 'Máximo de {maxCount} seleções',
noResults : 'Não encontrado.',
serverError : 'Erro de conexão com servidor'
},
onChange: function(value, text, $choice){
var choices = $choice.attr('value');
if (choices != undefined){
jQ("select#tlocation option").filter(":selected").val(choices);
}
}
});
}
function readMore(){
jQ('div.t2').each(function (idx,item) {
if(jQ(this).html().length > 500){
jQ(this).css("height","5em");
jQ(this).css("padding","2px");
jQ(this).css("overflow","hidden");
jQ(this).append("<div align='center'><span class='minusContent glyphicon glyphicon-chevron-up'></span></div>");
}
});
jQ('.minusContent').css("color","green");
var test;
jQ('div.t2').on('click',function () {
test = jQ(this);
});
jQ.fn.toggleClick = function (funcArray) {
return this.click(function () {
var elem = jQ(this);
var index = elem.data('index') || 0;
funcArray[index]();
elem.data('index', (index + 1) % funcArray.length);
});
};
jQ('div.t2').toggleClick([
function () {
if(test.html().length > 500){
jQ(test).css("height","");
}
},
function () {
if(test.html().length > 500){
jQ(test).css("height","5em");
}
}
]);
}
</script>]]>
|