Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.18 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.  
  12. var auxTarget = e.target;
  13. var dontDelete = false;
  14. // O carinha existe, vamos ver se eu cliquei dentro ou fora.
  15. if($("#containerCSSEditor")){
  16. while(auxTarget.tagName != "BODY"){
  17. if(auxTarget.getAttribute("id") == "containerCSSEditor")
  18. dontDelete = true;
  19. auxTarget = auxTarget.parentNode;
  20. }
  21. // Cliquei fora, pode deletar.
  22. if(!dontDelete) $("#containerCSSEditor").remove();
  23. }
  24. }
  25.  
  26. if (e.which == 3 || e.button == 2){
  27. elements = [];
  28. var target = e.target;
  29. var left = e.pageX;
  30. var top = e.pageY;
  31. auxTarget = target;
  32.  
  33. if($("#containerCSSEditor")){
  34. $("#containerCSSEditor").remove();
  35. }
  36. while(auxTarget.tagName != "BODY"){
  37. elements.push(auxTarget);
  38. auxTarget = auxTarget.parentNode;
  39. }
  40.  
  41. // Cria o container Geral.
  42. var cssEditForm = document.createElement("div");
  43. cssEditForm.setAttribute("id", "containerCSSEditor");
  44. // Cria o titulo do css;
  45. var cssTitle = document.createElement("h3");
  46. cssTitle.setAttribute("id", "cssEditorTitle");
  47. cssTitle.append("CSS Aplicados");
  48. // Cria a lista e vamos comecar a tacar as coisa ali. (TODO)
  49. var cssULContainer = document.createElement("ul");
  50. cssULContainer.setAttribute("id", "CSSEditorUlContainer");
  51. // Agora comeca a adicionar os elementos da lista.
  52. for(var i = 0; i < elements.length; i++){
  53. if(i != 0){
  54. cssULContainer.append(document.createElement("hr"));
  55. }
  56. var cssEditorLi = document.createElement("li");
  57. cssEditorLi.setAttribute("class", "cssEditorLi");
  58. cssEditorLi.setAttribute("id", "EditorLi"+i);
  59. cssEditorLi.setAttribute("onclick", "abreEditorCSS(" + i + ")");
  60. cssEditorLi.innerHTML = "< " + elements[i].tagName.toLowerCase() + " class='" + elements[i].className + "' id='" + elements[i].id + "' >";
  61. cssULContainer.append(cssEditorLi);
  62. }
  63. cssEditForm.append(cssTitle);
  64. cssEditForm.append(cssULContainer);
  65. $("body").append(cssEditForm);
  66. $("#containerCSSEditor").css("top", top).css("left", left);
  67. }
  68. }
  69.  
  70. function abreEditorCSS(index){
  71. var top = $("#containerCSSEditor").css("top");
  72. var left = $("#containerCSSEditor").css("left");
  73. $("#containerCSSEditor").remove();
  74. // Cria um novo editor, dessa vez com base em um form.
  75. var containerCSSEditorNode = document.createElement("div");
  76. containerCSSEditorNode.setAttribute("id", "containerCSSEditor");
  77.  
  78. // Botar um titulo pra ficar mais bonitin
  79. var cssTitleNode = document.createElement("h3");
  80. cssTitleNode.setAttribute("id", "cssEditorTitle");
  81. cssTitleNode.append("Alterar CSS");
  82. containerCSSEditorNode.append(cssTitleNode);
  83.  
  84. // Cria o form.
  85. var formCSSEditorNode = document.createElement("form");
  86. formCSSEditorNode.setAttribute("id", "formCSSEditor");
  87. formCSSEditorNode.setAttribute("method", "post");
  88. formCSSEditorNode.setAttribute("action", "google.com"); // TODO.
  89. // Agora cria os inputs do form
  90. // Nome do elemento.
  91. var inputNameCSSEditorNode = document.createElement("input");
  92. inputNameCSSEditorNode.setAttribute("readonly", "");
  93. inputNameCSSEditorNode.setAttribute("name", "divName");
  94. inputNameCSSEditorNode.setAttribute("id", "divName");
  95. inputNameCSSEditorNode.setAttribute("type", "text");
  96. inputNameCSSEditorNode.setAttribute("value", "< " + elements[index].tagName.toLowerCase() + " class='" + elements[index].className + "' id='" + elements[index].id + "' >");
  97. formCSSEditorNode.append(inputNameCSSEditorNode);
  98.  
  99. //var val = getComputedStyle(elements[index]);
  100. //$("#formCSSEditor").append("<input id='cssValue' name='css' value='"+val+"' />");
  101.  
  102.  
  103. var inputCssCSSEditorNode = document.createElement("textarea");
  104. inputCssCSSEditorNode.setAttribute("rows", "30")
  105. inputCssCSSEditorNode.setAttribute("name", "inputCSSEditorCSS");
  106. inputCssCSSEditorNode.setAttribute("id", "inputCSSEditorCSS");
  107. inputCssCSSEditorNode.setAttribute("type", "text");
  108. inputCssCSSEditorNode.setAttribute("placeholder", "Carregando...");
  109. formCSSEditorNode.append(inputCssCSSEditorNode);
  110.  
  111. // Botao de submit;
  112. var submitCSSEditorNode = document.createElement("button");
  113. submitCSSEditorNode.setAttribute("class", "button");
  114. submitCSSEditorNode.setAttribute("id", "saveButtonCSSEditor");
  115. submitCSSEditorNode.setAttribute("onclick", "removeFormCSSEditor");
  116. submitCSSEditorNode.innerHTML = "Enviar Alterações"
  117. // Agora comeca a putaria de juntar tudo.
  118. formCSSEditorNode.append(submitCSSEditorNode);
  119. containerCSSEditorNode.append(formCSSEditorNode);
  120. $("body").append(containerCSSEditorNode);
  121. // Aparentemente jquery so funciona se ele ja ta appended.
  122. $("#containerCSSEditor").css("top", top).css("left", left);
  123. // Por enquanto, nao quero nenhum submit.
  124. document.addEventListener("submit", function(e){
  125. e.preventDefault();
  126. })
  127. }
  128.  
  129. function removeFormCSSEditor(){
  130. $("#containerCSSEditor").remove();
  131. }
  132.  
  133. var sheet = (function(){
  134. var style = document.createElement("style");
  135. style.appendChild(document.createTextNode(""));
  136. document.head.appendChild(style);
  137.  
  138. return style.sheet;
  139. });
  140. var v = sheet();
  141. v.insertRule(
  142. "#containerCSSEditor{" +
  143. "position: absolute;" +
  144. "display: table;" +
  145. "height: 500px;" +
  146. "width: 400px;" +
  147. "background: #e6e6e6;" +
  148. "overflow: scroll;" +
  149. "border-radius: 10px;" +
  150. "border: 1px solid black;" +
  151. "padding-top: 10px;" +
  152. "}"
  153. );
  154. v.insertRule(
  155. "#containerCSSEditor input, #containerCSSEditor button, #containerCSSEditor textarea{" +
  156. "width: 80%; " +
  157. "box-sizing: border-box; " +
  158. "background: #616161; " +
  159. "margin-left: 10%;" +
  160. "margin-bottom: 4px; " +
  161. "color: #FFF; " +
  162. "font-family: monospace;" +
  163. "border-radius: 5px;" +
  164. "height: 20px;" +
  165. "z-index: 10;" +
  166. "}"
  167. );
  168. v.insertRule(
  169. "#cssEditorTitle{" +
  170. "margin-top: 0;" +
  171. "text-align: center;" +
  172. "padding-bottom: 10px;" +
  173. "border-bottom: 1px solid black;"+
  174. "}"
  175. )
  176. v.insertRule(
  177. "#CSSEditorUlContainer{" +
  178. "max-height: 450px;" +
  179. "overflow: scroll;" +
  180. "margin-left: -40px" +
  181. "}"
  182. );
  183. v.insertRule(
  184. ".cssEditorLi{" +
  185. "padding-top: 2px;" +
  186. "padding-bottom: 2px;" +
  187. "padding-left: 20px;" +
  188. "height: 25px;" +
  189. "width: 350px;" +
  190. "background: #e6e6e6;" +
  191. "font-size: 14px;" +
  192. "cursor: pointer;" +
  193. "list-style-type: none;" +
  194. "}"
  195. );
  196. v.insertRule(
  197. "#divName{"+
  198. "display: block;" +
  199. "text-align: center;" +
  200. "font-size: 14px;" +
  201. "}"
  202. );
  203. v.insertRule(
  204. "#saveButtonCSSEditor{" +
  205. "display: block;"+
  206. "}"
  207. );
  208. v.insertRule(
  209. "#inputCSSEditorCSS{" +
  210. "overflow: scroll;" +
  211. "height: 100%!important;" +
  212. "max-height: 360px!important;" +
  213. "margin-top: 10px!important;" +
  214. "margin-bottom: 10px!important;" +
  215. "}"
  216. );
  217. $("html").unbind().mousedown(rightclick);
  218.  
  219. //window.onload = function() {
  220. document.addEventListener("contextmenu", function(e){
  221. if(e.which == 3 || e.button == 2){
  222. e.preventDefault();
  223. }
  224. }, false);
  225. //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement