Results 1 to 2 of 2

Thread: How do I close a modal window, from within itself?

  1. #1
    Sencha User
    Join Date
    Dec 2011
    Posts
    1
    Vote Rating
    0
      0  

    Question Unanswered: How do I close a modal window, from within itself?

    Hey Everyone

    I want to close a modal window when the user clicks on the window itself (used for a full screen image zoom). i.e. I want the window to behave like it normally does when the user clicks on the grayed out area. I setup a click handler, which manages to hide the element, but doesn't unmask the original window. Here's a simple code sample that show's you my issue:

    Code:
    <!DOCTYPE html>
    <html>
    <head>
        <link rel="stylesheet" type="text/css" href="css-debug/sencha-touch.css" />
        <script type="text/javascript" src="lib/sencha-touch-debug-w-comments.js"></script>
    </head>
    <body>
    </body>
    <script>
        ImageZoom = Ext.extend(Ext.Panel, {
            floating: true,
            modal: true,
            centered: true,
            height: Ext.Element.getViewportHeight() * .95,
            width: Ext.Element.getViewportWidth() * .95,
            scroll: 'none',
    
    
            initComponent: function() {
                ImageZoom.superclass.initComponent.call(this);
                this.addListener({
                    el: {
                        tap: this.closeWindow
                    }
                });
            },
            closeWindow: function() {
                this.hide();
            },
            html: 'Hello'
        });
    
    
        new Ext.Application({
            launch: function() {
                new Ext.Panel({
                    fullscreen: true,
                    html: 'Hello World!',
                    listeners: {
                        body: {
                            tap: function(a,b,c) {
                                x = new ImageZoom("test");
                                x.show();
                            }
                        }
                    }
    
    
                });
            }
        });
    </script>
    </html>
    Any ideas? I tried calling this.parent.unmask(), but I think I might not be in the object hierarchy (but rather the dom)?

    Shaun

  2. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,323
    Answers
    3884
    Vote Rating
    1294
      0  

    Default

    You have a scoping issue. The scope of the el's tap event is the element but you need to execute hide() on the component, not the element:

    Code:
    ImageZoom = Ext.extend(Ext.Panel, {
        floating: true,
        modal: true,
        centered: true,
        height: Ext.Element.getViewportHeight() * .95,
        width: Ext.Element.getViewportWidth() * .95,
        scroll: 'none',
    
    
        initComponent: function() {
            ImageZoom.superclass.initComponent.call(this);
            this.addListener({
                el: {
                    scope: this,
                    tap: this.closeWindow
                }
            });
        },
        closeWindow: function() {
            this.hide();
        },
        html: 'Hello'
    });
    
    
    new Ext.Application({
        launch: function() {
            new Ext.Panel({
                fullscreen: true,
                html: 'Hello World!',
                listeners: {
                    body: {
                        tap: function(a,b,c) {
                            x = new ImageZoom("test");
                            x.show();
                        }
                    }
                }
    
    
            });
        }
    });
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •