📜 ⬆️ ⬇️

Very small framework or how to write your own Angularjs in 200 lines

Not so long ago, in one of the already practically written projects, it became necessary to use the similarity of web components . I want to tell what happened, I will try to briefly:

Purpose:

Start using the component approach in HTML layout (new semantics), namely the web component.

By component, I mean - “an independent module of software code, designed for reuse and deployment.” For example in another project.
')
Here I want to make a small digression and clarify - it’s about components, not widgets (functionally separate application units that combine the presentation, logic and / or data of a particular application - javascript + html + css) .
The difference, in my opinion, is that the component is not tied to a specific data model or the logic of a particular application - and you can easily transfer it to another application. And a widget is a unit of a specific application closely related to logic or data, and you cannot move it anywhere without internal changes to the widget itself.
As examples of a component, I can cite a select, accordion or tab, and for widgets, a status pane or a window for displaying messages in a chat.

What for:

Reusable code and ease of layout with the ability to extend HTML syntax.

As stated in the dock to one well-known framework:
“Directives is a unique and powerful feature available only in Angular. Newspaper syntax, specific to your application. ”
- I want to show that this is possible without angularjs.
And because I want to use the component approach (analogue to angularjs directives) with a widget-oriented architecture or with those template engines to which I find it convenient to work.
In general, use the application architecture or framework that is convenient for me in a particular case.

And the following is by no means the MV * framework, and never thought of it as such.

How:

In the simplest case, it is possible to consider the similarity of a web component consisting of two main parts: a template and a script.
Decorator (css) - for now we will not consider because of the additional logic in it possible. Yes, and it is better to compare with something already existing, so we touch a bit angularjs.
I think that no one will cause difficulties in calling the JavaScript function, so we mainly focused on the implementation of templates for HTML.

In a recently published article , two approaches are presented for templating on the client side.

Approach 1 - has been used for a long time already - creating an off-screen DOM, with its subsequent concealment.
<div id="mytemplate" hidden> <img src="logo.png"> <div class="comment"></div> </div> 

Advantages / Disadvantages:
+ Using the browser DOM - the browser knows what it is and knows how to work with it. If necessary, we can easily clone it.
+ Nothing extra is displayed - hidden prevents the template block from being shown.
- Inert - for example, even though our content is hidden, a network request will be sent and executed to load the image.
- design and thematization - the main page should load CSS markup for web components as well. This makes the approach fragile. There are no guarantees that we will not face name conflicts.

Approach 2 - Overload .
2008 , . , handlebars.js mustache.js.
<script id="mytemplate" type="text/x-handlebars-template"> <img src="logo.png"> <div class="comment"></div> </script>

/:
+ – , “display: none” .
+ – , .. JS, "text/javascript".
- – innerHtml. XSS .

:
1 – , DOM, ( getElementByID querySelector) . – . 2 – - JavaScript DOM addEventListener
- , .

- DOM . DOM – DOM. .

.. DOM , , , (, querySelectorAll(“component.name”) ).

( ) html , . . DOM innerHTML , DOM DOM.

:
javascript
component = { name: ..., template: ..., script: function (element, attrs) {….}, onattach: function (element) {….}, instantiate: true/false }

:
name – , html template – html (). script – ( element – , attrs – ). DOM onattach – DOM instantiate – . (element.component).
TagBuilder.register(component); html ,
<accordion> <accordion-page header=”Header 1”> … </accordion-page> <accordion-page class="open" header=”Header 2”> … </accordion-page> ... </accordion>
w-component=”accordion” DOM( ).
DOM
TagBuilder.apply('component css selector or components wrapper');
html , TagBuilder.compile(string, options); , TagBuilder.apply('component css selector or components wrapper'); . (w-component=”name”) .
          . 
2008 , . , handlebars.js mustache.js.
<script id="mytemplate" type="text/x-handlebars-template"> <img src="logo.png"> <div class="comment"></div> </script>

/:
+ – , “display: none” .
+ – , .. JS, "text/javascript".
- – innerHtml. XSS .

:
1 – , DOM, ( getElementByID querySelector) . – . 2 – - JavaScript DOM addEventListener
- , .

- DOM . DOM – DOM. .

