var isMobile = { Android: function() { return navigator.userAgent.match(/Android/i); }, BlackBerry: function() { return navigator.userAgent.match(/BlackBerry/i); }, iOS: function() { return navigator.userAgent.match(/iPhone|iPad|iPod/i); }, Opera: function() { return navigator.userAgent.match(/Opera Mini/i); }, Windows: function() { return navigator.userAgent.match(/IEMobile/i); }, any: function() { return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows()); } }; //Aggiunta main loading all\'unload del body window.onbeforeunload = function() { $('#mini-loader').hide(); $('#main_loading').show(); }; $(window).load(function() { $('#main_loading').fadeOut(); }); $(document).ready(function() { //Orologio clock(); //Calendario principale $('#daterange').daterangepicker({ ranges: { '': [moment(), moment()], '': [moment().subtract('days', 1), moment().subtract('days', 1)], '': [moment().subtract('days', 6), moment()], '': [moment().subtract('days', 29), moment()], '': [moment().startOf('month'), moment().endOf('month')], '': [moment().subtract('month', 1).startOf('month'), moment().subtract('month', 1).endOf('month')], "": [moment().startOf('year'), moment().endOf('year')], '': [moment().subtract('year', 1).startOf('year'), moment().subtract('year', 1).endOf('year')] }, locale: { format: 'DD/MM/YYYY', separator: " - ", applyLabel: '', cancelLabel: '', fromLabel: '', toLabel: '', customRangeLabel: '', monthNames: ['','','','','','','','','','','',''], daysOfWeek: ['','','','','','',''], "firstDay": 1 }, startDate: '', endDate: '', applyClass: 'btn btn-app btn-sm', cancelClass: 'btn btn-danger btn-sm' }, function(start, end) { //Submit period and refresh page $.get('/core.php?period_start=' + start.format('YYYY-MM-DD') + '&period_end=' + end.format('YYYY-MM-DD'), function() { location.href = location.href; }); } ); $('.ask').on('click', function(){ var msg = ""; if($(this).data("msg") != undefined) var msg = $(this).data("msg"); if(confirm(msg)){ var position= ""; if($(this).data("position") != undefined) position = $(this).data("position"); location.href = $(this).data("href") + "&op=" + $(this).data("op") + "&id=" + $(this).data("id"); } }); //Sidebar $('.sidebar-menu > li.treeview i.fa-angle-left').click(function(e) { e.preventDefault(); $(this).find('ul').stop().slideDown(); }); $('.sidebar-menu > li.treeview i.fa-angle-down').click(function(e) { e.preventDefault(); $(this).find('ul').stop().slideUp(); }); $menulist = $('.treeview-menu > li.active'); for (i = 0; i < $menulist.length; i++) { $list = jQuery($menulist[i]); $list.parent().show().parent().addClass('active'); $list.parent().parent().find('i.fa-angle-left').removeClass('fa-angle-left').addClass('fa-angle-down'); } $(".sidebar-offcanvas").addClass('collapse-left'); $(".content-wrapper").addClass('strech'); //Menu ordinabile $(".sidebar-menu").sortable({ cursor: 'move', stop: function(event, ui) { var order = $(this).sortable('toArray').toString(); $.post("/modules/aggiornamenti/actions.php?id_module=", { op: 'sortmodules', ids: order }); } }); //Tabs $('#tabs').tabs(); if ((location.hash).substr(0, 5) == '#tab_') { setTimeout(function() { window.scrollTo(0, 0); }, 1); } $('.nav-pills a').click(function(e) { e.preventDefault(); $(this).tab('show'); }) //Entra nel tab indicato al caricamento della pagina var hash = window.location.hash; if (hash != '') $('ul.nav a[href="' + hash + '"]').tab('show'); //Aggiunta nell'URL del nome tab su cui tornare dopo il submit $('form').on('submit', function() { id = $(this).closest('.tab-pane.active').attr('id'); if (id != '' || id != undefined) { $(this).attr('action', $(this).attr('action') + '#' + id); } }); //Messaggio di avviso salvataggio a comparsa sulla destra solo nella versione a desktop intero if ($(window).width() > 1023) { var i = 0; $('.alert-success').each(function() { i++; tops = 60 * i + 95; $(this).css({ 'position': 'fixed', 'z-index': 3, 'top': -100, 'right': 10, 'opacity': 1 }).delay(1000).animate({ 'top': tops, 'opacity': 1 }).delay(3000).animate({ 'top': -100, 'opacity': 0 }); }); } //Nascondo la notifica se passo sopra col mouse $('.alert-success').on('mouseover', function(){ $(this).stop().animate({ 'top': -100, 'opacity': 0 }); }); $('.widget').mouseover(function(e) { e.preventDefault(); start_widgets($("#widget-controller_top, #widget-controller_right")); }); backtotop_button(); //Barra di ricerca //JQuery-UI Autocomplete wrapper $.widget("custom.catcomplete", $.ui.autocomplete, { _renderMenu: function(ul, items) { if (items[0].value == undefined) { $('#supersearch').removeClass('wait'); ul.html(''); } else { var that = this, currentCategory = ""; ul.addClass('ui-autocomplete-scrollable'); $.each(items, function(index, item) { if (item.category != currentCategory) { ul.append("
  • " + item.category + "
  • "); currentCategory = item.category; } that._renderItemData(ul, item); }); } }, _renderItem: function(ul, item) { return $("
  • ") .append("" + item.value + "
    " + item.label + "
    ") .appendTo(ul); } }); $('#supersearch').keyup(function() { $(document).ajaxStop(); if ($(this).val() == '') { $(this).removeClass('wait'); } else { $(this).addClass('wait'); } }); //Configurazione supersearch $('#supersearch').catcomplete({ html: true, source: function(request, response) { $.ajax({ url: '/ajax_autocomplete.php?op=supersearch&module=*', async: false, dataType: "json", data: { term: request.term }, complete: function(jqXHR) { $('#supersearch').removeClass('wait'); }, success: function(data) { if (data == null) { response($.map(['a'], function(item) { return false; })); } else { response($.map(data, function(item) { labels = (item.labels).toString(); labels = labels.replace('
    ,', '
    '); return { label: labels, category: item.category, link: item.link, value: item.title } })); } }, minLength: 2, select: function(event, ui) { location.href = ui.link; } }); } }); }); //Widgets ordinabili function start_widgets($widgets) { cls = new Array(); for (i = 0; i < $widgets.length; i++) { $widget = jQuery($widgets[i]); list_name = ($widget.attr('id')).replace('widget-', ''); //Salvo le classi del primo elemento di ogni lista cls[list_name] = $widget.find('li:first').attr('class'); $widget.sortable({ items: 'li', cursor: 'move', dropOnEmpty: true, connectWith: '.widget', scroll: true, helper : 'clone', start: function(event, ui) { //Salvo la lista da cui proviene il drag src_list = ($(this).attr('id')).replace('widget-', ''); //Evidenzio le aree dei widget $('.widget').addClass('bordered').sortable('refreshPositions'); }, stop: function(event, ui) { //Rimuovo l'evidenziazione dell'area widget $('.widget').removeClass('bordered'); //Salvo la lista su cui ho eseguito il drop dst_list = (ui.item.parent().attr('id')).replace('widget-', ''); var new_class = ""; var order = $(this).sortable('toArray').toString(); $.post("/modules/aggiornamenti/actions.php?id_module=", { op: 'updatewidget', location: dst_list, id_module: globals.id_module, class: new_class, id: ui.item.attr('id') }); $.post("/modules/aggiornamenti/actions.php?id_module=", { op: 'sortwidget', location: dst_list, ids: order, id_module: globals.id_module, class: new_class }); } }); } } //Modal function launch_modal(title, href, init_modal=1, id='#bs-popup') { $('html').addClass('modal-open'); $(id).on('hidden.bs.modal', function() { $('html').removeClass('modal-open'); $(this).data('modal', null); }); //Lettura contenuto div if (href.substr(0, 1) == '#') { data = $(href).html(); $(id).html( '