开发者

Delay JSON Feed for jQuery Full Calendar

I noticed if you setup an event source(ie you going to be doing AJAX requests to the server) and start clicking next month rapidly it will fire off a request for each month. So if I click rapidly to get 5 tim开发者_高级运维es 5 requests will go off.

How can I make it so it will only fire once the user stops clicking. I find that such a waste of resources and can cause errors.


You are absolutely right about this and i Have already lodged an error with the development team about this.

http://code.google.com/p/fullcalendar/issues/detail?id=920&can=1&sort=-id&colspec=ID%20Type%20Status%20Milestone%20Summary%20Stars

The only way i can think of doing this for now is to use the viewDisaply event.

http://arshaw.com/fullcalendar/docs/display/viewDisplay/

And inside that viewDisapy event call the loading event

http://arshaw.com/fullcalendar/docs/event_data/loading/

The only way i can think now is todo a javascript setTimeout

var t=setTimeout( FUNCTION , TIME IN MS);

inside the timeout check is isLoading, and if true then set the timeout again.

Or just use setTimeout inside the viewDisplay function to 500ms/1second? to create the desired delayed effect you are looking for, and once it times out you can add the desired source using addEventSource http://arshaw.com/fullcalendar/docs/event_data/addEventSource/

There is another option that is built into the calendar.

http://arshaw.com/fullcalendar/docs/event_data/lazyFetching/

This options tells the plug-in to cache all events. so if you click next/next/previous/previous. It only calls ajax twice. Because the previous two months are loaded and cached.

There is no such thing as isClicking :D because we do not know if the user is going to click again or not.. :D so we only have to anticipate this by putting a setDelay if a user clicks the next month twice within 1 second.

So if somebody wants to go 6 months in advance they will quickly press the next buttons and we can detect that like this.

//global var

var clicks = 0;
var isClicking = false;

 //jquery on load and calender initialisation.

 loading: function(bool) { if (bool) 
            { 
                    clicks=0; //The source has loaded completely - user stopped clicking
                    }
            else 
            {
            //Still loading 
            }
        },


 viewDisplay: function(view) {
            click += 1; //user has clicked- and this will grow each time he clicks before the ajax finishes.
            if (click > 1) //Yea he is clicking and clicking.. so lets stop calling ajax.
            {
            $('#calendar').fullCalendar( 'removeEventSource', '/diaryFeed.aspx' ); //Remove the source so it stops firing on each click
            setTimeout ( $('#calendar').fullCalendar( 'addEventSource', '/diaryFeed.aspx' ); , 1000 ); //Add the source again and it will load and fire loading(true) and reset our click counter
            }

            //Handle other view changes like month/week and date changes
            },          
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