.. DOM , , , (, querySelectorAll(“component.name”) ).

( ) html , . . DOM innerHTML , DOM DOM.

:
javascript
component = { name: ..., template: ..., script: function (element, attrs) {….}, onattach: function (element) {….}, instantiate: true/false }

:
name – , html template – html (). script – ( element – , attrs – ). DOM onattach – DOM instantiate – . (element.component).
TagBuilder.register(component); html ,
<accordion> <accordion-page header=”Header 1”> … </accordion-page> <accordion-page class="open" header=”Header 2”> … </accordion-page> ... </accordion>
w-component=”accordion” DOM( ).
DOM
TagBuilder.apply('component css selector or components wrapper');
html , TagBuilder.compile(string, options); , TagBuilder.apply('component css selector or components wrapper'); . (w-component=”name”) .
.
2008 , . , handlebars.js mustache.js.
<script id="mytemplate" type="text/x-handlebars-template"> <img src="logo.png"> <div class="comment"></div> </script>

/:
+ – , “display: none” .
+ – , .. JS, "text/javascript".
- – innerHtml. XSS .

:
1 – , DOM, ( getElementByID querySelector) . – . 2 – - JavaScript DOM addEventListener
- , .

- DOM . DOM – DOM. .

.. DOM , , , (, querySelectorAll(“component.name”) ).

( ) html , . . DOM innerHTML , DOM DOM.

:
javascript
component = { name: ..., template: ..., script: function (element, attrs) {….}, onattach: function (element) {….}, instantiate: true/false }

:
name – , html template – html (). script – ( element – , attrs – ). DOM onattach – DOM instantiate – . (element.component).
TagBuilder.register(component); html ,
<accordion> <accordion-page header=”Header 1”> … </accordion-page> <accordion-page class="open" header=”Header 2”> … </accordion-page> ... </accordion>
w-component=”accordion” DOM( ).
DOM
TagBuilder.apply('component css selector or components wrapper');
html , TagBuilder.compile(string, options); , TagBuilder.apply('component css selector or components wrapper'); . (w-component=”name”) .
          . 
2008 , . , handlebars.js mustache.js.
<script id="mytemplate" type="text/x-handlebars-template"> <img src="logo.png"> <div class="comment"></div> </script>

/:
+ – , “display: none” .
+ – , .. JS, "text/javascript".
- – innerHtml. XSS .

:
1 – , DOM, ( getElementByID querySelector) . – . 2 – - JavaScript DOM addEventListener
- , .

- DOM . DOM – DOM. .

.. DOM , , , (, querySelectorAll(“component.name”) ).

( ) html , . . DOM innerHTML , DOM DOM.

