Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.00 KB | None | 0 0
  1. // Isso aqui ja faz pegar todos os pais.
  2.  
  3. var elements = [];
  4.  
  5. function rightclick() {
  6. var rightclick;
  7. var e = window.event;
  8.  
  9. // Detecta um clique esquerdo fora da caixa pra fechar ela.
  10. if(e.which == 1){
  11. var auxTarget = e.target;
  12. var dontDelete = false;
  13. // O carinha existe, vamos ver se eu cliquei dentro ou fora.
  14. if($("#containerCSSEditor")){
  15. while(auxTarget.tagName != "BODY"){
  16. if(auxTarget.getAttribute("id") == "containerCSSEditor")
  17. dontDelete = true;
  18. auxTarget = auxTarget.parentNode;
  19. }
  20. // Cliquei fora, pode deletar.
  21. if(!dontDelete) $("#containerCSSEditor").remove();
  22. }
  23. }
  24.  
  25. if (e.which == 3 || e.button == 2){
  26. e.preventDefault();
  27. if($("#containerCSSEditor")){
  28. $("#containerCSSEditor").remove();
  29. }
  30. var target = e.target;
  31. var left = e.pageX;
  32. var top = e.pageY;
  33. console.log(top);
  34. console.log(left);
  35. auxTarget = target;
  36. while(auxTarget.tagName != "BODY"){
  37. //console.log(auxTarget);
  38. elements.push(auxTarget);
  39. auxTarget = auxTarget.parentNode;
  40. }
  41. //console.log(elements);
  42. // Cria o container Geral.
  43. var cssEditForm = document.createElement("div");
  44. cssEditForm.setAttribute("id", "containerCSSEditor");
  45. // Cria o titulo do css;
  46. var cssTitle = document.createElement("h3");
  47. cssTitle.setAttribute("id", "cssEditorTitle");
  48. cssTitle.append("CSS Aplicados");
  49. // Cria a lista e vamos comecar a tacar as coisa ali. (TODO)
  50. var cssULContainer = document.createElement("ul");
  51. cssULContainer.setAttribute("id", "CSSEditorUlContainer");
  52. // Agora comeca a adicionar os elementos da lista.
  53. for(var i = 0; i < elements.length; i++){
  54. var cssEditorLi = document.createElement("li");
  55. cssEditorLi.setAttribute("class", "cssEditorLi");
  56. cssEditorLi.setAttribute("id", "EditorLi"+i);
  57. cssEditorLi.setAttribute("onclick", "abreEditorCSS(" + i + ")");
  58. cssEditorLi.style.height = "50px";
  59. cssEditorLi.style.width = "100%";
  60. cssEditorLi.style.background = "#e6e6e6";
  61. cssEditorLi.style.fontSize = "12px";
  62. cssEditorLi.style.cursor = "pointer";
  63. cssEditorLi.innerHTML = "< " + elements[i].tagName.toLowerCase() + " class='" + elements[i].className + "' >";
  64. cssULContainer.append(cssEditorLi);
  65. }
  66. cssEditForm.append(cssTitle);
  67. cssEditForm.append(cssULContainer);
  68. $("body").append(cssEditForm);
  69. $("#containerCSSEditor").css("top", top).css("left", left).css("border-radius", "10px").css("border", "1px solid black");
  70. return false;
  71. }
  72. return false;
  73. }
  74.  
  75. function abreEditorCSS(index){
  76. var top = $("#containerCSSEditor").css("top");
  77. var left = $("#containerCSSEditor").css("left");
  78. $("#containerCSSEditor").remove();
  79. // Cria um novo editor, dessa vez com base em um form.
  80. var containerCSSEditorNode = document.createElement("div");
  81. containerCSSEditorNode.setAttribute("id", "containerCSSEditor");
  82. var formCSSEditorNode = document.createElement("form");
  83. formCSSEditorNode.setAttribute("id", "formCSSEditor");
  84. formCSSEditorNode.setAttribute("method", "post");
  85. formCSSEditorNode.setAttribute("action", "google.com"); // TODO.
  86. formCSSEditorNode.style.display = "table";
  87. // Agora cria os inputs do form
  88. // Nome do elemento.
  89. var inputNameCSSEditorNode = document.createElement("input");
  90. inputNameCSSEditorNode.setAttribute("readonly", "");
  91. inputNameCSSEditorNode.setAttribute("name", "divName");
  92. inputNameCSSEditorNode.setAttribute("id", "divName");
  93. inputNameCSSEditorNode.setAttribute("type", "text");
  94. inputNameCSSEditorNode.setAttribute("value", elements[index].tagName);
  95. inputNameCSSEditorNode.style.display = "block";
  96. inputNameCSSEditorNode.style.textAlign = "center";
  97. inputNameCSSEditorNode.style.fontSize = "14px";
  98. formCSSEditorNode.append(inputNameCSSEditorNode);
  99. // Botao de submit;
  100. var submitCSSEditorNode = document.createElement("button");
  101. submitCSSEditorNode.setAttribute("class", "button");
  102. submitCSSEditorNode.setAttribute("onclick", "removeFormCSSEditor");
  103. submitCSSEditorNode.style.display = "block";
  104. submitCSSEditorNode.innerHTML = "Enviar Alterações"
  105. // Agora comeca a putaria de juntar tudo.
  106. formCSSEditorNode.append(submitCSSEditorNode);
  107. containerCSSEditorNode.append(formCSSEditorNode);
  108. $("body").append(containerCSSEditorNode);
  109. // Aparentemente jquery so funciona se ele ja ta appended.
  110. $("#containerCSSEditor").css("top", top).css("left", left).css("height", "400px");
  111. // Por enquanto, nao quero nenhum submit.
  112. document.addEventListener("submit", function(e){
  113. e.preventDefault();
  114. })
  115. }
  116.  
  117. function removeFormCSSEditor(){
  118. $("#containerCSSEditor").remove();
  119. }
  120.  
  121. var sheet = (function(){
  122. var style = document.createElement("style");
  123. style.appendChild(document.createTextNode(""));
  124. document.head.appendChild(style);
  125.  
  126. return style.sheet;
  127. });
  128. var v = sheet();
  129. v.insertRule(
  130. "#containerCSSEditor{" +
  131. "position: absolute;" +
  132. "display: table;" +
  133. "height: 300px;" +
  134. "width: 400px;" +
  135. "background: #e6e6e6;" +
  136. "overflow: scroll;" +
  137. "}"
  138. );
  139. v.insertRule(
  140. "#cssEditorTitle{" +
  141. "text-align: center;" +
  142. "padding-bottom: 10px;" +
  143. "border-bottom: 1px solid black;"+
  144. "}"
  145. )
  146. v.insertRule(
  147. "#CSSEditorUlContainer{" +
  148. "max-height: 300px;" +
  149. "overflow: scroll;" +
  150. "}"
  151. );
  152. $("html").unbind().mousedown(rightclick);
  153.  
  154. //window.onload = function() {
  155. document.addEventListener("contextmenu", function(e){
  156. e.preventDefault();
  157. }, false);
  158. //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement