What PatrickAkerstrand said is 100% true.
Here I want to add a development environment to vanilla JS, which can save you a lot of time and effort to implement it, since everything is thought out, honed and tested. It remains only to define your own widgets and use them.
Here is an example of how it looks.
Widget code
// inside a js file of a widget class (function () { var Module_Path = ["WidgetsLib", "a1", "Button"]; var curr = this; Module_Path.forEach(function(i){if (curr[i] == null) {addChildToTree(curr, i, {})} curr = curr[i]}); specialize_with(curr, { CSS_Literal: ' .{{WIDGET_CLASS_ID}}_Something { color: hsl(0, 0%, 20%); } ', HTML_Literal: ' <div onclick="{{WIDGET_INSTANCE}}.onclick(event)" class="{{WIDGET_CLASS_ID}}_Something" > SOME SUPER COOL WIDGET </div> ', new: typical_widget_new, }); })();
HTML:
<div id="w1" style="background-color: hsl(200, 50%, 50%);"></div> <script src="WidgetsLib/a1/Button/js"></script>
Custom JavaScript Code:
var b1 = WidgetsLib.a1.Button.new("w1", { onclick: function(ev) { ev.target.style.color = "#ffff00"; console.log("====== HERE"); } });
Please download and open Widget_v2.md.html in a browser, this is https://github.com/latitov/JS_HTML_Widgets .
What do you get:
- very interesting article about this;
- code fragments and examples;
- ready to use ... vanilla JS framework for creating your own widgets;
And enjoy creating reusable widgets of arbitrary complexity, easily!
Leonid Titov Sep 23 '19 at 19:20 2019-09-23 19:20
source share