:
javascript
component = { name: ..., template: ..., script: function (element, attrs) {….}, onattach: function (element) {….}, instantiate: true/false }
:
name – , html template – html (). script – ( element – , attrs – ). DOM onattach – DOM instantiate – . (element.component).
TagBuilder.register(component); html ,
<accordion> <accordion-page header=”Header 1”> … </accordion-page> <accordion-page class="open" header=”Header 2”> … </accordion-page> ... </accordion>
w-component=”accordion” DOM( ).
DOM
TagBuilder.apply('component css selector or components wrapper');
html , TagBuilder.compile(string, options); , TagBuilder.apply('component css selector or components wrapper'); . (w-component=”name”) .
    .
    2008 , . , handlebars.js mustache.js.
    <script id="mytemplate" type="text/x-handlebars-template"> <img src="logo.png"> <div class="comment"></div> </script>

    /:
    + – , “display: none” .
    + – , .. JS, "text/javascript".
    - – innerHtml. XSS .

    :
    1 – , DOM, ( getElementByID querySelector) . – . 2 – - JavaScript DOM addEventListener
    - , .

    - DOM . DOM – DOM. .

    .. DOM , , , (, querySelectorAll(“component.name”) ).

    ( ) html , . . DOM innerHTML , DOM DOM.

    :
    javascript
    component = { name: ..., template: ..., script: function (element, attrs) {….}, onattach: function (element) {….}, instantiate: true/false }
    :
    name – , html template – html (). script – ( element – , attrs – ). DOM onattach – DOM instantiate – . (element.component).
    TagBuilder.register(component); html ,
    <accordion> <accordion-page header=”Header 1”> … </accordion-page> <accordion-page class="open" header=”Header 2”> … </accordion-page> ... </accordion>
    w-component=”accordion” DOM( ).
    DOM
    TagBuilder.apply('component css selector or components wrapper');
    html , TagBuilder.compile(string, options); , TagBuilder.apply('component css selector or components wrapper'); . (w-component=”name”) .
  • .
    2008 , . , handlebars.js mustache.js.
    <script id="mytemplate" type="text/x-handlebars-template"> <img src="logo.png"> <div class="comment"></div> </script>

    /:
    + – , “display: none” .
    + – , .. JS, "text/javascript".
    - – innerHtml. XSS .

    :
    1 – , DOM, ( getElementByID querySelector) . – . 2 – - JavaScript DOM addEventListener
    - , .

    - DOM . DOM – DOM. .

    .. DOM , , , (, querySelectorAll(“component.name”) ).

    ( ) html , . . DOM innerHTML , DOM DOM.

    :
    javascript
    component = { name: ..., template: ..., script: function (element, attrs) {….}, onattach: function (element) {….}, instantiate: true/false }
    :
    name – , html template – html (). script – ( element – , attrs – ). DOM onattach – DOM instantiate – . (element.component).
    TagBuilder.register(component); html ,
    <accordion> <accordion-page header=”Header 1”> … </accordion-page> <accordion-page class="open" header=”Header 2”> … </accordion-page> ... </accordion>
    w-component=”accordion” DOM( ).
    DOM
    TagBuilder.apply('component css selector or components wrapper');
    html , TagBuilder.compile(string, options); , TagBuilder.apply('component css selector or components wrapper'); . (w-component=”name”) .
    .
    2008 , . , handlebars.js mustache.js.
    <script id="mytemplate" type="text/x-handlebars-template"> <img src="logo.png"> <div class="comment"></div> </script>

    /:
    + – , “display: none” .
    + – , .. JS, "text/javascript".
    - – innerHtml. XSS .

    :
    1 – , DOM, ( getElementByID querySelector) . – . 2 – - JavaScript DOM addEventListener
    - , .

    - DOM . DOM – DOM. .

    .. DOM , , , (, querySelectorAll(“component.name”) ).

    ( ) html , . . DOM innerHTML , DOM DOM.

    :
    javascript
    component = { name: ..., template: ..., script: function (element, attrs) {….}, onattach: function (element) {….}, instantiate: true/false }
    :
    name – , html template – html (). script – ( element – , attrs – ). DOM onattach – DOM instantiate – . (element.component).
    TagBuilder.register(component); html ,
    <accordion> <accordion-page header=”Header 1”> … </accordion-page> <accordion-page class="open" header=”Header 2”> … </accordion-page> ... </accordion>
    w-component=”accordion” DOM( ).
    DOM
    TagBuilder.apply('component css selector or components wrapper');
    html , TagBuilder.compile(string, options); , TagBuilder.apply('component css selector or components wrapper'); . (w-component=”name”) .
  • .
    2008 , . , handlebars.js mustache.js.
    <script id="mytemplate" type="text/x-handlebars-template"> <img src="logo.png"> <div class="comment"></div> </script>

    /:
    + – , “display: none” .
    + – , .. JS, "text/javascript".
    - – innerHtml. XSS .

    :
    1 – , DOM, ( getElementByID querySelector) . – . 2 – - JavaScript DOM addEventListener
    - , .

    - DOM . DOM – DOM. .

    .. DOM , , , (, querySelectorAll(“component.name”) ).

    ( ) html , . . DOM innerHTML , DOM DOM.

    :
    javascript
    component = { name: ..., template: ..., script: function (element, attrs) {….}, onattach: function (element) {….}, instantiate: true/false }
    :
    name – , html template – html (). script – ( element – , attrs – ). DOM onattach – DOM instantiate – . (element.component).
    TagBuilder.register(component); html ,
    <accordion> <accordion-page header=”Header 1”> … </accordion-page> <accordion-page class="open" header=”Header 2”> … </accordion-page> ... </accordion>
    w-component=”accordion” DOM( ).
    DOM
    TagBuilder.apply('component css selector or components wrapper');
    html , TagBuilder.compile(string, options); , TagBuilder.apply('component css selector or components wrapper'); . (w-component=”name”) .
    .
    2008 , . , handlebars.js mustache.js.
    <script id="mytemplate" type="text/x-handlebars-template"> <img src="logo.png"> <div class="comment"></div> </script>

    /:
    + – , “display: none” .
    + – , .. JS, "text/javascript".
    - – innerHtml. XSS .

    :
    1 – , DOM, ( getElementByID querySelector) . – . 2 – - JavaScript DOM addEventListener
    - , .

    - DOM . DOM – DOM. .

    .. DOM , , , (, querySelectorAll(“component.name”) ).

    ( ) html , . . DOM innerHTML , DOM DOM.

    :
    javascript
    component = { name: ..., template: ..., script: function (element, attrs) {….}, onattach: function (element) {….}, instantiate: true/false }
    :
    name – , html template – html (). script – ( element – , attrs – ). DOM onattach – DOM instantiate – . (element.component).
    TagBuilder.register(component); html ,
    <accordion> <accordion-page header=”Header 1”> … </accordion-page> <accordion-page class="open" header=”Header 2”> … </accordion-page> ... </accordion>
    w-component=”accordion” DOM( ).
    DOM
    TagBuilder.apply('component css selector or components wrapper');
    html , TagBuilder.compile(string, options); , TagBuilder.apply('component css selector or components wrapper'); . (w-component=”name”) .
  • .
    2008 , . , handlebars.js mustache.js.
    <script id="mytemplate" type="text/x-handlebars-template"> <img src="logo.png"> <div class="comment"></div> </script>

    /:
    + – , “display: none” .
    + – , .. JS, "text/javascript".
    - – innerHtml. XSS .

    :
    1 – , DOM, ( getElementByID querySelector) . – . 2 – - JavaScript DOM addEventListener
    - , .

    - DOM . DOM – DOM. .

    .. DOM , , , (, querySelectorAll(“component.name”) ).

    ( ) html , . . DOM innerHTML , DOM DOM.

    :
    javascript
    component = { name: ..., template: ..., script: function (element, attrs) {….}, onattach: function (element) {….}, instantiate: true/false }
    :
    name – , html template – html (). script – ( element – , attrs – ). DOM onattach – DOM instantiate – . (element.component).
    TagBuilder.register(component); html ,
    <accordion> <accordion-page header=”Header 1”> … </accordion-page> <accordion-page class="open" header=”Header 2”> … </accordion-page> ... </accordion>
    w-component=”accordion” DOM( ).
    DOM
    TagBuilder.apply('component css selector or components wrapper');
    html , TagBuilder.compile(string, options); , TagBuilder.apply('component css selector or components wrapper'); . (w-component=”name”) .
    .
    2008 , . , handlebars.js mustache.js.
    <script id="mytemplate" type="text/x-handlebars-template"> <img src="logo.png"> <div class="comment"></div> </script>

    /:
    + – , “display: none” .
    + – , .. JS, "text/javascript".
    - – innerHtml. XSS .

    :
    1 – , DOM, ( getElementByID querySelector) . – . 2 – - JavaScript DOM addEventListener
    - , .

    - DOM . DOM – DOM. .

    .. DOM , , , (, querySelectorAll(“component.name”) ).

    ( ) html , . . DOM innerHTML , DOM DOM.

    :
    javascript
    component = { name: ..., template: ..., script: function (element, attrs) {….}, onattach: function (element) {….}, instantiate: true/false }
    :
    name – , html template – html (). script – ( element – , attrs – ). DOM onattach – DOM instantiate – . (element.component).
    TagBuilder.register(component); html ,
    <accordion> <accordion-page header=”Header 1”> … </accordion-page> <accordion-page class="open" header=”Header 2”> … </accordion-page> ... </accordion>
    w-component=”accordion” DOM( ).
    DOM
    TagBuilder.apply('component css selector or components wrapper');
    html , TagBuilder.compile(string, options); , TagBuilder.apply('component css selector or components wrapper'); . (w-component=”name”) .
