mirror of
https://github.com/pebble-dev/clay.git
synced 2026-08-29 13:26:59 -04:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f62f960433 | ||
|
|
8fb67ce08d | ||
|
|
65b952d7f8 | ||
|
|
6c2a335b7c | ||
|
|
f717661eea | ||
|
|
35bdeb7519 | ||
|
|
93b927db63 | ||
|
|
9afdd2adb9 | ||
|
|
5fe87a04de | ||
|
|
7e2b75dd58 | ||
|
|
32e192e938 | ||
|
|
1af2b39db1 | ||
|
|
782eaf82f3 | ||
|
|
41d38e04a7 | ||
|
|
1611599a25 | ||
|
|
842cbc9e84 | ||
|
|
238d0e6a6c | ||
|
|
c5af3baaeb | ||
|
|
2030aa1af7 | ||
|
|
4445cb98cf | ||
|
|
12c420d861 | ||
|
|
dc33aa0b5d | ||
|
|
f200af909b | ||
|
|
6f3873ad6b | ||
|
|
70bb2e9d07 | ||
|
|
a9aaf0b940 | ||
|
|
80eb1506d8 | ||
|
|
68723d36f7 | ||
|
|
c937ee735e | ||
|
|
b553094742 | ||
|
|
f31ffed558 | ||
|
|
3f71f97b8b | ||
|
|
1a6308f621 | ||
|
|
7045c59a72 | ||
|
|
4ffb1018f7 | ||
|
|
e78c09f5be | ||
|
|
d8e73f2674 | ||
|
|
0358e820e6 | ||
|
|
1d821f61c3 | ||
|
|
e2ffa42595 | ||
|
|
3a2dcb187e | ||
|
|
08e3a21429 | ||
|
|
42a613caf4 | ||
|
|
4ff38eb0ba | ||
|
|
b466c48487 | ||
|
|
517d4f84ff | ||
|
|
e04a6c9f87 | ||
|
|
1f0867985d | ||
|
|
d0e5988024 | ||
|
|
d007d48afc | ||
|
|
07a847457f | ||
|
|
9347c9f3d2 | ||
|
|
4ee5a7361c | ||
|
|
dad8b2a025 | ||
|
|
d52f6d4aa2 | ||
|
|
a94eae9a16 | ||
|
|
317f6fd4e8 | ||
|
|
b19b07c47d | ||
|
|
0a2ddab597 | ||
|
|
005ac939b1 | ||
|
|
12b0ae9bd6 | ||
|
|
6f92c0d267 | ||
|
|
756cdc0d9e | ||
|
|
783bc84779 | ||
|
|
e621bbf0bd | ||
|
|
43c5c3cc9f | ||
|
|
d8738e06b2 | ||
|
|
67449ec34e | ||
|
|
5c63b00eda | ||
|
|
79eef99731 | ||
|
|
e5496c62d6 | ||
|
|
b1a6f184ba | ||
|
|
878fea0340 | ||
|
|
1142d1adee | ||
|
|
0873f5eba2 | ||
|
|
0faa585d5f | ||
|
|
3b7c4cda7c | ||
|
|
3839a47f5c | ||
|
|
85503d2846 | ||
|
|
d6ae6faef4 | ||
|
|
2c2f003e15 | ||
|
|
2bd9623ab1 | ||
|
|
9f3c78de17 | ||
|
|
1af5828b18 | ||
|
|
99dc081b69 | ||
|
|
37c64a6e05 | ||
|
|
34d83de59e | ||
|
|
e80a1630f1 | ||
|
|
d0af7b0fac | ||
|
|
1af4dfd8ef | ||
|
|
42fc8f1da4 | ||
|
|
d469d404ab | ||
|
|
ad807020ca | ||
|
|
bd3e4a55c8 | ||
|
|
f50f569c98 | ||
|
|
be17456f8b | ||
|
|
49f92de102 | ||
|
|
c4f6b17a58 | ||
|
|
061bb34c91 | ||
|
|
20e7460c2f | ||
|
|
6e5c2f5847 | ||
|
|
71ea309346 | ||
|
|
d63c6c832d | ||
|
|
de00ac1fd6 | ||
|
|
271a0d1cfd | ||
|
|
d6659db3ac | ||
|
|
264866ce26 | ||
|
|
069d4a80da | ||
|
|
c99ad44b5c | ||
|
|
75c846a8ba | ||
|
|
a1df49623d | ||
|
|
08e41036da | ||
|
|
663f91e9bd |
@@ -9,7 +9,7 @@
|
||||
},
|
||||
"rules": {
|
||||
"new-cap": [0],
|
||||
"max-params": [2, 4],
|
||||
"max-params": [2, 5],
|
||||
"require-jsdoc": [2, {
|
||||
"require": {
|
||||
"FunctionDeclaration": true,
|
||||
|
||||
@@ -20,11 +20,13 @@ Clay will eventually be built into the Pebble SDK. However, while it is still in
|
||||
var clayConfig = require('config.json');
|
||||
var clay = new Clay(clayConfig);
|
||||
```
|
||||
6. Next is the fun part - creating your config page. Edit your `config.js` file to build a layout of elements as described in the sections below.
|
||||
6. Add `configurable` to the `capabilities` array in your `appinfo.json`.
|
||||
7. Next is the fun part - creating your config page. Edit your `config.js` file to build a layout of elements as described in the sections below.
|
||||
|
||||
# Getting Started (CloudPebble)
|
||||
|
||||
Clay will eventually be built into CloudPebble. However while it is still in beta, you will need to follow some steps
|
||||
Clay will eventually be built into CloudPebble. However while it is still in beta, you will need to follow some steps.
|
||||
NOTE these are similar to using the SDK but instead of a data file called config.json, a javascript file config.js is required.
|
||||
|
||||
1. Create a new JavaScript file called `clay.js`.
|
||||
2. Copy the contents from the **clay.js** distribution file found in the [latest release](https://github.com/pebble/clay/releases/latest) into your newly created `clay.js` file.
|
||||
@@ -52,6 +54,8 @@ Your root element **must** be an array. This represents the entire page. Inside
|
||||
|
||||
#### Example
|
||||
|
||||
NOTE for config.js (rather than config.json) a leading `module.exports =` is required.
|
||||
|
||||
```javascript
|
||||
[
|
||||
{
|
||||
@@ -79,6 +83,7 @@ Sections help divide up the page into logical groups of items. It is recommended
|
||||
|----------|------|-------------|
|
||||
| type | string | Set to `section`. |
|
||||
| items | array | Array of items to include in this section. |
|
||||
| capabilities | array | Array of features that the connected watch must have for this section to be present |
|
||||
|
||||
##### Example
|
||||
|
||||
@@ -108,7 +113,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.
|
||||
|
||||
@@ -121,6 +126,7 @@ Headings can be used in anywhere and can have their size adjusted to suit the co
|
||||
| appKey | string (unique) | The AppMessage key matching the `appKey` item defined in your `appinfo.json`. Set this to a unique string to allow this item to be looked up using `Clay.getItemsByAppKey()` in your custom function. You must set this if you wish for the value of this item to be persisted after the user closes the config page. |
|
||||
| defaultValue | string/HTML | The heading's text. |
|
||||
| size | int | Defaults to `4`. An integer from 1 to 6 where 1 is the largest size and 6 is the smallest. (represents HTML `<h1>`, `<h2>`, `<h3>`, etc). |
|
||||
| capabilities | array | Array of features that the connected watch must have for this item to be present |
|
||||
|
||||
|
||||
##### Example
|
||||
@@ -138,7 +144,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`
|
||||
|
||||
@@ -150,6 +156,7 @@ Text is used to provide descriptions of sections or to explain complex parts of
|
||||
| id | string (unique) | Set this to a unique string to allow this item to be looked up using `Clay.getItemsById()` in your [custom function](#custom-function). |
|
||||
| appKey | string (unique) | The AppMessage key matching the `appKey` item defined in your `appinfo.json`. Set this to a unique string to allow this item to be looked up using `Clay.getItemsByAppKey()` in your custom function. You must set this if you wish for the value of this item to be persisted after the user closes the config page. |
|
||||
| defaultValue | string/HTML | The content of the text element. |
|
||||
| capabilities | array | Array of features that the connected watch must have for this item to be present |
|
||||
|
||||
|
||||
##### Example
|
||||
@@ -165,7 +172,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.
|
||||
|
||||
@@ -180,6 +187,7 @@ Standard text input field.
|
||||
| defaultValue | string | The default value of the input field. |
|
||||
| description | string | Optional sub-text to include below the component |
|
||||
| attributes | object | An object containing HTML attributes to set on the input field. You can add basic HTML5 validation this way by setting attributes such as `required` or `type`. |
|
||||
| capabilities | array | Array of features that the connected watch must have for this item to be present |
|
||||
|
||||
|
||||
##### Example
|
||||
@@ -203,7 +211,7 @@ Standard text input field.
|
||||
|
||||
#### Toggle
|
||||
|
||||
**Manipulator:** `checked`
|
||||
**Manipulator:** [`checked`](#checked)
|
||||
|
||||
Switch for a single item.
|
||||
|
||||
@@ -218,6 +226,7 @@ Switch for a single item.
|
||||
| defaultValue | int\|boolean | The default value of the toggle. Defaults to `false` if not specified. |
|
||||
| description | string | Optional sub-text to include below the component |
|
||||
| attributes | object | An object containing HTML attributes to set on the input field. You can add basic HTML5 validation this way by setting attribute such as `required`. |
|
||||
| capabilities | array | Array of features that the connected watch must have for this item to be present |
|
||||
|
||||
|
||||
##### Example
|
||||
@@ -238,7 +247,7 @@ Switch for a single item.
|
||||
|
||||
#### Select
|
||||
|
||||
**Manipulator:** `val`
|
||||
**Manipulator:** [`val`](#val)
|
||||
|
||||
A dropdown menu containing multiple options.
|
||||
|
||||
@@ -254,6 +263,7 @@ A dropdown menu containing multiple options.
|
||||
| description | string | Optional sub-text to include below the component |
|
||||
| attributes | object | An object containing HTML attributes to set on the input field. You can add basic HTML5 validation this way by setting attribute such as `required`. |
|
||||
| options | array of objects | The options you want to appear in the dropdown menu. Each option is an object with a `label` and `value` property. |
|
||||
| capabilities | array | Array of features that the connected watch must have for this item to be present |
|
||||
|
||||
##### Example
|
||||
|
||||
@@ -287,13 +297,72 @@ A dropdown menu containing multiple options.
|
||||
}
|
||||
```
|
||||
|
||||
If you wish to use optgroups, then use the following format:
|
||||
|
||||
```javascript
|
||||
{
|
||||
"type": "select",
|
||||
"appKey": "flavor",
|
||||
"defaultValue": "grape",
|
||||
"label": "Favorite Flavor",
|
||||
"options": [
|
||||
{
|
||||
"label": "",
|
||||
"value": ""
|
||||
},
|
||||
{
|
||||
"label": "Fruits",
|
||||
"value": [
|
||||
{
|
||||
"label": "Berry",
|
||||
"value": "berry"
|
||||
},
|
||||
{
|
||||
"label": "Grape",
|
||||
"value": "grape"
|
||||
},
|
||||
{
|
||||
"label": "Banana",
|
||||
"value": "banana"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"label": "Candy",
|
||||
"value": [
|
||||
{
|
||||
"label": "Chocolate",
|
||||
"value": "chocolate"
|
||||
},
|
||||
{
|
||||
"label": "Cream",
|
||||
"value": "cream"
|
||||
},
|
||||
{
|
||||
"label": "Lollipop",
|
||||
"value": "lollipop"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"attributes": {
|
||||
"required": "required"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
#### Color
|
||||
#### Color Picker
|
||||
|
||||
**Manipulator:** `color`
|
||||
**Manipulator:** [`color`](#color)
|
||||
|
||||
A color picker containing the 64 supported colors on Basalt and Chalk.
|
||||
A color picker that allows users to choose a color from the ones that are compatible with their Pebble smartwatch.
|
||||
The color picker will automatically show a different layout depending on the watch connected:
|
||||
|
||||
- Aplite (Firmware 2.x) - Black and white
|
||||
- Aplite (Firmware 3.x) - Black and white. Will also include gray (`#AAAAAA`) if `allowGray` is set to `true`
|
||||
- Basalt/chalk - The 64 colors compatible with color Pebble smartwatches.
|
||||
|
||||
##### Properties
|
||||
|
||||
@@ -303,9 +372,12 @@ A color picker containing the 64 supported colors on Basalt and Chalk.
|
||||
| id | string (unique) | Set this to a unique string to allow this item to be looked up using `Clay.getItemsById()` in your [custom function](#custom-function). |
|
||||
| appKey | string (unique) | The AppMessage key matching the `appKey` item defined in your `appinfo.json`. Set this to a unique string to allow this item to be looked up using `Clay.getItemsByAppKey()` in your custom function. You must set this if you wish for the value of this item to be persisted after the user closes the config page. |
|
||||
| label | string | The label that should appear next to this item. |
|
||||
| defaultValue | string OR int | The default color. Always use the uncorrected value even if `sunlight` is true. The component will do the conversion internally. |
|
||||
| defaultValue | string OR int | The default color. One of the [64 colors](https://developer.pebble.com/guides/tools-and-resources/color-picker/) compatible with Pebble smartwatches. Always use the uncorrected value even if `sunlight` is true. The component will do the conversion internally. |
|
||||
| description | string | Optional sub-text to include below the component |
|
||||
| sunlight | boolean | Use the color-corrected sunlight color palette if `true`, else the uncorrected version. Defaults to `true` if not specified. |
|
||||
| layout | string OR array | Optional. Use a custom layout for the color picker. Defaults to automatically choosing the most appropriate layout for the connected watch. The layout is represented by a two dimensional array. Use `false` to insert blank spaces. You may also use one of the preset layouts by setting `layout` to: `"COLOR"`, `"GRAY"` or `"BLACK_WHITE"` |
|
||||
| allowGray | boolean | Optional. Set this to `true` to include gray (`#AAAAAA`) in the color picker for aplite running on firmware 3 and above. This is optional because only a subset of the drawing operations support gray on aplite. Defaults to `false` |
|
||||
| capabilities | array | Array of features that the connected watch must have for this item to be present |
|
||||
|
||||
##### Example
|
||||
|
||||
@@ -313,17 +385,48 @@ A color picker containing the 64 supported colors on Basalt and Chalk.
|
||||
{
|
||||
"type": "color",
|
||||
"appKey": "background",
|
||||
"defaultValue": "FF0000",
|
||||
"defaultValue": "ff0000",
|
||||
"label": "Background Color",
|
||||
"sunlight": true
|
||||
"sunlight": true,
|
||||
"layout": [
|
||||
[false, "00aaff", false],
|
||||
["0055ff", "0000ff", "0000aa"],
|
||||
[false, "5555ff", false]
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
##### Example
|
||||
|
||||
```javascript
|
||||
{
|
||||
"type": "color",
|
||||
"appKey": "background",
|
||||
"defaultValue": "ffffff",
|
||||
"label": "Background Color",
|
||||
"sunlight": false,
|
||||
"layout": "BLACK_WHITE"
|
||||
}
|
||||
```
|
||||
|
||||
##### Example
|
||||
|
||||
```javascript
|
||||
{
|
||||
"type": "color",
|
||||
"appKey": "background",
|
||||
"defaultValue": "aaaaaa",
|
||||
"label": "Background Color",
|
||||
"sunlight": false,
|
||||
"allowGray": true
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
#### RadioGroup
|
||||
#### Radio Group
|
||||
|
||||
**Manipulator:** `radiogroup`
|
||||
**Manipulator:** [`radiogroup`](#radiogroup)
|
||||
|
||||
A list of options allowing the user can only choose one option to submit.
|
||||
|
||||
@@ -339,6 +442,7 @@ A list of options allowing the user can only choose one option to submit.
|
||||
| description | string | Optional sub-text to include below the component |
|
||||
| attributes | object | An object containing HTML attributes to set on the input field. You can add basic HTML5 validation this way by setting attribute such as `required`. |
|
||||
| options | array of objects | The options you want to appear in the radio group. Each option is an object with a `label` and `value` property. |
|
||||
| capabilities | array | Array of features that the connected watch must have for this item to be present |
|
||||
|
||||
##### Example
|
||||
|
||||
@@ -366,9 +470,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.
|
||||
|
||||
@@ -384,6 +488,7 @@ A list of options where a user may choose more than one option to submit.
|
||||
| description | string | Optional sub-text to include below the component |
|
||||
| attributes | object | An object containing HTML attributes to set on the input field. You can add basic HTML5 validation this way by setting attribute such as `required`. |
|
||||
| options | array of objects | The options you want to appear in the checkbox group. Each option is an object with a `label` and `value` property. |
|
||||
| capabilities | array | Array of features that the connected watch must have for this item to be present |
|
||||
|
||||
##### Example
|
||||
|
||||
@@ -412,9 +517,80 @@ 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 |
|
||||
| capabilities | array | Array of features that the connected watch must have for this item to be present |
|
||||
|
||||
##### Example
|
||||
|
||||
```javascript
|
||||
{
|
||||
"type": "button",
|
||||
"primary": true,
|
||||
"defaultValue": "Send"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Range Slider
|
||||
|
||||
**Manipulator:** [`slider`](#slider)
|
||||
|
||||
The range slider is used to allow users to select numbers between two values.
|
||||
|
||||
**NOTE** If you set the `step` property to anything less than `1`,
|
||||
it will multiply the final value sent to the watch by 10 to the power of the number of decimal places in the value of `step`.
|
||||
Eg: If you set the `step` to `0.25` and the slider has value of `34.5`, the watch will receive `3450`.
|
||||
The reason why this is necessary, is because you can not send floats to the watch via `Pebble.sendAppMessage()`.
|
||||
This allows your users to still be able to input values that have decimals,
|
||||
you must just remember to divide the received value on the watch accordingly.
|
||||
|
||||
##### Properties
|
||||
|
||||
| Property | Type | Description |
|
||||
|----------|------|-------------|
|
||||
| type | string | Set to `slider`. |
|
||||
| defaultValue | number | The value of the slider. |
|
||||
| label | string | The label that should appear next to this item. |
|
||||
| min | number | The minimum allowed value of the slider. Defaults to `100` |
|
||||
| max | number | The maximum allowed value of the slider. Defaults to `0` |
|
||||
| step | number | The multiple of the values allowed to be set on the slider. The slider will snap to these values. This value also determines the precision used when the value is sent to the watch. Defaults to 1 |
|
||||
| attributes | object | An object containing HTML attributes to set on the input field. |
|
||||
| description | string | Optional sub-text to include below the component |
|
||||
| capabilities | array | Array of features that the connected watch must have for this item to be present |
|
||||
|
||||
##### Example
|
||||
|
||||
```javascript
|
||||
{
|
||||
"type": "slider",
|
||||
"appKey": "slider",
|
||||
"defaultValue": 15,
|
||||
"label": "Slider",
|
||||
"description": "This is the description for the slider",
|
||||
"min": 10,
|
||||
"max": 20,
|
||||
"step": 0.25
|
||||
},
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 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.
|
||||
|
||||
@@ -425,6 +601,7 @@ The submit button for the page. You **MUST** include this component somewhere in
|
||||
| type | string | Set to `submit`. |
|
||||
| defaultValue | string | The text displayed on the button. |
|
||||
| attributes | object | An object containing HTML attributes to set on the input field. |
|
||||
| capabilities | array | Array of features that the connected watch must have for this item to be present |
|
||||
|
||||
##### Example
|
||||
|
||||
@@ -439,21 +616,83 @@ The submit button for the page. You **MUST** include this component somewhere in
|
||||
|
||||
### Coming Soon
|
||||
|
||||
- Range Slider
|
||||
- Generic Button
|
||||
- Tabs
|
||||
- Footer
|
||||
- Dynamic + draggable list
|
||||
|
||||
---
|
||||
### Showing items for specific platforms and features
|
||||
|
||||
If you want particular items or sections to only be present in the config based on the
|
||||
connected watch's capabilities, you can include the "capabilities" property in the item.
|
||||
The "capabilities" property is an array of features that the connected watch must have
|
||||
in order for the item or section to be included in the page. Note: all capabilities in
|
||||
the array must be present for item/section to be included.
|
||||
|
||||
You can also prefix the capability with `NOT_` to negate the capability. Eg: `NOT_HEALTH`
|
||||
will only be included in the page if the device does **NOT** support health.
|
||||
|
||||
**Warning:** Items that do not satisfy the capabilities will not be included in the page
|
||||
at all. You will not be able to use methods like `clayConfig.getItemByAppKey()` to
|
||||
obtain a reference to them. However, this does mean that you will be able to have
|
||||
multiple items with the same `appKey`as long as they do not both satisfy the
|
||||
same conditions.
|
||||
|
||||
##### Examples
|
||||
|
||||
```javascript
|
||||
{
|
||||
"type": "text",
|
||||
"defaultValue": "This item will only be visible for watches that are rectangular and have a microphone"
|
||||
"capabilities": ["MICROPHONE", "RECT"],
|
||||
}
|
||||
```
|
||||
|
||||
```javascript
|
||||
{
|
||||
"type": "section",
|
||||
"capabilities": ["NOT_HEALTH"],
|
||||
"items": [
|
||||
{
|
||||
"type": "text",
|
||||
"defaultValue": "Only visible for watches that do not support health"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
Below is the full list of capabilities
|
||||
|
||||
| Capability | Description |
|
||||
|------------|-------------|
|
||||
| PLATFORM_APLITE | Running on Pebble/Pebble Steel.|
|
||||
| PLATFORM_BASALT | Running on Pebble Time/Pebble Time Steel. |
|
||||
| PLATFORM_CHALK | Running on Pebble Time Round. |
|
||||
| PLATFORM_DIORITE | Running on Pebble 2 |
|
||||
| PLATFORM_EMERY | Running on Time 2. |
|
||||
| BW | Running on hardware that supports only black and white. |
|
||||
| COLOR | Running on hardware that supports 64 colors. |
|
||||
| MICROPHONE | Running on hardware that includes a microphone. |
|
||||
| SMARTSTRAP | Running on hardware that includes a smartstrap connector. |
|
||||
| SMARTSTRAP_POWER | Running on hardware that includes a powered smartstrap connector. |
|
||||
| HEALTH | Running on hardware that supports Pebble Health and the HealthService API. |
|
||||
| RECT | Running on hardware with a rectangular display. |
|
||||
| ROUND | Running on hardware with a round display. |
|
||||
| DISPLAY_144x168 | Running on hardware with a 144x168 pixels display. |
|
||||
| DISPLAY_180x180_ROUND | Running on hardware with a 180x180 pixels round display. |
|
||||
| DISPLAY_200x228 | Running on hardware with a 200x228 pixels display. |
|
||||
|
||||
## Manipulators
|
||||
|
||||
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 +703,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 +730,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 [`Clay.getSettings()`](#methods) |
|
||||
| `.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,12 +763,23 @@ 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 [`Clay.getSettings()`](#methods) |
|
||||
| `.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 |
|
||||
| `.show()` | `ClayItem` | `show` | Shows the item |
|
||||
|
||||
#### slider
|
||||
|
||||
| Method | Returns | Event Fired | Description |
|
||||
|--------|---------|-------------| ------------|
|
||||
| `.set( [number] value)` | `ClayItem` | `change` | Sets the value of this item. |
|
||||
| `.get()` | `number` | | Gets the value of this item. |
|
||||
| `.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 |
|
||||
| `.show()` | `ClayItem` | `show` | Shows the item |
|
||||
|
||||
# Extending Clay
|
||||
|
||||
Clay is built to allow developers to add their own basic interactivity to the config page. This can be done in a number of ways:
|
||||
@@ -532,15 +793,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
|
||||
@@ -556,8 +825,75 @@ Pebble.addEventListener('webviewclosed', function(e) {
|
||||
});
|
||||
```
|
||||
|
||||
## Clay and Pebble.js
|
||||
|
||||
If you are using [Pebble.js](https://developer.pebble.com/docs/pebblejs/) and would like to use Clay, There are some extra steps to follow:
|
||||
|
||||
1. Remove all your `Settings.config` calls. Clay will handle the settings from now on.
|
||||
2. Use the example below to modify your `app.js`. Notice that `autoHandleEvents` is set to `false` in the Clay constructor.:
|
||||
|
||||
```javascript
|
||||
var Settings = require('settings');
|
||||
var Clay = require('./clay');
|
||||
var clayConfig = require('./config');
|
||||
var clay = new Clay(clayConfig, null, {autoHandleEvents: false});
|
||||
|
||||
Pebble.addEventListener('showConfiguration', function(e) {
|
||||
Pebble.openURL(clay.generateUrl());
|
||||
});
|
||||
|
||||
Pebble.addEventListener('webviewclosed', function(e) {
|
||||
if (e && !e.response) {
|
||||
return;
|
||||
}
|
||||
var dict = clay.getSettings(e.response);
|
||||
|
||||
// Save the Clay settings to the Settings module.
|
||||
Settings.option(dict);
|
||||
});
|
||||
```
|
||||
|
||||
### Caveats
|
||||
|
||||
Clay treats colors as numbers. You will need to convert these numbers to CSS colors before they can be used by Pebble.js. Use the function below to convert the colors.
|
||||
|
||||
```javascript
|
||||
function cssColor(color) {
|
||||
color = color.toString(16);
|
||||
while (color.length < 6) {
|
||||
color = '0' + color;
|
||||
}
|
||||
return '#' + color;
|
||||
}
|
||||
|
||||
// Example usage with default:
|
||||
cssColor(Settings.option('BACKGROUND_COLOR') || 0xff0000);
|
||||
```
|
||||
|
||||
### `Clay([Array] config, [function] customFn, [object] options)`
|
||||
|
||||
#### Constructor Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
|----------|-------|-------------|
|
||||
| `config` | Array | The config that will be used to generate the configuration page |
|
||||
| `customFn` | Function\|null | (Optional) The [custom function](#custom-function) to be injected into the generated configuration page. |
|
||||
| `options` | Object | (Optional) See below for properties |
|
||||
| `options.autoHandleEvents` | Boolean | (Optional) Defaults to `true`. If set to `false`, Clay will not [auto handle the `showConfiguration` and `webviewclosed` events](#handling-the-showconfiguration-and-webviewclosed-events-manually) |
|
||||
| `options.userData` | Any | (Optional) Any arbitrary data you want to pass to your config page. It will be available in your custom function as `this.meta.userData` |
|
||||
|
||||
#### Properties
|
||||
|
||||
| Property | Type | Description |
|
||||
|----------|------|-------------|
|
||||
| `.config` | Array | Copy of the config passed to the constructor and used for generating the page. |
|
||||
| `.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). |
|
||||
| `.meta.userData` | Any | A deep copy of the arbitrary data provided in the `options.userData`. Defaults to an empty object |
|
||||
|
||||
#### Methods
|
||||
|
||||
| Method | Returns |
|
||||
@@ -565,7 +901,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( [object] response, [boolean] convert=true)` <br> `response` - the response object provided to the "webviewclosed" event <br> `convert` - Pass `false` to not convert the settings to be compatible with `Pebble.sendAppMessage()` | `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 will 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`. Pass `false` as the second parameter to disable this behavior |
|
||||
|
||||
---
|
||||
|
||||
@@ -588,35 +924,45 @@ Make sure to always wait for the config page to be built before manipulating ite
|
||||
var Clay = require('./clay');
|
||||
var clayConfig = require('./config');
|
||||
var customClay = require('./custom-clay');
|
||||
var clay = new Clay(clayConfig, customClay);
|
||||
var userData = {token: 'abc123'}
|
||||
var clay = new Clay(clayConfig, customClay, {userData: userData});
|
||||
```
|
||||
|
||||
##### custom-clay.js
|
||||
|
||||
```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();
|
||||
}
|
||||
|
||||
// Set the value of an item based on the userData
|
||||
$.request('get', 'https://some.cool/api', {token: clayConfig.meta.userData.token})
|
||||
.then(function(result) {
|
||||
// Do something interesting with the data from the server
|
||||
})
|
||||
.error(function(status, statusText, responseText) {
|
||||
// Handle the error
|
||||
});
|
||||
});
|
||||
|
||||
};
|
||||
@@ -626,7 +972,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
|
||||
|
||||
@@ -634,11 +980,14 @@ This is the main way of talking to your generated config page.
|
||||
|----------|------|-------------|
|
||||
| `.EVENTS.BEFORE_BUILD` | String | Dispatched prior to building the page. |
|
||||
| `.EVENTS.AFTER_BUILD` | String | Dispatched after building the page. |
|
||||
| `.EVENTS.BEFORE_DESTROY` | String | Dispatched prior to destroying the page. |
|
||||
| `.EVENTS.AFTER_DESTROY` | String | Dispatched after destroying the page. |
|
||||
| `.config` | Array | Reference to the config passed to the constructor and used for generating the page. |
|
||||
| `.meta` | Object | Contains information about the current user and watch |
|
||||
| `.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). |
|
||||
| `.meta.userData` | Any | The data passed in the `options.userData` of the [Clay constructor.](#clayarray-config-function-customfn-object-options) |
|
||||
|
||||
|
||||
#### Methods
|
||||
@@ -649,8 +998,9 @@ This is the main way of talking to your generated config page.
|
||||
| `.getItemByAppKey( [string] appKey )` | `ConfigItem\|undefined` - a single `ConfigItem` that has the provided `appKey`, otherwise `undefined`. |
|
||||
| `.getItemById( [string] id )` | `ConfigItem\|undefined` - a single `ConfigItem` that has the provided `id`, otherwise `undefined`. |
|
||||
| `.getItemsByType( [string] type )` | `Array.<ConfigItem>` - an array of config items that match the provided `type`. |
|
||||
| `.getSettings()` | `Object` - an object representing all items with an `appKey` where the key is the `appKey` and the value is the result of running `.get()` on the Clay item. |
|
||||
| `.build()` <br> Builds the config page. Will dispatch the `BEFORE_BUILD` event prior to building the page, then the `AFTER_BUILD` event once it is complete. | `ClayConfig` |
|
||||
| `.serialize()` | `Object` - an object representing all items with an `appKey` where the key is the `appKey` and the value is an object with the `value` property set to the result of running `.get()` on the Clay item. If the Clay item has a `precision` property set, it is included in the object |
|
||||
| `.build()` <br> Builds the config page. Will dispatch the `BEFORE_BUILD` event prior to building the page, then the `AFTER_BUILD` event once it is complete. If the config page has already been built, then the `ClayConfig.destroy()` method will be executed prior to building the page again. | `ClayConfig` |
|
||||
| `.destroy()` <br> Destroys the config page. Will dispatch the `BEFORE_DESTROY` event prior to destroying the page, then the `AFTER_DESTROY` event once it is complete. This method wipes the config page completely, including all existing items. You will need to make sure that you re-attach your event handlers for any items that are replaced | `ClayConfig` |
|
||||
| `.on( [string] events, [function] handler )` <br> Register an event to the provided handler. The handler will be called with this instance of `ClayConfig` as the context. If you wish to register multiple events to the same handler, then separate the events with a space | `ClayConfig` |
|
||||
| `.off( [function] handler )` <br> Remove the given event handler. **NOTE:** This will remove the handler from all registered events. | `ClayConfig` |
|
||||
| `.trigger( [string] name, [object] eventObj={} )` <br> Trigger the provided event and optionally pass extra data to the handler. | `ClayConfig` |
|
||||
@@ -701,7 +1051,7 @@ Components are simple objects with the following properties.
|
||||
| `style` | string | no | Any extra CSS styles you want to inject into the page. Make sure to namespace your CSS with a class that is unique to your component in order to avoid conflicts with other components. |
|
||||
| `manipulator` | string / manipulator | yes | Provide a string here to use one of the built-in manipulators, such as `val`. If an object is provided, it must have both a `.set(value)` and `.get()` method. |
|
||||
| `defaults` | object | Only if your template requires it. | An object of all the defaults your template requires. |
|
||||
| `initialize` | function | no | Method which will be called after the item has been added to the page. It will be called with the `ClayItem` as the context (`this`) and with `minified` as the first parameter. |
|
||||
| `initialize` | function | no | Method which will be called after the item has been added to the page. It will be called with the `ClayItem` as the context (`this`) and with [`minified`](#minified) as the first parameter and [`clayConfig`](#clayconfigobject-settings-array-config-minified-rootcontainer) as the second paramater |
|
||||
|
||||
### Registering a custom component.
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
'use strict';
|
||||
/* eslint-disable quotes */
|
||||
|
||||
module.exports = [
|
||||
{
|
||||
"type": "heading",
|
||||
"id": "main-heading",
|
||||
"defaultValue": "Clay Test Page",
|
||||
"size": 1
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"defaultValue": "This is config 2"
|
||||
},
|
||||
{
|
||||
"type": "section",
|
||||
"items": [
|
||||
{
|
||||
"type": "heading",
|
||||
"defaultValue": "This is a section"
|
||||
},
|
||||
{
|
||||
"type": "input",
|
||||
"appKey": "email",
|
||||
"defaultValue": "",
|
||||
"label": "Input Field",
|
||||
"description": "This is a new field",
|
||||
"attributes": {
|
||||
"placeholder": "Placeholder set with attributes"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "submit",
|
||||
"defaultValue": "Save"
|
||||
}
|
||||
];
|
||||
+56
-1
@@ -13,6 +13,17 @@ module.exports = [
|
||||
"defaultValue": "Some arbitrary text explaining how this all works. " +
|
||||
"It's cool if this wraps across multiple lines"
|
||||
},
|
||||
{
|
||||
"type": "section",
|
||||
"capabilities": ["RECT", "MICROPHONE"],
|
||||
"items": [
|
||||
{
|
||||
"type": "text",
|
||||
"defaultValue": "This section is only visible for rectangular devices that" +
|
||||
" have a microphone"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "section",
|
||||
"items": [
|
||||
@@ -20,6 +31,11 @@ module.exports = [
|
||||
"type": "heading",
|
||||
"defaultValue": "This is a section"
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"defaultValue": "This is only visible for aplite",
|
||||
"capabilities": ["APLITE"]
|
||||
},
|
||||
{
|
||||
"type": "input",
|
||||
"appKey": "email",
|
||||
@@ -31,6 +47,30 @@ module.exports = [
|
||||
"placeholder": "Placeholder set with attributes"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "input",
|
||||
"label": "Time Field",
|
||||
"attributes": {
|
||||
"type": "time"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "input",
|
||||
"label": "Date Field",
|
||||
"attributes": {
|
||||
"type": "date"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "slider",
|
||||
"appKey": "slider",
|
||||
"defaultValue": 15,
|
||||
"label": "Slider",
|
||||
"description": "This is the description for the slider",
|
||||
"min": 10,
|
||||
"max": 20,
|
||||
"step": 0.25
|
||||
},
|
||||
{
|
||||
"type": "toggle",
|
||||
"appKey": "cool_stuff",
|
||||
@@ -50,6 +90,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"'
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -90,7 +138,14 @@ module.exports = [
|
||||
{ "label": "", "value": "" },
|
||||
{ "label": "Berry", "value": "berry" },
|
||||
{ "label": "This Option is Selected", "value": "grape" },
|
||||
{ "label": "Banana", "value": "banana" }
|
||||
{ "label": "Banana", "value": "banana" },
|
||||
{
|
||||
"label": "This is an optgroup",
|
||||
"value": [
|
||||
{ "label": "Peach", "value": "peach" },
|
||||
{ "label": "Mango", "value": "mango" }
|
||||
]
|
||||
}
|
||||
],
|
||||
"attributes": {
|
||||
"required": "required"
|
||||
|
||||
@@ -16,9 +16,21 @@ module.exports = function() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {void}
|
||||
*/
|
||||
function handleButtonClick() {
|
||||
Clay.config = Clay.meta.userData.config2;
|
||||
Clay.build();
|
||||
}
|
||||
|
||||
Clay.on(Clay.EVENTS.AFTER_BUILD, function() {
|
||||
var coolStuffToggle = Clay.getItemByAppKey('cool_stuff');
|
||||
toggleBackground.call(coolStuffToggle);
|
||||
coolStuffToggle.on('change', toggleBackground);
|
||||
|
||||
Clay.getItemById('testButton').on('click', handleButtonClick);
|
||||
});
|
||||
|
||||
console.log('userData: ', Clay.meta.userData);
|
||||
};
|
||||
|
||||
+17
@@ -5,6 +5,23 @@ window.clayConfig = require('./config.js');
|
||||
window.claySettings = {};
|
||||
window.customFn = require('./custom-fn.js');
|
||||
window.clayComponents = require('../src/scripts/components');
|
||||
window.clayMeta = require('../test/fixture').meta({
|
||||
activeWatchInfo: {
|
||||
platform: 'basalt',
|
||||
model: 'qemu_platform_basalt',
|
||||
language: 'en_US',
|
||||
firmware: {
|
||||
major: 3,
|
||||
minor: 10,
|
||||
patch: 2,
|
||||
suffix: ''
|
||||
}
|
||||
},
|
||||
userData: {
|
||||
foo: 'bar',
|
||||
config2: require('./config-2')
|
||||
}
|
||||
});
|
||||
|
||||
var platform = window.navigator.userAgent.match(/Android/) ? 'android' : 'ios';
|
||||
document.documentElement.classList.add('platform-' + platform);
|
||||
|
||||
+6
-1
@@ -20,9 +20,14 @@
|
||||
|
||||
var returnTo = getQueryParam('return_to');
|
||||
var data = decodeURIComponent(location.hash.substring(1));
|
||||
if (data) {
|
||||
|
||||
// Check if we dealing with a base64 encoded URI
|
||||
if (data && data.charAt(0) !== '<') {
|
||||
data = window.atob(data).replace('$$RETURN_TO$$', returnTo);
|
||||
window.location.href = 'data:text/html;base64,' + encodeURIComponent(window.btoa(data));
|
||||
} else if (data) {
|
||||
data = data.replace('$$RETURN_TO$$', returnTo);
|
||||
window.location.href = 'data:text/html;charset=utf-8,' + encodeURIComponent(data);
|
||||
}
|
||||
</script>
|
||||
<body>
|
||||
|
||||
+4
-1
@@ -86,6 +86,7 @@ gulp.task('clay', ['inlineHtml'], function() {
|
||||
debug: false,
|
||||
standalone: 'clay'
|
||||
})
|
||||
.transform('deamdify')
|
||||
.transform(stringify(stringifyOptions))
|
||||
.transform(sassify, sassifyOptions)
|
||||
.transform(autoprefixify, autoprefixerOptions)
|
||||
@@ -93,7 +94,9 @@ gulp.task('clay', ['inlineHtml'], function() {
|
||||
.bundle()
|
||||
.pipe(source('clay.js'))
|
||||
.pipe(buffer())
|
||||
.pipe(uglify())
|
||||
.pipe(uglify({
|
||||
preserveComments: 'license'
|
||||
}))
|
||||
.pipe(insert.prepend(versionMessage))
|
||||
.pipe(gulp.dest('./dist/'));
|
||||
});
|
||||
|
||||
@@ -3,14 +3,17 @@
|
||||
var configPageHtml = require('./tmp/config-page.html');
|
||||
var toSource = require('tosource');
|
||||
var standardComponents = require('./src/scripts/components');
|
||||
var deepcopy = require('deepcopy/build/deepcopy.min');
|
||||
|
||||
/**
|
||||
* @param {Array} config - the Clay config
|
||||
* @param {function} [customFn] - Custom code to run from the config page. Will run
|
||||
* with the ClayConfig instance as context
|
||||
* @param {Object} [options] - Additional options to pass to Clay
|
||||
* @param {boolean} [options.autoHandleEvents] - If false, Clay will not
|
||||
* @param {boolean} [options.autoHandleEvents=true] - If false, Clay will not
|
||||
* automatically handle the 'showConfiguration' and 'webviewclosed' events
|
||||
* @param {*} [options.userData={}] - Arbitrary data to pass to the config page. Will
|
||||
* be available as `clayConfig.meta.userData`
|
||||
* @constructor
|
||||
*/
|
||||
function Clay(config, customFn, options) {
|
||||
@@ -26,15 +29,30 @@ function Clay(config, customFn, options) {
|
||||
|
||||
options = options || {};
|
||||
|
||||
self.config = config;
|
||||
self.config = deepcopy(config);
|
||||
self.customFn = customFn || function() {};
|
||||
self.components = {};
|
||||
self.meta = {
|
||||
activeWatchInfo: null,
|
||||
accountToken: '',
|
||||
watchToken: ''
|
||||
watchToken: '',
|
||||
userData: {}
|
||||
};
|
||||
|
||||
/**
|
||||
* Populate the meta with data from the Pebble object. Make sure to run this inside
|
||||
* either the "showConfiguration" or "ready" event handler
|
||||
* @return {void}
|
||||
*/
|
||||
function _populateMeta() {
|
||||
self.meta = {
|
||||
activeWatchInfo: Pebble.getActiveWatchInfo && Pebble.getActiveWatchInfo(),
|
||||
accountToken: Pebble.getAccountToken(),
|
||||
watchToken: Pebble.getWatchToken(),
|
||||
userData: deepcopy(options.userData || {})
|
||||
};
|
||||
}
|
||||
|
||||
// Let Clay handle all the magic
|
||||
if (options.autoHandleEvents !== false && typeof Pebble !== 'undefined') {
|
||||
|
||||
@@ -61,19 +79,6 @@ function Clay(config, customFn, options) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Populate the meta with data from the Pebble object. Make sure to run this inside
|
||||
* either the "showConfiguration" or "ready" event handler
|
||||
* @return {void}
|
||||
*/
|
||||
function _populateMeta() {
|
||||
self.meta = {
|
||||
activeWatchInfo: Pebble.getActiveWatchInfo && Pebble.getActiveWatchInfo(),
|
||||
accountToken: Pebble.getAccountToken(),
|
||||
watchToken: Pebble.getWatchToken()
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {Clay~ConfigItem|Array} item
|
||||
@@ -149,9 +154,10 @@ Clay.prototype.generateUrl = function() {
|
||||
/**
|
||||
* Parse the response from the webviewclosed event data
|
||||
* @param {string} response
|
||||
* @param {boolean} [convert=true]
|
||||
* @returns {Object}
|
||||
*/
|
||||
Clay.prototype.getSettings = function(response) {
|
||||
Clay.prototype.getSettings = function(response, convert) {
|
||||
// Decode and parse config data as JSON
|
||||
var settings = {};
|
||||
|
||||
@@ -161,64 +167,113 @@ Clay.prototype.getSettings = function(response) {
|
||||
throw new Error('The provided response was not valid JSON');
|
||||
}
|
||||
|
||||
localStorage.setItem('clay-settings', JSON.stringify(settings));
|
||||
return settings;
|
||||
// flatten the settings for localStorage
|
||||
var settingsStorage = {};
|
||||
Object.keys(settings).forEach(function(key) {
|
||||
if (typeof settings[key] === 'object' && settings[key]) {
|
||||
settingsStorage[key] = settings[key].value;
|
||||
} else {
|
||||
settingsStorage[key] = settings[key];
|
||||
}
|
||||
});
|
||||
|
||||
localStorage.setItem('clay-settings', JSON.stringify(settingsStorage));
|
||||
|
||||
return convert === false ? settings : Clay.prepareSettingsForAppMessage(settings);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} input
|
||||
* @param {string} [prefix]
|
||||
* @param {string} [prefix='data:text/html;charset=utf-8,']
|
||||
* @returns {string}
|
||||
*/
|
||||
Clay.encodeDataUri = function(input, prefix) {
|
||||
prefix = typeof prefix !== 'undefined' ? prefix : 'data:text/html;base64,';
|
||||
prefix = typeof prefix !== 'undefined' ? prefix : 'data:text/html;charset=utf-8,';
|
||||
return prefix + encodeURIComponent(input);
|
||||
};
|
||||
|
||||
if (window.btoa) {
|
||||
return prefix + encodeURIComponent(window.btoa(input));
|
||||
/**
|
||||
* 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
|
||||
* - Objects that have a "value" property will apply the above rules to the type of
|
||||
* value. If the value is a number or an array of numbers and the optional
|
||||
* property: "precision" is provided, then the number will be multipled by 10 to
|
||||
* the power of precision (value * 10 ^ precision) and then floored.
|
||||
* Eg: 1.4567 with a precision set to 3 will become 1456
|
||||
* @param {number|string|boolean|Array|Object} val
|
||||
* @param {number|string|boolean|Array} val.value
|
||||
* @param {number} [val.precision=0]
|
||||
* @returns {number|string|Array}
|
||||
*/
|
||||
Clay.prepareForAppMessage = function(val) {
|
||||
|
||||
/**
|
||||
* moves the decimal place of a number by precision then drop any remaining decimal
|
||||
* places.
|
||||
* @param {number} number
|
||||
* @param {number} precision - number of decimal places to move
|
||||
* @returns {number}
|
||||
* @private
|
||||
*/
|
||||
function _normalizeToPrecision(number, precision) {
|
||||
return Math.floor(number * Math.pow(10, precision || 0));
|
||||
}
|
||||
|
||||
// iOS doesn't have a window so we need to polyfil window.btoa
|
||||
// extracted from https://github.com/inexorabletash/polyfill
|
||||
var B64_ALPHABET =
|
||||
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
||||
input = String(input);
|
||||
var position = 0;
|
||||
var out = [];
|
||||
var o1;
|
||||
var o2;
|
||||
var o3;
|
||||
var e1;
|
||||
var e2;
|
||||
var e3;
|
||||
var e4;
|
||||
var result;
|
||||
|
||||
if (/[^\x00-\xFF]/.test(input)) { throw Error('InvalidCharacterError'); }
|
||||
|
||||
while (position < input.length) {
|
||||
o1 = input.charCodeAt(position++);
|
||||
o2 = input.charCodeAt(position++);
|
||||
o3 = input.charCodeAt(position++);
|
||||
|
||||
// 111111 112222 222233 333333
|
||||
e1 = o1 >> 2;
|
||||
e2 = ((o1 & 0x3) << 4) | (o2 >> 4);
|
||||
e3 = ((o2 & 0xf) << 2) | (o3 >> 6);
|
||||
e4 = o3 & 0x3f;
|
||||
|
||||
if (position === input.length + 2) {
|
||||
e3 = 64;
|
||||
e4 = 64;
|
||||
} else if (position === input.length + 1) {
|
||||
e4 = 64;
|
||||
if (Array.isArray(val)) {
|
||||
result = [];
|
||||
val.forEach(function(item) {
|
||||
var itemConverted = Clay.prepareForAppMessage(item);
|
||||
result.push(itemConverted);
|
||||
if (typeof itemConverted === 'string') {
|
||||
result.push(0);
|
||||
}
|
||||
});
|
||||
} else if (typeof val === 'object' && val) {
|
||||
if (typeof val.value === 'number') {
|
||||
result = _normalizeToPrecision(val.value, val.precision);
|
||||
} else if (Array.isArray(val.value)) {
|
||||
result = val.value.map(function(item) {
|
||||
if (typeof item === 'number') {
|
||||
return _normalizeToPrecision(item, val.precision);
|
||||
}
|
||||
return item;
|
||||
});
|
||||
} else {
|
||||
result = Clay.prepareForAppMessage(val.value);
|
||||
}
|
||||
|
||||
out.push(B64_ALPHABET.charAt(e1),
|
||||
B64_ALPHABET.charAt(e2),
|
||||
B64_ALPHABET.charAt(e3),
|
||||
B64_ALPHABET.charAt(e4));
|
||||
} else if (typeof val === 'boolean') {
|
||||
result = val ? 1 : 0;
|
||||
} else {
|
||||
result = val;
|
||||
}
|
||||
|
||||
return prefix + encodeURIComponent(out.join(''));
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a Clay settings dict into one that is compatible with
|
||||
* Pebble.sendAppMessage();
|
||||
* @see {prepareForAppMessage}
|
||||
* @param {Object} settings
|
||||
* @returns {{}}
|
||||
*/
|
||||
Clay.prepareSettingsForAppMessage = function(settings) {
|
||||
var result = {};
|
||||
Object.keys(settings).forEach(function(key) {
|
||||
result[key] = Clay.prepareForAppMessage(settings[key]);
|
||||
});
|
||||
return result;
|
||||
};
|
||||
|
||||
module.exports = Clay;
|
||||
|
||||
+2
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "pebble-clay",
|
||||
"version": "0.1.1",
|
||||
"version": "0.1.7",
|
||||
"description": "Pebble Config Framework",
|
||||
"main": "dist/clay.js",
|
||||
"directories": {
|
||||
@@ -35,6 +35,7 @@
|
||||
"browserify-istanbul": "^0.2.1",
|
||||
"chai": "^3.4.1",
|
||||
"deamdify": "^0.2.0",
|
||||
"deepcopy": "^0.6.1",
|
||||
"del": "^2.0.2",
|
||||
"eslint": "^1.5.1",
|
||||
"eslint-config-pebble": "^1.2.0",
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 116 KiB After Width: | Height: | Size: 135 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: ''
|
||||
}
|
||||
};
|
||||
+223
-92
@@ -9,117 +9,225 @@ module.exports = {
|
||||
label: '',
|
||||
description: ''
|
||||
},
|
||||
initialize: function(minified) {
|
||||
initialize: function(minified, clay) {
|
||||
var HTML = minified.HTML;
|
||||
var self = this;
|
||||
var useSunlight = self.config.sunlight !== false;
|
||||
var sunlightColorMap = {
|
||||
'000000': '000000',
|
||||
'000055': '001e41',
|
||||
'0000aa': '004387',
|
||||
'0000ff': '0068ca',
|
||||
'005500': '2b4a2c',
|
||||
'005555': '27514f',
|
||||
'0055aa': '16638d',
|
||||
'0055ff': '007dce',
|
||||
'00aa00': '5e9860',
|
||||
'00aa55': '5c9b72',
|
||||
'00aaaa': '57a5a2',
|
||||
'00aaff': '4cb4db',
|
||||
'00ff00': '8ee391',
|
||||
'00ff55': '8ee69e',
|
||||
'00ffaa': '8aebc0',
|
||||
'00ffff': '84f5f1',
|
||||
'550000': '4a161b',
|
||||
'550055': '482748',
|
||||
'5500aa': '40488a',
|
||||
'5500ff': '2f6bcc',
|
||||
'555500': '564e36',
|
||||
'555555': '545454',
|
||||
'5555aa': '4f6790',
|
||||
'5555ff': '4180d0',
|
||||
'55aa00': '759a64',
|
||||
'55aa55': '759d76',
|
||||
'55aaaa': '71a6a4',
|
||||
'55aaff': '69b5dd',
|
||||
'55ff00': '9ee594',
|
||||
'55ff55': '9de7a0',
|
||||
'55ffaa': '9becc2',
|
||||
'55ffff': '95f6f2',
|
||||
'aa0000': '99353f',
|
||||
'aa0055': '983e5a',
|
||||
'aa00aa': '955694',
|
||||
'aa00ff': '8f74d2',
|
||||
'aa5500': '9d5b4d',
|
||||
'aa5555': '9d6064',
|
||||
'aa55aa': '9a7099',
|
||||
'aa55ff': '9587d5',
|
||||
'aaaa00': 'afa072',
|
||||
'aaaa55': 'aea382',
|
||||
'aaaaaa': 'ababab',
|
||||
'ffffff': 'ffffff',
|
||||
'aaaaff': 'a7bae2',
|
||||
'aaff00': 'c9e89d',
|
||||
'aaff55': 'c9eaa7',
|
||||
'aaffaa': 'c7f0c8',
|
||||
'aaffff': 'c3f9f7',
|
||||
'ff0000': 'e35462',
|
||||
'ff0055': 'e25874',
|
||||
'ff00aa': 'e16aa3',
|
||||
'ff00ff': 'de83dc',
|
||||
'ff5500': 'e66e6b',
|
||||
'ff5555': 'e6727c',
|
||||
'ff55aa': 'e37fa7',
|
||||
'ff55ff': 'e194df',
|
||||
'ffaa00': 'f1aa86',
|
||||
'ffaa55': 'f1ad93',
|
||||
'ffaaaa': 'efb5b8',
|
||||
'ffaaff': 'ecc3eb',
|
||||
'ffff00': 'ffeeab',
|
||||
'ffff55': 'fff1b5',
|
||||
'ffffaa': 'fff6d3'
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string|boolean|number} color
|
||||
* @returns {string}
|
||||
*/
|
||||
function cssColor(color) {
|
||||
if (color === false) { return 'transparent'; }
|
||||
if (typeof color === 'number') {
|
||||
color = color.toString(16);
|
||||
} else if (!color) {
|
||||
return 'transparent';
|
||||
}
|
||||
while (color.length < 6) {
|
||||
color = '0' + color;
|
||||
}
|
||||
|
||||
color = padColorString(color);
|
||||
|
||||
return '#' + (useSunlight ? sunlightColorMap[color] : color);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} color
|
||||
* @return {string}
|
||||
*/
|
||||
function padColorString(color) {
|
||||
color = color.toLowerCase();
|
||||
|
||||
while (color.length < 6) {
|
||||
color = '0' + color;
|
||||
}
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number|string} value
|
||||
* @returns {string|*}
|
||||
*/
|
||||
function normalizeColor(value) {
|
||||
switch (typeof value) {
|
||||
case 'number': return padColorString(value.toString(16));
|
||||
case 'string': return value.replace(/^#|^0x/, '');
|
||||
default: return value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Array.<Array>} layout
|
||||
* @returns {Array}
|
||||
*/
|
||||
function flattenLayout(layout) {
|
||||
return layout.reduce(function(a, b) {
|
||||
return a.concat(b);
|
||||
}, []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert HEX color to LAB.
|
||||
* Adapted from: https://github.com/antimatter15/rgb-lab
|
||||
* @param {string} hex
|
||||
* @returns {Array} - [l, a, b]
|
||||
*/
|
||||
function hex2lab(hex) {
|
||||
hex = hex.replace(/^#|^0x/, '');
|
||||
|
||||
var r = parseInt(hex.slice(0, 2), 16) / 255;
|
||||
var g = parseInt(hex.slice(2, 4), 16) / 255;
|
||||
var b = parseInt(hex.slice(4), 16) / 255;
|
||||
|
||||
r = (r > 0.04045) ? Math.pow((r + 0.055) / 1.055, 2.4) : r / 12.92;
|
||||
g = (g > 0.04045) ? Math.pow((g + 0.055) / 1.055, 2.4) : g / 12.92;
|
||||
b = (b > 0.04045) ? Math.pow((b + 0.055) / 1.055, 2.4) : b / 12.92;
|
||||
|
||||
var x = (r * 0.4124 + g * 0.3576 + b * 0.1805) / 0.95047;
|
||||
var y = (r * 0.2126 + g * 0.7152 + b * 0.0722) / 1.00000;
|
||||
var z = (r * 0.0193 + g * 0.1192 + b * 0.9505) / 1.08883;
|
||||
|
||||
x = (x > 0.008856) ? Math.pow(x, 1 / 3) : (7.787 * x) + 16 / 116;
|
||||
y = (y > 0.008856) ? Math.pow(y, 1 / 3) : (7.787 * y) + 16 / 116;
|
||||
z = (z > 0.008856) ? Math.pow(z, 1 / 3) : (7.787 * z) + 16 / 116;
|
||||
|
||||
return [(116 * y) - 16, 500 * (x - y), 200 * (y - z)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the perceptual color distance between two LAB colors
|
||||
* @param {Array} labA
|
||||
* @param {Array} labB
|
||||
* @returns {number}
|
||||
*/
|
||||
function deltaE(labA, labB) {
|
||||
var deltaL = labA[0] - labB[0];
|
||||
var deltaA = labA[1] - labB[1];
|
||||
var deltaB = labA[2] - labB[2];
|
||||
|
||||
return Math.sqrt(Math.pow(deltaL, 2) +
|
||||
Math.pow(deltaA, 2) +
|
||||
Math.pow(deltaB, 2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the layout based on the connected watch
|
||||
* @returns {Array}
|
||||
*/
|
||||
function autoLayout() {
|
||||
if (!clay.meta.activeWatchInfo ||
|
||||
clay.meta.activeWatchInfo.firmware.major === 2 ||
|
||||
clay.meta.activeWatchInfo.platform === 'aplite' &&
|
||||
!self.config.allowGray) {
|
||||
return standardLayouts.BLACK_WHITE;
|
||||
}
|
||||
|
||||
if (clay.meta.activeWatchInfo.platform === 'aplite' && self.config.allowGray) {
|
||||
return standardLayouts.GRAY;
|
||||
}
|
||||
|
||||
return standardLayouts.COLOR;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number|string} color
|
||||
* @return {number}
|
||||
*/
|
||||
self.roundColorToLayout = function(color) {
|
||||
var itemValue = normalizeColor(color);
|
||||
|
||||
// if the color is not in the layout we will need find the closest match
|
||||
if (colorList.indexOf(itemValue) === -1) {
|
||||
var itemValueLAB = hex2lab(itemValue);
|
||||
var differenceArr = colorList.map(function(color) {
|
||||
var colorLAB = hex2lab(normalizeColor(color));
|
||||
return deltaE(itemValueLAB, colorLAB);
|
||||
});
|
||||
|
||||
// Get the lowest number from the differenceArray
|
||||
var lowest = Math.min.apply(Math, differenceArr);
|
||||
|
||||
// Get the index for that lowest number
|
||||
var index = differenceArr.indexOf(lowest);
|
||||
itemValue = colorList[index];
|
||||
}
|
||||
|
||||
return parseInt(itemValue, 16);
|
||||
};
|
||||
|
||||
var useSunlight = self.config.sunlight !== false;
|
||||
var sunlightColorMap = {
|
||||
'000000': '000000', '000055': '001e41', '0000aa': '004387', '0000ff': '0068ca',
|
||||
'005500': '2b4a2c', '005555': '27514f', '0055aa': '16638d', '0055ff': '007dce',
|
||||
'00aa00': '5e9860', '00aa55': '5c9b72', '00aaaa': '57a5a2', '00aaff': '4cb4db',
|
||||
'00ff00': '8ee391', '00ff55': '8ee69e', '00ffaa': '8aebc0', '00ffff': '84f5f1',
|
||||
'550000': '4a161b', '550055': '482748', '5500aa': '40488a', '5500ff': '2f6bcc',
|
||||
'555500': '564e36', '555555': '545454', '5555aa': '4f6790', '5555ff': '4180d0',
|
||||
'55aa00': '759a64', '55aa55': '759d76', '55aaaa': '71a6a4', '55aaff': '69b5dd',
|
||||
'55ff00': '9ee594', '55ff55': '9de7a0', '55ffaa': '9becc2', '55ffff': '95f6f2',
|
||||
'aa0000': '99353f', 'aa0055': '983e5a', 'aa00aa': '955694', 'aa00ff': '8f74d2',
|
||||
'aa5500': '9d5b4d', 'aa5555': '9d6064', 'aa55aa': '9a7099', 'aa55ff': '9587d5',
|
||||
'aaaa00': 'afa072', 'aaaa55': 'aea382', 'aaaaaa': 'ababab', 'ffffff': 'ffffff',
|
||||
'aaaaff': 'a7bae2', 'aaff00': 'c9e89d', 'aaff55': 'c9eaa7', 'aaffaa': 'c7f0c8',
|
||||
'aaffff': 'c3f9f7', 'ff0000': 'e35462', 'ff0055': 'e25874', 'ff00aa': 'e16aa3',
|
||||
'ff00ff': 'de83dc', 'ff5500': 'e66e6b', 'ff5555': 'e6727c', 'ff55aa': 'e37fa7',
|
||||
'ff55ff': 'e194df', 'ffaa00': 'f1aa86', 'ffaa55': 'f1ad93', 'ffaaaa': 'efb5b8',
|
||||
'ffaaff': 'ecc3eb', 'ffff00': 'ffeeab', 'ffff55': 'fff1b5', 'ffffaa': 'fff6d3'
|
||||
};
|
||||
|
||||
/* eslint-disable comma-spacing, no-multi-spaces, max-len,
|
||||
standard/array-bracket-even-spacing */
|
||||
var layout = self.config.layout || [
|
||||
[false , false , '55ff00', 'aaff55', false , 'ffff55', 'ffffaa', false , false ],
|
||||
[false , 'aaffaa', '55ff55', '00ff00', 'aaff00', 'ffff00', 'ffaa55', 'ffaaaa', false ],
|
||||
['55ffaa', '00ff55', '00aa00', '55aa00', 'aaaa55', 'aaaa00', 'ffaa00', 'ff5500', 'ff5555'],
|
||||
['aaffff', '00ffaa', '00aa55', '55aa55', '005500', '555500', 'aa5500', 'ff0000', 'ff0055'],
|
||||
[false , '55aaaa', '00aaaa', '005555', 'ffffff', '000000', 'aa5555', 'aa0000', false ],
|
||||
['55ffff', '00ffff', '00aaff', '0055aa', 'aaaaaa', '555555', '550000', 'aa0055', 'ff55aa'],
|
||||
['55aaff', '0055ff', '0000ff', '0000aa', '000055', '550055', 'aa00aa', 'ff00aa', 'ffaaff'],
|
||||
[false , '5555aa', '5555ff', '5500ff', '5500aa', 'aa00ff', 'ff00ff', 'ff55ff', false ],
|
||||
[false , false , false , 'aaaaff', 'aa55ff', 'aa55aa', false , false , false ]
|
||||
];
|
||||
standard/array-bracket-even-spacing */
|
||||
var standardLayouts = {
|
||||
COLOR: [
|
||||
[false , false , '55ff00', 'aaff55', false , 'ffff55', 'ffffaa', false , false ],
|
||||
[false , 'aaffaa', '55ff55', '00ff00', 'aaff00', 'ffff00', 'ffaa55', 'ffaaaa', false ],
|
||||
['55ffaa', '00ff55', '00aa00', '55aa00', 'aaaa55', 'aaaa00', 'ffaa00', 'ff5500', 'ff5555'],
|
||||
['aaffff', '00ffaa', '00aa55', '55aa55', '005500', '555500', 'aa5500', 'ff0000', 'ff0055'],
|
||||
[false , '55aaaa', '00aaaa', '005555', 'ffffff', '000000', 'aa5555', 'aa0000', false ],
|
||||
['55ffff', '00ffff', '00aaff', '0055aa', 'aaaaaa', '555555', '550000', 'aa0055', 'ff55aa'],
|
||||
['55aaff', '0055ff', '0000ff', '0000aa', '000055', '550055', 'aa00aa', 'ff00aa', 'ffaaff'],
|
||||
[false , '5555aa', '5555ff', '5500ff', '5500aa', 'aa00ff', 'ff00ff', 'ff55ff', false ],
|
||||
[false , false , false , 'aaaaff', 'aa55ff', 'aa55aa', false , false , false ]
|
||||
],
|
||||
GRAY: [
|
||||
['000000', 'aaaaaa', 'ffffff']
|
||||
],
|
||||
BLACK_WHITE: [
|
||||
['000000', 'ffffff']
|
||||
]
|
||||
};
|
||||
/* eslint-enable */
|
||||
|
||||
var layout = self.config.layout || autoLayout();
|
||||
|
||||
if (typeof layout === 'string') {
|
||||
layout = standardLayouts[layout];
|
||||
}
|
||||
|
||||
// make sure layout is a 2D array
|
||||
if (!Array.isArray(layout[0])) {
|
||||
layout = [layout];
|
||||
}
|
||||
|
||||
var colorList = flattenLayout(layout).map(function(item) {
|
||||
return normalizeColor(item);
|
||||
}).filter(function(item) {
|
||||
return item;
|
||||
});
|
||||
|
||||
var grid = '';
|
||||
var itemWidth = 100 / layout[0].length;
|
||||
var itemHeight = 100 / layout.length;
|
||||
var rows = layout.length;
|
||||
var cols = 0;
|
||||
layout.forEach(function(row) {
|
||||
cols = row.length > cols ? row.length : cols;
|
||||
});
|
||||
var itemWidth = 100 / cols;
|
||||
var itemHeight = 100 / rows;
|
||||
var $elem = self.$element;
|
||||
|
||||
for (var i = 0; i < layout.length; i++) {
|
||||
for (var j = 0; j < layout[i].length; j++) {
|
||||
for (var i = 0; i < rows; i++) {
|
||||
for (var j = 0; j < cols; j++) {
|
||||
|
||||
var color = layout[i][j];
|
||||
var color = normalizeColor(layout[i][j]);
|
||||
var selectable = (color ? ' selectable' : '');
|
||||
|
||||
var roundedTL = (i === 0 && j === 0) || i === 0 && !layout[i][j - 1] ||
|
||||
@@ -146,7 +254,7 @@ module.exports = {
|
||||
grid += '<i ' +
|
||||
'class="color-box ' + selectable + roundedTL + roundedTR + roundedBL +
|
||||
roundedBR + '" ' +
|
||||
'data-value="' + parseInt(color, 16) + '" ' +
|
||||
(color ? 'data-value="' + parseInt(color, 16) + '" ' : '') +
|
||||
'style="' +
|
||||
'width:' + itemWidth + '%; ' +
|
||||
'height:' + itemHeight + '%; ' +
|
||||
@@ -155,13 +263,34 @@ module.exports = {
|
||||
}
|
||||
}
|
||||
|
||||
$elem.select('.color-box-container').add(HTML(grid));
|
||||
// on very small layouts the boxes end up huge. The following adds extra padding
|
||||
// to prevent them from being so big.
|
||||
var extraPadding = 0;
|
||||
if (cols === 3) {
|
||||
extraPadding = 5;
|
||||
}
|
||||
if (cols === 2) {
|
||||
extraPadding = 8;
|
||||
}
|
||||
var vPadding = (extraPadding * itemWidth / itemHeight) + '%';
|
||||
var hPadding = extraPadding + '%';
|
||||
$elem.select('.color-box-container')
|
||||
.add(HTML(grid))
|
||||
.set('$paddingTop', vPadding)
|
||||
.set('$paddingRight', hPadding)
|
||||
.set('$paddingBottom', vPadding)
|
||||
.set('$paddingLeft', hPadding);
|
||||
|
||||
$elem.select('.color-box-wrap').set(
|
||||
'$paddingBottom',
|
||||
(itemWidth / itemHeight * 100) + '%'
|
||||
);
|
||||
|
||||
var $valueDisplay = $elem.select('.value');
|
||||
var $picker = $elem.select('.picker-wrap');
|
||||
var disabled = self.$manipulatorTarget.get('disabled');
|
||||
|
||||
$elem.select('label').on('click', function(ev) {
|
||||
$elem.select('label').on('click', function() {
|
||||
if (!disabled) {
|
||||
$picker.set('show'); // toggle visibility
|
||||
}
|
||||
@@ -191,5 +320,7 @@ module.exports = {
|
||||
disabled = false;
|
||||
});
|
||||
|
||||
// expose layout for testing
|
||||
self._layout = layout;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -10,5 +10,7 @@ module.exports = {
|
||||
text: require('./text'),
|
||||
toggle: require('./toggle'),
|
||||
radiogroup: require('./radiogroup'),
|
||||
checkboxgroup: require('./checkboxgroup')
|
||||
checkboxgroup: require('./checkboxgroup'),
|
||||
button: require('./button'),
|
||||
slider: require('./slider')
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
name: 'slider',
|
||||
template: require('../../templates/components/slider.tpl'),
|
||||
style: require('../../styles/clay/components/slider.scss'),
|
||||
manipulator: 'slider',
|
||||
defaults: {
|
||||
label: '',
|
||||
description: '',
|
||||
min: 0,
|
||||
max: 100,
|
||||
step: 1,
|
||||
attributes: {}
|
||||
},
|
||||
initialize: function() {
|
||||
var self = this;
|
||||
|
||||
var $value = self.$element.select('.value');
|
||||
var $valuePad = self.$element.select('.value-pad');
|
||||
var $slider = self.$manipulatorTarget;
|
||||
|
||||
/**
|
||||
* Sets the value display
|
||||
* @return {void}
|
||||
*/
|
||||
function setValueDisplay() {
|
||||
var value = self.get().toFixed(self.precision);
|
||||
$value.set('value', value);
|
||||
$valuePad.set('innerHTML', value);
|
||||
}
|
||||
|
||||
var step = $slider.get('step');
|
||||
step = step.toString(10).split('.')[1];
|
||||
self.precision = step ? step.length : 0;
|
||||
|
||||
self.on('change', setValueDisplay);
|
||||
$slider.on('|input', setValueDisplay);
|
||||
setValueDisplay();
|
||||
|
||||
$value.on('|input', function() {
|
||||
$valuePad.set('innerHTML', this.get('value'));
|
||||
});
|
||||
|
||||
$value.on('|change', function() {
|
||||
self.set(this.get('value'));
|
||||
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: {}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ var clayConfig = new ClayConfig(settings, config, $mainForm, clayMeta);
|
||||
$mainForm.on('submit', function() {
|
||||
// Set the return URL depending on the runtime environment
|
||||
location.href = returnTo +
|
||||
encodeURIComponent(JSON.stringify(clayConfig.getSettings()));
|
||||
encodeURIComponent(JSON.stringify(clayConfig.serialize()));
|
||||
});
|
||||
|
||||
// Run the custom function in the context of the ClayConfig
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
* @property {Object} [attributes]
|
||||
* @property {Array} [options]
|
||||
* @property {Array} [items]
|
||||
* @property {Array} [capabilities]
|
||||
*/
|
||||
|
||||
var HTML = require('../vendor/minified').HTML;
|
||||
@@ -33,10 +34,22 @@ function ClayConfig(settings, config, $rootContainer, meta) {
|
||||
var self = this;
|
||||
|
||||
var _settings = _.copyObj(settings);
|
||||
var _items = [];
|
||||
var _itemsById = {};
|
||||
var _itemsByAppKey = {};
|
||||
var _isBuilt = false;
|
||||
var _items;
|
||||
var _itemsById;
|
||||
var _itemsByAppKey;
|
||||
var _isBuilt;
|
||||
|
||||
/**
|
||||
* Initialize the item arrays and objects
|
||||
* @private
|
||||
* @return {void}
|
||||
*/
|
||||
function _initializeItems() {
|
||||
_items = [];
|
||||
_itemsById = {};
|
||||
_itemsByAppKey = {};
|
||||
_isBuilt = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add item(s) to the config
|
||||
@@ -49,34 +62,36 @@ function ClayConfig(settings, config, $rootContainer, meta) {
|
||||
item.forEach(function(item) {
|
||||
_addItems(item, $container);
|
||||
});
|
||||
} else if (item.type === 'section') {
|
||||
var $wrapper = HTML('<div class="section">');
|
||||
$container.add($wrapper);
|
||||
_addItems(item.items, $wrapper);
|
||||
} else {
|
||||
var _item = _.copyObj(item);
|
||||
_item.clayId = _items.length;
|
||||
} else if (utils.includesCapability(meta.activeWatchInfo, item.capabilities)) {
|
||||
if (item.type === 'section') {
|
||||
var $wrapper = HTML('<div class="section">');
|
||||
$container.add($wrapper);
|
||||
_addItems(item.items, $wrapper);
|
||||
} else {
|
||||
var _item = _.copyObj(item);
|
||||
_item.clayId = _items.length;
|
||||
|
||||
var clayItem = new ClayItem(_item).initialize(self);
|
||||
var clayItem = new ClayItem(_item).initialize(self);
|
||||
|
||||
if (_item.id) {
|
||||
_itemsById[_item.id] = clayItem;
|
||||
if (_item.id) {
|
||||
_itemsById[_item.id] = clayItem;
|
||||
}
|
||||
|
||||
if (_item.appKey) {
|
||||
_itemsByAppKey[_item.appKey] = clayItem;
|
||||
}
|
||||
|
||||
_items.push(clayItem);
|
||||
|
||||
// set the value of the item via the manipulator to ensure consistency
|
||||
var value = typeof _settings[_item.appKey] !== 'undefined' ?
|
||||
_settings[_item.appKey] :
|
||||
(_item.defaultValue || '');
|
||||
|
||||
clayItem.set(value);
|
||||
|
||||
$container.add(clayItem.$element);
|
||||
}
|
||||
|
||||
if (_item.appKey) {
|
||||
_itemsByAppKey[_item.appKey] = clayItem;
|
||||
}
|
||||
|
||||
_items.push(clayItem);
|
||||
|
||||
// set the value of the item via the manipulator to ensure consistency
|
||||
var value = typeof _settings[_item.appKey] !== 'undefined' ?
|
||||
_settings[_item.appKey] :
|
||||
(_item.defaultValue || '');
|
||||
|
||||
clayItem.set(value);
|
||||
|
||||
$container.add(clayItem.$element);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,6 +112,7 @@ function ClayConfig(settings, config, $rootContainer, meta) {
|
||||
}
|
||||
|
||||
self.meta = meta;
|
||||
self.$rootContainer = $rootContainer;
|
||||
|
||||
self.EVENTS = {
|
||||
/**
|
||||
@@ -111,7 +127,21 @@ function ClayConfig(settings, config, $rootContainer, meta) {
|
||||
* value set
|
||||
* @const
|
||||
*/
|
||||
AFTER_BUILD: 'AFTER_BUILD'
|
||||
AFTER_BUILD: 'AFTER_BUILD',
|
||||
|
||||
/**
|
||||
* Called if .build() is executed after the page has already been built and
|
||||
* before the existing content is destroyed
|
||||
* @const
|
||||
*/
|
||||
BEFORE_DESTROY: 'BEFORE_DESTROY',
|
||||
|
||||
/**
|
||||
* Called if .build() is executed after the page has already been built and after
|
||||
* the existing content is destroyed
|
||||
* @const
|
||||
*/
|
||||
AFTER_DESTROY: 'AFTER_DESTROY'
|
||||
};
|
||||
utils.updateProperties(self.EVENTS, {writable: false});
|
||||
|
||||
@@ -155,10 +185,19 @@ function ClayConfig(settings, config, $rootContainer, meta) {
|
||||
/**
|
||||
* @returns {Object}
|
||||
*/
|
||||
self.getSettings = function() {
|
||||
_checkBuilt('getSettings');
|
||||
self.serialize = function() {
|
||||
_checkBuilt('serialize');
|
||||
|
||||
_settings = {};
|
||||
|
||||
_.eachObj(_itemsByAppKey, function(appKey, item) {
|
||||
_settings[appKey] = item.get();
|
||||
_settings[appKey] = {
|
||||
value: item.get()
|
||||
};
|
||||
|
||||
if (item.precision) {
|
||||
_settings[appKey].precision = item.precision;
|
||||
}
|
||||
});
|
||||
return _settings;
|
||||
};
|
||||
@@ -166,18 +205,40 @@ function ClayConfig(settings, config, $rootContainer, meta) {
|
||||
// @todo maybe don't do this and force the static method
|
||||
self.registerComponent = ClayConfig.registerComponent;
|
||||
|
||||
/**
|
||||
* Empties the root container
|
||||
* @returns {ClayConfig}
|
||||
*/
|
||||
self.destroy = function() {
|
||||
var el = $rootContainer[0];
|
||||
self.trigger(self.EVENTS.BEFORE_DESTROY);
|
||||
while (el.firstChild) {
|
||||
el.removeChild(el.firstChild);
|
||||
}
|
||||
_initializeItems();
|
||||
self.trigger(self.EVENTS.AFTER_DESTROY);
|
||||
return self;
|
||||
};
|
||||
|
||||
/**
|
||||
* Build the config page. This must be run before any of the get methods can be run
|
||||
* If you call this method after the page has already been built, teh page will be
|
||||
* destroyed and built again.
|
||||
* @returns {ClayConfig}
|
||||
*/
|
||||
self.build = function() {
|
||||
if (_isBuilt) {
|
||||
self.destroy();
|
||||
}
|
||||
self.trigger(self.EVENTS.BEFORE_BUILD);
|
||||
_addItems(config, $rootContainer);
|
||||
_addItems(self.config, $rootContainer);
|
||||
_isBuilt = true;
|
||||
self.trigger(self.EVENTS.AFTER_BUILD);
|
||||
return self;
|
||||
};
|
||||
|
||||
_initializeItems();
|
||||
|
||||
// attach event methods
|
||||
ClayEvents.call(self, $rootContainer);
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ function ClayItem(config) {
|
||||
};
|
||||
|
||||
// attach event methods
|
||||
ClayEvents.call(self, self.$element);
|
||||
ClayEvents.call(self, self.$manipulatorTarget);
|
||||
|
||||
// attach the manipulator methods to the clayItem
|
||||
_.eachObj(_component.manipulator, function(methodName, method) {
|
||||
|
||||
@@ -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');
|
||||
},
|
||||
@@ -59,11 +85,27 @@ module.exports = {
|
||||
hide: hide,
|
||||
show: show
|
||||
},
|
||||
slider: {
|
||||
get: function() {
|
||||
return parseFloat(this.$manipulatorTarget.get('value'));
|
||||
},
|
||||
set: function(value) {
|
||||
var initVal = this.get();
|
||||
this.$manipulatorTarget.set('value', value);
|
||||
if (this.get() === initVal) { return this; }
|
||||
return this.trigger('change');
|
||||
},
|
||||
disable: disable,
|
||||
enable: enable,
|
||||
hide: hide,
|
||||
show: show
|
||||
},
|
||||
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 +119,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,11 +140,15 @@ 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('"', '\\"') + '"]')
|
||||
.select('input[value="' + value.toString(10).replace('"', '\\"') + '"]')
|
||||
.set('checked', true);
|
||||
});
|
||||
return self.trigger('change');
|
||||
@@ -113,15 +160,13 @@ module.exports = {
|
||||
},
|
||||
color: {
|
||||
get: function() {
|
||||
return parseInt(this.$manipulatorTarget.get('value'), 16);
|
||||
return parseInt(this.$manipulatorTarget.get('value'), 10) || 0;
|
||||
},
|
||||
set: function(value) {
|
||||
switch (typeof value) {
|
||||
case 'number': value = value.toString(16); break;
|
||||
case 'string': value = value.replace(/^#|^0x/, ''); break;
|
||||
}
|
||||
value = this.roundColorToLayout(value || 0);
|
||||
|
||||
this.$manipulatorTarget.set('value', value || '000000');
|
||||
if (this.get() === value) { return this; }
|
||||
this.$manipulatorTarget.set('value', value);
|
||||
return this.trigger('change');
|
||||
},
|
||||
disable: disable,
|
||||
|
||||
@@ -17,3 +17,119 @@ module.exports.updateProperties = function(obj, descriptor) {
|
||||
Object.defineProperty(obj, prop, descriptor);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.capabilityMap = {
|
||||
PLATFORM_APLITE: {
|
||||
platforms: ['aplite'],
|
||||
minFwMajor: 0,
|
||||
minFwMinor: 0
|
||||
},
|
||||
PLATFORM_BASALT: {
|
||||
platforms: ['basalt'],
|
||||
minFwMajor: 0,
|
||||
minFwMinor: 0
|
||||
},
|
||||
PLATFORM_CHALK: {
|
||||
platforms: ['chalk'],
|
||||
minFwMajor: 0,
|
||||
minFwMinor: 0
|
||||
},
|
||||
PLATFORM_DIORITE: {
|
||||
platforms: ['diorite'],
|
||||
minFwMajor: 0,
|
||||
minFwMinor: 0
|
||||
},
|
||||
PLATFORM_EMERY: {
|
||||
platforms: ['emery'],
|
||||
minFwMajor: 0,
|
||||
minFwMinor: 0
|
||||
},
|
||||
BW: {
|
||||
platforms: ['aplite', 'diorite'],
|
||||
minFwMajor: 0,
|
||||
minFwMinor: 0
|
||||
},
|
||||
COLOR: {
|
||||
platforms: ['basalt', 'chalk', 'emery'],
|
||||
minFwMajor: 0,
|
||||
minFwMinor: 0
|
||||
},
|
||||
MICROPHONE: {
|
||||
platforms: ['basalt', 'chalk', 'diorite', 'emery'],
|
||||
minFwMajor: 0,
|
||||
minFwMinor: 0
|
||||
},
|
||||
SMARTSTRAP: {
|
||||
platforms: ['basalt', 'chalk', 'diorite', 'emery'],
|
||||
minFwMajor: 3,
|
||||
minFwMinor: 4
|
||||
},
|
||||
SMARTSTRAP_POWER: {
|
||||
platforms: ['basalt', 'chalk', 'emery'],
|
||||
minFwMajor: 3,
|
||||
minFwMinor: 4
|
||||
},
|
||||
HEALTH: {
|
||||
platforms: ['basalt', 'chalk', 'diorite', 'emery'],
|
||||
minFwMajor: 3,
|
||||
minFwMinor: 10
|
||||
},
|
||||
RECT: {
|
||||
platforms: ['aplite', 'basalt', 'diorite', 'emery'],
|
||||
minFwMajor: 0,
|
||||
minFwMinor: 0
|
||||
},
|
||||
ROUND: {
|
||||
platforms: ['chalk'],
|
||||
minFwMajor: 0,
|
||||
minFwMinor: 0
|
||||
},
|
||||
DISPLAY_144x168: {
|
||||
platforms: ['aplite', 'basalt', 'diorite'],
|
||||
minFwMajor: 0,
|
||||
minFwMinor: 0
|
||||
},
|
||||
DISPLAY_180x180_ROUND: {
|
||||
platforms: ['chalk'],
|
||||
minFwMajor: 0,
|
||||
minFwMinor: 0
|
||||
},
|
||||
DISPLAY_200x228: {
|
||||
platforms: ['emery'],
|
||||
minFwMajor: 0,
|
||||
minFwMinor: 0
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks if all of the provided capabilities are compatible with the watch
|
||||
* @param {Object} activeWatchInfo
|
||||
* @param {Array<string>} [capabilities]
|
||||
* @return {boolean}
|
||||
*/
|
||||
module.exports.includesCapability = function(activeWatchInfo, capabilities) {
|
||||
var notRegex = /^NOT_/;
|
||||
var result = [];
|
||||
|
||||
if (!capabilities || !capabilities.length) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (var i = capabilities.length - 1; i >= 0; i--) {
|
||||
var capability = capabilities[i];
|
||||
var mapping = module.exports.capabilityMap[capability.replace(notRegex, '')];
|
||||
|
||||
if (!mapping ||
|
||||
mapping.platforms.indexOf(activeWatchInfo.platform) === -1 ||
|
||||
mapping.minFwMajor > activeWatchInfo.firmware.major ||
|
||||
mapping.minFwMajor === activeWatchInfo.firmware.major &&
|
||||
mapping.minFwMinor > activeWatchInfo.firmware.minor
|
||||
) {
|
||||
result.push(!!capability.match(notRegex));
|
||||
} else {
|
||||
result.push(!capability.match(notRegex));
|
||||
}
|
||||
}
|
||||
|
||||
return result.indexOf(false) === -1;
|
||||
};
|
||||
|
||||
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
|
||||
|
||||
@@ -67,6 +67,12 @@ h6 {
|
||||
@include font-size(0.8);
|
||||
}
|
||||
|
||||
input {
|
||||
font-family: inherit;
|
||||
font-size: inherit;
|
||||
line-height: inherit;
|
||||
}
|
||||
|
||||
label {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
@@ -107,6 +113,7 @@ label {
|
||||
|
||||
.tap-highlight {
|
||||
@include tap-highlight();
|
||||
border-radius: $border-radius;
|
||||
}
|
||||
|
||||
.component {
|
||||
@@ -183,6 +190,7 @@ label {
|
||||
padding: 0 $item-spacing-h $item-spacing-v ;
|
||||
@include font-size(0.9);
|
||||
color: $color-gray-9;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.inputs {
|
||||
|
||||
@@ -11,8 +11,6 @@ $item-spacing-v: $base-height / 2;
|
||||
$item-spacing-h: 0.75rem;
|
||||
$small-component-width: $base-height * $golden;
|
||||
|
||||
|
||||
|
||||
// ---- Colors ------
|
||||
$color-orange: #ff4700;
|
||||
$color-orange-dark: #993d19;
|
||||
@@ -34,7 +32,8 @@ $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;
|
||||
$box-shadow-small-components: 0 0.1rem 0.1rem $color-gray-1;
|
||||
$box-shadow-large-components: 0 rem(3px) rem(15px) rgba(0,0,0,0.4);
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
.component-button {
|
||||
text-align: center;
|
||||
|
||||
.section & {
|
||||
padding-bottom: 0;
|
||||
}
|
||||
|
||||
.description {
|
||||
padding-left: 0;
|
||||
padding-right: 0;
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@
|
||||
border-radius: $base-height / 2;
|
||||
box-shadow: $box-shadow-small-components;
|
||||
display: block;
|
||||
background: #000;
|
||||
}
|
||||
|
||||
.picker-wrap {
|
||||
@@ -20,17 +21,25 @@
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
position: fixed;
|
||||
padding: 1rem;
|
||||
background: rgba(0,0,0,0.7);
|
||||
padding: $item-spacing-v $item-spacing-h /2;
|
||||
background: rgba(0, 0, 0, 0.65);
|
||||
opacity: 0;
|
||||
transition: opacity 70ms ease-in 175ms;
|
||||
transition: opacity 100ms ease-in 175ms;
|
||||
pointer-events: none;
|
||||
z-index: 100;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
|
||||
.picker {
|
||||
padding: 1rem;
|
||||
background: $color-gray-11;
|
||||
padding: $item-spacing-v $item-spacing-h;
|
||||
background: $color-gray-4;
|
||||
box-shadow: $box-shadow-large-components;
|
||||
border-radius: $border-radius;
|
||||
width: 100%;
|
||||
max-width: 26rem;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
&.show {
|
||||
@@ -46,7 +55,6 @@
|
||||
height: 0;
|
||||
width: 100%;
|
||||
padding: 0 0 100% 0; // overridden with inline style
|
||||
margin: 0.6em 0 0;
|
||||
|
||||
.color-box-container {
|
||||
position: absolute;
|
||||
@@ -77,7 +85,7 @@
|
||||
}
|
||||
|
||||
&.selected {
|
||||
transform: scale(1.15);
|
||||
transform: scale(1.1);
|
||||
border-radius: $border-radius;
|
||||
box-shadow: #111 0 0 0.24rem;
|
||||
position: relative;
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
vertical-align: baseline;
|
||||
color: $color-white;
|
||||
font-size: inherit;
|
||||
appearance: none;
|
||||
min-height: $item-spacing-v + ($base-height + 0rem) ;
|
||||
|
||||
@include placeholder {
|
||||
color: $color-gray-8;
|
||||
|
||||
@@ -35,7 +35,6 @@
|
||||
right: 0;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
background: #000;
|
||||
width: 100%;
|
||||
border: none;
|
||||
margin:0;
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
@import "clay";
|
||||
|
||||
.component-slider {
|
||||
|
||||
.section & {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
label {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.label-container {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
padding-bottom: $item-spacing-v;
|
||||
}
|
||||
|
||||
.label {
|
||||
flex: 1;
|
||||
min-width: 1rem;
|
||||
display: block;
|
||||
padding-right: $item-spacing-h;
|
||||
}
|
||||
|
||||
.value-wrap {
|
||||
display: block;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.value,
|
||||
.value-pad {
|
||||
display: block;
|
||||
background: $color-gray-2;
|
||||
border-radius: $border-radius;
|
||||
padding: $item-spacing-v / 2 $item-spacing-h / 2;
|
||||
border: none;
|
||||
vertical-align: baseline;
|
||||
color: $color-white;
|
||||
text-align: right;
|
||||
margin: 0;
|
||||
min-width: 1rem;
|
||||
}
|
||||
|
||||
.value-pad {
|
||||
visibility: hidden;
|
||||
|
||||
&:before {
|
||||
content: ' ';
|
||||
display: inline-block;
|
||||
}
|
||||
}
|
||||
|
||||
.value {
|
||||
max-width: 100%;
|
||||
position: absolute;
|
||||
left:0;
|
||||
top:0
|
||||
}
|
||||
|
||||
.input-wrap {
|
||||
padding: 0 $item-spacing-h $item-spacing-v;
|
||||
}
|
||||
|
||||
.input {
|
||||
$track-height: rem(3px);
|
||||
|
||||
display: block;
|
||||
position: relative;
|
||||
min-width: 100%;
|
||||
height: $base-height;
|
||||
overflow: hidden;
|
||||
margin-left: 0;
|
||||
|
||||
&:before {
|
||||
content: '';
|
||||
display: block;
|
||||
position: absolute;
|
||||
height: $track-height;
|
||||
background: $color-gray-6;
|
||||
width: 100%;
|
||||
top: $base-height / 2 - $track-height / 2;
|
||||
}
|
||||
|
||||
.slider {
|
||||
display: block;
|
||||
width: 100%;
|
||||
appearance: none;
|
||||
position: relative;
|
||||
height: $base-height;
|
||||
margin: 0;
|
||||
background-color: transparent;
|
||||
|
||||
&:focus {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
&::-webkit-slider-runnable-track {
|
||||
border: none;
|
||||
height: $base-height;
|
||||
width: 100%;
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
&::-webkit-slider-thumb {
|
||||
appearance: none;
|
||||
position: relative;
|
||||
height: $base-height;
|
||||
width: $base-height;
|
||||
background-color: $color-orange;
|
||||
border-radius: 50%;
|
||||
|
||||
&:before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
left: -1000px;
|
||||
top: $base-height / 2 - $track-height / 2;
|
||||
height: $track-height;
|
||||
width: 1001px;
|
||||
background: $color-orange;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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>
|
||||
@@ -8,7 +8,6 @@
|
||||
type="checkbox"
|
||||
value="{{this.value}}"
|
||||
name="clay-{{clayId}}"
|
||||
data-manipulator-target
|
||||
{{each key: attributes}}{{key}}="{{this}}"{{/each}}
|
||||
/>
|
||||
<i></i>
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
type="radio"
|
||||
value="{{this.value}}"
|
||||
name="clay-{{clayId}}"
|
||||
data-manipulator-target
|
||||
{{each key: attributes}}{{key}}="{{this}}"{{/each}}
|
||||
/>
|
||||
<i></i>
|
||||
|
||||
@@ -4,7 +4,15 @@
|
||||
<span class="value"></span>
|
||||
<select data-manipulator-target {{each key: attributes}}{{key}}="{{this}}"{{/each}}>
|
||||
{{each options}}
|
||||
<option value="{{this.value}}" class="item-select-option">{{this.label}}</option>
|
||||
{{if Array.isArray(this.value)}}
|
||||
<optgroup label="{{this.label}}">
|
||||
{{each this.value}}
|
||||
<option value="{{this.value}}" class="item-select-option">{{this.label}}</option>
|
||||
{{/each}}
|
||||
</optgroup>
|
||||
{{else}}
|
||||
<option value="{{this.value}}" class="item-select-option">{{this.label}}</option>
|
||||
{{/if}}
|
||||
{{/each}}
|
||||
</select>
|
||||
</label>
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<div class="component component-slider">
|
||||
<label class="tap-highlight">
|
||||
<span class="label-container">
|
||||
<span class="label">{{{label}}}</span>
|
||||
<span class="value-wrap">
|
||||
<span class="value-pad"></span>
|
||||
<input type="text" class="value" />
|
||||
</span>
|
||||
</span>
|
||||
<span class="input">
|
||||
<input
|
||||
data-manipulator-target
|
||||
class="slider"
|
||||
type="range"
|
||||
min="{{min}}"
|
||||
max="{{max}}"
|
||||
step="{{step}}"
|
||||
{{each key: attributes}}{{key}}="{{this}}"{{/each}}
|
||||
/>
|
||||
</span>
|
||||
</label>
|
||||
{{if description}}
|
||||
<div class="description">{{{description}}}</div>
|
||||
{{/if}}
|
||||
</div>
|
||||
+17
-6
@@ -11,12 +11,13 @@ var componentRegistry = require('../src/scripts/lib/component-registry');
|
||||
var idCounter = 0;
|
||||
|
||||
/**
|
||||
* @param {Object} [extra] - add/replace keys in the meta
|
||||
* @returns {{accountToken: string, watchToken: string, activeWatchInfo: {platform:
|
||||
* string, model: string, language: string, firmware: {major: number, minor:
|
||||
* number, patch: number, suffix: string}}}}
|
||||
* number, patch: number, suffix: string}}, userData: {}}}
|
||||
*/
|
||||
module.exports.meta = function() {
|
||||
return {
|
||||
module.exports.meta = function(extra) {
|
||||
var result = {
|
||||
accountToken: '0123456789abcdef0123456789abcdef',
|
||||
watchToken: '0123456789abcdef0123456789abcdef',
|
||||
activeWatchInfo: {
|
||||
@@ -29,8 +30,15 @@ module.exports.meta = function() {
|
||||
patch: 2,
|
||||
suffix: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
userData: {}
|
||||
};
|
||||
|
||||
_.eachObj(extra || {}, function(key, val) {
|
||||
result[key] = val;
|
||||
});
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -87,14 +95,15 @@ module.exports.config = function(types, autoRegister) {
|
||||
* @param {boolean} [build=true] - run the build method on the result
|
||||
* @param {boolean} [autoRegister=true]
|
||||
* @param {Object} [settings] - settings to pass to constructor
|
||||
* @param {Object} [meta] - override the meta
|
||||
* @returns {ClayConfig}
|
||||
*/
|
||||
module.exports.clayConfig = function(types, build, autoRegister, settings) {
|
||||
module.exports.clayConfig = function(types, build, autoRegister, settings, meta) {
|
||||
var clayConfig = new ClayConfig(
|
||||
settings || {},
|
||||
module.exports.config(types, autoRegister),
|
||||
$(HTML('<div>')),
|
||||
module.exports.meta()
|
||||
module.exports.meta(meta)
|
||||
);
|
||||
return build === false ? clayConfig : clayConfig.build();
|
||||
};
|
||||
@@ -106,6 +115,8 @@ module.exports.clayConfig = function(types, build, autoRegister, settings) {
|
||||
* @param {Object} [options] - Additional options to pass to Clay
|
||||
* @param {boolean} [options.autoHandleEvents] - If false, Clay will not
|
||||
* automatically handle the 'showConfiguration' and 'webviewclosed' events
|
||||
* @param {*} [options.userData={}] - Arbitrary data to pass to the config page. Will
|
||||
* be available as `clayConfig.meta.userData`
|
||||
* @param {boolean} [destroyLocalStorage=true]
|
||||
* @return {Clay}
|
||||
*/
|
||||
|
||||
@@ -12,6 +12,12 @@ module.exports = function(config) {
|
||||
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
|
||||
frameworks: ['browserify', 'source-map-support', 'mocha'],
|
||||
|
||||
client: {
|
||||
mocha: {
|
||||
timeout: 10000 // 10 sec because Travis struggles sometimes.
|
||||
}
|
||||
},
|
||||
|
||||
browserify: {
|
||||
debug: true,
|
||||
transform: [
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
{
|
||||
"env": {
|
||||
"mocha": true
|
||||
},
|
||||
"rules": {
|
||||
"max-params": [0]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,48 @@
|
||||
var assert = require('chai').assert;
|
||||
var fixture = require('../../fixture');
|
||||
|
||||
var sunlightColorMap = {
|
||||
'000000': '000000', '000055': '001e41', '0000aa': '004387', '0000ff': '0068ca',
|
||||
'005500': '2b4a2c', '005555': '27514f', '0055aa': '16638d', '0055ff': '007dce',
|
||||
'00aa00': '5e9860', '00aa55': '5c9b72', '00aaaa': '57a5a2', '00aaff': '4cb4db',
|
||||
'00ff00': '8ee391', '00ff55': '8ee69e', '00ffaa': '8aebc0', '00ffff': '84f5f1',
|
||||
'550000': '4a161b', '550055': '482748', '5500aa': '40488a', '5500ff': '2f6bcc',
|
||||
'555500': '564e36', '555555': '545454', '5555aa': '4f6790', '5555ff': '4180d0',
|
||||
'55aa00': '759a64', '55aa55': '759d76', '55aaaa': '71a6a4', '55aaff': '69b5dd',
|
||||
'55ff00': '9ee594', '55ff55': '9de7a0', '55ffaa': '9becc2', '55ffff': '95f6f2',
|
||||
'aa0000': '99353f', 'aa0055': '983e5a', 'aa00aa': '955694', 'aa00ff': '8f74d2',
|
||||
'aa5500': '9d5b4d', 'aa5555': '9d6064', 'aa55aa': '9a7099', 'aa55ff': '9587d5',
|
||||
'aaaa00': 'afa072', 'aaaa55': 'aea382', 'aaaaaa': 'ababab', 'ffffff': 'ffffff',
|
||||
'aaaaff': 'a7bae2', 'aaff00': 'c9e89d', 'aaff55': 'c9eaa7', 'aaffaa': 'c7f0c8',
|
||||
'aaffff': 'c3f9f7', 'ff0000': 'e35462', 'ff0055': 'e25874', 'ff00aa': 'e16aa3',
|
||||
'ff00ff': 'de83dc', 'ff5500': 'e66e6b', 'ff5555': 'e6727c', 'ff55aa': 'e37fa7',
|
||||
'ff55ff': 'e194df', 'ffaa00': 'f1aa86', 'ffaa55': 'f1ad93', 'ffaaaa': 'efb5b8',
|
||||
'ffaaff': 'ecc3eb', 'ffff00': 'ffeeab', 'ffff55': 'fff1b5', 'ffffaa': 'fff6d3'
|
||||
};
|
||||
|
||||
/* eslint-disable comma-spacing, no-multi-spaces, max-len,
|
||||
standard/array-bracket-even-spacing */
|
||||
var standardLayouts = {
|
||||
COLOR: [
|
||||
[false , false , '55ff00', 'aaff55', false , 'ffff55', 'ffffaa', false , false ],
|
||||
[false , 'aaffaa', '55ff55', '00ff00', 'aaff00', 'ffff00', 'ffaa55', 'ffaaaa', false ],
|
||||
['55ffaa', '00ff55', '00aa00', '55aa00', 'aaaa55', 'aaaa00', 'ffaa00', 'ff5500', 'ff5555'],
|
||||
['aaffff', '00ffaa', '00aa55', '55aa55', '005500', '555500', 'aa5500', 'ff0000', 'ff0055'],
|
||||
[false , '55aaaa', '00aaaa', '005555', 'ffffff', '000000', 'aa5555', 'aa0000', false ],
|
||||
['55ffff', '00ffff', '00aaff', '0055aa', 'aaaaaa', '555555', '550000', 'aa0055', 'ff55aa'],
|
||||
['55aaff', '0055ff', '0000ff', '0000aa', '000055', '550055', 'aa00aa', 'ff00aa', 'ffaaff'],
|
||||
[false , '5555aa', '5555ff', '5500ff', '5500aa', 'aa00ff', 'ff00ff', 'ff55ff', false ],
|
||||
[false , false , false , 'aaaaff', 'aa55ff', 'aa55aa', false , false , false ]
|
||||
],
|
||||
GRAY: [
|
||||
['000000', 'aaaaaa', 'ffffff']
|
||||
],
|
||||
BLACK_WHITE: [
|
||||
['000000', 'ffffff']
|
||||
]
|
||||
};
|
||||
/* eslint-enable */
|
||||
|
||||
/**
|
||||
* @param {ClayItem} colorItem
|
||||
* @returns {void}
|
||||
@@ -11,6 +53,182 @@ function openPicker(colorItem) {
|
||||
colorItem.$element.select('label')[0].click();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} hex
|
||||
* @returns {string} - eg: "rgb(1, 2, 3)"
|
||||
*/
|
||||
function hexToRgb(hex) {
|
||||
var result = /^(?:#|0x)?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
||||
return result ?
|
||||
'rgb(' +
|
||||
parseInt(result[1], 16) + ', ' +
|
||||
parseInt(result[2], 16) + ', ' +
|
||||
parseInt(result[3], 16) + ')' :
|
||||
hex;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number|string} value
|
||||
* @returns {string}
|
||||
*/
|
||||
function normalizeColor(value) {
|
||||
switch (typeof value) {
|
||||
case 'number': value = value.toString(16); break;
|
||||
case 'string': value = value.replace(/^#|^0x/, ''); break;
|
||||
}
|
||||
return value || '000000';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Array.<Array>} layout
|
||||
* @returns {Array}
|
||||
*/
|
||||
function flattenLayout(layout) {
|
||||
return layout.reduce(function(a, b) {
|
||||
return a.concat(b);
|
||||
}, []);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Array|string} [layout=color]
|
||||
* @param {Array} [expectedColors]
|
||||
* @return {void}
|
||||
*/
|
||||
function testCustomLayout(layout, expectedColors) {
|
||||
|
||||
describe('layout: ' + JSON.stringify(layout || 'default'), function() {
|
||||
|
||||
describe('Normal', function() {
|
||||
testColors(false, layout, expectedColors);
|
||||
});
|
||||
|
||||
describe('Sunlight', function() {
|
||||
testColors(true, layout, expectedColors);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} platform
|
||||
* @param {Array} layout
|
||||
* @param {boolean} allowGray
|
||||
* @param {string} desc
|
||||
* @param {Object} activeWatchInfo
|
||||
* @return {void}
|
||||
*/
|
||||
function testAutoLayout(platform, layout, allowGray, desc, activeWatchInfo) {
|
||||
it('chooses the best layout for the ' + (desc || platform) +
|
||||
' platform when allowGray is ' + allowGray,
|
||||
function() {
|
||||
var clayConfig = fixture.clayConfig(
|
||||
[{type: 'color', allowGray: allowGray}],
|
||||
true,
|
||||
true,
|
||||
{},
|
||||
{
|
||||
activeWatchInfo: activeWatchInfo
|
||||
}
|
||||
);
|
||||
var colorItem = clayConfig.getItemsByType('color')[0];
|
||||
assert.deepEqual(colorItem._layout, layout);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number|string} input
|
||||
* @param {number} expected
|
||||
* @param {array|string} layout
|
||||
* @return {void}
|
||||
*/
|
||||
function testClosestToLayout(input, expected, layout) {
|
||||
it('rounds ' + input + ' to ' + expected.toString(16) +
|
||||
' in layout: ' + JSON.stringify(layout),
|
||||
function() {
|
||||
var clayConfig;
|
||||
var colorItem;
|
||||
|
||||
clayConfig = fixture.clayConfig([{
|
||||
type: 'color',
|
||||
sunlight: false,
|
||||
layout: layout
|
||||
}]);
|
||||
colorItem = clayConfig.getItemsByType('color')[0];
|
||||
colorItem.set(input);
|
||||
assert.strictEqual(colorItem.get(), expected);
|
||||
|
||||
clayConfig = fixture.clayConfig([{
|
||||
type: 'color',
|
||||
sunlight: false,
|
||||
layout: layout
|
||||
}]);
|
||||
colorItem = clayConfig.getItemsByType('color')[0];
|
||||
colorItem.set(input);
|
||||
assert.strictEqual(colorItem.get(), expected);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {boolean} sunlight
|
||||
* @param {Array|string} [layout=color]
|
||||
* @param {Array} [expectedColors]
|
||||
* @return {void}
|
||||
*/
|
||||
function testColors(sunlight, layout, expectedColors) {
|
||||
var clayConfig;
|
||||
var colorItem;
|
||||
var $colorBoxes;
|
||||
var colors;
|
||||
|
||||
beforeEach(function() {
|
||||
clayConfig = fixture.clayConfig([
|
||||
{
|
||||
type: 'color',
|
||||
layout: layout,
|
||||
sunlight: sunlight
|
||||
}
|
||||
]);
|
||||
colorItem = clayConfig.getItemsByType('color')[0];
|
||||
|
||||
layout = layout || 'COLOR';
|
||||
if (typeof layout === 'string') {
|
||||
layout = standardLayouts[layout];
|
||||
}
|
||||
|
||||
colors = expectedColors || flattenLayout(layout);
|
||||
$colorBoxes = colorItem.$element.select('.color-box');
|
||||
});
|
||||
|
||||
it('Has the correct items in the layout', function() {
|
||||
colors.forEach(function(color, index) {
|
||||
if (color === false) {
|
||||
assert.strictEqual($colorBoxes[index].dataset.value, undefined);
|
||||
} else {
|
||||
assert.strictEqual(
|
||||
parseInt($colorBoxes[index].dataset.value, 10),
|
||||
parseInt(color || 0, 16)
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('sets the color correctly', function() {
|
||||
colors.forEach(function(color, index) {
|
||||
if (color === false) {
|
||||
assert.strictEqual(
|
||||
$colorBoxes[index].style.backgroundColor,
|
||||
'transparent'
|
||||
);
|
||||
} else {
|
||||
var normalizedColor = normalizeColor(color);
|
||||
assert.strictEqual(
|
||||
$colorBoxes[index].style.backgroundColor,
|
||||
hexToRgb(sunlight ? sunlightColorMap[normalizedColor] : normalizedColor)
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
describe('component - color', function() {
|
||||
it('shows the sunlit colors in the value display', function() {
|
||||
var clayConfig = fixture.clayConfig([
|
||||
@@ -105,4 +323,158 @@ describe('component - color', function() {
|
||||
$picker[0].click();
|
||||
assert.strictEqual($picker.get('classList').contains('show'), false);
|
||||
});
|
||||
|
||||
describe('color rounding', function() {
|
||||
var layout = 'GRAY';
|
||||
testClosestToLayout('000000', 0x000000, layout);
|
||||
testClosestToLayout('005500', 0x000000, layout);
|
||||
testClosestToLayout('55aa55', 0xaaaaaa, layout);
|
||||
testClosestToLayout('ffaaff', 0xaaaaaa, layout);
|
||||
testClosestToLayout('ffffaa', 0xffffff, layout);
|
||||
testClosestToLayout('ffffff', 0xffffff, layout);
|
||||
|
||||
layout = 'BLACK_WHITE';
|
||||
testClosestToLayout('000000', 0x000000, layout);
|
||||
testClosestToLayout('005500', 0x000000, layout);
|
||||
testClosestToLayout('55aa55', 0xffffff, layout);
|
||||
testClosestToLayout('ffaaff', 0xffffff, layout);
|
||||
testClosestToLayout('ffffaa', 0xffffff, layout);
|
||||
testClosestToLayout('ffffff', 0xffffff, layout);
|
||||
|
||||
layout = 'COLOR';
|
||||
testClosestToLayout('000000', 0x000000, layout);
|
||||
testClosestToLayout('005500', 0x005500, layout);
|
||||
testClosestToLayout('55bb55', 0x55aa55, layout);
|
||||
testClosestToLayout('ff99ff', 0xffaaff, layout);
|
||||
testClosestToLayout('ffffee', 0xffffff, layout);
|
||||
testClosestToLayout('ffffff', 0xffffff, layout);
|
||||
|
||||
layout = ['ff0000', 'ff5500', 'ff00ff', '00ff00', '555555'];
|
||||
testClosestToLayout('000000', 0x555555, layout);
|
||||
testClosestToLayout('ff0000', 0xff0000, layout);
|
||||
testClosestToLayout('ff1111', 0xff0000, layout);
|
||||
testClosestToLayout('00aa00', 0x00ff00, layout);
|
||||
testClosestToLayout('ff55ff', 0xff00ff, layout);
|
||||
testClosestToLayout('aaaaaa', 0x555555, layout);
|
||||
testClosestToLayout('ffffff', 0x555555, layout);
|
||||
});
|
||||
|
||||
describe('layouts', function() {
|
||||
|
||||
// allow gray does nothing for 2.x
|
||||
testAutoLayout('aplite', standardLayouts.BLACK_WHITE, true, 'aplite (2.x)',
|
||||
null
|
||||
);
|
||||
testAutoLayout('aplite', standardLayouts.BLACK_WHITE, true, 'aplite (2.x)', {
|
||||
platform: 'aplite',
|
||||
model: 'qemu_platform_aplite',
|
||||
language: 'en_US',
|
||||
firmware: {
|
||||
major: 2,
|
||||
minor: 10,
|
||||
patch: 0,
|
||||
suffix: ''
|
||||
}
|
||||
});
|
||||
testAutoLayout('aplite', standardLayouts.BLACK_WHITE, false, 'aplite (2.x)',
|
||||
null
|
||||
);
|
||||
testAutoLayout('aplite', standardLayouts.BLACK_WHITE, false, 'aplite (2.x)', {
|
||||
platform: 'aplite',
|
||||
model: 'qemu_platform_aplite',
|
||||
language: 'en_US',
|
||||
firmware: {
|
||||
major: 2,
|
||||
minor: 10,
|
||||
patch: 0,
|
||||
suffix: ''
|
||||
}
|
||||
});
|
||||
testAutoLayout('aplite', standardLayouts.BLACK_WHITE, false, 'aplite (3.x)', {
|
||||
platform: 'aplite',
|
||||
model: 'qemu_platform_aplite',
|
||||
language: 'en_US',
|
||||
firmware: {
|
||||
major: 3,
|
||||
minor: 10,
|
||||
patch: 0,
|
||||
suffix: ''
|
||||
}
|
||||
});
|
||||
testAutoLayout('aplite', standardLayouts.GRAY, true, 'aplite (3.x)', {
|
||||
platform: 'aplite',
|
||||
model: 'qemu_platform_aplite',
|
||||
language: 'en_US',
|
||||
firmware: {
|
||||
major: 3,
|
||||
minor: 10,
|
||||
patch: 0,
|
||||
suffix: ''
|
||||
}
|
||||
});
|
||||
testAutoLayout('basalt', standardLayouts.COLOR, true, '', {
|
||||
platform: 'basalt',
|
||||
model: 'qemu_platform_basalt',
|
||||
language: 'en_US',
|
||||
firmware: {
|
||||
major: 3,
|
||||
minor: 10,
|
||||
patch: 0,
|
||||
suffix: ''
|
||||
}
|
||||
});
|
||||
testAutoLayout('chalk', standardLayouts.COLOR, true, '', {
|
||||
platform: 'chalk',
|
||||
model: 'qemu_platform_chalk',
|
||||
language: 'en_US',
|
||||
firmware: {
|
||||
major: 3,
|
||||
minor: 10,
|
||||
patch: 0,
|
||||
suffix: ''
|
||||
}
|
||||
});
|
||||
|
||||
testCustomLayout();
|
||||
testCustomLayout('COLOR');
|
||||
testCustomLayout('GRAY');
|
||||
testCustomLayout('BLACK_WHITE');
|
||||
testCustomLayout(['aaffaa', '55ff55', '00ff00']);
|
||||
testCustomLayout([false, '55ff55', '00ff00']);
|
||||
testCustomLayout([['aaffaa', '55ff55', '00ff00']]);
|
||||
testCustomLayout(
|
||||
[['AAFFAA', '#55ff55', '0x00ff00', 0xff5500, null]],
|
||||
['aaffaa', '55ff55', '00ff00', 'ff5500', false]
|
||||
);
|
||||
testCustomLayout([
|
||||
['aaffaa', '55ff55', '00ff00'],
|
||||
['005555', 'ffffff', '000000']]
|
||||
);
|
||||
testCustomLayout([
|
||||
['aaffaa', '55ff55', '00ff00'],
|
||||
[false, 'ffffff', false]]
|
||||
);
|
||||
testCustomLayout(
|
||||
[
|
||||
['aaffaa', '55ff55', '00ff00'],
|
||||
[false, 'ffffff']
|
||||
],
|
||||
['aaffaa', '55ff55', '00ff00', false, 'ffffff', false]
|
||||
);
|
||||
testCustomLayout(
|
||||
[
|
||||
['aaffaa', '55ff55', false],
|
||||
[false, 'ffffff']
|
||||
],
|
||||
['aaffaa', '55ff55', false, false, 'ffffff', false]
|
||||
);
|
||||
testCustomLayout(
|
||||
[
|
||||
['aaffaa', '55ff55'],
|
||||
[false, 'ffffff', '000000']
|
||||
],
|
||||
['aaffaa', '55ff55', false, false, 'ffffff', '000000']
|
||||
);
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,6 +7,7 @@ var HTML = require('../../../src/scripts/vendor/minified').HTML;
|
||||
var components = require('../../../src/scripts/components');
|
||||
var manipulators = require('../../../src/scripts/lib/manipulators');
|
||||
var fixture = require('../../fixture');
|
||||
var sinon = require('sinon');
|
||||
|
||||
var componentSchema = Joi.object().keys({
|
||||
name: Joi.string().required(),
|
||||
@@ -39,6 +40,20 @@ describe('components', function() {
|
||||
it('is able to be passed to ClayConfig', function() {
|
||||
fixture.clayConfig([component.name]);
|
||||
});
|
||||
|
||||
it('only has one $manipulatorTarget', function() {
|
||||
var configItem = fixture.clayConfig([component.name]).getAllItems()[0];
|
||||
assert.strictEqual(configItem.$manipulatorTarget.length, 1);
|
||||
});
|
||||
|
||||
it('only dispatches change events once', function() {
|
||||
var configItem = fixture.clayConfig([component.name]).getAllItems()[0];
|
||||
var handler = sinon.spy();
|
||||
configItem.on('change', handler);
|
||||
configItem.trigger('change');
|
||||
assert.strictEqual(handler.callCount, 1);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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([
|
||||
{
|
||||
@@ -21,4 +21,26 @@ describe('component - color', function() {
|
||||
selectItem.set('value-2');
|
||||
assert.strictEqual($valueDisplay.get('innerHTML'), 'label 2');
|
||||
});
|
||||
|
||||
it('sets the value display to the correct value on change when using optgroups',
|
||||
function() {
|
||||
var clayConfig = fixture.clayConfig([
|
||||
{
|
||||
type: 'select',
|
||||
defaultValue: 'value-1',
|
||||
options: [
|
||||
{ label: 'label 1', value: 'value-1' },
|
||||
{ label: 'group', value: [
|
||||
{ label: 'label 2', value: 'value-2' },
|
||||
{ label: 'label 3', value: 'value-3' }
|
||||
]}
|
||||
]
|
||||
}
|
||||
]);
|
||||
var selectItem = clayConfig.getItemsByType('select')[0];
|
||||
var $valueDisplay = selectItem.$element.select('.value');
|
||||
assert.strictEqual($valueDisplay.get('innerHTML'), 'label 1');
|
||||
selectItem.set('value-2');
|
||||
assert.strictEqual($valueDisplay.get('innerHTML'), 'label 2');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var fixture = require('../../fixture');
|
||||
|
||||
describe('component - slider', function() {
|
||||
it('sets the value display to the correct value on set', function() {
|
||||
var clayConfig = fixture.clayConfig(['slider']);
|
||||
var sliderItem = clayConfig.getItemsByType('slider')[0];
|
||||
var $valueDisplay = sliderItem.$element.select('.value');
|
||||
var $valueDisplayPad = sliderItem.$element.select('.value-pad');
|
||||
|
||||
assert.strictEqual($valueDisplay.get('value'), '50');
|
||||
assert.strictEqual($valueDisplayPad.get('innerHTML'), '50');
|
||||
sliderItem.set(75);
|
||||
assert.strictEqual($valueDisplay.get('value'), '75');
|
||||
assert.strictEqual($valueDisplayPad.get('innerHTML'), '75');
|
||||
});
|
||||
|
||||
it('sets the value display to the correct value on slider change', function() {
|
||||
var clayConfig = fixture.clayConfig(['slider']);
|
||||
var sliderItem = clayConfig.getItemsByType('slider')[0];
|
||||
var $valueDisplay = sliderItem.$element.select('.value');
|
||||
var $valueDisplayPad = sliderItem.$element.select('.value-pad');
|
||||
var $slider = sliderItem.$element.select('.slider');
|
||||
|
||||
assert.strictEqual($valueDisplay.get('value'), '50');
|
||||
assert.strictEqual($valueDisplayPad.get('innerHTML'), '50');
|
||||
$slider.set('value', 75).trigger('change');
|
||||
assert.strictEqual($valueDisplay.get('value'), '75');
|
||||
assert.strictEqual($valueDisplayPad.get('innerHTML'), '75');
|
||||
});
|
||||
|
||||
it('sets the value-pad to the same value as what the user is typing', function() {
|
||||
var clayConfig = fixture.clayConfig(['slider']);
|
||||
var sliderItem = clayConfig.getItemsByType('slider')[0];
|
||||
var $valueDisplay = sliderItem.$element.select('.value');
|
||||
var $valueDisplayPad = sliderItem.$element.select('.value-pad');
|
||||
|
||||
assert.strictEqual($valueDisplay.get('value'), '50');
|
||||
assert.strictEqual($valueDisplayPad.get('innerHTML'), '50');
|
||||
$valueDisplay.set('value', 75).trigger('input');
|
||||
assert.strictEqual($valueDisplay.get('value'), '75');
|
||||
assert.strictEqual($valueDisplayPad.get('innerHTML'), '75');
|
||||
});
|
||||
|
||||
it('sets the slider to the correct value on user input', function() {
|
||||
var clayConfig = fixture.clayConfig(['slider']);
|
||||
var sliderItem = clayConfig.getItemsByType('slider')[0];
|
||||
var $valueDisplay = sliderItem.$element.select('.value');
|
||||
var $slider = sliderItem.$element.select('.slider');
|
||||
|
||||
assert.strictEqual($valueDisplay.get('value'), '50');
|
||||
assert.strictEqual($slider.get('value'), '50');
|
||||
$valueDisplay.set('value', 75).trigger('change');
|
||||
assert.strictEqual($slider.get('value'), '75');
|
||||
});
|
||||
|
||||
it('sets the precision correctly', function() {
|
||||
var clayConfig = fixture.clayConfig([{
|
||||
type: 'slider',
|
||||
step: 0.25
|
||||
}]);
|
||||
var sliderItem = clayConfig.getItemsByType('slider')[0];
|
||||
|
||||
assert.strictEqual(sliderItem.precision, 2);
|
||||
});
|
||||
|
||||
it('always displays decimal when precision is less than 1', function() {
|
||||
var clayConfig = fixture.clayConfig([{
|
||||
type: 'slider',
|
||||
step: 0.05
|
||||
}]);
|
||||
var sliderItem = clayConfig.getItemsByType('slider')[0];
|
||||
var $valueDisplay = sliderItem.$element.select('.value');
|
||||
var $valueDisplayPad = sliderItem.$element.select('.value-pad');
|
||||
var $slider = sliderItem.$element.select('.slider');
|
||||
|
||||
assert.strictEqual($valueDisplay.get('value'), '50.00');
|
||||
assert.strictEqual($valueDisplayPad.get('innerHTML'), '50.00');
|
||||
assert.strictEqual($slider.get('value'), '50');
|
||||
sliderItem.set(75);
|
||||
assert.strictEqual($valueDisplay.get('value'), '75.00');
|
||||
assert.strictEqual($valueDisplayPad.get('innerHTML'), '75.00');
|
||||
assert.strictEqual($slider.get('value'), '75');
|
||||
sliderItem.set(33.25);
|
||||
assert.strictEqual($valueDisplay.get('value'), '33.25');
|
||||
assert.strictEqual($valueDisplayPad.get('innerHTML'), '33.25');
|
||||
assert.strictEqual($slider.get('value'), '33.25');
|
||||
sliderItem.set(17.1);
|
||||
assert.strictEqual($valueDisplay.get('value'), '17.10');
|
||||
assert.strictEqual($valueDisplayPad.get('innerHTML'), '17.10');
|
||||
assert.strictEqual($slider.get('value'), '17.1');
|
||||
});
|
||||
});
|
||||
+202
-78
@@ -7,31 +7,19 @@ var standardComponents = require('../../src/scripts/components');
|
||||
var sinon = require('sinon');
|
||||
var toSource = require('tosource');
|
||||
|
||||
var accountToken = '0123456789abcdef0123456789abcdef';
|
||||
var watchToken = '0123456789abcdef0123456789abcdef';
|
||||
var activeWatchInfo = {
|
||||
platform: 'chalk',
|
||||
model: 'qemu_platform_chalk',
|
||||
language: 'en_US',
|
||||
firmware: {
|
||||
major: 3,
|
||||
minor: 3,
|
||||
patch: 2,
|
||||
suffix: ''
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {void}
|
||||
*/
|
||||
function stubPebble() {
|
||||
var meta = fixture.meta();
|
||||
|
||||
global.Pebble = {
|
||||
addEventListener: sinon.stub(),
|
||||
openURL: sinon.stub(),
|
||||
sendAppMessage: sinon.stub(),
|
||||
getActiveWatchInfo: sinon.stub().returns(activeWatchInfo),
|
||||
getAccountToken: sinon.stub().returns(accountToken),
|
||||
getWatchToken: sinon.stub().returns(watchToken)
|
||||
getActiveWatchInfo: sinon.stub().returns(meta.activeWatchInfo),
|
||||
getAccountToken: sinon.stub().returns(meta.accountToken),
|
||||
getWatchToken: sinon.stub().returns(meta.watchToken)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -74,8 +62,6 @@ describe('Clay', function() {
|
||||
|
||||
it('handles the "showConfiguration" event if autoHandleEvents is not false',
|
||||
function() {
|
||||
this.timeout(10000); // 10 seconds
|
||||
|
||||
stubPebble();
|
||||
var clay = fixture.clay([]);
|
||||
|
||||
@@ -135,6 +121,15 @@ describe('Clay', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('.config', function() {
|
||||
it('is a copy not a reference', function() {
|
||||
var config = fixture.config(['input', 'text', 'color']);
|
||||
var clay = fixture.clay(config);
|
||||
assert.notStrictEqual(clay.config, config);
|
||||
assert.deepEqual(clay.config, config);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.registerComponent()', function() {
|
||||
it('adds the component to the this.components', function() {
|
||||
var clay = fixture.clay([]);
|
||||
@@ -156,7 +151,7 @@ describe('Clay', function() {
|
||||
* @returns {string}
|
||||
*/
|
||||
function decodeUrl(url) {
|
||||
return atob(decodeURIComponent(url.replace(/^.*?[#,]/, '')));
|
||||
return decodeURIComponent(url.replace(/^.*?[#,]/, ''));
|
||||
}
|
||||
|
||||
describe('string substitutions', function() {
|
||||
@@ -235,13 +230,21 @@ describe('Clay', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('.getSettings()', function() {
|
||||
describe('.getSettings', function() {
|
||||
it('stores the response to localStorage and returns the decoded data',
|
||||
function() {
|
||||
var clay = fixture.clay([]);
|
||||
var result = clay.getSettings('%7B%22appKey%22%3A%22value%22%7D');
|
||||
assert.equal(localStorage.getItem('clay-settings'), '{"appKey":"value"}');
|
||||
assert.deepEqual(result, {appKey: 'value'});
|
||||
var settings = encodeURIComponent(JSON.stringify({
|
||||
key1: 'value1',
|
||||
key2: {value: 'value2'}
|
||||
}));
|
||||
var expected = {
|
||||
key1: 'value1',
|
||||
key2: 'value2'
|
||||
};
|
||||
var result = clay.getSettings(settings);
|
||||
assert.equal(localStorage.getItem('clay-settings'), JSON.stringify(expected));
|
||||
assert.deepEqual(result, expected);
|
||||
});
|
||||
|
||||
it('does not store the response if it is invalid JSON and logs an error',
|
||||
@@ -254,43 +257,95 @@ describe('Clay', function() {
|
||||
}, /Not Valid JSON/i);
|
||||
assert.equal(localStorage.getItem('clay-settings'), '{"appKey":"value"}');
|
||||
});
|
||||
|
||||
it('Prepares the settings for sendAppMessage', function() {
|
||||
var clay = fixture.clay([]);
|
||||
var response = encodeURIComponent(JSON.stringify({
|
||||
test1: false,
|
||||
test2: 'val-2',
|
||||
test3: true,
|
||||
test4: ['cb-1', 'cb-3'],
|
||||
test5: 12345,
|
||||
test6: [1, 2, 3, 4],
|
||||
test7: [true, false, true],
|
||||
test8: {
|
||||
precision: 2,
|
||||
value: 12.34
|
||||
},
|
||||
test9: {
|
||||
precision: 1,
|
||||
value: [1, 2, 3, 4]
|
||||
}
|
||||
}));
|
||||
var expected = {
|
||||
test1: 0,
|
||||
test2: 'val-2',
|
||||
test3: 1,
|
||||
test4: ['cb-1', 0, 'cb-3', 0],
|
||||
test5: 12345,
|
||||
test6: [1, 2, 3, 4],
|
||||
test7: [1, 0, 1],
|
||||
test8: 1234,
|
||||
test9: [10, 20, 30, 40]
|
||||
};
|
||||
|
||||
assert.deepEqual(clay.getSettings(response), expected);
|
||||
});
|
||||
|
||||
it('does not prepare the settings for sendAppMessage if convert is false',
|
||||
function() {
|
||||
var clay = fixture.clay([]);
|
||||
var settings = {
|
||||
test1: false,
|
||||
test2: 'val-2',
|
||||
test3: true,
|
||||
test4: ['cb-1', 'cb-3'],
|
||||
test5: 12345,
|
||||
test6: [1, 2, 3, 4],
|
||||
test7: [true, false, true],
|
||||
test8: {
|
||||
precision: 2,
|
||||
value: 12.34
|
||||
}
|
||||
};
|
||||
var response = encodeURIComponent(JSON.stringify(settings));
|
||||
|
||||
assert.deepEqual(clay.getSettings(response, false), settings);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.meta', function() {
|
||||
var emptyMeta = {
|
||||
activeWatchInfo: null,
|
||||
accountToken: '',
|
||||
watchToken: ''
|
||||
watchToken: '',
|
||||
userData: {}
|
||||
};
|
||||
|
||||
it('populates the meta in the showConfiguration handler', function() {
|
||||
stubPebble();
|
||||
var clay = fixture.clay([]);
|
||||
var userData = {foo: 'bar'};
|
||||
var clay = fixture.clay([], null, {userData: userData});
|
||||
|
||||
// meta only gets populated after showConfiguration happens
|
||||
assert.deepEqual(clay.meta, emptyMeta);
|
||||
Pebble.addEventListener.withArgs('showConfiguration').callArg(1);
|
||||
|
||||
assert.deepEqual(clay.meta, {
|
||||
activeWatchInfo: activeWatchInfo,
|
||||
accountToken: accountToken,
|
||||
watchToken: watchToken
|
||||
});
|
||||
assert.deepEqual(clay.meta, fixture.meta({userData: userData}));
|
||||
});
|
||||
|
||||
it('populates the meta in the ready handler', function() {
|
||||
stubPebble();
|
||||
var clay = fixture.clay([], null, {autoHandleEvents: false});
|
||||
var userData = {foo: 'bar'};
|
||||
var clay = fixture.clay([], null, {
|
||||
autoHandleEvents: false,
|
||||
userData: userData
|
||||
});
|
||||
|
||||
// meta only gets populated after ready happens
|
||||
assert.deepEqual(clay.meta, emptyMeta);
|
||||
Pebble.addEventListener.withArgs('ready').callArg(1);
|
||||
|
||||
assert.deepEqual(clay.meta, {
|
||||
activeWatchInfo: activeWatchInfo,
|
||||
accountToken: accountToken,
|
||||
watchToken: watchToken
|
||||
});
|
||||
assert.deepEqual(clay.meta, fixture.meta({userData: userData}));
|
||||
});
|
||||
|
||||
it('populates the meta with with empty values when there is no Pebble global',
|
||||
@@ -303,49 +358,118 @@ describe('Clay', function() {
|
||||
});
|
||||
|
||||
describe('Clay.encodeDataUri()', function() {
|
||||
|
||||
/**
|
||||
* @return {void}
|
||||
*/
|
||||
function testEncodeDataUri() {
|
||||
it('adds the correct prefix', function() {
|
||||
assert.equal(Clay.encodeDataUri('test', 'prefix:'), 'prefix:dGVzdA%3D%3D');
|
||||
assert.equal(
|
||||
Clay.encodeDataUri('test'),
|
||||
'data:text/html;base64,dGVzdA%3D%3D'
|
||||
);
|
||||
});
|
||||
|
||||
it('encodes the data correctly', function() {
|
||||
assert.equal(Clay.encodeDataUri('test', ''), 'dGVzdA%3D%3D');
|
||||
assert.equal(Clay.encodeDataUri('test{2}', ''), 'dGVzdHsyfQ%3D%3D');
|
||||
assert.equal(Clay.encodeDataUri('test{10}', ''), 'dGVzdHsxMH0%3D');
|
||||
});
|
||||
|
||||
it('throws if the input is invalid', function() {
|
||||
assert.throws(function() {
|
||||
Clay.encodeDataUri('♥');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
describe('native', function() {
|
||||
testEncodeDataUri();
|
||||
it('adds the correct prefix', function() {
|
||||
assert.equal(Clay.encodeDataUri('<test>', 'prefix:'), 'prefix:%3Ctest%3E');
|
||||
assert.equal(
|
||||
Clay.encodeDataUri('<test>'),
|
||||
'data:text/html;charset=utf-8,%3Ctest%3E'
|
||||
);
|
||||
});
|
||||
|
||||
describe('polyfill', function() {
|
||||
var btoaOriginal = window.btoa;
|
||||
|
||||
before(function() {
|
||||
window.btoa = undefined;
|
||||
});
|
||||
|
||||
testEncodeDataUri();
|
||||
|
||||
after(function() {
|
||||
window.btoa = btoaOriginal;
|
||||
});
|
||||
it('encodes the data correctly', function() {
|
||||
assert.equal(Clay.encodeDataUri('test', ''), 'test');
|
||||
assert.equal(Clay.encodeDataUri('test{2}', ''), 'test%7B2%7D');
|
||||
assert.equal(Clay.encodeDataUri('test{10}', ''), 'test%7B10%7D');
|
||||
});
|
||||
|
||||
it('does not throw if unicode character is provided', function() {
|
||||
assert.doesNotThrow(function() {
|
||||
Clay.encodeDataUri('♥');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('.prepareForAppMessage', function() {
|
||||
it('converts an array correctly when array contains numbers', function() {
|
||||
assert.deepEqual(Clay.prepareForAppMessage([1, 2, 3]), [1, 2, 3]);
|
||||
assert.deepEqual(Clay.prepareForAppMessage(
|
||||
{value: [1.5, 2.34, 3], precision: 2}),
|
||||
[150, 234, 300]
|
||||
);
|
||||
});
|
||||
|
||||
it('converts an array correctly when array contains booleans', function() {
|
||||
assert.deepEqual(Clay.prepareForAppMessage([true, false, true]), [1, 0, 1]);
|
||||
assert.deepEqual(
|
||||
Clay.prepareForAppMessage([{value: true}, false, true]),
|
||||
[1, 0, 1]);
|
||||
});
|
||||
|
||||
it('converts booleans to ints', function() {
|
||||
assert.strictEqual(Clay.prepareForAppMessage(false), 0);
|
||||
assert.strictEqual(Clay.prepareForAppMessage(true), 1);
|
||||
assert.strictEqual(Clay.prepareForAppMessage({value: false}), 0);
|
||||
assert.strictEqual(Clay.prepareForAppMessage({value: true}), 1);
|
||||
});
|
||||
|
||||
it('leaves strings alone', function() {
|
||||
assert.strictEqual(Clay.prepareForAppMessage('test'), 'test');
|
||||
assert.strictEqual(Clay.prepareForAppMessage({value: 'test'}), 'test');
|
||||
});
|
||||
|
||||
it('Multiples the number by the precision', function() {
|
||||
assert.strictEqual(Clay.prepareForAppMessage(123), 123);
|
||||
assert.strictEqual(Clay.prepareForAppMessage({
|
||||
value: 1.23,
|
||||
precision: 3
|
||||
}), 1230);
|
||||
assert.strictEqual(Clay.prepareForAppMessage({
|
||||
value: 123,
|
||||
precision: 2
|
||||
}), 12300);
|
||||
assert.strictEqual(Clay.prepareForAppMessage({
|
||||
value: 1.23456,
|
||||
precision: 4
|
||||
}), 12345);
|
||||
});
|
||||
|
||||
it('ignores precision for anything but numbers', function() {
|
||||
assert.strictEqual(Clay.prepareForAppMessage({
|
||||
value: 'not a number',
|
||||
precision: 3
|
||||
}), 'not a number');
|
||||
|
||||
assert.deepEqual(Clay.prepareForAppMessage({
|
||||
value: ['not', 'a', 'number'],
|
||||
precision: 3
|
||||
}), ['not', 'a', 'number']);
|
||||
});
|
||||
|
||||
it('treats an undefined precision as 0', function() {
|
||||
assert.strictEqual(Clay.prepareForAppMessage({
|
||||
value: 12.45,
|
||||
precision: undefined
|
||||
}), 12);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.prepareSettingsForAppMessage', function() {
|
||||
it('converts the settings correctly', function() {
|
||||
var settings = {
|
||||
test1: false,
|
||||
test2: 'val-2',
|
||||
test3: true,
|
||||
test4: ['cb-1', 'cb-3'],
|
||||
test5: 12345,
|
||||
test6: [1, 2, 3, 4],
|
||||
test7: [true, false, true],
|
||||
test8: {
|
||||
precision: 2,
|
||||
value: 12.34
|
||||
}
|
||||
};
|
||||
var expected = {
|
||||
test1: 0,
|
||||
test2: 'val-2',
|
||||
test3: 1,
|
||||
test4: ['cb-1', 0, 'cb-3', 0],
|
||||
test5: 12345,
|
||||
test6: [1, 2, 3, 4],
|
||||
test7: [1, 0, 1],
|
||||
test8: 1234
|
||||
};
|
||||
|
||||
assert.deepEqual(Clay.prepareSettingsForAppMessage(settings), expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+318
-24
@@ -15,7 +15,7 @@ describe('ClayConfig', function() {
|
||||
'getItemByAppKey',
|
||||
'getItemById',
|
||||
'getItemsByType',
|
||||
'getSettings',
|
||||
'serialize',
|
||||
'registerComponent',
|
||||
'build',
|
||||
'on',
|
||||
@@ -27,6 +27,191 @@ describe('ClayConfig', function() {
|
||||
checkReadOnly(clayConfig, properties);
|
||||
});
|
||||
|
||||
/**
|
||||
* Tests if the provided capabilities of the platform match
|
||||
* @param {string} platform
|
||||
* @param {number} fwMajor
|
||||
* @param {number} fwMinor
|
||||
* @param {Array} capabilities
|
||||
* @param {number} expected
|
||||
* @param {number} notExpected
|
||||
* @return {void}
|
||||
*/
|
||||
function testCapabilities(platform, fwMajor, fwMinor, capabilities, expected,
|
||||
notExpected) {
|
||||
it(platform + ' is' + (expected ? '' : ' not') + ' included on firmware ' +
|
||||
fwMajor + '.' + fwMinor + ' for capabilities ' + JSON.stringify(capabilities),
|
||||
function() {
|
||||
var item = {
|
||||
type: 'input',
|
||||
capabilities: capabilities
|
||||
};
|
||||
var meta = {
|
||||
activeWatchInfo: {
|
||||
platform: platform,
|
||||
model: 'qemu_platform_' + platform,
|
||||
language: 'en_US',
|
||||
firmware: {
|
||||
major: fwMajor,
|
||||
minor: fwMinor,
|
||||
patch: 0,
|
||||
suffix: ''
|
||||
}
|
||||
}
|
||||
};
|
||||
var clayConfig = fixtures.clayConfig([item], true, true, null, meta);
|
||||
|
||||
assert.strictEqual(clayConfig.getAllItems().length, expected);
|
||||
|
||||
// now we test the NOT_ prefix
|
||||
item.capabilities = item.capabilities.map(function(capability) {
|
||||
return 'NOT_' + capability.replace(/^NOT_/, '');
|
||||
});
|
||||
|
||||
notExpected = typeof notExpected !== 'undefined' ? notExpected : ~expected + 2;
|
||||
clayConfig = fixtures.clayConfig([item], true, true, null, meta);
|
||||
assert.strictEqual(clayConfig.getAllItems().length, notExpected);
|
||||
});
|
||||
}
|
||||
|
||||
describe('capability filtering', function() {
|
||||
testCapabilities('aplite', 2, 9, ['BW'], 1);
|
||||
testCapabilities('aplite', 2, 9, ['COLOR'], 0);
|
||||
testCapabilities('aplite', 2, 9, ['MICROPHONE'], 0);
|
||||
testCapabilities('aplite', 2, 9, ['SMARTSTRAP'], 0);
|
||||
testCapabilities('aplite', 2, 9, ['SMARTSTRAP_POWER'], 0);
|
||||
testCapabilities('aplite', 2, 9, ['HEALTH'], 0);
|
||||
testCapabilities('aplite', 2, 9, ['RECT'], 1);
|
||||
testCapabilities('aplite', 2, 9, ['ROUND'], 0);
|
||||
testCapabilities('aplite', 2, 9, ['DISPLAY_144x168'], 1);
|
||||
testCapabilities('aplite', 2, 9, ['DISPLAY_180x180_ROUND'], 0);
|
||||
testCapabilities('aplite', 2, 9, ['DISPLAY_200x228'], 0);
|
||||
testCapabilities('aplite', 2, 9, ['PLATFORM_APLITE'], 1);
|
||||
testCapabilities('aplite', 2, 9, ['PLATFORM_BASALT'], 0);
|
||||
testCapabilities('aplite', 2, 9, ['PLATFORM_CHALK'], 0);
|
||||
testCapabilities('aplite', 2, 9, ['PLATFORM_DIORITE'], 0);
|
||||
testCapabilities('aplite', 2, 9, ['PLATFORM_EMERY'], 0);
|
||||
|
||||
testCapabilities('aplite', 3, 10, ['BW'], 1);
|
||||
testCapabilities('aplite', 3, 10, ['COLOR'], 0);
|
||||
testCapabilities('aplite', 3, 10, ['MICROPHONE'], 0);
|
||||
testCapabilities('aplite', 3, 10, ['SMARTSTRAP'], 0);
|
||||
testCapabilities('aplite', 3, 4, ['SMARTSTRAP'], 0);
|
||||
testCapabilities('aplite', 3, 3, ['SMARTSTRAP'], 0);
|
||||
testCapabilities('aplite', 3, 10, ['SMARTSTRAP_POWER'], 0);
|
||||
testCapabilities('aplite', 3, 10, ['HEALTH'], 0);
|
||||
testCapabilities('aplite', 3, 9, ['HEALTH'], 0);
|
||||
testCapabilities('aplite', 3, 10, ['RECT'], 1);
|
||||
testCapabilities('aplite', 3, 10, ['ROUND'], 0);
|
||||
testCapabilities('aplite', 3, 10, ['DISPLAY_144x168'], 1);
|
||||
testCapabilities('aplite', 3, 10, ['DISPLAY_180x180_ROUND'], 0);
|
||||
testCapabilities('aplite', 3, 10, ['DISPLAY_200x228'], 0);
|
||||
testCapabilities('aplite', 3, 10, ['PLATFORM_APLITE'], 1);
|
||||
testCapabilities('aplite', 3, 10, ['PLATFORM_BASALT'], 0);
|
||||
testCapabilities('aplite', 3, 10, ['PLATFORM_CHALK'], 0);
|
||||
testCapabilities('aplite', 3, 10, ['PLATFORM_DIORITE'], 0);
|
||||
testCapabilities('aplite', 3, 10, ['PLATFORM_EMERY'], 0);
|
||||
|
||||
testCapabilities('basalt', 3, 10, ['BW'], 0);
|
||||
testCapabilities('basalt', 3, 10, ['COLOR'], 1);
|
||||
testCapabilities('basalt', 3, 10, ['MICROPHONE'], 1);
|
||||
testCapabilities('basalt', 3, 10, ['SMARTSTRAP'], 1);
|
||||
testCapabilities('basalt', 3, 4, ['SMARTSTRAP'], 1);
|
||||
testCapabilities('basalt', 3, 3, ['SMARTSTRAP'], 0);
|
||||
testCapabilities('basalt', 3, 10, ['SMARTSTRAP_POWER'], 1);
|
||||
testCapabilities('basalt', 3, 4, ['SMARTSTRAP_POWER'], 1);
|
||||
testCapabilities('basalt', 3, 3, ['SMARTSTRAP_POWER'], 0);
|
||||
testCapabilities('basalt', 3, 10, ['HEALTH'], 1);
|
||||
testCapabilities('basalt', 3, 9, ['HEALTH'], 0);
|
||||
testCapabilities('basalt', 3, 10, ['RECT'], 1);
|
||||
testCapabilities('basalt', 3, 10, ['ROUND'], 0);
|
||||
testCapabilities('basalt', 3, 10, ['DISPLAY_144x168'], 1);
|
||||
testCapabilities('basalt', 3, 10, ['DISPLAY_180x180_ROUND'], 0);
|
||||
testCapabilities('basalt', 3, 10, ['DISPLAY_200x228'], 0);
|
||||
testCapabilities('basalt', 3, 10, ['PLATFORM_APLITE'], 0);
|
||||
testCapabilities('basalt', 3, 10, ['PLATFORM_BASALT'], 1);
|
||||
testCapabilities('basalt', 3, 10, ['PLATFORM_CHALK'], 0);
|
||||
testCapabilities('basalt', 3, 10, ['PLATFORM_DIORITE'], 0);
|
||||
testCapabilities('basalt', 3, 10, ['PLATFORM_EMERY'], 0);
|
||||
|
||||
testCapabilities('chalk', 3, 10, ['BW'], 0);
|
||||
testCapabilities('chalk', 3, 10, ['COLOR'], 1);
|
||||
testCapabilities('chalk', 3, 10, ['MICROPHONE'], 1);
|
||||
testCapabilities('chalk', 3, 10, ['SMARTSTRAP'], 1);
|
||||
testCapabilities('chalk', 3, 4, ['SMARTSTRAP'], 1);
|
||||
testCapabilities('chalk', 3, 3, ['SMARTSTRAP'], 0);
|
||||
testCapabilities('chalk', 3, 10, ['SMARTSTRAP_POWER'], 1);
|
||||
testCapabilities('chalk', 3, 4, ['SMARTSTRAP_POWER'], 1);
|
||||
testCapabilities('chalk', 3, 3, ['SMARTSTRAP_POWER'], 0);
|
||||
testCapabilities('chalk', 3, 10, ['HEALTH'], 1);
|
||||
testCapabilities('chalk', 3, 9, ['HEALTH'], 0);
|
||||
testCapabilities('chalk', 3, 10, ['RECT'], 0);
|
||||
testCapabilities('chalk', 3, 10, ['ROUND'], 1);
|
||||
testCapabilities('chalk', 3, 10, ['DISPLAY_144x168'], 0);
|
||||
testCapabilities('chalk', 3, 10, ['DISPLAY_180x180_ROUND'], 1);
|
||||
testCapabilities('chalk', 3, 10, ['DISPLAY_200x228'], 0);
|
||||
testCapabilities('chalk', 3, 10, ['PLATFORM_APLITE'], 0);
|
||||
testCapabilities('chalk', 3, 10, ['PLATFORM_BASALT'], 0);
|
||||
testCapabilities('chalk', 3, 10, ['PLATFORM_CHALK'], 1);
|
||||
testCapabilities('chalk', 3, 10, ['PLATFORM_DIORITE'], 0);
|
||||
testCapabilities('chalk', 3, 10, ['PLATFORM_EMERY'], 0);
|
||||
|
||||
testCapabilities('diorite', 3, 10, ['BW'], 1);
|
||||
testCapabilities('diorite', 3, 10, ['COLOR'], 0);
|
||||
testCapabilities('diorite', 3, 10, ['MICROPHONE'], 1);
|
||||
testCapabilities('diorite', 3, 10, ['SMARTSTRAP'], 1);
|
||||
testCapabilities('diorite', 3, 4, ['SMARTSTRAP'], 1);
|
||||
testCapabilities('diorite', 3, 3, ['SMARTSTRAP'], 0);
|
||||
testCapabilities('diorite', 3, 10, ['SMARTSTRAP_POWER'], 0);
|
||||
testCapabilities('diorite', 3, 4, ['SMARTSTRAP_POWER'], 0);
|
||||
testCapabilities('diorite', 3, 3, ['SMARTSTRAP_POWER'], 0);
|
||||
testCapabilities('diorite', 3, 10, ['HEALTH'], 1);
|
||||
testCapabilities('diorite', 3, 9, ['HEALTH'], 0);
|
||||
testCapabilities('diorite', 3, 10, ['RECT'], 1);
|
||||
testCapabilities('diorite', 3, 10, ['ROUND'], 0);
|
||||
testCapabilities('diorite', 3, 10, ['DISPLAY_144x168'], 1);
|
||||
testCapabilities('diorite', 3, 10, ['DISPLAY_180x180_ROUND'], 0);
|
||||
testCapabilities('diorite', 3, 10, ['DISPLAY_200x228'], 0);
|
||||
testCapabilities('diorite', 3, 10, ['PLATFORM_APLITE'], 0);
|
||||
testCapabilities('diorite', 3, 10, ['PLATFORM_BASALT'], 0);
|
||||
testCapabilities('diorite', 3, 10, ['PLATFORM_CHALK'], 0);
|
||||
testCapabilities('diorite', 3, 10, ['PLATFORM_DIORITE'], 1);
|
||||
testCapabilities('diorite', 3, 10, ['PLATFORM_EMERY'], 0);
|
||||
|
||||
testCapabilities('emery', 3, 10, ['BW'], 0);
|
||||
testCapabilities('emery', 3, 10, ['COLOR'], 1);
|
||||
testCapabilities('emery', 3, 10, ['MICROPHONE'], 1);
|
||||
testCapabilities('emery', 3, 10, ['SMARTSTRAP'], 1);
|
||||
testCapabilities('emery', 3, 4, ['SMARTSTRAP'], 1);
|
||||
testCapabilities('emery', 3, 3, ['SMARTSTRAP'], 0);
|
||||
testCapabilities('emery', 3, 10, ['SMARTSTRAP_POWER'], 1);
|
||||
testCapabilities('emery', 3, 4, ['SMARTSTRAP_POWER'], 1);
|
||||
testCapabilities('emery', 3, 3, ['SMARTSTRAP_POWER'], 0);
|
||||
testCapabilities('emery', 3, 10, ['HEALTH'], 1);
|
||||
testCapabilities('emery', 3, 9, ['HEALTH'], 0);
|
||||
testCapabilities('emery', 3, 10, ['RECT'], 1);
|
||||
testCapabilities('emery', 3, 10, ['ROUND'], 0);
|
||||
testCapabilities('emery', 3, 10, ['DISPLAY_144x168'], 0);
|
||||
testCapabilities('emery', 3, 10, ['DISPLAY_180x180_ROUND'], 0);
|
||||
testCapabilities('emery', 3, 10, ['DISPLAY_200x228'], 1);
|
||||
testCapabilities('emery', 3, 10, ['PLATFORM_APLITE'], 0);
|
||||
testCapabilities('emery', 3, 10, ['PLATFORM_BASALT'], 0);
|
||||
testCapabilities('emery', 3, 10, ['PLATFORM_CHALK'], 0);
|
||||
testCapabilities('emery', 3, 10, ['PLATFORM_DIORITE'], 0);
|
||||
testCapabilities('emery', 3, 10, ['PLATFORM_EMERY'], 1);
|
||||
|
||||
testCapabilities('aplite', 3, 10, ['BW', 'HEALTH'], 0, 0);
|
||||
testCapabilities('emery', 3, 10, ['COLOR', 'HEALTH'], 1);
|
||||
testCapabilities('emery', 3, 10, ['MICROPHONE'], 1);
|
||||
testCapabilities('chalk', 3, 10, ['PLATFORM_APLITE', 'PLATFORM_BASALT'], 0);
|
||||
testCapabilities('basalt', 3, 10, ['SMARTSTRAP', 'SMARTSTRAP_POWER'], 1);
|
||||
testCapabilities('aplite', 3, 10, ['COLOR', 'PLATFORM_APLITE'], 0, 0);
|
||||
testCapabilities('aplite', 3, 10, ['PLATFORM_APLITE', 'COLOR'], 0, 0);
|
||||
testCapabilities('aplite', 3, 10, ['BW', 'NOT_COLOR'], 1, 0);
|
||||
testCapabilities('aplite', 3, 10, ['NOT_BASALT', 'RECT'], 1, 0);
|
||||
testCapabilities('aplite', 3, 10, ['NOT_CHALK', 'BW', 'PLATFORM_APLITE'], 1, 0);
|
||||
});
|
||||
|
||||
describe('.meta', function() {
|
||||
it('populates meta', function() {
|
||||
var clayConfig = fixtures.clayConfig(['input']);
|
||||
@@ -39,7 +224,7 @@ describe('ClayConfig', function() {
|
||||
'getItemByAppKey',
|
||||
'getItemById',
|
||||
'getItemsByType',
|
||||
'getSettings'
|
||||
'serialize'
|
||||
].forEach(function(method) {
|
||||
it('.' + method + '()', function() {
|
||||
var clayConfig = fixtures.clayConfig(['input', 'text'], false);
|
||||
@@ -99,37 +284,84 @@ describe('ClayConfig', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('.getSettings()', function() {
|
||||
describe('.serialize()', function() {
|
||||
it('returns the correct settings', function() {
|
||||
var clayConfig = fixtures.clayConfig(
|
||||
[
|
||||
{type: 'input', appKey: 'test1', defaultValue: 'default val'},
|
||||
{type: 'select', appKey: 'test2', options: [
|
||||
{label: 'label-1', value: 'val-1'},
|
||||
{label: 'label-2', value: 'val-2'}
|
||||
]},
|
||||
{type: 'toggle', appKey: 'test3'}
|
||||
],
|
||||
true,
|
||||
true,
|
||||
{
|
||||
test2: 'val-2' // set one of the values via settings
|
||||
}
|
||||
);
|
||||
var config = [
|
||||
{type: 'input', appKey: 'test1', defaultValue: 'default val'},
|
||||
{type: 'select', appKey: 'test2', options: [
|
||||
{label: 'label-1', value: 'val-1'},
|
||||
{label: 'label-2', value: 'val-2'}
|
||||
]},
|
||||
{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'}
|
||||
]},
|
||||
{type: 'slider', appKey: 'test5', step: 0.05, defaultValue: 12.5}
|
||||
];
|
||||
var settings = {
|
||||
test2: 'val-2'
|
||||
};
|
||||
|
||||
assert.deepEqual(clayConfig.getSettings(), {
|
||||
test1: 'default val',
|
||||
test2: 'val-2',
|
||||
test3: 0
|
||||
var clayConfig = fixtures.clayConfig(config, true, true, settings);
|
||||
|
||||
assert.deepEqual(clayConfig.serialize(), {
|
||||
test1: {value: 'default val'},
|
||||
test2: {value: 'val-2'},
|
||||
test3: {value: false},
|
||||
test4: {value: []},
|
||||
test5: {value: 12.5, precision: 2}
|
||||
});
|
||||
|
||||
clayConfig.getItemByAppKey('test1').set('val-1');
|
||||
clayConfig.getItemByAppKey('test3').set(true);
|
||||
clayConfig.getItemByAppKey('test4').set(['cb-1', 'cb-3']);
|
||||
|
||||
assert.deepEqual(clayConfig.getSettings(), {
|
||||
assert.deepEqual(clayConfig.serialize(), {
|
||||
test1: {value: 'val-1'},
|
||||
test2: {value: 'val-2'},
|
||||
test3: {value: true},
|
||||
test4: {value: ['cb-1', 'cb-3']},
|
||||
test5: {value: 12.5, precision: 2}
|
||||
});
|
||||
|
||||
// make sure the result of serialize() can actually be fed back in to
|
||||
// a new instance of ClayConfig
|
||||
var clay = fixtures.clay(config);
|
||||
var response = encodeURIComponent(JSON.stringify(clayConfig.serialize()));
|
||||
clay.getSettings(response);
|
||||
var loadedSettings = JSON.parse(localStorage.getItem('clay-settings'));
|
||||
|
||||
assert.deepEqual(loadedSettings, {
|
||||
test1: 'val-1',
|
||||
test2: 'val-2',
|
||||
test3: 1
|
||||
test3: true,
|
||||
test4: ['cb-1', 'cb-3'],
|
||||
test5: 12.5
|
||||
});
|
||||
assert.doesNotThrow(function() {
|
||||
fixtures.clayConfig(config, true, true, loadedSettings);
|
||||
});
|
||||
});
|
||||
|
||||
it('only returns the settings present in the config', function() {
|
||||
var config = [
|
||||
{type: 'input', appKey: 'test1', defaultValue: 'default val'},
|
||||
{type: 'select', appKey: 'test2', options: [
|
||||
{label: 'label-1', value: 'val-1'},
|
||||
{label: 'label-2', value: 'val-2'}
|
||||
]}
|
||||
];
|
||||
var settings = {
|
||||
test2: 'val-2',
|
||||
notInTheConfig: 'Should not exist'
|
||||
};
|
||||
|
||||
var clayConfig = fixtures.clayConfig(config, true, true, settings);
|
||||
assert.deepEqual(clayConfig.serialize(), {
|
||||
test1: {value: 'default val'},
|
||||
test2: {value: 'val-2'}
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -227,7 +459,69 @@ describe('ClayConfig', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('.destroy().', function() {
|
||||
it('Destroys all the items on the page and in the items array', function() {
|
||||
var clayConfig = fixtures.clayConfig(['input', 'text', 'input'], false);
|
||||
|
||||
clayConfig.build();
|
||||
clayConfig.destroy();
|
||||
|
||||
// this should throw because the config has not been built yet
|
||||
assert.throws(clayConfig.getAllItems);
|
||||
|
||||
// there should be no DOM inside the container
|
||||
assert.strictEqual(clayConfig.$rootContainer[0].children.length, 0);
|
||||
});
|
||||
|
||||
it('dispatches the BEFORE_DESTROY event at the right time', function(done) {
|
||||
var clayConfig = fixtures.clayConfig(['input', 'text', 'input'], false);
|
||||
|
||||
clayConfig.on(clayConfig.EVENTS.BEFORE_DESTROY, function() {
|
||||
assert.strictEqual(clayConfig.getAllItems().length, 3);
|
||||
done();
|
||||
});
|
||||
|
||||
clayConfig.build();
|
||||
clayConfig.destroy();
|
||||
|
||||
assert.strictEqual(clayConfig.getAllItems().length, 0);
|
||||
});
|
||||
|
||||
it('dispatches the AFTER_DESTROY event at the right time', function(done) {
|
||||
var clayConfig = fixtures.clayConfig(['input', 'text', 'input'], false);
|
||||
|
||||
clayConfig.on(clayConfig.EVENTS.AFTER_DESTROY, function() {
|
||||
|
||||
// this should throw because the config has not been built yet
|
||||
assert.throws(clayConfig.getAllItems);
|
||||
done();
|
||||
});
|
||||
|
||||
clayConfig.build();
|
||||
assert.strictEqual(clayConfig.getAllItems().length, 3);
|
||||
clayConfig.destroy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('.build()', function() {
|
||||
it('Destroys the config if called a consecutive time', function() {
|
||||
var clayConfig = fixtures.clayConfig(['input', 'text', 'input'], false);
|
||||
var destroyHandlerSpy = sinon.spy();
|
||||
|
||||
clayConfig.on(clayConfig.EVENTS.AFTER_DESTROY, destroyHandlerSpy);
|
||||
|
||||
clayConfig.build();
|
||||
assert.strictEqual(clayConfig.getAllItems().length, 3);
|
||||
|
||||
clayConfig.config = fixtures.config(['select']);
|
||||
clayConfig.build();
|
||||
assert.strictEqual(clayConfig.getAllItems().length, 1);
|
||||
assert(destroyHandlerSpy.calledOnce);
|
||||
|
||||
clayConfig.build();
|
||||
assert(destroyHandlerSpy.calledTwice);
|
||||
});
|
||||
|
||||
it('dispatches the BEFORE_BUILD event at the right time', function(done) {
|
||||
var clayConfig = fixtures.clayConfig(['input', 'text', 'input'], false);
|
||||
clayConfig.on(clayConfig.EVENTS.BEFORE_BUILD, function() {
|
||||
|
||||
@@ -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
|
||||
@@ -138,32 +143,67 @@ describe('manipulators', function() {
|
||||
}
|
||||
|
||||
describe('html', function() {
|
||||
testSetGet('text', 'test123');
|
||||
testShow('text');
|
||||
testHide('text');
|
||||
var type = 'text';
|
||||
testSetGet(type, 'test123');
|
||||
testSetGet(type, '<span>some HTML</span>');
|
||||
testShow(type);
|
||||
testHide(type);
|
||||
});
|
||||
|
||||
describe('button', function() {
|
||||
var type = 'button';
|
||||
testSetGet(type, 'test123');
|
||||
testSetGet(type, '<span>some HTML</span>');
|
||||
testDisable(type);
|
||||
testEnable(type);
|
||||
testShow(type);
|
||||
testHide(type);
|
||||
});
|
||||
|
||||
describe('val', function() {
|
||||
testSetGet('input', 'test321');
|
||||
testDisable('input');
|
||||
testEnable('input');
|
||||
testShow('text');
|
||||
testHide('text');
|
||||
var type = 'input';
|
||||
testSetGet(type, 'test321');
|
||||
testSetGet(type, 1234, '1234');
|
||||
testDisable(type);
|
||||
testEnable(type);
|
||||
testShow(type);
|
||||
testHide(type);
|
||||
});
|
||||
|
||||
describe('slider', function() {
|
||||
var type = {
|
||||
type: 'slider',
|
||||
min: 0,
|
||||
max: 100,
|
||||
step: 0.1
|
||||
};
|
||||
|
||||
testSetGet(type, '12', 12);
|
||||
testSetGet(type, 12);
|
||||
testSetGet(type, '12.3', 12.3);
|
||||
testSetGet(type, 12.3);
|
||||
testSetGet(type, 12.34, 12.3);
|
||||
testSetGet(type, '12.34', 12.3);
|
||||
testDisable(type);
|
||||
testEnable(type);
|
||||
testShow(type);
|
||||
testHide(type);
|
||||
});
|
||||
|
||||
describe('checked', function() {
|
||||
testSetGet('toggle', true, 1);
|
||||
testSetGet('toggle', 1);
|
||||
testSetGet('toggle', false, 0);
|
||||
testSetGet('toggle', 0);
|
||||
testDisable('toggle');
|
||||
testEnable('toggle');
|
||||
testShow('toggle');
|
||||
testHide('toggle');
|
||||
var type = 'toggle';
|
||||
testSetGet({type: type, defaultValue: false}, 1, true);
|
||||
testSetGet({type: type, defaultValue: false}, true);
|
||||
testSetGet({type: type, defaultValue: true}, 0, false);
|
||||
testSetGet({type: type, defaultValue: true}, false);
|
||||
testDisable(type);
|
||||
testEnable(type);
|
||||
testShow(type);
|
||||
testHide(type);
|
||||
});
|
||||
|
||||
describe('radiogroup', function() {
|
||||
var item = {
|
||||
var type = {
|
||||
type: 'radiogroup',
|
||||
clayId: 1,
|
||||
options: [
|
||||
@@ -172,47 +212,49 @@ describe('manipulators', function() {
|
||||
{ label: '3', value: 'three "quote' }
|
||||
]
|
||||
};
|
||||
testSetGet(item, 'one');
|
||||
testSetGet(item, 'two');
|
||||
testSetGet(item, 'three "quote');
|
||||
testDisable(item);
|
||||
testEnable(item);
|
||||
testShow(item);
|
||||
testHide(item);
|
||||
testSetGet(type, 'one');
|
||||
testSetGet(type, 'two');
|
||||
testSetGet(type, 'three "quote');
|
||||
testDisable(type);
|
||||
testEnable(type);
|
||||
testShow(type);
|
||||
testHide(type);
|
||||
});
|
||||
|
||||
describe('checkboxgroup', function() {
|
||||
var item = {
|
||||
var type = {
|
||||
type: 'checkboxgroup',
|
||||
clayId: 1,
|
||||
defaultValue: ['two'],
|
||||
options: [
|
||||
{ label: '1', value: 'one' },
|
||||
{ label: '2', value: 'two' },
|
||||
{ label: '3', value: 'three "quote' }
|
||||
]
|
||||
};
|
||||
testSetGet(item, ['one', 'two']);
|
||||
testSetGet(item, ['three "quote']);
|
||||
testSetGet(item, []);
|
||||
testSetGet(item, false, []);
|
||||
testDisable(item);
|
||||
testEnable(item);
|
||||
testShow(item);
|
||||
testHide(item);
|
||||
testSetGet(type, ['one', 'two']);
|
||||
testSetGet(type, ['three "quote']);
|
||||
testSetGet(type, []);
|
||||
testSetGet(type, false, []);
|
||||
testDisable(type);
|
||||
testEnable(type);
|
||||
testShow(type);
|
||||
testHide(type);
|
||||
});
|
||||
|
||||
describe('color', function() {
|
||||
testSetGet('color', 'FF0000', 0xff0000);
|
||||
testSetGet('color', '#FF0000', 0xff0000);
|
||||
testSetGet('color', '0xFF0000', 0xff0000);
|
||||
testSetGet('color', '#ff0000', 0xff0000);
|
||||
testSetGet('color', 0xff0000, 0xff0000);
|
||||
testSetGet('color', '', 0x000000);
|
||||
testSetGet('color', false, 0x000000);
|
||||
testSetGet('color', undefined, 0x000000);
|
||||
testDisable('color');
|
||||
testEnable('color');
|
||||
testShow('color');
|
||||
testHide('color');
|
||||
var type = 'color';
|
||||
testSetGet(type, 'FF0000', 0xff0000);
|
||||
testSetGet(type, '#FF0000', 0xff0000);
|
||||
testSetGet(type, '0xFF0000', 0xff0000);
|
||||
testSetGet(type, '#ff0000', 0xff0000);
|
||||
testSetGet(type, 0xff0000, 0xff0000);
|
||||
testSetGet({type: type, defaultValue: 0x00ff00}, '', 0x000000);
|
||||
testSetGet({type: type, defaultValue: 0x00ff00}, false, 0x000000);
|
||||
testSetGet({type: type, defaultValue: 0x00ff00}, undefined, 0x000000);
|
||||
testDisable(type);
|
||||
testEnable(type);
|
||||
testShow(type);
|
||||
testHide(type);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -27,3 +27,4 @@ describe('Utils', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user