<?php
    /**
    *
    * copyright (c) 2013-2020 Heliac Technologies
    * license http://opensource.org/licenses/gpl-license.php GNU GPL v3 
    *
    * linee guida per l'utilizzo del logo http://www.geecom.org/articolo.php?id=34&alias=linee-guida-per-l%27uso-del-logo-geecom
    */

    /*
        include il js comune a tutte le pagine, più la favicon
    */
?>
    <script src="../../../plugins/jQuery/jquery-3.4.1.min.js" type="text/javascript"></script>
    <script src="../../../js/util.js" type="text/javascript"></script>
    <script src="../../../plugins/popper/popper.min.js" type="text/javascript"></script>
    <script src="../../../plugins/bootstrap/bootstrap.min.js" type="text/javascript"></script>
    
    <!-- Tooltips e Popover -->
    <script>
        $(function () {
          $('[data-toggle="tooltip"]').tooltip()
        }) 

        $(function(){

                $("[data-toggle=popover]").popover({
                        html : true,
                        content: function() {
                                var content = $(this).attr("data-popover-content");
                                return $(content).children(".popover-body").html();
                        },
                        title: function() {
                                var title = $(this).attr("data-popover-content");
                                return $(title).children(".popover-heading").html();
                        }
                });

        });

         $('body').on('click', function (e) {
                $('[data-toggle="popover"]').each(function () {
                        //the 'is' for buttons that trigger popups
                        //the 'has' for icons within a button that triggers a popup
                        if (!$(this).is(e.target) && $(this).has(e.target).length === 0 && $('.popover').has(e.target).length === 0) {
                                $(this).popover('hide');
                        }
                });
        });

    </script> 


    <!-- Switchery -->
    <script type="text/javascript" src="../../../plugins/switchery/switchery.min.js"></script>
    <script type="text/javascript">
        var elems = Array.prototype.slice.call(document.querySelectorAll('.js-switch'));

        elems.forEach(function(html) {
          var switchery = new Switchery(html, { size: 'small', color: 'var(--primary)', jackColor: '#FFF' });

        });
    </script>

    <!-- Color Picker -->
    <script src="../../../plugins/bootstrap-colorpicker/colorpicker.js" type="text/javascript"></script>
    <script>
        $(function () {
            $('.selettore-colore').colorpicker({
                format: 'hex'
            });
        });
    </script>
    
    <!-- Mostra div con radio button -->
    <script type="text/javascript">
            $(document).ready(function(){
                    $('input[type="radio"]').click(function(){
                            var inputValue = $(this).attr("value");
                            var targetBox = $("." + inputValue);
                            $(".none").not(targetBox).hide();
                            $(targetBox).show();
                    });
            });
    </script>

     <!-- Mostra div con select -->
    <script type="text/javascript">
    $(document).ready(function(){
            $("select").change(function(){
                    $(this).find("option:selected").each(function(){
                            var optionValue = $(this).attr("value");
                            if(optionValue){
                                    $(".none").not("." + optionValue).hide();
                                    $("." + optionValue).show();
                            } else{
                                    $(".none").hide();
                            }
                    });
            }).change();
    });
    </script>

    <script>
            $('.custom-file-input').on('change',function(){
                var fileName = $(this).val().replace("C:\\fakepath\\",""); // rimuovo il percorso finto aggiunto dal browser
                $(this).next('.custom-file-label').html(fileName);
            })
    </script>
    
    <!-- Nestable2 -->
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/nestable2/1.6.0/jquery.nestable.min.js"></script>
    <script>
          $('.dd').nestable({ 
                  'depth': 1,
                  'parent_id': 'contenitore-sezioni-pagina'
          });
    </script>
    
    <script src="../../../plugins/bootstrap-select/bootstrap-select.min.js" type="text/javascript"></script>
        
    <!-- TinyMCE --> 
    <script src="../../../plugins/tinymce/tinymce.min.js"></script>
    <script>
        tinymce.init({
            selector:'.tiny',
            plugins: [
                'advlist autolink pagebreak lists link image charmap print preview anchor textcolor',
                'searchreplace visualblocks code fullscreen',
                'insertdatetime media table contextmenu paste code wordcount'
            ],
            pagebreak_separator: "<!-- leggi tutto -->",
            toolbar: 'insert | undo redo  pagebreak |  formatselect | bold italic link unlink forecolor backcolor  | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | removeformat | code',
            height:'400',
            language : 'it',
            valid_elements : '*[*]',
            branding:false
        });
    </script>
    
    <!-- Codice per evitare il problema delle modal in modal con Tinymce --> 
    <script>
        $(document).on('focusin', function(e) {
            if ($(e.target).closest(".mce-window").length) {
              e.stopImmediatePropagation();
            }
          });
    </script>
