Commit afd6a480 by Sebastián Katzer

Small coding changes

parent d28f1aaf
...@@ -58,10 +58,14 @@ LocalNotification.prototype = { ...@@ -58,10 +58,14 @@ LocalNotification.prototype = {
/** /**
* @private * @private
* Merge settings with default values *
* Merges custom properties with the default values.
* *
* @param {Object} options * @param {Object} options
* Set of custom values
*
* @retrun {Object} * @retrun {Object}
* The merged property list
*/ */
mergeWithDefaults: function (options) { mergeWithDefaults: function (options) {
var defaults = this.getDefaults(); var defaults = this.getDefaults();
...@@ -77,6 +81,11 @@ LocalNotification.prototype = { ...@@ -77,6 +81,11 @@ LocalNotification.prototype = {
/** /**
* @private * @private
*
* Merges the platform specific properties into the default properties.
*
* @return {Object}
* The default properties for the platform
*/ */
applyPlatformSpecificOptions: function () { applyPlatformSpecificOptions: function () {
var defaults = this._defaults; var defaults = this._defaults;
...@@ -94,13 +103,18 @@ LocalNotification.prototype = { ...@@ -94,13 +103,18 @@ LocalNotification.prototype = {
defaults.image = null; defaults.image = null;
defaults.wideImage = null; defaults.wideImage = null;
}; };
return defaults;
}, },
/** /**
* Add a new entry to the registry * Add a new entry to the registry
* *
* @param {Object} options * @param {Object} options
* @return {Number} The notification's ID * The notification properties
*
* @return {Number}
* The notification's ID
*/ */
add: function (options) { add: function (options) {
var options = this.mergeWithDefaults(options), var options = this.mergeWithDefaults(options),
...@@ -130,77 +144,93 @@ LocalNotification.prototype = { ...@@ -130,77 +144,93 @@ LocalNotification.prototype = {
}, },
/** /**
* Cancels the specified notification * Cancels the specified notification.
* *
* @param {String} id of the notification * @param {String} id
* The ID of the notification
*/ */
cancel: function (id) { cancel: function (id) {
cordova.exec(null, null, 'LocalNotification', 'cancel', [id.toString()]); var id = id.toString();
cordova.exec(null, null, 'LocalNotification', 'cancel', [id]);
}, },
/** /**
* Removes all previously registered notifications * Removes all previously registered notifications.
*/ */
cancelAll: function () { cancelAll: function () {
cordova.exec(null, null, 'LocalNotification', 'cancelAll', []); cordova.exec(null, null, 'LocalNotification', 'cancelAll', []);
}, },
/** /**
* @async
*
* Retrieves a list with all currently pending notifications. * Retrieves a list with all currently pending notifications.
* *
* @param {Function} callback * @param {Function} callback
* A callback function to be called with the list
*/ */
getScheduledIds: function (callback) { getScheduledIds: function (callback) {
cordova.exec(callback, null, 'LocalNotification', 'getScheduledIds', []); cordova.exec(callback, null, 'LocalNotification', 'getScheduledIds', []);
}, },
/** /**
* @async
*
* Checks wether a notification with an ID is scheduled. * Checks wether a notification with an ID is scheduled.
* *
* @param {String} id * @param {String} id
* The ID of the notification
* @param {Function} callback * @param {Function} callback
* A callback function to be called with the list
*/ */
isScheduled: function (id, callback) { isScheduled: function (id, callback) {
cordova.exec(callback, null, 'LocalNotification', 'isScheduled', [id.toString()]); var id = id.toString();
cordova.exec(callback, null, 'LocalNotification', 'isScheduled', [id]);
}, },
/** /**
* Occurs when a notification was added. * Occurs when a notification was added.
* *
* @param {String} id The ID of the notification * @param {String} id
* @param {String} state Either "foreground" or "background" * The ID of the notification
* @param {String} json A custom (JSON) string * @param {String} state
* Either "foreground" or "background"
* @param {String} json
* A custom (JSON) string
*/ */
onadd: function (id, state, json) {}, onadd: function (id, state, json) {},
/** /**
* Occurs when the notification is triggered. * Occurs when the notification is triggered.
* *
* @param {String} id The ID of the notification * @param {String} id
* @param {String} state Either "foreground" or "background" * The ID of the notification
* @param {String} json A custom (JSON) string * @param {String} state
* Either "foreground" or "background"
* @param {String} json
* A custom (JSON) string
*/ */
ontrigger: function (id, state, json) {}, ontrigger: function (id, state, json) {},
/** /**
* Fires after the notification was clicked. * Fires after the notification was clicked.
* *
* @param {String} id The ID of the notification * @param {String} id
* @param {String} state Either "foreground" or "background" * The ID of the notification
* @param {String} json A custom (JSON) string * @param {String} state
* Either "foreground" or "background"
* @param {String} json
* A custom (JSON) string
*/ */
onclick: function (id, state, json) {}, onclick: function (id, state, json) {},
/** /**
* Fires if the notification was canceled. * Fires if the notification was canceled.
* *
* @param {String} id The ID of the notification * @param {String} id
* @param {String} state Either "foreground" or "background" * The ID of the notification
* @param {String} json A custom (JSON) string * @param {String} state
* Either "foreground" or "background"
* @param {String} json
* A custom (JSON) string
*/ */
oncancel: function (id, state, json) {} oncancel: function (id, state, json) {}
}; };
...@@ -208,24 +238,32 @@ LocalNotification.prototype = { ...@@ -208,24 +238,32 @@ LocalNotification.prototype = {
var plugin = new LocalNotification(), var plugin = new LocalNotification(),
channel = require('cordova/channel'); channel = require('cordova/channel');
// Called after all 'deviceready' listener are called
channel.deviceready.subscribe( function () { channel.deviceready.subscribe( function () {
// Device is ready now, the listeners are registered and all queued events
// can be executed now.
cordova.exec(null, null, 'LocalNotification', 'deviceready', []); cordova.exec(null, null, 'LocalNotification', 'deviceready', []);
}); });
channel.onCordovaReady.subscribe( function () { channel.onCordovaReady.subscribe( function () {
// The cordova device plugin is ready now
channel.onCordovaInfoReady.subscribe( function () { channel.onCordovaInfoReady.subscribe( function () {
if (device.platform == 'Android') { if (device.platform == 'Android') {
channel.onPause.subscribe( function () { channel.onPause.subscribe( function () {
// Necessary to set the state to `background`
cordova.exec(null, null, 'LocalNotification', 'pause', []); cordova.exec(null, null, 'LocalNotification', 'pause', []);
}); });
channel.onResume.subscribe( function () { channel.onResume.subscribe( function () {
// Necessary to set the state to `foreground`
cordova.exec(null, null, 'LocalNotification', 'resume', []); cordova.exec(null, null, 'LocalNotification', 'resume', []);
}); });
// Necessary to set the state to `foreground`
cordova.exec(null, null, 'LocalNotification', 'resume', []); cordova.exec(null, null, 'LocalNotification', 'resume', []);
} }
// Merges the platform specific properties into the default properties
plugin.applyPlatformSpecificOptions(); plugin.applyPlatformSpecificOptions();
}); });
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment