secondary_extensions
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
secondary_extensions [2019/08/18 16:52] – Degand Patrick | secondary_extensions [2024/09/01 14:30] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 5: | Line 5: | ||
**Those extensions are editable with witsec or deltapi code-editors !** | **Those extensions are editable with witsec or deltapi code-editors !** | ||
+ | |||
+ | Δπ | ||
+ | |||
+ | ====== Documentation ====== | ||
+ | |||
+ | ===== Components formatting ===== | ||
+ | |||
+ | ==== Adjustment of a `params.json` file for a secondary type component ==== | ||
+ | |||
+ | |||
+ | |||
+ | A components list should be presented in this format: | ||
+ | |||
+ | < | ||
+ | " | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | ... | ||
+ | ] | ||
+ | </ | ||
+ | Avoid using attributes like '' | ||
+ | |||
+ | ==== A component file structure ==== | ||
+ | |||
+ | * template.html | ||
+ | * style.less | ||
+ | * thumb.png | ||
+ | |||
+ | A catalog may contain some images, it’s possible to refer to them the ways described below. | ||
+ | |||
+ | From parameters: | ||
+ | |||
+ | < | ||
+ | <input type=" | ||
+ | </ | ||
+ | From a template: | ||
+ | |||
+ | < | ||
+ | <img src=" | ||
+ | </ | ||
+ | ==== Component settings (attributes) ==== | ||
+ | |||
+ | Component attributes are used in a parent element of a template. | ||
+ | |||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | |||
+ | Example for a menu component: | ||
+ | |||
+ | < | ||
+ | <section | ||
+ | group=" | ||
+ | plugins=" | ||
+ | always-top | ||
+ | global | ||
+ | not-draggable | ||
+ | position-absolute | ||
+ | ></ | ||
+ | </ | ||
+ | **ALERT:** The `group` attribute doesn' | ||
+ | |||
+ | ===== Expressions ===== | ||
+ | |||
+ | The expressions work in interpolation of values, directives and `conditions` within parameters (check the ' | ||
+ | |||
+ | * - The context is only local: there are no variables except for the ones declared in the parameters. | ||
+ | * - A tolerance to non-declared variables: the script does not fail if there is no variable or value. | ||
+ | * - There is a filter support (not maintained? | ||
+ | * - Assigning values is not allowed. | ||
+ | * - Square brackets are not allowed - '' | ||
+ | * - Using of loops, conditionals and exceptions is not allowed. | ||
+ | * - Declaring functions isn't allowed. | ||
+ | * - Using of RegExp with literal notation isn't allowed. | ||
+ | * - Creating objects using the '' | ||
+ | * - Using of bitwise-operators, | ||
+ | |||
+ | ===== Parameters ===== | ||
+ | |||
+ | All tags that cannot be interpreted as parameters are ignored. | ||
+ | |||
+ | ==== A section title ==== | ||
+ | |||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | ==== A break line ==== | ||
+ | |||
+ | < | ||
+ | <hr/> | ||
+ | </ | ||
+ | ==== Text fields ==== | ||
+ | |||
+ | < | ||
+ | <input type=" | ||
+ | </ | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | ==== Checkboxes/ | ||
+ | |||
+ | < | ||
+ | <input type=" | ||
+ | </ | ||
+ | < | ||
+ | <input type=" | ||
+ | </ | ||
+ | < | ||
+ | <input type=" | ||
+ | </ | ||
+ | ==== A drop-down options list ==== | ||
+ | |||
+ | < | ||
+ | <select title=" | ||
+ | <option value=" | ||
+ | <option value=" | ||
+ | <option value=" | ||
+ | </ | ||
+ | </ | ||
+ | It supports the '' | ||
+ | |||
+ | < | ||
+ | <select inline title=" | ||
+ | <option value=" | ||
+ | <option value=" | ||
+ | <option value=" | ||
+ | </ | ||
+ | </ | ||
+ | ==== Color ==== | ||
+ | |||
+ | < | ||
+ | <input type=" | ||
+ | </ | ||
+ | ==== Range ==== | ||
+ | |||
+ | < | ||
+ | <input type=" | ||
+ | </ | ||
+ | It supports the '' | ||
+ | |||
+ | < | ||
+ | <input type=" | ||
+ | </ | ||
+ | ==== Font ==== | ||
+ | |||
+ | < | ||
+ | <input type=" | ||
+ | </ | ||
+ | ==== Image ==== | ||
+ | |||
+ | < | ||
+ | <input type=" | ||
+ | </ | ||
+ | ==== Video ==== | ||
+ | |||
+ | < | ||
+ | <input type=" | ||
+ | </ | ||
+ | ==== Background ==== | ||
+ | |||
+ | < | ||
+ | < | ||
+ | <input type=" | ||
+ | <input type=" | ||
+ | <input type=" | ||
+ | </ | ||
+ | </ | ||
+ | The '' | ||
+ | |||
+ | This parameter supports only three background types '' | ||
+ | |||
+ | The value of the bg variable for the previous example looks this way: | ||
+ | |||
+ | < | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | The selected type of background is stored in the '' | ||
+ | |||
+ | Some variables are used in CSS too, but only partically. | ||
+ | |||
+ | < | ||
+ | @bg-value: " | ||
+ | @bg-type: " | ||
+ | @bg-color-value: | ||
+ | @bg-parallax: | ||
+ | </ | ||
+ | It's possible to access only the current selection through variables. The exception is '' | ||
+ | |||
+ | As you can see, to get the access to the values, you need to use the hyphen instead of the dot - '' | ||
+ | |||
+ | ==== Map ==== | ||
+ | |||
+ | It's used along with the **mbr-map** directive. | ||
+ | |||
+ | < | ||
+ | <input type=" | ||
+ | </ | ||
+ | ==== A hidden parameter ==== | ||
+ | |||
+ | < | ||
+ | <input type=" | ||
+ | </ | ||
+ | ==== Conditionals ==== | ||
+ | |||
+ | The '' | ||
+ | |||
+ | < | ||
+ | <input type=" | ||
+ | </ | ||
+ | ===== Templates ===== | ||
+ | |||
+ | ==== The mbr-text directive ==== | ||
+ | |||
+ | A simple text without an extended text editor. | ||
+ | |||
+ | < | ||
+ | <div mbr-text> | ||
+ | </ | ||
+ | This directive is set automatically for the following tags: **H1**, **H2**, **H3**, **H4**, **H5**, **P**. | ||
+ | |||
+ | ==== The mbr-article directive ==== | ||
+ | |||
+ | An article text with an extended text editor. | ||
+ | |||
+ | < | ||
+ | <div mbr-article> | ||
+ | < | ||
+ | ... | ||
+ | </ | ||
+ | </ | ||
+ | ==== The mbr-buttons directive ==== | ||
+ | |||
+ | The element is interpreted as a buttons group. | ||
+ | |||
+ | < | ||
+ | <div mbr-buttons> | ||
+ | <a class=" | ||
+ | <a class=" | ||
+ | </ | ||
+ | </ | ||
+ | ==== The mbr-menu directive ==== | ||
+ | |||
+ | An element is interpreted as a menu. | ||
+ | |||
+ | < | ||
+ | <ul class=" | ||
+ | <li class=" | ||
+ | <li class=" | ||
+ | </ul> | ||
+ | | ||
+ | </ | ||
+ | ==== The <IMG> tag ==== | ||
+ | |||
+ | An element is interpreted as an image automatically. | ||
+ | |||
+ | < | ||
+ | <img src=" | ||
+ | </ | ||
+ | or | ||
+ | < | ||
+ | <a href="#">< | ||
+ | </ | ||
+ | **ALERT:** Don't add directives like '' | ||
+ | |||
+ | ==== The mbr-icon directive ==== | ||
+ | |||
+ | It specifies an icon. | ||
+ | |||
+ | < | ||
+ | <span mbr-icon class=" | ||
+ | </ | ||
+ | or | ||
+ | |||
+ | < | ||
+ | <a href="#">< | ||
+ | </ | ||
+ | **ALERT:** You shouldn' | ||
+ | |||
+ | **ALERT:** Don't add directives like '' | ||
+ | |||
+ | ==== The mbr-video directive ==== | ||
+ | |||
+ | An element is interpreted as a video: | ||
+ | |||
+ | < | ||
+ | <div mbr-video> | ||
+ | <iframe src=" | ||
+ | </ | ||
+ | </ | ||
+ | ==== The mbr-map directive ==== | ||
+ | |||
+ | A parameter name is used as an attribute value. Only one parameter type is supported: **map**. | ||
+ | |||
+ | < | ||
+ | <div class=" | ||
+ | </ | ||
+ | A map has several states: | ||
+ | |||
+ | **Loading** | ||
+ | < | ||
+ | <div class=" | ||
+ | <div data-state-details></ | ||
+ | </ | ||
+ | | ||
+ | </ | ||
+ | **Loading error (if a location is not found)** | ||
+ | < | ||
+ | <div class=" | ||
+ | <div data-state-details> | ||
+ | </ | ||
+ | </ | ||
+ | **Map representation** | ||
+ | < | ||
+ | <div class=" | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | Styles are needed during the change of address to make clear what is going on. There' | ||
+ | |||
+ | < | ||
+ | .google-map { | ||
+ | |||
+ | height: 25rem; | ||
+ | position: relative; | ||
+ | |||
+ | iframe { | ||
+ | height: 100%; | ||
+ | width: 100%; | ||
+ | } | ||
+ | |||
+ | [data-state-details] { | ||
+ | color: #6b6763; | ||
+ | font-family: | ||
+ | height: 1.5em; | ||
+ | margin-top: -0.75em; | ||
+ | padding-left: | ||
+ | padding-right: | ||
+ | position: absolute; | ||
+ | text-align: center; | ||
+ | top: 50%; | ||
+ | width: 100%; | ||
+ | } | ||
+ | |||
+ | & | ||
+ | background: #e9e5dc; | ||
+ | } | ||
+ | |||
+ | & | ||
+ | |||
+ | [data-state-details] { | ||
+ | display: none; | ||
+ | } | ||
+ | |||
+ | &:: | ||
+ | // loader | ||
+ | } | ||
+ | |||
+ | } | ||
+ | |||
+ | } | ||
+ | </ | ||
+ | ==== The mbr-form directive ==== | ||
+ | |||
+ | An element is interpreted as a **form**: | ||
+ | |||
+ | < | ||
+ | <form mbr-form class=" | ||
+ | </ | ||
+ | It can have a nested structure. An element with a **data-form-alert** attribute is intended to show messages with the result of a form sending. To make a message initially hidden, use the **hidden** attribute. | ||
+ | |||
+ | < | ||
+ | <div mbr-form> | ||
+ | <div data-form-alert hidden> | ||
+ | Thanks for filling out the form! | ||
+ | </ | ||
+ | <form class=" | ||
+ | <input type=" | ||
+ | <a data-app-btn=' | ||
+ | </ | ||
+ | </ | ||
+ | | ||
+ | </ | ||
+ | The **name** attribute of the form is responsible for a title of a submited form. | ||
+ | |||
+ | The **action** attribute may contain an e-mail or a handler script URL. | ||
+ | |||
+ | < | ||
+ | <form name=" | ||
+ | </ | ||
+ | Elements **input** placed inside a form should contain a unique **name** attribute. | ||
+ | |||
+ | The **data-form-field** value is a name of a field in a form editor window. | ||
+ | |||
+ | < | ||
+ | <input type=" | ||
+ | </ | ||
+ | It's possible to add **< | ||
+ | |||
+ | < | ||
+ | <label mbr-text class=" | ||
+ | </ | ||
+ | < | ||
+ | <input type=" | ||
+ | </ | ||
+ | Also there is a possibility to control visibility of html elements inside a form depending on the visibility of certain inputs of this form. It's necessary to define the **data-for** attribute with a name attribute of a needed input as a value. Only one dependency can exist at this time. | ||
+ | |||
+ | < | ||
+ | <div class=" | ||
+ | <input type=" | ||
+ | </ | ||
+ | |||
+ | </ | ||
+ | ==== The mbr-if directive ==== | ||
+ | |||
+ | It shows/hides a block depending on a condition: | ||
+ | |||
+ | < | ||
+ | <h1 mbr-if=" | ||
+ | </ | ||
+ | or | ||
+ | < | ||
+ | <div mbr-if=" | ||
+ | <h1 mbr-if=" | ||
+ | <div mbr-if=" | ||
+ | </ | ||
+ | </ | ||
+ | ==== The mbr-style directive ==== | ||
+ | |||
+ | < | ||
+ | <section mbr-style=" | ||
+ | </ | ||
+ | **ALERT:** '' | ||
+ | |||
+ | ==== The mbr-class directive ==== | ||
+ | |||
+ | Parameters: | ||
+ | |||
+ | < | ||
+ | showTitle = true | ||
+ | showText | ||
+ | blockType = " | ||
+ | |||
+ | <span mbr-class=" | ||
+ | |||
+ | <span class=" | ||
+ | </ | ||
+ | or | ||
+ | < | ||
+ | <span mbr-class=" | ||
+ | |||
+ | <span class=" | ||
+ | </ | ||
+ | or | ||
+ | < | ||
+ | <span mbr-class=" | ||
+ | |||
+ | <span class=" | ||
+ | </ | ||
+ | or | ||
+ | < | ||
+ | <span mbr-class=" | ||
+ | |||
+ | <span class=" | ||
+ | </ | ||
+ | ==== Interpolation in attributes ==== | ||
+ | |||
+ | Any attribute if it contains a syntactically correct expression inside double braces '' | ||
+ | |||
+ | < | ||
+ | <div title=" | ||
+ | </ | ||
+ | or | ||
+ | < | ||
+ | <div style=" | ||
+ | </ | ||
+ | or | ||
+ | < | ||
+ | <div data-video-src=" | ||
+ | </ | ||
+ | ===== Tracing of component changes from custom scripts ===== | ||
+ | |||
+ | Component changes can be traced on a **JavaScript** user level. Example: | ||
+ | |||
+ | < | ||
+ | $(function(){ | ||
+ | $(document).on(' | ||
+ | // this code will be applied to every added component | ||
+ | // to access the component, event.target can be used | ||
+ | }); | ||
+ | }); | ||
+ | </ | ||
+ | All generated events have one namespace '' | ||
+ | |||
+ | ==== Recommendations for Use ==== | ||
+ | |||
+ | Events are needed only for work with the program, and a site would operate normally without them. It means that events should be used only when it's absolutely necessary. | ||
+ | |||
+ | The most proper way for using of events is when it's necessary to use some third-party library or script. | ||
+ | |||
+ | Let's take a look at a circle progress bar. We have a parameter of a **range** type here: | ||
+ | |||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | And a template: | ||
+ | |||
+ | < | ||
+ | <div class=" | ||
+ | </ | ||
+ | I.e. a **progress** value is used in percents in a '' | ||
+ | |||
+ | < | ||
+ | $(' | ||
+ | $(this).circleProgress({ | ||
+ | | ||
+ | }); | ||
+ | } ); | ||
+ | | ||
+ | </ | ||
+ | The thing is that this code should be applied not only during loading, but also when a component is added. So we do it this way: | ||
+ | |||
+ | < | ||
+ | function initCircleProgress(card) { | ||
+ | // we search .circle-progress inside a block and call the circleProgress() method | ||
+ | $(card).find(' | ||
+ | $(this).circleProgress({ | ||
+ | | ||
+ | }); | ||
+ | } ); | ||
+ | } | ||
+ | |||
+ | $(document).on(' | ||
+ | initCircleProgress(event.target); | ||
+ | }); | ||
+ | | ||
+ | | ||
+ | </ | ||
+ | This code should work during a project loading and while adding a component. What can we do with the change of the **progress** value? | ||
+ | |||
+ | < | ||
+ | $(document).on(' | ||
+ | if (paramName == ' | ||
+ | initCircleProgress(event.target); | ||
+ | } | ||
+ | }); | ||
+ | </ | ||
+ | **ALERT:** It is recommended to avoid using '' | ||
+ | |||
+ | During initialization some libraries start tracking events (for example, onScroll or onResize of a browser window), and they has a special method to reset all to initialization state. It's important to remember that: | ||
+ | |||
+ | < | ||
+ | $(document).on(' | ||
+ | $(event.target).find(' | ||
+ | }); | ||
+ | </ | ||
+ | There is one issue left: what if a site is opened in a browser but not in the program. How to call an **add.cards** event? | ||
+ | |||
+ | If we call '' | ||
+ | |||
+ | There are some options to avoid it, the easiest one is to check where a script is, is it in the program or in a browser? The code will look like this: | ||
+ | |||
+ | < | ||
+ | $(function(){ | ||
+ | |||
+ | var isBuilder = $(' | ||
+ | |||
+ | function initCircleProgress(card) { | ||
+ | $(card).find(' | ||
+ | $(this).circleProgress({ | ||
+ | | ||
+ | }); | ||
+ | } ); | ||
+ | } | ||
+ | |||
+ | if (isBuilder) { | ||
+ | $(document).on(' | ||
+ | initCircleProgress(event.target); | ||
+ | }).on(' | ||
+ | $(event.target).find(' | ||
+ | }).on(' | ||
+ | if (paramName == ' | ||
+ | initCircleProgress(event.target); | ||
+ | } | ||
+ | }); | ||
+ | } else { | ||
+ | initCircleProgress(document.body); | ||
+ | } | ||
+ | |||
+ | }); | ||
+ | </ | ||
+ | ==== add.cards Event ==== | ||
+ | |||
+ | It happens when a component is added or it loads from a project. It's possible to access the added element using '' | ||
+ | |||
+ | ==== delete.cards Event ==== | ||
+ | |||
+ | It happens when a component is removed. Using '' | ||
+ | |||
+ | ==== drag.cards Event ==== | ||
+ | |||
+ | It happens when a component is dragged. Here is an example: | ||
+ | |||
+ | < | ||
+ | $(function(){ | ||
+ | $(document).on(' | ||
+ | // this code will be executed for a dragged component | ||
+ | // event.target - a dragged component | ||
+ | // oldPrevCard - a component that was located above a dragged component before the dragging | ||
+ | }); | ||
+ | }); | ||
+ | </ | ||
+ | ==== changeParameter.cards Event ==== | ||
+ | |||
+ | It happens when a parameter is changed. Here is an example: | ||
+ | |||
+ | < | ||
+ | $(function(){ | ||
+ | $(document).on(' | ||
+ | // this code will be executed when a parameter is changed | ||
+ | // event.target - a component in which the parameters have changed | ||
+ | // paramName - a parameter name | ||
+ | // value - a value of a parameter | ||
+ | // key - a value to be changed (rarely used) | ||
+ | }); | ||
+ | }); | ||
+ | </ | ||
+ | **key** can help with the work with a **background** parameter, for example: when **parallax** is changed, there is an array as a **value**: '' | ||
+ | |||
+ | < | ||
+ | $(function(){ | ||
+ | $(document).on(' | ||
+ | if (paramName == ' | ||
+ | switch (key) { | ||
+ | case ' | ||
+ | // a background type is changed | ||
+ | break; | ||
+ | case ' | ||
+ | // change of the color or image or video location | ||
+ | // (it depends on the background type) | ||
+ | break; | ||
+ | case ' | ||
+ | // parallax is enabled/ | ||
+ | break; | ||
+ | } | ||
+ | } | ||
+ | }); | ||
+ | }); | ||
+ | |||
+ | </ | ||
+ | ==== changeContent.cards Event ==== | ||
+ | |||
+ | Happens after editing of icons, images or videos. Example: | ||
+ | |||
+ | < | ||
+ | $(function(){ | ||
+ | $(document).on(' | ||
+ | // event.target - an edited item | ||
+ | // type - a type of an edited item | ||
+ | }); | ||
+ | }); | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ |
secondary_extensions.1566139965.txt.gz · Last modified: 2024/09/01 14:30 (external edit)