https://github.com/firstandthird/hapi-mobile-views
Loads mobile views
https://github.com/firstandthird/hapi-mobile-views
hapi-plugin
Last synced: about 2 months ago
JSON representation
Loads mobile views
- Host: GitHub
- URL: https://github.com/firstandthird/hapi-mobile-views
- Owner: firstandthird
- Created: 2016-02-19T00:43:47.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2018-09-18T21:41:55.000Z (almost 8 years ago)
- Last Synced: 2025-12-31T21:13:50.600Z (6 months ago)
- Topics: hapi-plugin
- Language: JavaScript
- Size: 12.7 KB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- Contributing: .github/CONTRIBUTING.md
Awesome Lists containing this project
README
# hapi-mobile-views
[](https://travis-ci.org/firstandthird/hapi-mobile-views)
[](https://coveralls.io/github/firstandthird/hapi-mobile-views?branch=master)
Detects mobile user agents and serves mobile views when available.
## Install
`npm install hapi-mobile-views`
## Usage
Basic:
```js
// index.js
server.register(require('hapi-mobile-views'));
```
[Rapptor](https://github.com/firstandthird/rapptor):
```yaml
# default.yaml
plugins:
hapi-mobile-views:
```
## Serving mobile views
**NOTE:** Currently only `*.html` view files are supported and we're only testing against the `vision` module.
This plugin handles everything except creating the mobile views for you. In order to service up a mobile view you will need to create a file that matches a view but end with `-mobile` in the name.
If your return looks like and the template was `pages/homepage.html`
```js
reply('pages/homepage');
```
You'd name the mobile version `pages/homepage-mobile.html`
We also expose a global view context `__isMobile`. Useful if you don't need to change the whole page, just a part. (You should still use media queries if you can).
## Manual Override
Direct the user to the same url but with a `ftDeviceType=` query string. Valid types are `mobile` and `desktop`. The user will be redirected to the original url with a cookie set with the device type.