modulatum2.html 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title></title>
  5. <style type="text/css">
  6. html , body { height: 100%; width: 100%; margin: 0px; padding: 0px; }
  7. #editor { width: 30%; background-color: #afafaf; height: 100%; position: relative; float: right; overflow: hidden;}
  8. #holder { width: 70%; background-color: #ffddff; height: 100%;}
  9. #editor textarea {height: 70%; width: 100%; font-family: monospace; font-size: 11px; line-height: 13px;}
  10. </style>
  11. </head>
  12. <body onload="startit();">
  13. <div id="editor"></div>
  14. <div id="holder">
  15. <div id="main"></div>
  16. </div>
  17. <script>
  18. function loada(){
  19. var header = document.getElementsByTagName("head")[0];
  20. var current_script = document.getElementById("current_script");
  21. var current_style = document.getElementById("current_style");
  22. header.removeChild(current_script);
  23. header.removeChild(current_style);
  24. var newscript = document.createElement("script");
  25. newscript.type = "text/javascript";
  26. newscript.src = "./current.js?"+Math.random();
  27. newscript.id = "current_script";
  28. header.appendChild(newscript);
  29. var newstyle = document.createElement("link");
  30. newstyle.type = "text/css";
  31. newstyle.rel = "stylesheet";
  32. newstyle.href = "./current.css?"+Math.random();
  33. newstyle.id = "current_style";
  34. header.appendChild(newstyle);
  35. }
  36. function MT(){
  37. this.modules = [];
  38. this.events = {};
  39. }
  40. MT.prototype.register = function(name,func) {
  41. console.log("register",name,func);
  42. this[name] = func;
  43. }
  44. MT.prototype.on = function(eventName,func){
  45. this.events[eventName] = this.events[eventName] || [];
  46. this.events[eventName].push(func);
  47. }
  48. MT.prototype.emit = function(eventName,content){
  49. (this.events[eventName]||[]).map(function(func){
  50. func.apply(func,[content]);
  51. })
  52. }
  53. var site = new MT();
  54. var data = new MT();
  55. var types = new MT();
  56. var register = function(name, func) {
  57. site.register(name, func)
  58. };
  59. function strip(str) {
  60. var reg = new RegExp(/\/\*([\s\S]*?)\*\//gi);
  61. str = str.replace(reg, function(matched, attrstr, content, line, d) {
  62. //console.log("COMMENT:;",attrstr)
  63. return "";
  64. })
  65. return str;
  66. }
  67. function tryparse(str) {
  68. var astr = strip(str);
  69. var ret = {};
  70. try{
  71. ret.res = eval('(function(d){ '+str+' ; return d})({})') ;// JSON.parse(astr);
  72. }catch(e){
  73. ret.error = e;
  74. }
  75. return ret;
  76. }
  77. var currentres={};
  78. function startit(){
  79. var status = document.createElement("div");
  80. var result = document.createElement("div");
  81. var editor = document.createElement("textarea");
  82. editor.addEventListener("input",function(ev){
  83. status.innerHTML = "";
  84. var res = tryparse(ev.target.value)
  85. if(res.error){
  86. status.innerHTML = res.error;
  87. }else{
  88. currentres = res;
  89. result.innerHTML = "Last known valid result: "+JSON.stringify(res);
  90. }
  91. });
  92. document.getElementById("editor").appendChild(editor);
  93. document.getElementById("editor").appendChild(result);
  94. document.getElementById("editor").appendChild(status);
  95. site.emit("start","helo");
  96. };
  97. site.on("addElement",function(type){
  98. console.log("ADDING",type);
  99. site.modules.push( type )
  100. render();
  101. });
  102. function guid() {
  103. function s4() {
  104. return Math.floor((1 + Math.random()) * 0x10000)
  105. .toString(16)
  106. .substring(1);
  107. }
  108. return s4() + '-' + s4() + s4();
  109. }
  110. </script>
  111. <script>
  112. console.log("OKOKOKO");
  113. /*
  114. raws: rendable
  115. im: a blog post type
  116. { def }
  117. im: a menu thing type
  118. im: a video window type
  119. im: a contact formular
  120. im: a privacy statment
  121. im: a note
  122. function Note(){}
  123. im: a comment
  124. im: a picture
  125. im: a window with collection
  126. im: a graphics
  127. im: a map
  128. im: a button
  129. im: a layout
  130. */
  131. </script>
  132. </body>
  133. </html>