You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by koki142 <ko...@gmail.com> on 2010/09/06 06:10:20 UTC

Alert on ajax activity

Hi,

I'm trying to show an alert if the user is going to move from current page
while there is some ajax activity in the background. I have a chat program
and sometimes if the user writes a message and clicks on different page,
that message never reach the destination. I want to show something like
"There is some activity going on, please wait until the activity indicator
disappears". 

Is kind of the same Gmail does, any idea how to do this?

Thank you!
Oskar



-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Alert-on-ajax-activity-tp2527887p2527887.html
Sent from the Wicket - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Alert on ajax activity

Posted by koki142 <ko...@gmail.com>.
Thank you all for your replies, I did what Pedro said and it works exactly as
I wanted!!!

Thanks!!
Oskar

-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Alert-on-ajax-activity-tp2527887p2529111.html
Sent from the Wicket - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Alert on ajax activity

Posted by Pedro Santos <pe...@gmail.com>.
You can use javascript call handlers, ex:

Wicket.Ajax.registerPreCallHandler(
    function(){
            window.onbeforeunload = function() {
                return "There is some activity going on, please wait until
the activity indicator disappears";
            };
     }
);
Wicket.Ajax.registerPostCallHandler(
    function(){
            window.onbeforeunload = null;
     }
);

On Mon, Sep 6, 2010 at 1:10 AM, koki142 <ko...@gmail.com> wrote:

>
> Hi,
>
> I'm trying to show an alert if the user is going to move from current page
> while there is some ajax activity in the background. I have a chat program
> and sometimes if the user writes a message and clicks on different page,
> that message never reach the destination. I want to show something like
> "There is some activity going on, please wait until the activity indicator
> disappears".
>
> Is kind of the same Gmail does, any idea how to do this?
>
> Thank you!
> Oskar
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Alert-on-ajax-activity-tp2527887p2527887.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
Pedro Henrique Oliveira dos Santos

Re: Alert on ajax activity

Posted by "robert.mcguinness" <ro...@gmail.com>.

this snippet was handed to me long ago and I've slightly modified over time.



$().ready(function() {
    $(document).click(clickFunc);
    
    hideBusysign();
    
    if (typeof Wicket == 'object' && typeof Wicket.Ajax == 'object') {
        Wicket.Ajax.registerPreCallHandler(showBusysign);
        Wicket.Ajax.registerPostCallHandler(hideBusysign);
        Wicket.Ajax.registerFailureHandler(hideBusysign);
    }

    function hideBusysign() {
        $("#ajaxLoader").hide();
    }

    function showBusysign() {
        var ajaxLoader = $("#ajaxLoader");
        var scrollPosition = $(window).scrollTop();
        ajaxLoader.css('top', scrollPosition);
        ajaxLoader.css('left', 20);
        ajaxLoader.show();
    }

    function clickFunc(eventData) {
        
        // IGNORE RIGHT CLICKS
        if (window.event && event.button == 2) {            
            return;
        }else if (eventData.which == 3) {            
            return;            
        }
                
        var clickedElement = (window.event) ? event.srcElement :
eventData.target;
        if ((clickedElement.tagName.toUpperCase() == 'A' &&
((clickedElement.target == null) || (clickedElement.target.length <= 0))
                && (clickedElement.href.lastIndexOf('#') !=
(clickedElement.href.length - 1)) && (!('nobusy' in clickedElement))
                && (clickedElement.href.indexOf('mailto') < 0)
                && (clickedElement.href.indexOf('WicketAjaxDebug') < 0) &&
(clickedElement.href.lastIndexOf('.doc') != (clickedElement.href.length -
4))
                && (clickedElement.href.lastIndexOf('.csv') !=
(clickedElement.href.length - 4))
                && (clickedElement.href.lastIndexOf('.xls') !=
(clickedElement.href.length - 4)) && ((clickedElement.onclick == null) ||
(clickedElement.onclick
                .toString().indexOf('window.open') <= 0))
                || (clickedElement.parentNode != 'undefined' &&
clickedElement.parentNode.tagName != null &&
clickedElement.parentNode.tagName.toUpperCase() == 'A'
                        && ((clickedElement.parentNode.target == null) ||
(clickedElement.parentNode.target.length <= 0))
                        && (clickedElement.parentNode.href.indexOf('mailto')
< 0)
                        && (clickedElement.parentNode.href.lastIndexOf('#')
!= (clickedElement.parentNode.href.length - 1))
                        &&
(clickedElement.parentNode.href.lastIndexOf('.doc') !=
(clickedElement.parentNode.href.length - 4))
                        &&
(clickedElement.parentNode.href.lastIndexOf('.csv') !=
(clickedElement.parentNode.href.length - 4))
                        &&
(clickedElement.parentNode.href.lastIndexOf('.xls') !=
(clickedElement.parentNode.href.length - 4)) &&
((clickedElement.parentNode.onclick == null) ||
(clickedElement.parentNode.onclick
                        .toString().indexOf('window.open') <= 0)))
                || (((clickedElement.onclick == null) ||
((clickedElement.onclick.toString().indexOf('confirm') <= 0)
                        &&
(clickedElement.onclick.toString().indexOf('alert') <= 0) &&
(clickedElement.onclick.toString().indexOf('Wicket.Palette') <= 0) &&
clickedElement.onclick.toString().indexOf("window.print") <= 0) )) &&
(clickedElement.tagName
                        .toUpperCase() == 'INPUT' &&
(clickedElement.type.toUpperCase() == 'BUTTON' ||
clickedElement.type.toUpperCase() == 'SUBMIT' || clickedElement.type
                        .toUpperCase() == 'IMAGE')))) {
            showBusysign();
        }
    }

});


-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Alert-on-ajax-activity-tp2527887p2528293.html
Sent from the Wicket - User mailing list archive at Nabble.com.