Page
Page is one of the main components (containers) used to display app content.
As you may note, each page has a attribute with a unique page name. It’s not required but can be useful within “page events” or “page callbacks”. It can help us to define which page is loaded and available so you can make required manipulations to the page.
Page Content
All visual content (like list views, forms, etc.) should put inside of <div class="page-content">
which should be a child of <div class="page">
. It’s required for correct styling, layout and scrolling.
Lets see how we can use these events. There are two ways to add page event handlers:
When a new page is loading and transitioned into the view (main visible part of the app) it has different classes on page element.
When we load/open new page the following happens:
- Currently active page has
**page-current**
class. - If page we load not in DOM (e.g. loaded via Ajax or using template or from component) it will be added to DOM.
- Router element (
<div class="view">
) will have additional**router-transition-forward**
class that does the following:- page with
page-next
(new page) class moves into the view - page with
page-current
(current page) class moves out of the view
- page with
- After transition completed, the new page that we loaded will have
**page-current**
class - And the page that was previously active will have
**page-previous**
class
- Currently active page has
**page-current**
class. - If page we go back to not in DOM (e.g. loaded via Ajax or using template or from component) it will be added to DOM.
- Page that we go back to will have additional
**page-previous**
class set on its element. - Router element () will have additional
**router-transition-backward**
class that does the following:- page with
page-current
(current page) class moves out of the view
- page with
- After transition completed, the new page that we returned to will have
**page-current**
class - And the page that was previously active will have
**page-next**
class. In case this page was added to DOM dynamically, it will be removed from DOM.
As you may see it is pretty easy, but how do you determine which page is loaded when we use only one handler? For this case we have Page Data in the event details:
Or in case the event handler was assigned using Dom7 like in example above then it will be passed in second argument:
Now, in the example above we have page data in **page**
variable. It is an object with the following properties:
page.app | object | Initialized app instance |
page.view | object | View instance that contains this page (if this View was initialized) |
page.router | object | Router instance that contains this page (if this View was initialized). Same as page.view.router |
page.app | string | Initialized app instance |
page.name | string | Value of page’s data-name attribute |
page.el | HTMLElement | Page element |
page.$el | object | Dom7 instance with Page element |
page.navbarEl | HTMLElement | Related navbar element for this page. Available only in iOS theme with dynamic navbar enabled. |
page.$navbarEl | object | Dom7 instance with related navbar element for this page. Available only in iOS theme with dynamic navbar enabled. |
page.from | string | Page position before transition or direction of where this Page comes from. It will be next if you load new page, previous - if you go back to this page, or current if this page replaces the currently active one. |
page.to | string | New page position or where this page goes to. Can be same next , previous or current |
page.position | string | Alias for page.from |
page.direction | string | Direction of page transition (if applicable). Can be or backward |
page.route | object | Route associated with this page, object with current route data that was used to load this page. It has the following properties
|
page.pageFrom | object | Page data of the page that was currently active before this new page. |
page.context | object | Template7 context that was passed for this page when using Template7 pages |