.
2008 , . , handlebars.js mustache.js.
<script id="mytemplate" type="text/x-handlebars-template"> <img src="logo.png"> <div class="comment"></div> </script>

/:
+ – , “display: none” .
+ – , .. JS, "text/javascript".
- – innerHtml. XSS .

:
1 – , DOM, ( getElementByID querySelector) . – . 2 – - JavaScript DOM addEventListener
- , .

- DOM . DOM – DOM. .

.. DOM , , , (, querySelectorAll(“component.name”) ).

( ) html , . . DOM innerHTML , DOM DOM.

:
javascript
component = { name: ..., template: ..., script: function (element, attrs) {….}, onattach: function (element) {….}, instantiate: true/false }
:
name – , html template – html (). script – ( element – , attrs – ). DOM onattach – DOM instantiate – . (element.component).
TagBuilder.register(component); html ,
<accordion> <accordion-page header=”Header 1”> … </accordion-page> <accordion-page class="open" header=”Header 2”> … </accordion-page> ... </accordion>
w-component=”accordion” DOM( ).
DOM
TagBuilder.apply('component css selector or components wrapper');
html , TagBuilder.compile(string, options); , TagBuilder.apply('component css selector or components wrapper'); . (w-component=”name”) .
.
2008 , . , handlebars.js mustache.js.
<script id="mytemplate" type="text/x-handlebars-template"> <img src="logo.png"> <div class="comment"></div> </script>

