mirror of
https://github.com/pebble-dev/clay.git
synced 2026-08-31 06:16:51 -04:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ad807020ca | ||
|
|
bd3e4a55c8 | ||
|
|
f50f569c98 | ||
|
|
be17456f8b | ||
|
|
49f92de102 | ||
|
|
c4f6b17a58 | ||
|
|
061bb34c91 | ||
|
|
20e7460c2f | ||
|
|
6e5c2f5847 | ||
|
|
71ea309346 | ||
|
|
d63c6c832d | ||
|
|
de00ac1fd6 | ||
|
|
271a0d1cfd | ||
|
|
d6659db3ac | ||
|
|
264866ce26 | ||
|
|
069d4a80da | ||
|
|
c99ad44b5c | ||
|
|
75c846a8ba | ||
|
|
a1df49623d | ||
|
|
08e41036da | ||
|
|
663f91e9bd |
@@ -108,7 +108,7 @@ Sections help divide up the page into logical groups of items. It is recommended
|
||||
|
||||
### Heading
|
||||
|
||||
**Manipulator:** `html`
|
||||
**Manipulator:** [`html`](#html)
|
||||
|
||||
Headings can be used in anywhere and can have their size adjusted to suit the context. If you place a heading item at the first position of a section's `items` array then it will automatically be styled as the header for that section.
|
||||
|
||||
@@ -138,7 +138,7 @@ Headings can be used in anywhere and can have their size adjusted to suit the co
|
||||
|
||||
### Text
|
||||
|
||||
**Manipulator:** `html`
|
||||
**Manipulator:** [`html`](#html)
|
||||
|
||||
Text is used to provide descriptions of sections or to explain complex parts of your page. Feel free to add any extra HTML you require to the `defaultValue`
|
||||
|
||||
@@ -165,7 +165,7 @@ Text is used to provide descriptions of sections or to explain complex parts of
|
||||
|
||||
### Input
|
||||
|
||||
**Manipulator:** `val`
|
||||
**Manipulator:** [`val`](#val)
|
||||
|
||||
Standard text input field.
|
||||
|
||||
@@ -203,7 +203,7 @@ Standard text input field.
|
||||
|
||||
#### Toggle
|
||||
|
||||
**Manipulator:** `checked`
|
||||
**Manipulator:** [`checked`](#checked)
|
||||
|
||||
Switch for a single item.
|
||||
|
||||
@@ -238,7 +238,7 @@ Switch for a single item.
|
||||
|
||||
#### Select
|
||||
|
||||
**Manipulator:** `val`
|
||||
**Manipulator:** [`val`](#val)
|
||||
|
||||
A dropdown menu containing multiple options.
|
||||
|
||||
@@ -291,7 +291,7 @@ A dropdown menu containing multiple options.
|
||||
|
||||
#### Color
|
||||
|
||||
**Manipulator:** `color`
|
||||
**Manipulator:** [`color`](#color)
|
||||
|
||||
A color picker containing the 64 supported colors on Basalt and Chalk.
|
||||
|
||||
@@ -321,9 +321,9 @@ A color picker containing the 64 supported colors on Basalt and Chalk.
|
||||
|
||||
---
|
||||
|
||||
#### RadioGroup
|
||||
#### Radio Group
|
||||
|
||||
**Manipulator:** `radiogroup`
|
||||
**Manipulator:** [`radiogroup`](#radiogroup)
|
||||
|
||||
A list of options allowing the user can only choose one option to submit.
|
||||
|
||||
@@ -366,9 +366,9 @@ A list of options allowing the user can only choose one option to submit.
|
||||
|
||||
---
|
||||
|
||||
#### CheckboxGroup
|
||||
#### Checkbox Group
|
||||
|
||||
**Manipulator:** `checkboxgroup`
|
||||
**Manipulator:** [`checkboxgroup`](#checkboxgroup)
|
||||
|
||||
A list of options where a user may choose more than one option to submit.
|
||||
|
||||
@@ -412,9 +412,35 @@ A list of options where a user may choose more than one option to submit.
|
||||
|
||||
---
|
||||
|
||||
### Generic Button
|
||||
|
||||
**Manipulator:** [`button`](#button)
|
||||
|
||||
##### Properties
|
||||
|
||||
| Property | Type | Description |
|
||||
|----------|------|-------------|
|
||||
| type | string | Set to `button`. |
|
||||
| defaultValue | string | The text displayed on the button. |
|
||||
| primary | boolean | If `true` the button will be orange, if `false`, the button will be gray (defaults to `false`)|
|
||||
| attributes | object | An object containing HTML attributes to set on the input field. |
|
||||
| description | string | Optional sub-text to include below the component |
|
||||
|
||||
##### Example
|
||||
|
||||
```javascript
|
||||
{
|
||||
"type": "button",
|
||||
"primary": true,
|
||||
"defaultValue": "Send"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Submit
|
||||
|
||||
**Manipulator:** `html`
|
||||
**Manipulator:** [`button`](#button)
|
||||
|
||||
The submit button for the page. You **MUST** include this component somewhere in the config page (traditionally at the bottom) or users will not be able to save the form.
|
||||
|
||||
@@ -440,7 +466,6 @@ The submit button for the page. You **MUST** include this component somewhere in
|
||||
### Coming Soon
|
||||
|
||||
- Range Slider
|
||||
- Generic Button
|
||||
- Tabs
|
||||
- Footer
|
||||
- Dynamic + draggable list
|
||||
@@ -452,8 +477,12 @@ The submit button for the page. You **MUST** include this component somewhere in
|
||||
Each component has a **manipulator**. This is a set of methods used to talk to the item on the page.
|
||||
At a minimum, manipulators must have a `.get()` and `.set(value)` method however there are also methods to assist in interactivity such as `.hide()` and `.disable()`.
|
||||
**NOTE:** There is currently no way to disable or hide an entire section. You must disable/hide each item in the section to achieve this effect.
|
||||
|
||||
When the config page is closed, the `.get()` method is run on all components registered with an `appKey` to construct the object sent to the C app.
|
||||
Many of these methods fire an event when the method is called. You can listen for these events with `ClayItem.on()`.
|
||||
|
||||
Many of these methods fire an event when the method is called. You can listen for these events with `ClayItem.on()`.
|
||||
**NOTE** These events will only be fired if the state actually changes.
|
||||
Eg: If you run the `.show()` manipulator on an item that is already visible, the `show` event will not be triggered.
|
||||
|
||||
#### html
|
||||
|
||||
@@ -464,6 +493,17 @@ Many of these methods fire an event when the method is called. You can listen fo
|
||||
| `.hide()` | `ClayItem` | `hide` | Hides the item |
|
||||
| `.show()` | `ClayItem` | `show` | Shows the item |
|
||||
|
||||
#### button
|
||||
|
||||
| Method | Returns | Event Fired | Description |
|
||||
|--------|---------|-------------| ------------|
|
||||
| `.set( [string\|HTML] value)` | `ClayItem` | `change` | Sets the content of this item. |
|
||||
| `.get()` | `string` | | Gets the content of this item. |
|
||||
| `.disable()` | `ClayItem` | `disabled` | Prevents this item from being clicked by the user. |
|
||||
| `.enable()` | `ClayItem` | `enabled` | Allows this item to be clicked by the user. |
|
||||
| `.hide()` | `ClayItem` | `hide` | Hides the item |
|
||||
| `.show()` | `ClayItem` | `show` | Shows the item |
|
||||
|
||||
#### val
|
||||
|
||||
| Method | Returns | Event Fired | Description |
|
||||
@@ -480,7 +520,7 @@ Many of these methods fire an event when the method is called. You can listen fo
|
||||
| Method | Returns | Event Fired | Description |
|
||||
|--------|---------|-------------| ------------|
|
||||
| `.set( [boolean\|int] value)` | `ClayItem` | `change` | Check/uncheck the state of this item. |
|
||||
| `.get()` | `int` | | 1 if checked, 0 if not checked |
|
||||
| `.get()` | `boolean` | | `true` if checked, `false` if not. **NOTE** this will be converted to a `1` or `0` when sent to the watch. See [`ClayConfig.getSettings()`](#methods-1) |
|
||||
| `.disable()` | `ClayItem` | `disabled` | Prevents this item from being edited by the user. |
|
||||
| `.enable()` | `ClayItem` | `enabled` | Allows this item to be edited by the user. |
|
||||
| `.hide()` | `ClayItem` | `hide` | Hides the item |
|
||||
@@ -513,7 +553,7 @@ Many of these methods fire an event when the method is called. You can listen fo
|
||||
| Method | Returns | Event Fired | Description |
|
||||
|--------|---------|-------------| ------------|
|
||||
| `.set( [array] value)` | `ClayItem` | `change` | Checks the checkboxes that corresponds to the provided list of values. |
|
||||
| `.get()` | `Array.<string>` | | Gets an array of strings representing the list of the values of the checked items |
|
||||
| `.get()` | `Array.<string>` | | Gets an array of strings representing the list of the values of the checked items. **NOTE:** each item in the array will be separated by a zero when sent to the watch. See [`ClayConfig.getSettings()`](#methods-1) |
|
||||
| `.disable()` | `ClayItem` | `disabled` | Prevents this item from being edited by the user. |
|
||||
| `.enable()` | `ClayItem` | `enabled` | Allows this item to be edited by the user. |
|
||||
| `.hide()` | `ClayItem` | `hide` | Hides the item |
|
||||
@@ -532,15 +572,23 @@ Example:
|
||||
```javascript
|
||||
var Clay = require('./clay');
|
||||
var clayConfig = require('./config');
|
||||
var clayConfigAplite = require('./config-aplite');
|
||||
var clay = new Clay(clayConfig, null, { autoHandleEvents: false });
|
||||
|
||||
Pebble.addEventListener('showConfiguration', function(e) {
|
||||
|
||||
// This is an example of how you might load a different config based on platform.
|
||||
var platform = clay.meta.activeWatchInfo.platform || 'aplite';
|
||||
if (platform === 'aplite') {
|
||||
clay.config = clayConfigAplite;
|
||||
}
|
||||
|
||||
Pebble.openURL(clay.generateUrl());
|
||||
});
|
||||
|
||||
Pebble.addEventListener('webviewclosed', function(e) {
|
||||
if (e && !e.response) {
|
||||
return;
|
||||
if (e && !e.response) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the keys and values from each config item
|
||||
@@ -558,6 +606,17 @@ Pebble.addEventListener('webviewclosed', function(e) {
|
||||
|
||||
### `Clay([Array] config, [function] customFn, [object] options)`
|
||||
|
||||
#### Properties
|
||||
|
||||
| Property | Type | Description |
|
||||
|----------|------|-------------|
|
||||
| `.config` | Array | Reference to the config passed to the constructor and used for generating the page. **WARNING** this is a direct reference, not a copy of the config so any modification you make to it, will be reflected on the original as well |
|
||||
| `.customFn` | Function | Reference to the custom function passed to the constructor. **WARNING** this is a direct reference, not a copy of the custom function so any modification you make to it, will be reflected on the original as well |
|
||||
| `.meta` | Object | Contains information about the current user and watch. **WARNING** This will only be populated in the `showConfiguration` event handler. (See example above) |
|
||||
| `.meta.activeWatchInfo` | watchinfo\|null | An object containing information on the currently connected Pebble smartwatch or null if unavailable. Read more [here](https://developer.pebble.com/docs/js/Pebble/#getActiveWatchInfo). |
|
||||
| `.meta.accountToken` | String | A unique account token that is associated with the Pebble account of the current user. Read more [here](https://developer.pebble.com/docs/js/Pebble/#getAccountToken). |
|
||||
| `.meta.watchToken` | String | A unique token that can be used to identify a Pebble device. Read more [here](https://developer.pebble.com/docs/js/Pebble/#getWatchToken). |
|
||||
|
||||
#### Methods
|
||||
|
||||
| Method | Returns |
|
||||
@@ -565,7 +624,7 @@ Pebble.addEventListener('webviewclosed', function(e) {
|
||||
| `Clay( [array] config, [function] customFn=null, [object] options={autoHandleEvents: true})` <br> `config` - an Array representing your config <br> `customFn` - function to be run in the context of the generated page <br> `options.autoHandleEvents` - set to `false` to prevent Clay from automatically handling the "showConfiguration" and "webviewclosed" events | `Clay` - a new instance of Clay. |
|
||||
| `.registerComponent( [ClayComponent] component )` <br> Registers a custom component. | `void`. |
|
||||
| `.generateUrl()` | `string` - The URL to open with `Pebble.openURL()` to use the Clay-generated config page. |
|
||||
| `.getSettings(response)` <br> `response` - the response object provided to the "webviewclosed" event | `Object` - object of keys and values for each config page item with an `appKey`, where the key is the `appKey` and the value is the chosen value of that item. |
|
||||
| `.getSettings(response)` <br> `response` - the response object provided to the "webviewclosed" event | `Object` - object of keys and values for each config page item with an `appKey`, where the key is the `appKey` and the value is the chosen value of that item. This method may do some conversions depending on the type of the setting. Arrays containing strings will have zeros inserted before each item. eg `['one', 'two']` becomes `['one', 0, 'two', 0]`. Booleans will be converted to numbers. eg `true` becomes `1` and `false` becomes `0` |
|
||||
|
||||
---
|
||||
|
||||
@@ -595,27 +654,27 @@ var clay = new Clay(clayConfig, customClay);
|
||||
|
||||
```javascript
|
||||
module.exports = function(minified) {
|
||||
var Clay = this;
|
||||
var clayConfig = this;
|
||||
var _ = minified._;
|
||||
var $ = minified.$;
|
||||
var HTML = minified.HTML;
|
||||
|
||||
function toggleBackground() {
|
||||
if (this.get()) {
|
||||
Clay.getItemByAppKey('background').enable();
|
||||
clayConfig.getItemByAppKey('background').enable();
|
||||
} else {
|
||||
Clay.getItemByAppKey('background').disable();
|
||||
clayConfig.getItemByAppKey('background').disable();
|
||||
}
|
||||
}
|
||||
|
||||
Clay.on(Clay.EVENTS.AFTER_BUILD, function() {
|
||||
var coolStuffToggle = Clay.getItemByAppKey('cool_stuff');
|
||||
clayConfig.on(clayConfig.EVENTS.AFTER_BUILD, function() {
|
||||
var coolStuffToggle = clayConfig.getItemByAppKey('cool_stuff');
|
||||
toggleBackground.call(coolStuffToggle);
|
||||
coolStuffToggle.on('change', toggleBackground);
|
||||
|
||||
// Hide the color picker for aplite
|
||||
if (Clay.meta.activeWatchInfo.platform === 'aplite') {
|
||||
Clay.getItemByAppKey('background').hide();
|
||||
if (!clayConfig.meta.activeWatchInfo || clayConfig.meta.activeWatchInfo.platform === 'aplite') {
|
||||
clayConfig.getItemByAppKey('background').hide();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -626,7 +685,7 @@ module.exports = function(minified) {
|
||||
|
||||
### `ClayConfig([Object] settings, [Array] config, [$Minified] $rootContainer)`
|
||||
|
||||
This is the main way of talking to your generated config page.
|
||||
This is the main way of talking to your generated config page. An instance of this class will be passed as the context of your custom function when it runs on the generated config page.
|
||||
|
||||
#### Properties
|
||||
|
||||
|
||||
@@ -50,6 +50,14 @@ module.exports = [
|
||||
"defaultValue": "00FF00",
|
||||
"label": "Sunny Color Picker",
|
||||
"sunlight": true
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
id: 'testButton',
|
||||
primary: false,
|
||||
defaultValue: 'Generic Button',
|
||||
description: 'This is a generic button. ' +
|
||||
'You can listen for standard events like "click"'
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "pebble-clay",
|
||||
"version": "0.1.1",
|
||||
"version": "0.1.2",
|
||||
"description": "Pebble Config Framework",
|
||||
"main": "dist/clay.js",
|
||||
"directories": {
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 116 KiB After Width: | Height: | Size: 124 KiB |
@@ -0,0 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
name: 'button',
|
||||
template: require('../../templates/components/button.tpl'),
|
||||
style: require('../../styles/clay/components/button.scss'),
|
||||
manipulator: 'button',
|
||||
defaults: {
|
||||
primary: false,
|
||||
attributes: {},
|
||||
description: ''
|
||||
}
|
||||
};
|
||||
@@ -10,5 +10,6 @@ module.exports = {
|
||||
text: require('./text'),
|
||||
toggle: require('./toggle'),
|
||||
radiogroup: require('./radiogroup'),
|
||||
checkboxgroup: require('./checkboxgroup')
|
||||
checkboxgroup: require('./checkboxgroup'),
|
||||
button: require('./button')
|
||||
};
|
||||
|
||||
@@ -16,11 +16,18 @@ module.exports = {
|
||||
|
||||
var $value = self.$element.select('.value');
|
||||
|
||||
self.on('change', function() {
|
||||
/**
|
||||
* Updates the HTML value of the component to match the slected option's label
|
||||
* @return {void}
|
||||
*/
|
||||
function setValueDisplay() {
|
||||
var selectedIndex = self.$manipulatorTarget.get('selectedIndex');
|
||||
var $options = self.$manipulatorTarget.select('option');
|
||||
var value = $options[selectedIndex] && $options[selectedIndex].innerHTML;
|
||||
$value.set('innerHTML', value);
|
||||
});
|
||||
}
|
||||
|
||||
setValueDisplay();
|
||||
self.on('change', setValueDisplay);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -4,7 +4,7 @@ module.exports = {
|
||||
name: 'submit',
|
||||
template: require('../../templates/components/submit.tpl'),
|
||||
style: require('../../styles/clay/components/submit.scss'),
|
||||
manipulator: 'html',
|
||||
manipulator: 'button',
|
||||
defaults: {
|
||||
attributes: {}
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ function ClayConfig(settings, config, $rootContainer, meta) {
|
||||
self.getSettings = function() {
|
||||
_checkBuilt('getSettings');
|
||||
_.eachObj(_itemsByAppKey, function(appKey, item) {
|
||||
_settings[appKey] = item.get();
|
||||
_settings[appKey] = utils.prepareForAppMessage(item.get());
|
||||
});
|
||||
return _settings;
|
||||
};
|
||||
|
||||
@@ -1,35 +1,45 @@
|
||||
'use strict';
|
||||
|
||||
var _ = require('../vendor/minified')._;
|
||||
|
||||
/**
|
||||
* @returns {ClayEvents}
|
||||
* @returns {ClayItem|ClayEvents}
|
||||
* @extends {ClayItem}
|
||||
*/
|
||||
function disable() {
|
||||
if (this.$manipulatorTarget.get('disabled')) { return this; }
|
||||
this.$element.set('+disabled');
|
||||
this.$manipulatorTarget.set('disabled', true);
|
||||
return this.trigger('disabled');
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {ClayEvents}
|
||||
* @returns {ClayItem|ClayEvents}
|
||||
* @extends {ClayItem}
|
||||
*/
|
||||
function enable() {
|
||||
if (!this.$manipulatorTarget.get('disabled')) { return this; }
|
||||
this.$element.set('-disabled');
|
||||
this.$manipulatorTarget.set('disabled', false);
|
||||
return this.trigger('enabled');
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {ClayEvents}
|
||||
* @returns {ClayItem|ClayEvents}
|
||||
* @extends {ClayItem}
|
||||
*/
|
||||
function hide() {
|
||||
if (this.$element[0].classList.contains('hide')) { return this; }
|
||||
this.$element.set('+hide');
|
||||
return this.trigger('hide');
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {ClayEvents}
|
||||
* @returns {ClayItem|ClayEvents}
|
||||
* @extends {ClayItem}
|
||||
*/
|
||||
function show() {
|
||||
if (!this.$element[0].classList.contains('hide')) { return this; }
|
||||
this.$element.set('-hide');
|
||||
return this.trigger('show');
|
||||
}
|
||||
@@ -40,17 +50,33 @@ module.exports = {
|
||||
return this.$manipulatorTarget.get('innerHTML');
|
||||
},
|
||||
set: function(value) {
|
||||
if (this.get() === value.toString(10)) { return this; }
|
||||
this.$manipulatorTarget.set('innerHTML', value);
|
||||
return this.trigger('change');
|
||||
},
|
||||
hide: hide,
|
||||
show: show
|
||||
},
|
||||
button: {
|
||||
get: function() {
|
||||
return this.$manipulatorTarget.get('innerHTML');
|
||||
},
|
||||
set: function(value) {
|
||||
if (this.get() === value.toString(10)) { return this; }
|
||||
this.$manipulatorTarget.set('innerHTML', value);
|
||||
return this.trigger('change');
|
||||
},
|
||||
disable: disable,
|
||||
enable: enable,
|
||||
hide: hide,
|
||||
show: show
|
||||
},
|
||||
val: {
|
||||
get: function() {
|
||||
return this.$manipulatorTarget.get('value');
|
||||
},
|
||||
set: function(value) {
|
||||
if (this.get() === value.toString(10)) { return this; }
|
||||
this.$manipulatorTarget.set('value', value);
|
||||
return this.trigger('change');
|
||||
},
|
||||
@@ -61,9 +87,10 @@ module.exports = {
|
||||
},
|
||||
checked: {
|
||||
get: function() {
|
||||
return this.$manipulatorTarget.get('checked') ? 1 : 0;
|
||||
return this.$manipulatorTarget.get('checked');
|
||||
},
|
||||
set: function(value) {
|
||||
if (!this.get() === !value) { return this; }
|
||||
this.$manipulatorTarget.set('checked', !!value);
|
||||
return this.trigger('change');
|
||||
},
|
||||
@@ -77,6 +104,7 @@ module.exports = {
|
||||
return this.$element.select('input:checked').get('value');
|
||||
},
|
||||
set: function(value) {
|
||||
if (this.get() === value.toString(10)) { return this; }
|
||||
this.$element
|
||||
.select('input[value="' + value.replace('"', '\\"') + '"]')
|
||||
.set('checked', true);
|
||||
@@ -97,8 +125,12 @@ module.exports = {
|
||||
},
|
||||
set: function(values) {
|
||||
var self = this;
|
||||
self.$element.select('input').set('checked', false);
|
||||
values = values || [];
|
||||
|
||||
if (_.equals(this.get(), values)) { return this; }
|
||||
|
||||
self.$element.select('input').set('checked', false);
|
||||
|
||||
values.map(function(value) {
|
||||
self.$element
|
||||
.select('input[value="' + value.replace('"', '\\"') + '"]')
|
||||
@@ -120,8 +152,10 @@ module.exports = {
|
||||
case 'number': value = value.toString(16); break;
|
||||
case 'string': value = value.replace(/^#|^0x/, ''); break;
|
||||
}
|
||||
value = value || '000000';
|
||||
|
||||
this.$manipulatorTarget.set('value', value || '000000');
|
||||
if (this.get() === parseInt(value, 16)) { return this; }
|
||||
this.$manipulatorTarget.set('value', value);
|
||||
return this.trigger('change');
|
||||
},
|
||||
disable: disable,
|
||||
|
||||
@@ -17,3 +17,39 @@ module.exports.updateProperties = function(obj, descriptor) {
|
||||
Object.defineProperty(obj, prop, descriptor);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts the val into a type compatible with Pebble.sendAppMessage().
|
||||
* - Strings will be returned without modification
|
||||
* - Numbers will be returned without modification
|
||||
* - Booleans will be converted to a 0 or 1
|
||||
* - Arrays that contain strings will be split with a zero.
|
||||
* eg: ['one', 'two'] becomes ['one', 0, 'two', 0]
|
||||
* - Arrays that contain numbers will be returned without modification
|
||||
* eg: [1, 2] becomes [1, 2]
|
||||
* - Arrays that contain booleans will be converted to a 0 or 1
|
||||
* eg: [true, false] becomes [1, 0]
|
||||
* - Arrays must be single dimensional
|
||||
* @param {number|string|boolean|Array} val
|
||||
* @returns {number|string|Array}
|
||||
*/
|
||||
module.exports.prepareForAppMessage = function(val) {
|
||||
var result;
|
||||
|
||||
if (typeof val === 'boolean') {
|
||||
result = val ? 1 : 0;
|
||||
} else if (Array.isArray(val)) {
|
||||
result = [];
|
||||
val.forEach(function(item) {
|
||||
var itemConverted = module.exports.prepareForAppMessage(item);
|
||||
result.push(itemConverted);
|
||||
if (typeof itemConverted === 'string') {
|
||||
result.push(0);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
result = val;
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
Vendored
+53
-3
@@ -1,8 +1,8 @@
|
||||
// minified.js config start -- use this comment to re-create a configuration in the Builder
|
||||
// - Only sections add, always, amdsupport, copyobj, dollardollar,
|
||||
// - each, eachobj, error, extend, find, format, formathtml, get, ht, html,
|
||||
// - isobject, off, on, ready, request, select, set, template, trigger, underscore,
|
||||
// - wait.
|
||||
// - each, eachobj, equals, error, extend, find, format, formathtml, get, ht,
|
||||
// - html, isobject, off, on, ready, request, select, set, template, trigger,
|
||||
// - underscore, wait.
|
||||
|
||||
|
||||
// WARNING! This file is autogenerated from minified-master.js and others.
|
||||
@@ -1550,6 +1550,53 @@ define('minified', function() {
|
||||
*/
|
||||
'each': listBind(each),
|
||||
|
||||
/*$
|
||||
* @id equals
|
||||
* @group LIST
|
||||
* @requires
|
||||
* @configurable default
|
||||
* @name .equals()
|
||||
* @altname _.equals()
|
||||
* @syntax list.equals(otherObject)
|
||||
* @syntax _.equals(thisObject, otherObject)
|
||||
* @module UTIL
|
||||
* Checks whether two values, lists or objects are equal in a deep comparison.
|
||||
*
|
||||
* First <var>equals()</var> checks whether it got a function as parameter.
|
||||
* If yes, it will be invoked without arguments and <var>equals()</var> calls itself recursively with the function's result.
|
||||
*
|
||||
* Once both values are no functions anymore, the values will be evaluated, If the first value is...
|
||||
* <ul><li>...<var>null</var> or <var>undefined</var>, they are only equal if the other one is also either <var>null</var> or <var>undefined</var>.</li>
|
||||
* <li>...a value as defined by ##_.isValue(), but not a Date, they are equal if the other value is the same type and is equal according to the '==' operator.</li>
|
||||
* <li>...a Date, they are equal if the other value is a Date representing the same time.</li>
|
||||
* <li>...a list or array, they are equal if the other value is also either a list or an array, has the same number of items and all items equal the items of the other
|
||||
* list at the same position. The equality of list items is determined recursively using the same rules, so you can also nest lists.</li>
|
||||
* <li>...a function, it will be invoked without arguments and its return value is evaluated using these rules as if the value has been passed. </li>
|
||||
* <li>...any other object, they are equal if they contain exactly the same keys (as defined by ##_.eachObj()) and all values are equal as determined using these rules
|
||||
* recursively.</li>
|
||||
* </ul>
|
||||
*
|
||||
* Please note that, according to the rules, a ##list#Minified list## is equal to an array, as long as their content is equal. <var>equals</var> does not
|
||||
* differentiate between <var>null</var> and <var>undefined</var>.
|
||||
*
|
||||
* <var>equals</var> is commutative. If you swap the parameters, the result is the same as long as no functions are involved.
|
||||
*
|
||||
* @example Compare a list and an array:
|
||||
* <pre>
|
||||
* _.equals([1, 2, 3], _(1, 2, 3)); // returns true
|
||||
* </pre>
|
||||
*
|
||||
* @example Same result, but with a list method:
|
||||
* <pre>
|
||||
* _(1, 2, 3).equals([1, 2, 3]); // returns true
|
||||
* </pre>
|
||||
*
|
||||
* @param thisObject The first reference to evaluate.
|
||||
* @param otherObject The second reference to evaluate.
|
||||
* @return true if both references are equal. False otherwise.
|
||||
*/
|
||||
'equals': listBind(equals),
|
||||
|
||||
/*$
|
||||
* @id find
|
||||
* @group LIST
|
||||
@@ -2626,6 +2673,9 @@ define('minified', function() {
|
||||
// @condblock find
|
||||
'find': find,
|
||||
// @condend
|
||||
// @condblock equals
|
||||
'equals': equals,
|
||||
// @condend
|
||||
|
||||
/*$
|
||||
* @id copyobj
|
||||
|
||||
@@ -183,6 +183,7 @@ label {
|
||||
padding: 0 $item-spacing-h $item-spacing-v ;
|
||||
@include font-size(0.9);
|
||||
color: $color-gray-9;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.inputs {
|
||||
|
||||
@@ -34,7 +34,7 @@ $color-gray-9: #a4a4a4 ;
|
||||
$color-gray-10: #ececec;
|
||||
$color-gray-11: #f2f2f2;
|
||||
|
||||
$button-padding: 0.7rem;
|
||||
$button-padding-ios: 0.6rem;
|
||||
$button-padding: 0.6rem;
|
||||
$button-padding-ios: 0.5rem;
|
||||
|
||||
$box-shadow-small-components: $color-gray-1 0 0.1rem 0.1rem;
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
.component-button {
|
||||
text-align: center;
|
||||
|
||||
.section & {
|
||||
padding-bottom: 0;
|
||||
}
|
||||
|
||||
.description {
|
||||
padding-left: 0;
|
||||
padding-right: 0;
|
||||
}
|
||||
}
|
||||
@@ -3,52 +3,30 @@
|
||||
button,
|
||||
.button {
|
||||
@include font-pfdin(medium);
|
||||
@include font-size(1);
|
||||
text-transform: uppercase;
|
||||
background-color: $color-gray-4;
|
||||
background-color: $color-gray-7;
|
||||
border-radius: $border-radius;
|
||||
font-size: 1rem;
|
||||
line-height: 1;
|
||||
border: none;
|
||||
display: inline-block;
|
||||
|
||||
color: $color-white;
|
||||
min-width: 12rem;
|
||||
text-align: center;
|
||||
margin: 0 auto;
|
||||
-webkit-tap-highlight-color: rgba(0,0,0,0);
|
||||
|
||||
margin: 0 auto $item-spacing-v;
|
||||
padding: $button-padding;
|
||||
|
||||
@include tap-highlight($color-gray-8);
|
||||
|
||||
.platform-ios & {
|
||||
padding: $button-padding-ios;
|
||||
}
|
||||
|
||||
&:disabled {
|
||||
background-color: $color-gray-3;
|
||||
color: $color-gray-8;
|
||||
}
|
||||
|
||||
&:not(:disabled):active {
|
||||
background-color: $color-gray-8;
|
||||
}
|
||||
|
||||
&.orange, &[type="submit"] {
|
||||
&.primary, &[type="submit"] {
|
||||
background-color: $color-orange;
|
||||
|
||||
&:disabled {
|
||||
background-color: $color-orange-dark;
|
||||
color: $color-gray-3;
|
||||
}
|
||||
|
||||
&:not(:disabled):active {
|
||||
background-color: $color-red;
|
||||
}
|
||||
@include tap-highlight($color-red);
|
||||
}
|
||||
|
||||
&.light-grey {
|
||||
background-color: $color-gray-5;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
a.button {
|
||||
|
||||
Executable
+11
@@ -0,0 +1,11 @@
|
||||
<div class="component component-button">
|
||||
<button
|
||||
type="button"
|
||||
data-manipulator-target
|
||||
class="{{primary ? 'primary' : ''}}"
|
||||
{{each key: attributes}}{{key}}="{{this}}"{{/each}}
|
||||
></button>
|
||||
{{if description}}
|
||||
<div class="description">{{{description}}}</div>
|
||||
{{/if}}
|
||||
</div>
|
||||
@@ -3,7 +3,7 @@
|
||||
var assert = require('chai').assert;
|
||||
var fixture = require('../../fixture');
|
||||
|
||||
describe('component - color', function() {
|
||||
describe('component - select', function() {
|
||||
it('sets the value display to the correct value on change', function() {
|
||||
var clayConfig = fixture.clayConfig([
|
||||
{
|
||||
|
||||
@@ -108,7 +108,12 @@ describe('ClayConfig', function() {
|
||||
{label: 'label-1', value: 'val-1'},
|
||||
{label: 'label-2', value: 'val-2'}
|
||||
]},
|
||||
{type: 'toggle', appKey: 'test3'}
|
||||
{type: 'toggle', appKey: 'test3'},
|
||||
{type: 'checkboxgroup', appKey: 'test4', options: [
|
||||
{label: 'label-1', value: 'cb-1'},
|
||||
{label: 'label-2', value: 'cb-2'},
|
||||
{label: 'label-2', value: 'cb-3'}
|
||||
]}
|
||||
],
|
||||
true,
|
||||
true,
|
||||
@@ -120,16 +125,19 @@ describe('ClayConfig', function() {
|
||||
assert.deepEqual(clayConfig.getSettings(), {
|
||||
test1: 'default val',
|
||||
test2: 'val-2',
|
||||
test3: 0
|
||||
test3: 0,
|
||||
test4: []
|
||||
});
|
||||
|
||||
clayConfig.getItemByAppKey('test1').set('val-1');
|
||||
clayConfig.getItemByAppKey('test3').set(true);
|
||||
clayConfig.getItemByAppKey('test4').set(['cb-1', 'cb-3']);
|
||||
|
||||
assert.deepEqual(clayConfig.getSettings(), {
|
||||
test1: 'val-1',
|
||||
test2: 'val-2',
|
||||
test3: 1
|
||||
test3: 1,
|
||||
test4: ['cb-1', 0, 'cb-3', 0]
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -19,9 +19,10 @@ describe('manipulators', function() {
|
||||
it('sets: "' + value + '" and gets: "' + expected + '" then triggers "change"',
|
||||
function() {
|
||||
var handlerSpy = sinon.spy();
|
||||
var clayItem = fixture.clayItem(itemType);
|
||||
var clayItem = fixture.clayConfig([itemType]).getAllItems()[0];
|
||||
clayItem.on('change', handlerSpy);
|
||||
|
||||
clayItem.set(value);
|
||||
clayItem.set(value);
|
||||
assert.deepEqual(clayItem.get(), expected);
|
||||
assert.strictEqual(handlerSpy.callCount, 1, 'handler not called once');
|
||||
@@ -45,6 +46,7 @@ describe('manipulators', function() {
|
||||
false
|
||||
);
|
||||
clayItem.disable();
|
||||
clayItem.disable();
|
||||
assert.strictEqual(
|
||||
clayItem.$element[0].classList.contains('disabled'),
|
||||
true
|
||||
@@ -73,6 +75,7 @@ describe('manipulators', function() {
|
||||
true
|
||||
);
|
||||
clayItem.enable();
|
||||
clayItem.enable();
|
||||
assert.strictEqual(
|
||||
clayItem.$element[0].classList.contains('disabled'),
|
||||
false
|
||||
@@ -100,6 +103,7 @@ describe('manipulators', function() {
|
||||
false
|
||||
);
|
||||
clayItem.hide();
|
||||
clayItem.hide();
|
||||
assert.strictEqual(
|
||||
clayItem.$element[0].classList.contains('hide'),
|
||||
true
|
||||
@@ -127,6 +131,7 @@ describe('manipulators', function() {
|
||||
true
|
||||
);
|
||||
clayItem.show();
|
||||
clayItem.show();
|
||||
assert.strictEqual(
|
||||
clayItem.$element[0].classList.contains('hide'),
|
||||
false
|
||||
@@ -139,12 +144,23 @@ describe('manipulators', function() {
|
||||
|
||||
describe('html', function() {
|
||||
testSetGet('text', 'test123');
|
||||
testSetGet('button', '<span>some HTML</span>');
|
||||
testShow('text');
|
||||
testHide('text');
|
||||
});
|
||||
|
||||
describe('button', function() {
|
||||
testSetGet('button', 'test123');
|
||||
testSetGet('button', '<span>some HTML</span>');
|
||||
testDisable('button');
|
||||
testEnable('button');
|
||||
testShow('button');
|
||||
testHide('button');
|
||||
});
|
||||
|
||||
describe('val', function() {
|
||||
testSetGet('input', 'test321');
|
||||
testSetGet('input', 1234, '1234');
|
||||
testDisable('input');
|
||||
testEnable('input');
|
||||
testShow('text');
|
||||
@@ -152,10 +168,10 @@ describe('manipulators', function() {
|
||||
});
|
||||
|
||||
describe('checked', function() {
|
||||
testSetGet('toggle', true, 1);
|
||||
testSetGet('toggle', 1);
|
||||
testSetGet('toggle', false, 0);
|
||||
testSetGet('toggle', 0);
|
||||
testSetGet({type: 'toggle', defaultValue: false}, 1, true);
|
||||
testSetGet({type: 'toggle', defaultValue: false}, true);
|
||||
testSetGet({type: 'toggle', defaultValue: true}, 0, false);
|
||||
testSetGet({type: 'toggle', defaultValue: true}, false);
|
||||
testDisable('toggle');
|
||||
testEnable('toggle');
|
||||
testShow('toggle');
|
||||
@@ -185,6 +201,7 @@ describe('manipulators', function() {
|
||||
var item = {
|
||||
type: 'checkboxgroup',
|
||||
clayId: 1,
|
||||
defaultValue: ['two'],
|
||||
options: [
|
||||
{ label: '1', value: 'one' },
|
||||
{ label: '2', value: 'two' },
|
||||
@@ -207,9 +224,9 @@ describe('manipulators', function() {
|
||||
testSetGet('color', '0xFF0000', 0xff0000);
|
||||
testSetGet('color', '#ff0000', 0xff0000);
|
||||
testSetGet('color', 0xff0000, 0xff0000);
|
||||
testSetGet('color', '', 0x000000);
|
||||
testSetGet('color', false, 0x000000);
|
||||
testSetGet('color', undefined, 0x000000);
|
||||
testSetGet({type: 'color', defaultValue: 0x00ff00}, '', 0x000000);
|
||||
testSetGet({type: 'color', defaultValue: 0x00ff00}, false, 0x000000);
|
||||
testSetGet({type: 'color', defaultValue: 0x00ff00}, undefined, 0x000000);
|
||||
testDisable('color');
|
||||
testEnable('color');
|
||||
testShow('color');
|
||||
|
||||
@@ -26,4 +26,34 @@ describe('Utils', function() {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.prepareForAppMessage', function() {
|
||||
it('converts an array correctly when array contains strings', function() {
|
||||
assert.deepEqual(
|
||||
utils.prepareForAppMessage(['one', 'two']),
|
||||
['one', 0, 'two', 0]
|
||||
);
|
||||
});
|
||||
|
||||
it('converts an array correctly when array contains numbers', function() {
|
||||
assert.deepEqual(utils.prepareForAppMessage([1, 2, 3]), [1, 2, 3]);
|
||||
});
|
||||
|
||||
it('converts an array correctly when array contains booleans', function() {
|
||||
assert.deepEqual(utils.prepareForAppMessage([true, false, true]), [1, 0, 1]);
|
||||
});
|
||||
|
||||
it('converts booleans to ints', function() {
|
||||
assert.strictEqual(utils.prepareForAppMessage(false), 0);
|
||||
assert.strictEqual(utils.prepareForAppMessage(true), 1);
|
||||
});
|
||||
|
||||
it('leaves strings alone', function() {
|
||||
assert.strictEqual(utils.prepareForAppMessage('test'), 'test');
|
||||
});
|
||||
|
||||
it('leaves numbers alone', function() {
|
||||
assert.strictEqual(utils.prepareForAppMessage(123), 123);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user