├── .gitignore ├── package.json ├── readme.md └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | coverage/ 3 | npm-debug.log* 4 | .nyc_output 5 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "choo-cordova", 3 | "description": "Choo hooks for the cordova API", 4 | "author": "YerkoPalma", 5 | "version": "0.1.1", 6 | "main": "index.js", 7 | "files": [ 8 | "index.js" 9 | ], 10 | "scripts": { 11 | "test": "standard --verbose | snazzy", 12 | "start": "node index.js" 13 | }, 14 | "repository": "YerkoPalma/choo-cordova", 15 | "license": "MIT", 16 | "keywords": [ 17 | "choo", 18 | "cordova", 19 | "mobile" 20 | ], 21 | "devDependencies": { 22 | "snazzy": "^7.1.1", 23 | "standard": "^11.0.1", 24 | "tap-summary": "^4.0.0", 25 | "tape": "^4.9.0" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # choo-cordova 2 | [![Build Status](https://img.shields.io/travis/YerkoPalma/choo-cordova/master.svg?style=flat-square)](https://travis-ci.org/YerkoPalma/choo-cordova) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard) 3 | 4 | > Choo hooks for the cordova API 5 | 6 | ## Usage 7 | 8 | ```js 9 | var choo = require('choo') 10 | 11 | var app = choo() 12 | 13 | app.use(require('choo-cordova')) 14 | 15 | app.route('/', require('./views/main')) 16 | app.mount('#app') 17 | ``` 18 | 19 | ## Events 20 | This store emit events for every cordova events. Those events are: 21 | 22 | - `'deviceready'` 23 | - `'pause'` 24 | - `'resume'` 25 | - `'backbutton'` 26 | - `'menubutton'` 27 | - `'searchbutton'` 28 | - `'startcallbutton'` 29 | - `'endcallbutton'` 30 | - `'volumedownbutton'` 31 | - `'volumeupbutton'` 32 | - `'activated'` 33 | 34 | For further documentation about those, check [cordova docs](https://cordova.apache.org/docs/en/latest/cordova/events/events.html) 35 | 36 | ## API 37 | After registering this store, a `cordova` property will be added to the store. This will have some of the cordova object properties. As the time of writing, this object looks like. 38 | 39 | ```js 40 | JSON.stringify(choo.state.cordova, null, 2) 41 | "{ 42 | "version": "5.0.3", 43 | "platformVersion": "5.0.3", 44 | "platformId": "browser", 45 | "callbackId": 65806389, 46 | "callbacks": {}, 47 | "callbackStatus": { 48 | "NO_RESULT": 0, 49 | "OK": 1, 50 | "CLASS_NOT_FOUND_EXCEPTION": 2, 51 | "ILLEGAL_ACCESS_EXCEPTION": 3, 52 | "INSTANTIATION_EXCEPTION": 4, 53 | "MALFORMED_URL_EXCEPTION": 5, 54 | "IO_EXCEPTION": 6, 55 | "INVALID_ACTION": 7, 56 | "JSON_EXCEPTION": 8, 57 | "ERROR": 9 58 | }, 59 | "commandProxy": {} 60 | }" 61 | ``` 62 | 63 | ## License 64 | [MIT](/license) 65 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /* global cordova */ 2 | module.exports = store 3 | 4 | var events = store.events = { 5 | DEVICE_READY: 'deviceready', 6 | PAUSE: 'pause', 7 | RESUME: 'resume', 8 | BACK_BUTTON: 'backbutton', 9 | MENU_BUTTON: 'menubutton', 10 | SEARCH_BUTTON: 'searchbutton', 11 | START_CALL_BUTTON: 'startcallbutton', 12 | END_CALL_BUTTON: 'endcallbutton', 13 | VOLUME_DOWN_BUTTON: 'volumedownbutton', 14 | VOLUME_UP_BUTTON: 'volumeupbutton', 15 | ACTIVATED: 'activated' 16 | } 17 | 18 | function store (state, emitter) { 19 | state.cordova = {} 20 | document.addEventListener(events.DEVICE_READY, () => { 21 | Object.keys(cordova).forEach(key => { 22 | if (cordova.hasOwnProperty(key) && typeof cordova[key] !== 'function') { 23 | state.cordova[key] = cordova[key] 24 | } 25 | }) 26 | emitter.emit(events.DEVICE_READY) 27 | }, false) 28 | 29 | document.addEventListener(events.PAUSE, () => { 30 | emitter.emit(events.PAUSE) 31 | }, false) 32 | 33 | document.addEventListener(events.RESUME, () => { 34 | // iOS hack 35 | setTimeout(() => { 36 | emitter.emit(events.RESUME) 37 | }, 0) 38 | }, false) 39 | 40 | document.addEventListener(events.BACK_BUTTON, () => { 41 | emitter.emit(events.BACK_BUTTON) 42 | }, false) 43 | 44 | document.addEventListener(events.MENU_BUTTON, () => { 45 | emitter.emit(events.MENU_BUTTON) 46 | }, false) 47 | 48 | document.addEventListener(events.SEARCH_BUTTON, () => { 49 | emitter.emit(events.SEARCH_BUTTON) 50 | }, false) 51 | 52 | document.addEventListener(events.START_CALL_BUTTON, () => { 53 | emitter.emit(events.START_CALL_BUTTON) 54 | }, false) 55 | 56 | document.addEventListener(events.END_CALL_BUTTON, () => { 57 | emitter.emit(events.END_CALL_BUTTON) 58 | }, false) 59 | 60 | document.addEventListener(events.VOLUME_DOWN_BUTTON, () => { 61 | emitter.emit(events.VOLUME_DOWN_BUTTON) 62 | }, false) 63 | 64 | document.addEventListener(events.VOLUME_UP_BUTTON, () => { 65 | emitter.emit(events.VOLUME_DOWN_BUTTON) 66 | }, false) 67 | 68 | document.addEventListener(events.ACTIVATED, args => { 69 | emitter.emit(events.ACTIVATED, args) 70 | }, false) 71 | } 72 | --------------------------------------------------------------------------------