NoNameCracksInc

JS PLAYGROUND

Apr 13th, 2016
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.98 KB | None | 0 0
  1. JavaScript system handling custom element creation, pushing nodes into database.
  2.  
  3. var tm = {
  4.  
  5. image : function()
  6. {
  7. var e = document.createElement("img");
  8. e.width = "30";
  9. e.height = "30";
  10. e.style.border = "1px solid";
  11. e.style.position = "absolute";
  12. e.className = "moveable";
  13. e.style.backgroundColor = "transparent";
  14. document.getElementById("playground").appendChild(e);
  15. },
  16.  
  17. custom : function()
  18. {
  19. var e = document.createElement("div");
  20. e.style.width = "30px";
  21. e.style.height = "30px";
  22. e.style.border = "1px solid";
  23. e.style.position = "absolute";
  24. e.className = "moveable";
  25. e.style.zIndex = 1;
  26. e.style.backgroundColor = "transparent";
  27. e.style.textAlign = "center";
  28. e.style.fontSize = "15px";
  29.  
  30. if(tm.a.tagName == "DIV")
  31. {
  32. e.style.width = (tm.a.offsetWidth - parseInt(tm.a.style.borderWidth.replace("px",""))*2) /2 + "px";
  33. e.style.height = (tm.a.offsetHeight - parseInt(tm.a.style.borderWidth.replace("px",""))*2) /2+ "px";
  34. e.style.Zindex = tm.a.style.Zindex + 1;
  35. tm.a.appendChild(e);
  36. }
  37.  
  38. else
  39. document.getElementById("playground").appendChild(e);
  40. },
  41.  
  42. ac : function(el)
  43. {
  44. if(el == ''){return;}
  45. var vls = document.getElementsByClassName("inp");
  46. this.fn = this.fn || [];
  47.  
  48. el.style.width = vls[0].value + "px";
  49. el.style.height = vls[1].value + "px";
  50. el.style.borderColor = vls[2].value;
  51. el.style.borderWidth = vls[3].value + "px";
  52. el.style.backgroundColor = vls[4].value;
  53. el.style.fontSize = vls[5].value + "px";
  54. el.innerHTML = vls[6] == "" ? el.innerHTML : vls[6].value;
  55.  
  56. tm.cw(document.getElementById("playground").cloneNode(true));
  57. },
  58.  
  59. qz : function(obj)
  60. {
  61.  
  62. var pairs = "";
  63. for(var i=0; i<=obj.length-1; i++)
  64. {
  65. pairs = pairs+"('"+obj[i][0]+"','"+obj[i][1]+"'),";
  66. }
  67.  
  68. pairs = pairs.replace(/,\s*$/, "");
  69. var query = "INSERT INTO `nodes` VALUES "+pairs;
  70. ajax_id_base(query,"query");
  71. },
  72.  
  73. cw : function(html)
  74. {
  75. document.getElementById("view").innerHTML = "";
  76. html.removeChild(html.children[0]);
  77. this.fn = [];
  78.  
  79. for(var i=0;i<=html.getElementsByClassName("moveable").length-1;i++)
  80. {
  81. html.getElementsByClassName("moveable")[i].style.width = (document.getElementById("playground").getElementsByClassName("moveable")[i].offsetWidth/document.getElementById("playground").getElementsByClassName("moveable")[i].parentNode.offsetWidth)*100+"%";
  82. html.getElementsByClassName("moveable")[i].style.left = (document.getElementById("playground").getElementsByClassName("moveable")[i].offsetLeft/document.getElementById("playground").getElementsByClassName("moveable")[i].parentNode.offsetWidth)*100+"%";
  83. }
  84.  
  85. for(var i=0;i<=html.children.length-1;i++){document.getElementById("view").appendChild(html.children[i].cloneNode(true));}
  86. for(var i=0;i<=document.getElementById("view").children.length-1;i++){this.fn.push([document.getElementById("view").children[i].outerHTML,document.getElementById("view").children[i].offsetHeight - parseInt(document.getElementById("view").children[i].style.borderWidth.replace("px",""))*2]);}
  87. },
  88.  
  89. gs : function()
  90. {
  91. var vls = document.getElementsByClassName("inp");
  92. vls[0].value = tm.a.offsetWidth - parseInt(tm.a.style.borderWidth.replace("px",""))*2;
  93. vls[1].value = tm.a.offsetHeight - parseInt(tm.a.style.borderWidth.replace("px",""))*2;
  94. vls[2].value = tm.a.style.borderColor;
  95. vls[3].value = tm.a.style.borderWidth.replace("px","");
  96. vls[4].value = tm.a.style.backgroundColor;
  97. vls[5].value = tm.a.style.fontSize.replace("px","");
  98. vls[6].value = tm.a.innerHTML.indexOf(">") > -1 ? "" : tm.a.innerHTML;
  99. },
  100.  
  101. a : ""
  102. }
  103.  
  104. document.getElementById("playground").onmousedown = function(e)
  105. {
  106. if(e.target.className != "moveable"){return;}
  107.  
  108. var mouse_x_origin = e.pageX;
  109. var mouse_y_origin = e.pageY;
  110. var origin_left = e.target.offsetLeft;
  111. var origin_top = e.target.offsetTop;
  112.  
  113. tm.a = e.target;
  114. tm.gs();
  115.  
  116. document.getElementById("playground").onmousemove = function(e)
  117. {
  118. var mouse_relative_left = e.pageX;
  119. var mouse_relative_top = e.pageY;
  120. tm.a.style.left = origin_left + mouse_relative_left-mouse_x_origin + "px";
  121. tm.a.style.top = origin_top + mouse_relative_top-mouse_y_origin + "px";
  122. }
  123. }
  124. document.getElementById("playground").onmouseup = function(e){document.getElementById("playground").onmousemove = function(e){return false;}}
Advertisement
Add Comment
Please, Sign In to add comment