App / Core

When we init the app we can use the new Framework7 constructor and pass an object with main app parameters:

  1. var app = new Framework7({
  2. // App id
  3. id: 'com.myapp.test',
  4. // Enable swipe panel
  5. panel: {
  6. swipe: 'left',
  7. },
  8. // ... other parameters
  9. });

This constructor returns main app Framework7 instance.

App Parameters

Lets look at the list of available parameters:

ParameterTypeDefaultDescription
rootstringbodyApp root element. If you main app layout is not a direct child of the <body> then it is required to specify root element here
idstringio.framework7.testappApp bundle id.
namestringFramework7App name. Can be used by other components, e.g. as the default title for Dialog component.
versionstring1.0.0App version. Can be used by other components.
themestringautoApp theme. Can be ios, md or auto. In case of auto it will use iOS theme for iOS devices and MD theme for all other devices.
languagestringApp language. Can be used by other components. By default equal to the current browser/webview language (i.e. navigator.language).
routesarray[]Array with default routes to all views.
datafunctionApp root data. Must be a function that returns an object with root data. For example:
  1. var app = new Framework7({
  2. data: function () {
  3. return {
  4. username: vladimir’,
  5. firstName: Vladimir’,
  6. lastName: Kharlampidi
  7. };
  8. },
  9. });

Note, that this inside of this data function points to app Framework7 instance.

methodsobject{}App root methods. Object with methods, e.g.
  1. var app = new Framework7({
  2. methods: {
  3. alert: function() {
  4. app.dialog.alert(‘Hello World’);
  5. }
  6. }
  7. });

Note, that this inside of each method points to app Framework7 instance.

lazyModulesPathstringPath to Framework7’s lazy components. Required to use Lazy Modules with browser modules.
initbooleantrueBy default Framework7 will be initialized automatically when you call new Framework7(). If you want to prevent this behavior you can disable it with this option and then initialize it manually with app.init() when you need it.
initOnDeviceReadybooleantrueIf automatic initialization is enabled with init: true parameter and app is running under cordova environment then it will be initialized on deviceready event.
onobject{}Object with events handlers. For example:
  1. var app = new Framework7({
  2. on: {
  3. init: function () {
  4. console.log(‘App initialized’),
  5. },
  6. pageInit: function () {
  7. console.log(‘Page initialized’),
  8. },
  9. }
  10. })
Clicks Module Parameters
clicksobjectObject with clicks-module related parameters:
  1. var app = new Framework7({
  2. clicks: {
  3. externalLinks: ‘.external’,
  4. }
  5. })
{
externalLinksstring‘.external’CSS selector for links that should be treated as external and shouldn’t be handled by Framework7. For example such ‘.external’ value will match to links like <a href=”somepage.html” class=”external”> (with class “external”)
}
Touch Module Parameters
touchobjectObject with touch-module related parameters:
  1. var app = new Framework7({
  2. touch: {
  3. tapHold: true,
  4. }
  5. })
{
fastClicksbooleantrueFast clicks is a built-in library that removes 300ms delay from links and form elements in mobile browser while you click them. You can disable this built-in library if you want to use other third party fast clicks script.
fastClicksDistanceThresholdnumber10Distance threshold (in px) to prevent short taps. So if tap/move distance is larger than this value then “click” will not be triggered
fastClicksDelayBetweenClicksnumber50Minimal allowed delay (in ms) between multiple clicks
fastClicksExcludestringThis parameter allows to specify elements not handled by fast clicks by passing CSS selector of such elements
disableContextMenubooleantrue
tapHoldbooleanfalseEnables tap hold
tapHoldDelaynumber750Determines how long (in ms) the user must hold their tap before the taphold event is fired on the target element
tapHoldPreventClicksbooleantrueWhen enabled (by default), then click event will not be fired after tap hold event
activeStatebooleantrueWhen enabled, app will add “active-state” class to currently touched (:active) element.
activeStateElementsstringa, button, label, span, .actions-buttonCSS selector of elements where enabled activeState will add appropriate active class
materialRipplebooleantrueEnables Material theme specific touch ripple effect
materialRippleElementsstring.ripple, .link, .item-link, .links-list a, .button, button, .input-clear-button, .dialog-button, .tab-link, .item-radio, .item-checkbox, .actions-button, .searchbar-disable-button, .fab a, .checkbox, .radio, .data-table .sortable-cell, .notification-close-buttonCSS selector of elements to apply touch ripple effect on click
}