/:
+ – , “display: none” .
+ – , .. JS, "text/javascript".
- – innerHtml. XSS .

:
1 – , DOM, ( getElementByID querySelector) . – . 2 – - JavaScript DOM addEventListener
- , .

- DOM . DOM – DOM. .

.. DOM , , , (, querySelectorAll(“component.name”) ).

( ) html , . . DOM innerHTML , DOM DOM.

:
javascript
component = { name: ..., template: ..., script: function (element, attrs) {….}, onattach: function (element) {….}, instantiate: true/false }
:
name – , html template – html (). script – ( element – , attrs – ). DOM onattach – DOM instantiate – . (element.component).
TagBuilder.register(component); html ,
<accordion> <accordion-page header=”Header 1”> … </accordion-page> <accordion-page class="open" header=”Header 2”> … </accordion-page> ... </accordion>
w-component=”accordion” DOM( ).
DOM
TagBuilder.apply('component css selector or components wrapper');
html , TagBuilder.compile(string, options); , TagBuilder.apply('component css selector or components wrapper'); . (w-component=”name”) .
.
2008 , . , handlebars.js mustache.js.
<script id="mytemplate" type="text/x-handlebars-template"> <img src="logo.png"> <div class="comment"></div> </script>

/:
+ – , “display: none” .
+ – , .. JS, "text/javascript".
- – innerHtml. XSS .

:
1 – , DOM, ( getElementByID querySelector) . – . 2 – - JavaScript DOM addEventListener
- , .

- DOM . DOM – DOM. .

.. DOM , , , (, querySelectorAll(“component.name”) ).

( ) html , . . DOM innerHTML , DOM DOM.

