Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 990 | Blame | Last modification | View Log | RSS feed

$(document).ready(function() {
        // Popover
        $('.btn-pop').popover();
        
        // CSS switcher
        $('.toggle-button').click(function(e) {
        $('link#custom-css').attr('href', $(this).attr('CssUrl'));
        return false;
    });
        
        // Slider images : photoswipe  
        if (document.getElementById('galerie_carte')) {
                var psc = $('#galerie_carte a').photoSwipe({ 
                        enableMouseWheel: false , 
                        enableKeyboard: false,
                        preventSlideshow: true
                });
        }
        if (document.getElementById('galerie_images')) {
                var psi = $('#galerie_images a').photoSwipe({ 
                        enableMouseWheel: false , 
                        enableKeyboard: false ,
                        captionAndToolbarAutoHideDelay: 0
                });
        }
        
        // Slider images : bootstrap
        if (document.getElementById('slider-pictures')) {
                $('#slider-pictures').hide(); 
                $('#slider-pictures').swiperight(function() {  
                        $('#slider-pictures').carousel('prev');  
                });  
                $('#slider-pictures').swipeleft(function() {  
                        $('#slider-pictures').carousel('next');  
                });
        }
});

/*----------------------------------------------------------------------------------------------------------*/
// POPOVER
var nbrPopup = 0,
        popupOuverte = false;

function gestionPopover() {
        if (popupOuverte && nbrPopup != 0) {
                $('.btn-pop').popover('hide');
                popupOuverte = false;
        }
        nbrPopup++;
}

function resetPopover() {
        nbrPopup = 0; 
        popupOuverte = true;
}

/*----------------------------------------------------------------------------------------------------------*/
// SLIDER BOOTSTRAP
function gestionSlider() {
        if ($('#slider-pictures').is(':visible')) {
                $('#gstn-img').show();
                $('#slider-pictures').hide();
        } else {
                $('#gstn-img').hide();
                $('#slider-pictures').show();
        }       
}

/*----------------------------------------------------------------------------------------------------------*/
// CANVAS FLORAISON, FRUCTIFICATION
var moisAbbr = new Array('J', 'F', 'M', 'A', 'M', 'J', 'J', 'A', 'S', 'O', 'N', 'D', ''),
        intervalle = false;

function dessinCanvas(canvas, color, valeur) {
        var ctx = canvas.getContext('2d'),
                i = 0,
                arr = getTableauMois(valeur),
                index0 = arr[0],
                index1 = -1,
                size = canvas.width;
        
        if (intervalle) {
                index1 = arr[arr.length - 1];
        }
        
        for (var abscisse = 10; abscisse < size; abscisse += (size/13)) {
                ctx.beginPath();
                ctx.moveTo(abscisse, 0);
                ctx.lineTo(abscisse, 55);
                ctx.stroke();

                if (in_array(i, arr)) {
                        if (i == index0 && index1 != -1) {
                                var linearGradient = ctx.createLinearGradient(abscisse, 10, abscisse+30, 10);
                                
                                linearGradient.addColorStop(0, "#fff");
                                linearGradient.addColorStop(1, color);
                                ctx.beginPath();
                                ctx.fillStyle = linearGradient;
                                ctx.moveTo(abscisse, 25);
                                ctx.lineTo(abscisse+(size/13), 25);
                                ctx.lineTo(abscisse+(size/13), 10);
                                ctx.lineTo(abscisse, 25);
                                ctx.fill();
                        } else {
                                if (i == index1) {
                                        var linearGradient = ctx.createLinearGradient(abscisse, 10, abscisse+25, 10);

                                        linearGradient.addColorStop(0, color);
                                        linearGradient.addColorStop(1, "#fff");
                                        ctx.beginPath();
                                        ctx.fillStyle = linearGradient;
                                        ctx.moveTo(abscisse, 10);
                                        ctx.lineTo(abscisse, 25);
                                        ctx.lineTo(abscisse+(size/13), 25);
                                        ctx.lineTo(abscisse, 10);
                                        ctx.fill();
                                } else {
                                        ctx.fillStyle = color;
                                        ctx.fillRect(abscisse, 10, (size/13), 15); 
                                }
                        }
                }
                
                ctx.font = '20px Georgia';
                ctx.fillStyle = '#000';
                ctx.fillText(moisAbbr[i++], abscisse + 5, 50);
        }
}

function getTableauMois(elt) {
        var arr = new Array(),
                temp = elt.split('-');

        if (typeof temp[1] === 'undefined') {
                arr.push(elt);
        } else {
                intervalle = true;
                temp[0] = parseInt(temp[0]);
                temp[1] = parseInt(temp[1]);
                if (temp[0] < temp[1]) {
                        for (var c = temp[0]; c <= temp[1]; c++) {
                                arr.push(c);
                        }       
                } else {
                        for (var c = temp[0]; c < 12; c++) {
                                arr.push(c);
                        }
                        for (var c = 0; c <= temp[1]; c++) {
                                arr.push(c);
                        }
                }
        }       
        return arr;
}

function in_array(needle, haystack) {
    var inArray = 0;
        for (var i in haystack) {
        if (haystack[i] == needle) {
                inArray++;
        }
    }
    return (inArray != 0);
}