These are default app parameters for app core module.

Most of components that has JavaScript API may extend this list of parameters with the property named as component. For example Panel component extends app parameters with panel property that accepts Panel specific parameters.

Example:

  1. var app = new Framework7({
  2. id: 'com.myapp.test',
  3. // Extended by Panel component:
  4. panel: {
  5. swipe: 'left',
  6. leftBreakpoint: 768,
  7. rightBreakpoint: 1024,
  8. },
  9. // Extended by Dialog component:
  10. dialog: {
  11. title: 'My App',
  12. },
  13. // Extended by Statusbar component:
  14. statusbar: {
  15. iosOverlaysWebview: true,
  16. },
  17. });

App Methods & Properties

Returned Framework7 instance app contains a lot of useful properties and methods:

Properties
app.idApp ID passed in parameters
app.nameApp name passed in parameters
app.versionApp version
app.routesApp routes
app.languageApp language
app.rootDom7 instance with app root element
app.rtlBoolean property indicating app is in RTL layout or not
app.themeCurrent app theme. Can be md or ios
app.dataObject with app root data passed on intialization
app.methodsObject with app root methods
app.widthApp width in px
app.heightApp height in px
app.leftApp left offset in px
app.topApp top offset in px
app.initializedBoolean property indicating app is initialized or not
app.$Dom7 alias
app.t7Template7 alias
app.paramsApp parameters
app.supportObject with properties about supported features. Check the Support utilities section
app.deviceObject with properties about device. Check the Device utilities section
app.utilsObject with some useful utilities. Check the Utils section
app.requestContains methods to work with XHR requests. Check the Request utilities section
Methods
app.on(event, handler)Add event handler
app.once(event, handler)Add event handler that will be removed after it was fired
app.off(event, handler)Remove event handler
app.off(event)Remove all handlers for specified event
app.emit(event, …args)Fire event on instance
app.init()Initialize app. In case you disabled auto initialization with init: false parameter

Same as with app parameters most of components that has JavaScript API may extend this list of properties with the property named as component. For example Panel component extends app instance properties with panel property that accepts Panel specific properties and methods.

Example:

  1. // Open panel
  2. app.panel.open('left');
  3. // Hide statusbar
  4. app.statusbar.hide();

App Events

App instance emits the following core events:

EventArgumentsDescription
initEvent will be fired on app initialization. Automatically after new Framework7() or after app.init() if you disabled auto init.
resizeEvent will be fired on app resize (window resize).
orientationchangeEvent will be fired on app orientation change (window orientantion change).
clickeventEvent will be fired on app click
touchstart:activeeventEvent will be fired on touch start (mousedown) event added as active listener (possible to prevent default)
touchmove:activeeventEvent will be fired on touch move (mousemove) event added as active listener (possible to prevent default)
touchend:activeeventEvent will be fired on touch end (mouseup) event added as active listener (possible to prevent default)
touchstart:passiveeventEvent will be fired on touch start (mousedown) event added as passive listener (impossible to prevent default)
touchmove:passiveeventEvent will be fired on touch move (mousemove) event added as passive listener (impossible to prevent default)
touchend:passiveeventEvent will be fired on touch end (mouseup) event added as passive listener (impossible to prevent default)

And again, most of components that has JavaScript API may extend this list of events like Panel component will also trigger additional events on app instance.

Example:

  1. app.on('panelOpen', function (panel) {
  2. console.log('Panel ' + panel.side + ' opened');
  3. });