// Main Caruosel
$(function () {
if ($('#main_carousel').length) {
$('#main_carousel').carousel({
interval: 5000,
pause: "true"
});
}
if($('.carousel-items').length){
$('.carousel-items').slick({
slidesToShow: 5,
slidesToScroll: 1,
autoplay: true,
autoplaySpeed: 5000
});
}
});
function inicializacion() {
// Inicialización de custom select
if ($("[data-function='fc-select']").length) {
$("[data-function='fc-select']").selectmenu();
//evento change de los select
$("[data-function='fc-select']").on( "selectmenuchange", function( event, item ) {
console.log(item); //item es un objeto que es la opcion seleccionada y permite acceder a datos de esa opcion, y del select padre
});
}
// Inicialización de Acordeon
if ($("[data-function='fc-accordion']").length) {
$("[data-function='fc-accordion']").accordion({
collapsible: true,
active:false,
heightStyle: "content"
});
/*$("[data-function='fc-accordion']").focusout(function() {
$("[data-function='fc-accordion']").accordion('option', {active: false});
});*/
}
// Inicialización de custom scroll
if ($("[data-function='fc-scroll']").length) {
$("[data-function='fc-scroll']").mCustomScrollbar();
}
// Inicialización del datepicker
if ($("[data-function='fc-datepicker']").length) {
if ($("[data-function='fc-datepicker']").val() != "") {
$("[data-function='fc-datepicker']").addClass("xui-date");
}
//Personalización de textos del datepicker
$.datepicker.regional['es'] = {
closeText: 'Cerrar',
prevText: 'Ant',
nextText: 'Sig',
currentText: 'Hoy',
monthNames: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'],
monthNamesShort: ['Ene','Feb','Mar','Abr', 'May','Jun','Jul','Ago','Sep', 'Oct','Nov','Dic'],
dayNames: ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'],
dayNamesShort: ['Dom','Lun','Mar','Mié','Juv','Vie','Sáb'],
dayNamesMin: ['D','L','M','X','J','V','S'],
weekHeader: 'Sm',
dateFormat: 'yy-mm-dd',
firstDay: 1,
isRTL: false,
showMonthAfterYear: false,
yearSuffix: ''
};
$.datepicker.setDefaults($.datepicker.regional['es']);
// inicialización del componente
$("[data-function='fc-datepicker']").datepicker({
dateFormat: "yy-mm-dd",
showOtherMonths: true,
onSelect: function(){
if ($(this).datepicker( "getDate" ) != null) { //si se ha seleccionado una fecha
$(this).addClass("xui-date");
}
}
});
$("[data-function='fc-datepicker']").focus(function() {
$(this).addClass("xui-cal-open");
});
$("[data-function='fc-datepicker']").blur(function() {
var dp = $(this);
dp.removeClass("xui-cal-open");
if (dp.datepicker( "getDate" ) == null) { //si al perder el foco el campo esta vacio
dp.removeClass("xui-date");
}
});
}
//Comportamiento de checkbox en departamentos
if ($("[data-function='fc-check']").length) {
$("[data-function='fc-check'] .fmf-checkbox").unbind('click').click(function(e){
var numChecked = 0; //numero de elemntos checados
var arrow = ""
var idCheck = $(this).attr('id').split(".")[0];
// si el checkbox pulsado no es "Todos" y se ha checado en el click
if ($(this).hasClass("all") == false && $(this).hasClass("none") == false && $(this).is(':checked')) {
$("[data-function='fc-check'] [id^=" + idCheck + "].fmf-checkbox").each(function(){
if ($(this).hasClass("all") || $(this).hasClass("none")){
$(this).removeAttr("checked")
}
if ($(this).is(':checked')) {
numChecked++;
}
});
if (numChecked > 1) {
$(".filter [id^=" + idCheck + "] .ui-accordion-header").eq(0).html(numChecked + " seleccionados" + arrow);
}
else{
var add = $(this).siblings().text();
$(".filter [id^=" + idCheck + "] .ui-accordion-header").eq(0).html(add + arrow);
}
}
// si el checkbox pulsado no es "Todos" y se ha deschecado en el click
else if ($(this).hasClass("all") == false && $(this).is(':checked') == false){
var opt;
$("[data-function='fc-check'] [id^=" + idCheck + "].fmf-checkbox").each(function(){
if ($(this).is(':checked')) {
numChecked++;
opt = $(this).siblings().text();
}
});
if (numChecked > 1) {
$(".filter [id^=" + idCheck + "] .ui-accordion-header").eq(0).html(numChecked + " seleccionados" + arrow);
}
else if (numChecked < 1) {
$("[data-function='fc-check'] [id^=" + idCheck + "].all").eq(0).trigger("click");
}
else{
$(".filter [id^=" + idCheck + "] .ui-accordion-header").eq(0).html(opt + arrow);
}
}
// si el checkbox pulsado es "Todos" y se ha deschecado en el click
else if ($(this).hasClass("all") && $(this).is(':checked') == false) {
setTimeout(function(){
$("[data-function='fc-check'] [id^=" + idCheck + "].all").eq(0).click();
}, 50);
} else if ($(this).hasClass("none") && $(this).is(':checked')) {
$("[data-function='fc-check'] [id^=" + idCheck + "].fmf-checkbox").each(function(){
if ($(this).is(':checked') && $(this).hasClass("none") == false) {
$(this).removeAttr("checked");
}
else if ($(this).hasClass("none")) {
var all = $(this).siblings().text();
$(".filter [id^=" + idCheck + "] .ui-accordion-header").eq(0).html(all + arrow);
}
});
}
else {
$("[data-function='fc-check'] [id^=" + idCheck + "].fmf-checkbox").each(function(){
if ($(this).is(':checked') && $(this).hasClass("all") == false) {
$(this).removeAttr("checked");
}
else if ($(this).hasClass("all")) {
var all = $(this).siblings().text();
$(".filter [id^=" + idCheck + "] .ui-accordion-header").eq(0).html(all + arrow);
}
});
}
});
}
//Control de texto del acordeon de filtro de busqueda
if ($(".filter__more").length) {
$(".filter__more").eq(0).find(".accordion-toggle").addClass("collapsed");
$(".filter__more").eq(0).find(".accordion-toggle").click(function(){
if ($(this).hasClass("collapsed")) {
$(this).html("Menos filtros ");
}
else {
$(this).html("Más filtros ");
}
});
}
// Añadido de clases para los select de fecha
if ($("[data-function='fc-dateselect']").length) {
var dateSel = $("[data-function='fc-dateselect'] > .ui-selectmenu-button");
dateSel.eq(0).addClass("day-select");
dateSel.eq(1).addClass("month-select");
dateSel.eq(2).addClass("year-select");
}
// Inicializacion de placeholder para IE9
if ($('input, textarea').length) {
$('input, textarea').placeholder();
}
}
// Main menu
$(document).on('click', '.yamm .dropdown-menu', function(e) {
e.stopPropagation()
})
$('.dropdown').hover(function() {
if (!($(this).hasClass('open'))) {
$('.dropdown-toggle', this).trigger('click');
$('.dropdown-toggle', this).addClass('disabled');
}
}, function() {
if ($(this).hasClass('open')) {
$('.dropdown-toggle', this).trigger('click');
$('.dropdown-toggle', this).removeClass('disabled');
$(this).removeClass('open')
}
});
//Nuevo funcionamiento dropDown idiomas
$('#language_list .dropdown').click(function() {
$('.dropdown-toggle', this).removeClass('disabled');
if ($(this).hasClass('open')) {
$(this).removeClass('open');
}
});
//Focus para boton buscar barra buscador cabecera
$("#inputBusq").focusin(function() {
$(".icon-search_b").addClass("search-head-focus");
});
$("#inputBusq").focusout(function() {
$(".icon-search_b").removeClass("search-head-focus");
});