|
2 | 2 |
|
3 | 3 | ## Summary
|
4 | 4 |
|
5 |
| -As part of the Page Builder application, we provide new Knockout bindings you can use in your custom content types: |
| 5 | +As part of the Page Builder application, we provide a number of new Knockout bindings to add additional functionality to certain content types through Knockouts binding syntax. |
6 | 6 |
|
7 |
| -| Name | Description | Usage | |
8 |
| -| -------------- | -------------------------------------------------------------- | ------------------------------------- | |
9 |
| -| sortable | Enables sorting the children of a bound element. | \<div data-bind="sortable: {}"></div> | |
10 |
| -| draggable | Enables draggable functionality on DOM elements. | \<div data-bind="draggable: {}"></div> | |
11 |
| -| live-edit | Enables editing text directly from the Admin stage. | \<div data-bind="liveEdit: {}"></div> | |
12 |
| -| focus | Enables default focus on DOM elements. | \<div data-bind="hasFocusNoScroll: $parent.focusedSlide() === $index()"></div> | |
| 7 | +| Binding Name | Description | |
| 8 | +| -------------- | -------------------------------------------------------------- | |
| 9 | +| `sortable` | Enables sorting the children of a bound element. We use this within container content types such as the root container, row and columns to enable drag and drop capabilities on their children content types. This can be used for easy access to the jQuery UI sortable functionality within your module. | |
| 10 | +| `draggable` | Enables draggable functionality on DOM elements. We use this to enable the content types in the left menu to be dragged and dropped into containers on the stage. | |
| 11 | +| `liveEdit` | Enables basic live text editing on the stage, this also supports displaying additional items within the live edit UI for easier modification. You can read more about how to use live edit within our [How to add a custom Toolbar](../how-to/how-to-add-custom-toolbar.md) guide. | |
| 12 | +| `hasFocusNoScroll` | Enables an element to use Knockout `hasFocus` binding without it causing the browser to scroll to the element, we use this within Slider to ensure the correct slide is focused but we do not want to scroll this into view always. | |
| 13 | +{:style="table-layout:auto"} |
13 | 14 |
|
14 |
| -### Sortable binding |
| 15 | +### `sortable` binding |
15 | 16 |
|
16 | 17 | ```shell
|
17 |
| -app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/binding/sortable.ts |
| 18 | +view/adminhtml/web/ts/js/binding/sortable.ts |
18 | 19 | ```
|
19 | 20 |
|
20 |
| -The options in this binding are passed to the jQuery UI sortable instance. All options and their descriptions are available on the jQuery UI site: http://api.jqueryui.com/sortable/. |
| 21 | +This binding serves as an interface for jQuery UI Sortable. |
21 | 22 |
|
22 | 23 | Within Page Builder, we use the `sortable` binding to pass preview-component options to the drag-and-drop binding. We bind multiple options and events to the `sortable` instance so we can correctly respond to user actions when dragging and dropping content. Configuration and usage of the `sortable` binding can be seen in the Preview component:
|
23 | 24 |
|
24 |
| -Example Configuration: |
| 25 | +**Configuration:** |
25 | 26 |
|
26 |
| -```shell |
27 |
| -app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/content-type/preview.ts |
28 |
| -``` |
| 27 | +Please see the options listed on jQuery UI's Sortable API page: http://api.jqueryui.com/sortable/ |
29 | 28 |
|
30 |
| -Example Usage: |
| 29 | +**Usage:** |
31 | 30 |
|
32 |
| -```shell |
33 |
| -app/code/Magento/PageBuilder/view/adminhtml/web/template/content-type/preview.html |
| 31 | +```html |
| 32 | +<div data-bind="sortable: getSortableOptions()" /> |
34 | 33 | ```
|
| 34 | +_As jQuery UI can have callback functions we recommend providing this configuration from a function within your Knockout view model._ |
35 | 35 |
|
36 |
| -### Draggable binding |
| 36 | +### `draggable` binding |
37 | 37 |
|
38 | 38 | ```shell
|
39 |
| -app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/binding/draggable.ts |
| 39 | +view/adminhtml/web/ts/js/binding/draggable.ts |
40 | 40 | ```
|
41 | 41 |
|
42 |
| -The options provided in this binding are passed to the jQuery UI draggable instance. All options and their descriptions are available on the jQuery UI site: http://api.jqueryui.com/draggable/. |
| 42 | +This binding serves as an interface for jQuery UI Draggable. |
43 | 43 |
|
44 | 44 | Within Page Builder, we use this binding for the left panel's content types. The configuration and usage of the `draggable` binding can be seen in the Panel component:
|
45 | 45 |
|
46 |
| -Example Configuration: |
| 46 | +**Configuration:** |
47 | 47 |
|
48 |
| -```shell |
49 |
| -app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/panel.ts |
| 48 | +Please see the options listed on jQuery UI's Sortable API page: http://api.jqueryui.com/draggable/ |
| 49 | + |
| 50 | +**Usage:** |
| 51 | + |
| 52 | +```html |
| 53 | +<div data-bind="draggable: getDraggableOptions()" /> |
50 | 54 | ```
|
| 55 | +_As jQuery UI can have callback functions we recommend providing this configuration from a function within your Knockout view model._ |
51 | 56 |
|
52 |
| -Example Usage: |
| 57 | +### `liveEdit` binding |
53 | 58 |
|
54 |
| -```shell |
55 |
| -app/code/Magento/PageBuilder/view/adminhtml/web/template/panel.html |
| 59 | +This binding provides basic text live editing functionality to the current element, it does this by adding the `contenteditable` functionality to the bound element. |
| 60 | + |
| 61 | +**Configuration:** |
| 62 | + |
| 63 | +| Name | Description | |
| 64 | +| -------------- | -------------------------------------------------------------- | |
| 65 | +| `field` | The field name from the UI component form which you wish the live edit instance to edit. | |
| 66 | +| `placeholder` | _Optional_. A placeholder to display if there is no data for this field. |
| 67 | +| `selectAll` | _Optional_. Selects all text on focus within the live edit field. We use this within tabs. | |
| 68 | +{:style="table-layout:auto"} |
| 69 | + |
| 70 | +**Usage:** |
| 71 | +```html |
| 72 | +<div data-bind="liveEdit: { field: 'field', placeholder: $t('Placeholder'), selectAll: true }" /> |
56 | 73 | ```
|
57 | 74 |
|
| 75 | +### `hasFocusNoScroll` binding |
| 76 | + |
| 77 | +This binding enables the functionality of Knockout's [hasFocus](https://knockoutjs.com/documentation/hasfocus-binding.html) binding whilst removing the automatic scrolling that will occur when focusing an element within the browser. |
| 78 | + |
| 79 | +The binding has no configuration and must be passed an observable with a boolean value. |
| 80 | + |
| 81 | +**Usage:** |
| 82 | +```html |
| 83 | +<div data-bind="hasFocusNoScroll: anObservable" /> |
| 84 | +``` |
0 commit comments