:
javascript
component = { name: ..., template: ..., script: function (element, attrs) {….}, onattach: function (element) {….}, instantiate: true/false }
:
name – , html template – html (). script – ( element – , attrs – ). DOM onattach – DOM instantiate – . (element.component).
TagBuilder.register(component); html ,
<accordion> <accordion-page header=”Header 1”> … </accordion-page> <accordion-page class="open" header=”Header 2”> … </accordion-page> ... </accordion>
w-component=”accordion” DOM( ).
DOM
TagBuilder.apply('component css selector or components wrapper');
html , TagBuilder.compile(string, options); , TagBuilder.apply('component css selector or components wrapper'); . (w-component=”name”) .
    .
    2008 , . , handlebars.js mustache.js.
    <script id="mytemplate" type="text/x-handlebars-template"> <img src="logo.png"> <div class="comment"></div> </script>

    /:
    + – , “display: none” .
    + – , .. JS, "text/javascript".
    - – innerHtml. XSS .

    :
    1 – , DOM, ( getElementByID querySelector) . – . 2 – - JavaScript DOM addEventListener
    - , .

    - DOM . DOM – DOM. .

    .. DOM , , , (, querySelectorAll(“component.name”) ).

    ( ) html , . . DOM innerHTML , DOM DOM.

    :
    javascript
    component = { name: ..., template: ..., script: function (element, attrs) {….}, onattach: function (element) {….}, instantiate: true/false }
    :
    name – , html template – html (). script – ( element – , attrs – ). DOM onattach – DOM instantiate – . (element.component).
    TagBuilder.register(component); html ,
    <accordion> <accordion-page header=”Header 1”> … </accordion-page> <accordion-page class="open" header=”Header 2”> … </accordion-page> ... </accordion>
    w-component=”accordion” DOM( ).
    DOM
    TagBuilder.apply('component css selector or components wrapper');
    html , TagBuilder.compile(string, options); , TagBuilder.apply('component css selector or components wrapper'); . (w-component=”name”) .
  • .
    2008 , . , handlebars.js mustache.js.
    <script id="mytemplate" type="text/x-handlebars-template"> <img src="logo.png"> <div class="comment"></div> </script>

    /:
    + – , “display: none” .
    + – , .. JS, "text/javascript".
    - – innerHtml. XSS .

    :
    1 – , DOM, ( getElementByID querySelector) . – . 2 – - JavaScript DOM addEventListener
    - , .

    - DOM . DOM – DOM. .

    .. DOM , , , (, querySelectorAll(“component.name”) ).

    ( ) html , . . DOM innerHTML , DOM DOM.

    :
    javascript
    component = { name: ..., template: ..., script: function (element, attrs) {….}, onattach: function (element) {….}, instantiate: true/false }

    :
    name – , html template – html (). script – ( element – , attrs – ). DOM onattach – DOM instantiate – . (element.component).
    TagBuilder.register(component); html ,
    <accordion> <accordion-page header=”Header 1”> … </accordion-page> <accordion-page class="open" header=”Header 2”> … </accordion-page> ... </accordion>
    w-component=”accordion” DOM( ).
    DOM
    TagBuilder.apply('component css selector or components wrapper');
    html , TagBuilder.compile(string, options); , TagBuilder.apply('component css selector or components wrapper'); . (w-component=”name”) .
.
2008 , . , handlebars.js mustache.js.
<script id="mytemplate" type="text/x-handlebars-template"> <img src="logo.png"> <div class="comment"></div> </script>

/:
+ – , “display: none” .
+ – , .. JS, "text/javascript".
- – innerHtml. XSS .

:
1 – , DOM, ( getElementByID querySelector) . – . 2 – - JavaScript DOM addEventListener
- , .

- DOM . DOM – DOM. .

.. DOM , , , (, querySelectorAll(“component.name”) ).

( ) html , . . DOM innerHTML , DOM DOM.

:
javascript
component = { name: ..., template: ..., script: function (element, attrs) {….}, onattach: function (element) {….}, instantiate: true/false }

