EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: korenanzo on April 13, 2016, 09:01:22 AM



Title: Escape from Modal window
Post by: korenanzo on April 13, 2016, 09:01:22 AM
Hi,

I've found that you can escape from a modal window, if someone or something gives the focus to a blocked object

try this

http://code.reloado.com/oeasyrik1/2/edit#preview


Is there a way to avoid it?

I think so, because the overridden jQuery().dialog() works fine

http://code.reloado.com/oeasyrik2/2/edit

Thanks, RIc


Title: Re: Escape from Modal window
Post by: korenanzo on April 19, 2016, 08:57:58 AM
no chance to fix it?


Title: Re: Escape from Modal window
Post by: stworthy on April 20, 2016, 01:19:30 AM
Please look at this topic http://www.jeasyui.com/forum/index.php?topic=5693.0


Title: Re: Escape from Modal window
Post by: korenanzo on April 20, 2016, 01:39:22 AM
it was me again  ;D

anyway the problem I am describing is similar but not the same

I mean, watchTab() resolves partially the problem

In fact, even with watchTab activated, I can do

$('#t').textbox('textbox').focus()

so the modal dialog loses the focus.

As you can see in the other example,this does not happen with the jQuery.ui.dialog


Title: Re: Escape from Modal window
Post by: stworthy on April 20, 2016, 11:59:58 PM
Please try to call this 'watchTab' method.
Code:
(function($){
    $(function(){
        $(document).unbind('.watchTab').bind('focusin.watchTab', function(e){
            var ww = $.fn.window.mwindows || [];
            if (ww.length){
                $('#'+ww[ww.length-1]).focus();
            }
        });
    });
    $.fn.window.mwindows = $.fn.window.mwindows || [];
    var WININDEX = 1;
    $.extend($.fn.window.methods, {
        watchTab: function(jq){
            return jq.each(function(){
            var target = this;
                var opts = $(target).window('options');
                if (!opts.modal){return;}
                var onOpen = opts.onOpen;
                var onClose = opts.onClose;
                $(target).window({
                onOpen: function(){
                        if (opts.modal){
                            var id = $(this).attr('id');
                            if (!id){
                                id = '_windows_'+WININDEX++;
                                $(this).attr('id', id);
                            }
                            $.fn.window.mwindows.push(id);
                            $(target).focus();
                        }
                onOpen.call(this);
                },
                onClose: function(){
                        var index = $.inArray($(this).attr('id'), $.fn.window.mwindows);
                        if (index >= 0){
                            $.fn.window.mwindows.splice(index,1);
                        }
                onClose.call(this);
                }
                });
                $(target).attr('tabindex','-1').css('outline',0).unbind('.watchTab').bind('focusin.watchTab', function(e){
                return false;
                }).bind('keydown.watchTab', function(e){
                    if (e.keyCode == 9){
                        var first = $(this).find(':input:enabled:visible:first');
                        var last = $(this).find(':input:enabled:visible:last');
                        if (e.target == last[0] && !e.shiftKey){
                            first.focus();
                            return false;
                        } else if (e.target == first[0] && e.shiftKey){
                            last.focus();
                            return false;
                        }
                    }
                })
            })
        }
    })
})(jQuery);


Title: Re: Escape from Modal window
Post by: korenanzo on April 21, 2016, 10:41:19 AM
kudos!!  8) 8) :o :o



Title: Re: Escape from Modal window
Post by: korenanzo on April 22, 2016, 03:42:38 AM
Please try to call this 'watchTab' method.


One more thing...
how to include the buttoner buttons in the tab loop?