index.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. var $s, $show, basicKeys = ["text1", "textarea", "menu","select", "check1", "someInput", "numberTable", "hashTable", "checks", "radios", "ediTable"];
  2. var persons = [{ name: "Ivan",
  3. surname: "Ivanovv",
  4. age: "57",
  5. note: {value: "Buhaet", name: 'ivanovvsTextArea'},
  6. married: true},
  7. { name: "Petr",
  8. surname: "Petroff",
  9. age: "17",
  10. note: "Tyolki v golove",
  11. married: false,
  12. },
  13. { name: "Mary",
  14. surname: "Tester",
  15. married: true,
  16. note: "Ovulyashka",
  17. age: "27"} ];
  18. setTimeout(function(){
  19. $s = nbInit({
  20. text1: "txt",
  21. textarea: "txt area",
  22. // p1: "para",
  23. //menu: {0: "Main", 1: "About Us"},
  24. menu: ["Main", "About Us", 'yep'],
  25. select: {"": "--",
  26. M: "Male",
  27. F: "Female",
  28. X: "Xenomorph"},
  29. check1: true,
  30. someInput: {type: "number", placeholder: "percents", max: "100", min: "0", value: 50},
  31. numberTable: [[[1],2,[3],4,5,6],
  32. [7,8,9,10,11,12],
  33. [13,14,15,16,17,18],
  34. [19,20,21,22,23,24]],
  35. hashTable: persons,
  36. checks: [
  37. {check: {name: "first", checked: true},
  38. description: "first check"},
  39. {check: {name: "second", checked: false},
  40. description: "second check"},
  41. {check: {name: "third", checked: true},
  42. description: "third check"},
  43. ],
  44. radios: [
  45. {radio: {name: "sexism", value: "M"},
  46. description: "Male"},
  47. {radio: {name: "sexism", value: "F", checked: true},
  48. description: "Female"},
  49. {radio: {name: "racism", value: "white", checked: true},
  50. description: "White"},
  51. {radio: {name: "racism", value: "black"},
  52. description: "Black"}, ],
  53. });
  54. // $s.textarea; $s.select; $s.dzen; $s.check1; $s.note; $s.married; //just for init
  55. //$s.btn = {onclick: function(){
  56. //var thisLine = this.parentElement.parentElement;
  57. //var newLine = thisLine.cloneNode(true);
  58. //newLine.nbData = Object.assign({},thisLine.nbData);
  59. //thisLine.parentElement.insertBefore(newLine,thisLine);
  60. //$s.btn = {onclick: arguments.callee};
  61. //}};
  62. var ediNumbers = [];
  63. function ediFunc(){
  64. if ($s.ediInput){
  65. this.innerHTML = $s.ediInput;
  66. }
  67. else {
  68. var text = this.innerHTML;
  69. this.innerHTML = "<input id='ediInput'/>";
  70. $s.ediInput = text;
  71. }
  72. }
  73. for (var i=0;i<10;i++){
  74. ediNumbers[i] = [];
  75. for (var j=0;j<10;j++){
  76. //ediNumbers[i][j] = [i*j]; //one-level lower trick; uncomment input in html
  77. //ediNumbers[i][j] = i*j; //read only table
  78. ediNumbers[i][j] = {ondblclick: ediFunc,
  79. innerHTML: i*j, //read only table
  80. }
  81. }
  82. }
  83. $s.ediTable = ediNumbers;
  84. $show = nbInit({});
  85. document.onchange();
  86. },2000);
  87. function onUpdate(){
  88. var key = this.parentElement.getElementsByClassName("key")[0].innerHTML;
  89. var value = this.parentElement.getElementsByClassName("data")[0].value;
  90. eval(key + value);
  91. }
  92. document.onchange = function(evt){
  93. //$s.state = "";
  94. //$s.state = JSON.stringify($s, null, 4);
  95. //
  96. if (evt && evt.target.className == 'data'){
  97. return;
  98. }
  99. var data = [];
  100. for (var i=0,key=basicKeys[i];i<basicKeys.length;i++,key=basicKeys[i]){
  101. data.push({key: "$s." + key + " = ", data: JSON.stringify($s[key], null, 4), update: {onclick: onUpdate}});
  102. }
  103. $show.rightColumn = data;
  104. }