Popup

    Popup is a popup window with any HTML content that pops up over App’s main content. Popup as all other overlays is part of so called “Temporary Views”.

    Popup layout is pretty simple:

    Popup Size

    By default Popup has a bit different size on phones and tablets (iPad). On phones it is fullscreen while on tablets it is 630px width and height. If you want to make it fullscreen size on tablets, you should add additional “popup-tablet-fullscreen“ class to the required popup:

    1. ...
    2. <!-- This popup has fullscreen size on tablets -->
    3. <div class="popup popup-tablet-fullscreen">
    4. Any HTML content goes here
    5. </div>
    6. </body>

    Let’s look at related App methods to work with Popup:

    app.popup.create(parameters)- create Popup instance

    • parameters - object. Object with popup parameters

    Method returns created Popup’s instance

    app.popup.destroy(el)- destroy Popup instance

    • el - HTMLElement or string (with CSS Selector) or object. Popup element or Popup instance to destroy.
    • el - HTMLElement or string (with CSS Selector). Popup element.

    Method returns Popup’s instance

    app.popup.open(el, animate)- opens Popup

    • el - HTMLElement or string (with CSS Selector). Popup element to open.
    • animate - boolean. Open Popup with animation.

    Method returns Popup’s instance

    app.popup.close(el, animate)- closes Popup

    • el - HTMLElement or string (with CSS Selector). Popup element to close.
    • animate - boolean. Close Popup with animation.

    Method returns Popup’s instance

    Popup Parameters

    Now let’s look at list of available parameters we need to create Popup:

    Note that all following parameters can be used in global app parameters under popup property to set defaults for all popups. For example:

    1. var app = new Framework7({
    2. popup: {
    3. closeByBackdropClick: false,
    4. }
    5. });

    After that we have its initialized instance (like popup variable in example above) with useful methods and properties:

    Control Popup With Links

    It is possible to open and close required popup (if you have them in DOM) using special classes and data attributes on links:

    • To open popup we need to add “popup-open“ class to any HTML element (prefered to link)

    • If you have more than one popup in DOM, you need to specify appropriate popup via additional data-popup=”.my-popup” attribute on this HTML element

    According to above note:

    1. <!-- In data-popup attribute we specify CSS selector of popup we need to open -->
    2. <p><a href="#" data-popup=".my-popup" class="popup-open">Open Popup</a></p>
    3. <!-- And somewhere in DOM -->
    4. <div class="popup my-popup">
    5. <div class="view">
    6. <div class="page">
    7. <div class="navbar">
    8. <div class="navbar-inner">
    9. <div class="title">Popup</div>
    10. <!-- Link to close popup -->
    11. <a class="link popup-close">Close</a>
    12. </div>
    13. </div>
    14. </div>
    15. <div class="page-content">
    16. ...
    17. </div>
    18. </div>
    19. </div>
    20. ...
    21. </div>

    Popup will fire the following DOM events on popup element and events on app and popup instance:

    App and Popup Instance Events

    Examples

    1. var app = new Framework7();
    2. var $$ = Dom7;
    3. // DOM events for About popup
    4. $$('.popup-about').on('popup:open', function (e, popup) {
    5. console.log('About popup open');
    6. });
    7. console.log('About popup opened');
    8. });
    9. // Create dynamic Popup
    10. var dynamicPopup = app.popup.create({
    11. '<div class="block">'+
    12. '<p>Popup created dynamically.</p>'+
    13. '<p><a href="#" class="link popup-close">Close me</a></p>'+
    14. '</div>'+
    15. '</div>',
    16. // Events
    17. on: {
    18. open: function (popup) {
    19. console.log('Popup open');
    20. },
    21. opened: function (popup) {
    22. console.log('Popup opened');
    23. },
    24. }
    25. });
    26. // Events also can be assigned on instance later
    27. dynamicPopup.on('close', function (popup) {
    28. console.log('Popup close');
    29. });
    30. dynamicPopup.on('closed', function (popup) {
    31. console.log('Popup closed');
    32. });
    33. // Open dynamic popup
    34. $$('.dynamic-popup').on('click', function () {
    35. dynamicPopup.open();