项目作者: latitov

项目描述 :
Easily create widget objects of arbitrary complexity
高级语言: JavaScript
项目地址: git://github.com/latitov/JS_HTML_Widgets.git
创建时间: 2019-09-23T18:55:10Z
项目社区:https://github.com/latitov/JS_HTML_Widgets

开源协议:

下载


JS_HTML_Widgets

Easily create widget objects of arbitrary complexity

By Leonid Titov, 2019-09-23

Please download, and open the Widget_v3.md.html in a browser, and read. Or, go to the Githab Pages of this https://latitov.github.io/JS_HTML_Widgets/, then follow the link to whitepaper from there.

What you’ll get:

  • very interesting article about this;
  • snippets of code and examples;
  • ready to use… framework in vanilla JS, to create widgets of your own;

Note: this version is outdated. If you are interested in a production ready one, and in a help to migrate to it, please contact me.

Here’s an example of what it look like.

A widget code

  1. // inside a js file of a widget class
  2. (function () {
  3. var Module_Path = ["WidgetsLib", "a1", "Button"];
  4. var curr = this;
  5. Module_Path.forEach(function(i){if (curr[i] == null) {addChildToTree(curr, i, {})} curr = curr[i]});
  6. specialize_with(curr, {
  7. CSS_Literal: `
  8. .{{WIDGET_CLASS_ID}}_Something {
  9. color: hsl(0, 0%, 20%);
  10. }
  11. `,
  12. HTML_Literal: `
  13. <div onclick="{{WIDGET_INSTANCE}}.onclick(event)"
  14. class="{{WIDGET_CLASS_ID}}_Something"
  15. >
  16. SOME SUPER COOL WIDGET
  17. </div>
  18. `,
  19. new: typical_widget_new,
  20. WidgetSpecializer: {
  21. remove: typical_widget_remove,
  22. }
  23. });
  24. })();

An HTML:

  1. <div id="w1" style="background-color: hsl(200, 50%, 50%);"></div>
  2. <script src="WidgetsLib/a1/Button/js"></script>

A user JavaScript code:

  1. var b1 = WidgetsLib.a1.Button.new("w1", {
  2. onclick: function(ev) {
  3. ev.target.style.color = "#ffff00";
  4. console.log("====== HERE");
  5. }
  6. });

Download and enjoy reading and using it. Then try demo_test.html, and see inside it.