mirror of
https://github.com/pebble-dev/clay.git
synced 2026-08-28 21:06:58 -04:00
Automatically handle the "showConfiguration" and "webviewclosed" events + other minor code cleanup
This commit is contained in:
@@ -12,7 +12,7 @@ var returnTo = window.returnTo || 'pebblejs://close#';
|
||||
var customFn = window.customFn || function() {};
|
||||
var clayComponents = window.clayComponents || {};
|
||||
|
||||
var platform = window.navigator.userAgent.match(/Android/) ? 'android' : 'ios';
|
||||
var platform = window.navigator.userAgent.match(/android/i) ? 'android' : 'ios';
|
||||
document.documentElement.classList.add('platform-' + platform);
|
||||
|
||||
// Register the passed components
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
|
||||
/**
|
||||
* A Clay config Item
|
||||
* @typedef {object} Clay~ConfigItem
|
||||
* @typedef {Object} Clay~ConfigItem
|
||||
* @property {string} type
|
||||
* @property {string|boolean|number} defaultValue
|
||||
* @property {string} [appKey]
|
||||
* @property {string} [id]
|
||||
* @property {string} [label]
|
||||
* @property {object} [attributes]
|
||||
* @property {Object} [attributes]
|
||||
* @property {Array} [options]
|
||||
* @property {Array} [items]
|
||||
*/
|
||||
@@ -23,8 +23,8 @@ var manipulators = require('./manipulators');
|
||||
|
||||
/**
|
||||
* @extends ClayEvents
|
||||
* @param {{}} settings - setting that were set from a previous session
|
||||
* @param {[]|{}} config
|
||||
* @param {Object} settings - setting that were set from a previous session
|
||||
* @param {Array|Object} config
|
||||
* @param {M} $rootContainer
|
||||
* @constructor
|
||||
*/
|
||||
@@ -150,7 +150,7 @@ function ClayConfig(settings, config, $rootContainer) {
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {object}
|
||||
* @returns {Object}
|
||||
*/
|
||||
self.getSettings = function() {
|
||||
_checkBuilt('getSettings');
|
||||
@@ -188,13 +188,13 @@ function ClayConfig(settings, config, $rootContainer) {
|
||||
|
||||
/**
|
||||
* Register a component to Clay. This must be called prior to .build();
|
||||
* @param {{}} component - the clay component to register
|
||||
* @param {Object} component - the clay component to register
|
||||
* @param {string} component.name - the name of the component
|
||||
* @param {string} component.template - HTML template to use for the component
|
||||
* @param {string|{}} component.manipulator - methods to attach to the component
|
||||
* @param {string|Object} component.manipulator - methods to attach to the component
|
||||
* @param {function} component.manipulator.set - set manipulator method
|
||||
* @param {function} component.manipulator.get - get manipulator method
|
||||
* @param {{}} [component.defaults] - template defaults
|
||||
* @param {Object} [component.defaults] - template defaults
|
||||
* @param {function} [component.initialize] - method to scaffold the component
|
||||
* @return {boolean} - Returns true if component was registered correctly
|
||||
*/
|
||||
@@ -217,6 +217,10 @@ ClayConfig.registerComponent = function(component) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!_component.manipulator) {
|
||||
throw new Error('The manipulator must be defined');
|
||||
}
|
||||
|
||||
if (typeof _component.manipulator.set !== 'function' ||
|
||||
typeof _component.manipulator.get !== 'function') {
|
||||
throw new Error('The manipulator must have both a `get` and `set` method');
|
||||
|
||||
@@ -88,7 +88,7 @@ function ClayEvents($eventTarget) {
|
||||
/**
|
||||
* Trigger an event.
|
||||
* @param {string} name - a single event name to trigger
|
||||
* @param {object} [eventObj] - an object to pass to the event handler,
|
||||
* @param {Object} [eventObj] - an object to pass to the event handler,
|
||||
* provided the handler does not have custom arguments.
|
||||
* @returns {ClayEvents}
|
||||
*/
|
||||
|
||||
@@ -19,7 +19,7 @@ function ClayItem(config) {
|
||||
var _component = componentRegistry[config.type];
|
||||
|
||||
if (!_component) {
|
||||
throw new Error('the component: ' + config.type + ' is not registered. ' +
|
||||
throw new Error('The component: ' + config.type + ' is not registered. ' +
|
||||
'Make sure to register it with ClayConfig.registerComponent()');
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ function ClayItem(config) {
|
||||
/** @type {string|null} */
|
||||
self.appKey = config.appKey || null;
|
||||
|
||||
/** @type {object} */
|
||||
/** @type {Object} */
|
||||
self.config = config;
|
||||
|
||||
/** @type {M} */
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
/**
|
||||
* Batch update all the properties of an object.
|
||||
* @param {object} obj
|
||||
* @param {object} descriptor
|
||||
* @param {Object} obj
|
||||
* @param {Object} descriptor
|
||||
* @param {boolean} [descriptor.configurable]
|
||||
* @param {boolean} [descriptor.enumerable]
|
||||
* @param {*} [descriptor.value]
|
||||
|
||||
Reference in New Issue
Block a user