简体   繁体   中英

In fullcalendar event tooltip is not visisble

In my laravel 5.8 / Bootstrap v4.1.2 / jquery jQuery v3.3.1 fullcalendar v4.3.1 app I want to add tooltip to events of fullcalendar and looking at this sample https://codepen.io/pen/?&editable=true&editors=001

I do it as :

eventRender: function (eventInfo) {
    console.log("eventInfo" )
    console.log( eventInfo )

    console.log("eventInfo.el" )
    console.log( eventInfo.el )

   var tooltip = new Tooltip(eventInfo.el, {        
        title: 'Lorem  ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod  tempor', //eventInfo.event.extendedProps.description,
        placement: 'top',
        trigger: 'hover',
        container: 'body'
    });

    eventInfo.el.querySelector('.fc-title').innerHTML += "<i class='fa fa-external-link pull-right'" +
        " onclick=\"javascript:backendEvent.editCalendarEvent(event," + eventInfo.event.id + "); return" +
        " false;\">Edit</i>";

    return;

I have no any errors in console and no tooltip text.

and in console I see eventInfo.el as : https://imgur.com/a/S9GuW2V I suppose they are valid elements

In my resources/views/admin/event/index.blade.php I have included :

<script src="{{ asset('js/fullcalendar/core/main.js') }}"></script>
<!-- FullCalendar Core Package v4.3.1 -->


<script src="{{ asset('js/fullcalendar/daygrid/main.js') }}"></script>
<!-- FullCalendar Day Grid Plugin v4.3.0 -->


<script src="{{ asset('js/popper.min.js') }}"></script>
<!--   Copyright (C) Federico Zivolo 2019 -->    


<script src="{{ asset('js/tooltip.min.js') }}"></script>
<!-- Copyright (C) Federico Zivolo 2019 -->
In the example I see that tooltip var is created but never used . Is it ok ?

How to fix it ?

MODIFIED BLOCK :

All js functionality is in public/js/defaultBS41Backend/admin/event.js file and it is loaded after fullcalendar files : https://imgur.com/a/eMcCQKa

FullCsalendar is inited in js functions :

backendEvent.prototype.evenstLoadWithFullCalendar = function () {
    var dataArray = {
        "_token": this_csrf_token,
        "filter_event_name": $("#filter_event_name").val(),
        "filter_start_date": $("#filter_start_date").val(),
        "filter_end_date": $("#filter_end_date").val(),
        "filter_type": $("#filter_type").val(),
        "filter_status": $("#filter_status").val()
    }

    var href = this_backend_home_url + "/admin/get_events_fc_listing";
    $.ajax({
        type: "POST",
        dataType: "json",
        url: href,
        data: dataArray,
        success: function (response) {
            if (response.error_code == 0) {
                initFullCalendar(response.events);
            }
        },
        error: function (error) {
            popupErrorMessage(error.responseJSON.message)
        }
    });

}


function initFullCalendar(eventsList) {
    if (typeof window.calendarEventsObject != "undefined") { // clear existing instance
        window.calendarEventsObject.destroy();
    }

    var calendarEl = document.getElementById('events_calendar');

    var effective_device_width = effectiveDeviceWidth('width') //TODO

    window.calendarEventsObject = new FullCalendar.Calendar(calendarEl, {
        plugins: ['dayGrid'],

        eventRender: function (eventInfo) {
            console.log("eventInfo" )
            console.log( eventInfo )

            console.log("eventInfo.el" )
            console.log( eventInfo.el )

           var tooltip = new Tooltip(eventInfo.el, {        // example : https://fullcalendar.io/docs/event-tooltip-demo
                // title: eventInfo.event.extendedProps.description,
                title: 'Lorem  ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod  tempor', //eventInfo.event.extendedProps.description,
                placement: 'top',
                trigger: 'hover',
                container: 'body'
            });

            eventInfo.el.querySelector('.fc-title').innerHTML += "<i class='fa fa-external-link pull-right'" +
                " onclick=\"javascript:backendEvent.editCalendarEvent(event," + eventInfo.event.id + "); return" +
                " false;\">Edit</i>";

        },

        events: eventsList,
        // events: [],

        header: {
            left: 'LEFT98',
            center: 'title123',
            right: 'Right 444'
        },

        showNonCurrentDates: false,

        editable: true,
        allDaySlot: true,
        selectable: true,
        selectHelper: true,
        selectOverlap: false,
        fixedWeekCount: false,

        aspectRatio: 0.4,
        height: 700,

        select: function (start, end) {
            alert( "select:::"+var_dump(-50) )
            var title = "Available";
            var evid = SaveEvent(start, end, '1');
            $('#events_calendar').fullCalendar('unselect');
        },

        eventClick: function (clickObj) {
            alert( "eventClick clickObj.el::"+var_dump(clickObj.el) )
            if (clickObj.el.href != "") {
                // alert( "::"+var_dump(-4) )
                let el_href = clickObj.el.href
                clickObj.el.href = ""
                window.open(el_href, "_blank");
                // clickObj.event.preventDefault();
                alert( "::"+var_dump(-41) )
                return false;
            }
            return false;
        },
    });

    window.calendarEventsObject.render(
        {
            backgroundColor: 'green',
            textColor: 'yellow',
        }
    );

    jQuery('.eo-fullcalendar').on('click', '.fc-event', function (e) {
        e.preventDefault();
        window.open(jQuery(this).attr('href'), '_blank');
    });

}   // function initFullCalendar() {

I know that when data are loaded with ajax (as in my case) it can raise issue with some jquery components. Can it be that after I loaded data with ajax I have to init tooltip 1 more time?

Valid decision in my case was :

eventRender: function (eventInfo) {

    $(eventInfo.el).tooltip({                
        title: "<i class=\"fa fa-users\"></i>&nbsp;<b>"+eventInfo.event.extendedProps.attendees_count+"&nbsp;attendee(s)</b>" +
            " <br><smalUUl>"+eventInfo.event.extendedProps.description+"</smalUUl>",
        html: true,
    });

},

where description and attendees_count my custom fields sent to event. Without any additive libs

eventAfterAllRender: function(view){
   $('.has-tooltip').tooltip({container:'#calendar',placement:'top'});
},

You can put eventAfterAllRender to show tooltip

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM