Framework7 jQuery Cordova Setup
August 7, 2025 · AI Conversations
Also use pages
—
### ✅ Folder Structure (Recommended)
www/
├── css/
│ └── framework7.bundle.min.css
├── js/
│ ├── framework7.bundle.min.js
│ ├── jquery-3.6.0.min.js
│ └── app.js ← your custom JS
├── pages/
│ ├── home.html
│ ├── about.html
│ └── staff.html
├── index.html
├── cordova.js (auto-generated)
—
### ✅ Step-by-step Setup
#### 1. `index.html`
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<title>Framework7 + jQuery + Cordova</title>
<link rel="stylesheet" href="css/framework7.bundle.min.css" />
</head>
<body>
<!-- App Root -->
<div id="app">
<!-- View -->
<div class="view view-main">
<div class="page" data-name="home">
<div class="navbar">
<div class="navbar-inner">
<div class="title">Home</div>
</div>
</div>
<div class="page-content">
<p><a href="/about/" class="link">Go to About</a></p>
<p><a href="/staff/" class="link">Go to Staff</a></p>
</div>
</div>
</div>
</div>
<!-- Scripts -->
<script src="cordova.js"></script>
<script src="js/jquery-3.6.0.min.js"></script>
<script src="js/framework7.bundle.min.js"></script>
<script src="js/app.js"></script>
</body>
</html>
—
#### 2. `js/app.js`
document.addEventListener('deviceready', function () {
// Init Framework7 App
window.f7App = new Framework7({
el: '#app',
name: 'MyCordovaApp',
theme: 'auto',
routes: [
{
path: '/about/',
url: 'pages/about.html',
},
{
path: '/staff/',
url: 'pages/staff.html',
},
],
});
console.log('Cordova and Framework7 are ready!');
// Example jQuery usage
$(document).on('click', '.go-back', function () {
f7App.views.main.router.back();
});
});
—
#### 3. `pages/about.html`
<div class="page" data-name="about">
<div class="navbar">
<div class="navbar-inner">
<div class="left">
<a href="#" class="link back go-back"><i class="icon f7-icons">arrow_left</i></a>
</div>
<div class="title">About</div>
</div>
</div>
<div class="page-content">
<p>This is the About Page</p>
</div>
</div>
—
#### 4. `pages/staff.html`
<div class="page" data-name="staff">
<div class="navbar">
<div class="navbar-inner">
<div class="left">
<a href="#" class="link back go-back"><i class="icon f7-icons">arrow_left</i></a>
</div>
<div class="title">Staff</div>
</div>
</div>
<div class="page-content">
<p>Welcome to the Staff Section</p>
</div>
</div>
—
### ✅ Notes
– Use **Framework7 Core version** (not React/Vue/Svelte).
– All links for routing should use Framework7 syntax: “.
– jQuery can be used freely for DOM manipulation or AJAX alongside Framework7.
—
Would you like me to generate a complete ZIP of this starter project too?
Don't give me backend code
—
### ✅ 1. Add route in `app.js`
routes: [
{
path: '/about/',
url: 'pages/about.html',
},
{
path: '/staff/',
url: 'pages/staff.html',
},
{
path: '/events/',
url: 'pages/events.html',
on: {
pageInit: function (e, page) {
f7App.dialog.preloader('Loading Events...');
$.ajax({
url: 'https://yourdomain.com/api/events.php',
method: 'GET',
success: function (res) {
f7App.dialog.close();
// Assume res is HTML list items or JSON
let html = '';
const events = JSON.parse(res);
$.each(events, function (i, item) {
html += `<li class="item-content">
<div class="item-inner">
<div class="item-title">${item.title}</div>
<div class="item-after">${item.date}</div>
</div>
</li>`;
});
$('#event-list').html(html);
},
error: function () {
f7App.dialog.close();
f7App.dialog.alert('Failed to load events');
}
});
}
}
}
]
—
### ✅ 2. Create `pages/events.html`
<div class="page" data-name="events">
<div class="navbar">
<div class="navbar-inner">
<div class="left">
<a href="#" class="link back"><i class="icon f7-icons">arrow_left</i></a>
</div>
<div class="title">Events</div>
</div>
</div>
<div class="page-content">
<div class="block-title">Today's Events</div>
<div class="list">
<ul id="event-list">
<!-- Event items will be injected here -->
</ul>
</div>
</div>
</div>
—
### ✅ 3. Add link in your `index.html` (or home page)
<p><a href="/events/" class="link">View Events</a></p>
—
### 📝 What this does:
– When the user clicks **“View Events”**, the Framework7 router loads the `events.html` page.
– The `on: pageInit` callback triggers an AJAX request to your PHP backend.
– Fetched event data is displayed in the “.
Let me know if you want pagination or filtering in this too.
Here’s the clean structure and how to organize it:
—
### ✅ Suggested File Structure
www/
├── js/
│ ├── jquery-3.6.0.min.js ← jQuery library
│ ├── app.js ← Framework7 config, routing
│ └── events.js ← Page-specific logic (e.g. load events)
—
### ✅ 1. `index.html` (Include jQuery and files in correct order)
<script src="cordova.js"></script>
<script src="js/jquery-3.6.0.min.js"></script>
<script src="js/framework7.bundle.min.js"></script>
<script src="js/app.js"></script>
<script src="js/events.js"></script>
> ✅ **Always include `events.js` after `app.js`** so Framework7 is already initialized.
—
### ✅ 2. In `app.js` (basic setup, routes only)
window.f7App = new Framework7({
el: '#app',
name: 'MyApp',
theme: 'auto',
routes: [
{
path: '/events/',
url: 'pages/events.html',
}
]
});
—
### ✅ 3. In `events.js` (page logic using jQuery)
$(document).on('page:init', '.page[data-name="events"]', function () {
f7App.dialog.preloader('Loading Events...');
$.ajax({
url: 'https://yourdomain.com/api/events.php',
method: 'GET',
success: function (res) {
f7App.dialog.close();
let html = '';
const events = JSON.parse(res);
$.each(events, function (i, item) {
html += `<li class="item-content">
<div class="item-inner">
<div class="item-title">${item.title}</div>
<div class="item-after">${item.date}</div>
</div>
</li>`;
});
$('#event-list').html(html);
},
error: function () {
f7App.dialog.close();
f7App.dialog.alert('Failed to load events');
}
});
});
—
### ✅ Summary:
– `app.js` = App config and routing only
– `events.js` = Page-specific logic (with jQuery)
– You can create more files like `staff.js`, `login.js` for modular code
Would you like me to show how to dynamically load these page-specific scripts only when the route is visited (optional)?
—
### ✅ In `app.js`
document.addEventListener('deviceready', function () {
console.log('Cordova is ready');
// Initialize Framework7 app
window.f7App = new Framework7({
el: '#app',
name: 'MyApp',
theme: 'auto',
routes: [
{
path: '/events/',
url: 'pages/events.html',
},
// add more routes as needed
]
});
}, false);
—
### ✅ In `events.js` or any other custom file
document.addEventListener('deviceready', function () {
// Add your jQuery-based page logic
$(document).on('page:init', '.page[data-name="events"]', function () {
console.log('Events page loaded after Cordova is ready');
f7App.dialog.preloader('Loading Events...');
$.ajax({
url: 'https://yourdomain.com/api/events.php',
method: 'GET',
success: function (res) {
f7App.dialog.close();
const events = JSON.parse(res);
let html = '';
$.each(events, function (i, item) {
html += `<li class="item-content">
<div class="item-inner">
<div class="item-title">${item.title}</div>
<div class="item-after">${item.date}</div>
</div>
</li>`;
});
$('#event-list').html(html);
},
error: function () {
f7App.dialog.close();
f7App.dialog.alert('Failed to load events');
}
});
});
});
—
### ✅ Summary
– Cordova must be initialized before accessing any native plugins or starting your app logic.
– **Use `document.addEventListener('deviceready', callback)`** for both `app.js` and any page-specific logic files (`events.js`, `login.js`, etc.).
– You can add multiple `deviceready` listeners—Cordova will call them all once it's ready.
Would you like me to show how to ensure this works even in browser (for testing)?