:
name – , html template – html (). script – ( element – , attrs – ). DOM onattach – DOM instantiate – . (element.component).
TagBuilder.register(component); html ,
<accordion> <accordion-page header=”Header 1”> … </accordion-page> <accordion-page class="open" header=”Header 2”> … </accordion-page> ... </accordion>
w-component=”accordion” DOM( ).
DOM
TagBuilder.apply('component css selector or components wrapper');
html , TagBuilder.compile(string, options); , TagBuilder.apply('component css selector or components wrapper'); . (w-component=”name”) .
  • .
    2008 , . , handlebars.js mustache.js.
    <script id="mytemplate" type="text/x-handlebars-template"> <img src="logo.png"> <div class="comment"></div> </script>

    /:
    + – , “display: none” .
    + – , .. JS, "text/javascript".
    - – innerHtml. XSS .

    :
    1 – , DOM, ( getElementByID querySelector) . – . 2 – - JavaScript DOM addEventListener
    - , .

    - DOM . DOM – DOM. .

    .. DOM , , , (, querySelectorAll(“component.name”) ).

    ( ) html , . . DOM innerHTML , DOM DOM.

    :
    javascript
    component = { name: ..., template: ..., script: function (element, attrs) {….}, onattach: function (element) {….}, instantiate: true/false }

    :
    name – , html template – html (). script – ( element – , attrs – ). DOM onattach – DOM instantiate – . (element.component).
    TagBuilder.register(component); html ,
    <accordion> <accordion-page header=”Header 1”> … </accordion-page> <accordion-page class="open" header=”Header 2”> … </accordion-page> ... </accordion>
    w-component=”accordion” DOM( ).
    DOM
    TagBuilder.apply('component css selector or components wrapper');
    html , TagBuilder.compile(string, options); , TagBuilder.apply('component css selector or components wrapper'); . (w-component=”name”) .
              . 
    2008 , . , handlebars.js mustache.js.
    <script id="mytemplate" type="text/x-handlebars-template"> <img src="logo.png"> <div class="comment"></div> </script>

    /:
    + – , “display: none” .
    + – , .. JS, "text/javascript".
    - – innerHtml. XSS .

    :
    1 – , DOM, ( getElementByID querySelector) . – . 2 – - JavaScript DOM addEventListener
    - , .

    - DOM . DOM – DOM. .

    .. DOM , , , (, querySelectorAll(“component.name”) ).

    ( ) html , . . DOM innerHTML , DOM DOM.

    :
    javascript
    component = { name: ..., template: ..., script: function (element, attrs) {….}, onattach: function (element) {….}, instantiate: true/false }

    :
    name – , html template – html (). script – ( element – , attrs – ). DOM onattach – DOM instantiate – . (element.component).
    TagBuilder.register(component); html ,
    <accordion> <accordion-page header=”Header 1”> … </accordion-page> <accordion-page class="open" header=”Header 2”> … </accordion-page> ... </accordion>
    w-component=”accordion” DOM( ).
    DOM
    TagBuilder.apply('component css selector or components wrapper');
    html , TagBuilder.compile(string, options); , TagBuilder.apply('component css selector or components wrapper'); . (w-component=”name”) .
  • .
    2008 , . , handlebars.js mustache.js.
    <script id="mytemplate" type="text/x-handlebars-template"> <img src="logo.png"> <div class="comment"></div> </script>

    /:
    + – , “display: none” .
    + – , .. JS, "text/javascript".
    - – innerHtml. XSS .

    :
    1 – , DOM, ( getElementByID querySelector) . – . 2 – - JavaScript DOM addEventListener
    - , .

    - DOM . DOM – DOM. .

    .. DOM , , , (, querySelectorAll(“component.name”) ).

    ( ) html , . . DOM innerHTML , DOM DOM.

    :
    javascript
    component = { name: ..., template: ..., script: function (element, attrs) {….}, onattach: function (element) {….}, instantiate: true/false }

    :
    name – , html template – html (). script – ( element – , attrs – ). DOM onattach – DOM instantiate – . (element.component).
    TagBuilder.register(component); html ,
    <accordion> <accordion-page header=”Header 1”> … </accordion-page> <accordion-page class="open" header=”Header 2”> … </accordion-page> ... </accordion>
    w-component=”accordion” DOM( ).
    DOM
    TagBuilder.apply('component css selector or components wrapper');
    html , TagBuilder.compile(string, options); , TagBuilder.apply('component css selector or components wrapper'); . (w-component=”name”) .
              . 
    2008 , . , handlebars.js mustache.js.
    <script id="mytemplate" type="text/x-handlebars-template"> <img src="logo.png"> <div class="comment"></div> </script>

    /:
    + – , “display: none” .
    + – , .. JS, "text/javascript".
    - – innerHtml. XSS .

    :
    1 – , DOM, ( getElementByID querySelector) . – . 2 – - JavaScript DOM addEventListener
    - , .

    - DOM . DOM – DOM. .

    .. DOM , , , (, querySelectorAll(“component.name”) ).

    ( ) html , . . DOM innerHTML , DOM DOM.

    :
    javascript
    component = { name: ..., template: ..., script: function (element, attrs) {….}, onattach: function (element) {….}, instantiate: true/false }

    :
    name – , html template – html (). script – ( element – , attrs – ). DOM onattach – DOM instantiate – . (element.component).
    TagBuilder.register(component); html ,
    <accordion> <accordion-page header=”Header 1”> … </accordion-page> <accordion-page class="open" header=”Header 2”> … </accordion-page> ... </accordion>
    w-component=”accordion” DOM( ).
    DOM
    TagBuilder.apply('component css selector or components wrapper');
    html , TagBuilder.compile(string, options); , TagBuilder.apply('component css selector or components wrapper'); . (w-component=”name”) .
    .
    2008 , . , handlebars.js mustache.js.
    <script id="mytemplate" type="text/x-handlebars-template"> <img src="logo.png"> <div class="comment"></div> </script>

    /:
    + – , “display: none” .
    + – , .. JS, "text/javascript".
    - – innerHtml. XSS .

    :
    1 – , DOM, ( getElementByID querySelector) . – . 2 – - JavaScript DOM addEventListener
    - , .

    - DOM . DOM – DOM. .

    .. DOM , , , (, querySelectorAll(“component.name”) ).

    ( ) html , . . DOM innerHTML , DOM DOM.

    :
    javascript
    component = { name: ..., template: ..., script: function (element, attrs) {….}, onattach: function (element) {….}, instantiate: true/false }

    :
    name – , html template – html (). script – ( element – , attrs – ). DOM onattach – DOM instantiate – . (element.component).
    TagBuilder.register(component); html ,
    <accordion> <accordion-page header=”Header 1”> … </accordion-page> <accordion-page class="open" header=”Header 2”> … </accordion-page> ... </accordion>
    w-component=”accordion” DOM( ).
    DOM
    TagBuilder.apply('component css selector or components wrapper');
    html , TagBuilder.compile(string, options); , TagBuilder.apply('component css selector or components wrapper'); . (w-component=”name”) .
              . 
    2008 , . , handlebars.js mustache.js.
    <script id="mytemplate" type="text/x-handlebars-template"> <img src="logo.png"> <div class="comment"></div> </script>

    /:
    + – , “display: none” .
    + – , .. JS, "text/javascript".
    - – innerHtml. XSS .

    :
    1 – , DOM, ( getElementByID querySelector) . – . 2 – - JavaScript DOM addEventListener
    - , .

    - DOM . DOM – DOM. .

    .. DOM , , , (, querySelectorAll(“component.name”) ).

    ( ) html , . . DOM innerHTML , DOM DOM.

    :
    javascript
    component = { name: ..., template: ..., script: function (element, attrs) {….}, onattach: function (element) {….}, instantiate: true/false }

    :
    name – , html template – html (). script – ( element – , attrs – ). DOM onattach – DOM instantiate – . (element.component).
    TagBuilder.register(component); html ,
    <accordion> <accordion-page header=”Header 1”> … </accordion-page> <accordion-page class="open" header=”Header 2”> … </accordion-page> ... </accordion>
    w-component=”accordion” DOM( ).
    DOM
    TagBuilder.apply('component css selector or components wrapper');
    html , TagBuilder.compile(string, options); , TagBuilder.apply('component css selector or components wrapper'); . (w-component=”name”) .
    .
    2008 , . , handlebars.js mustache.js.
    <script id="mytemplate" type="text/x-handlebars-template"> <img src="logo.png"> <div class="comment"></div> </script>

    /:
    + – , “display: none” .
    + – , .. JS, "text/javascript".
    - – innerHtml. XSS .

    :
    1 – , DOM, ( getElementByID querySelector) . – . 2 – - JavaScript DOM addEventListener
    - , .

    - DOM . DOM – DOM. .

    .. DOM , , , (, querySelectorAll(“component.name”) ).

    ( ) html , . . DOM innerHTML , DOM DOM.

    :
    javascript
    component = { name: ..., template: ..., script: function (element, attrs) {….}, onattach: function (element) {….}, instantiate: true/false }

    :
    name – , html template – html (). script – ( element – , attrs – ). DOM onattach – DOM instantiate – . (element.component).
    TagBuilder.register(component); html ,
    <accordion> <accordion-page header=”Header 1”> … </accordion-page> <accordion-page class="open" header=”Header 2”> … </accordion-page> ... </accordion>
    w-component=”accordion” DOM( ).
    DOM
    TagBuilder.apply('component css selector or components wrapper');
    html , TagBuilder.compile(string, options); , TagBuilder.apply('component css selector or components wrapper'); . (w-component=”name”) .
  • Source: https://habr.com/ru/post/171821/


    All Articles