index.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. function btnDel(){
  56. var thisLine = this.parentElement.parentElement;
  57. thisLine.remove();
  58. $s["#hashTable tr:first-child button"] = false; //turn off first button of deletion
  59. };
  60. $s.btnDel = {onclick: btnDel};
  61. $s.addPerson = {onclick: function(){
  62. var newLine = document.getElementById('hashTable').copy.children[0].cloneNode(true);
  63. newLine.nbData = Object.assign({},persons[0]);
  64. document.getElementById('hashTable').appendChild(newLine);
  65. $s.btnDel = {onclick: btnDel};
  66. }}
  67. var ediNumbers = [];
  68. function ediFunc(){
  69. if ($s.ediInput){
  70. this.innerHTML = $s.ediInput;
  71. }
  72. else {
  73. var text = this.innerHTML;
  74. this.innerHTML = "<input id='ediInput'/>";
  75. $s.ediInput = text;
  76. }
  77. }
  78. for (var i=0;i<10;i++){
  79. ediNumbers[i] = [];
  80. for (var j=0;j<10;j++){
  81. //ediNumbers[i][j] = [i*j]; //one-level lower trick; uncomment input in html
  82. //ediNumbers[i][j] = i*j; //read only table
  83. ediNumbers[i][j] = {ondblclick: ediFunc,
  84. innerHTML: i*j, //read only table
  85. }
  86. }
  87. }
  88. $s.ediTable = ediNumbers;
  89. $show = nbInit({});
  90. document.onchange();
  91. },2000);
  92. function onUpdate(){
  93. var key = this.parentElement.getElementsByClassName("key")[0].innerHTML;
  94. var value = this.parentElement.getElementsByClassName("data")[0].value;
  95. eval(key + value);
  96. }
  97. document.onchange = function(evt){
  98. //$s.state = "";
  99. //$s.state = JSON.stringify($s, null, 4);
  100. //
  101. if (evt && evt.target.className == 'data'){
  102. return;
  103. }
  104. var data = [];
  105. for (var i=0,key=basicKeys[i];i<basicKeys.length;i++,key=basicKeys[i]){
  106. data.push({key: "$s." + key + " = ", data: JSON.stringify($s[key], null, 4), update: {onclick: onUpdate}});
  107. }
  108. $show.rightColumn = data;
  109. }