Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.02 KB | None | 0 0
  1. // Isso aqui ja faz pegar todos os pais.
  2.  
  3. var elements = [];
  4. var posicaoX = 0;
  5. var posicaoY = 0;
  6.  
  7. function rightclick() {
  8. var rightclick;
  9. var e = window.event;
  10.  
  11. // Detecta um clique esquerdo fora da caixa pra fechar ela.
  12. if(e.which == 1){
  13. var auxTarget = e.target;
  14. var dontDelete = false;
  15.  
  16. // O carinha existe, vamos ver se eu cliquei dentro ou fora.
  17. if($("#containerCSSEditor")){
  18.  
  19. while(auxTarget.tagName != "BODY"){
  20. if(auxTarget.getAttribute("id") == "containerCSSEditor")
  21. dontDelete = true;
  22. auxTarget = auxTarget.parentNode;
  23. }
  24.  
  25. // Cliquei fora, pode deletar.
  26. if(!dontDelete) $("#containerCSSEditor").remove();
  27. }
  28. }
  29.  
  30. if (e.which == 3 || e.button == 2){
  31. elements = [];
  32. var target = e.target;
  33. posicaoX = e.pageX;
  34. posicaoY = e.pageY;
  35. auxTarget = target;
  36.  
  37. if($("#containerCSSEditor")){
  38. $("#containerCSSEditor").remove();
  39. }
  40.  
  41. while(auxTarget.tagName != "BODY"){
  42. elements.push(auxTarget);
  43. auxTarget = auxTarget.parentNode;
  44. }
  45.  
  46. criarListaCSS(false);
  47. }
  48. }
  49.  
  50. function criarListaCSS(verdade){
  51.  
  52. $("#containerCSSEditor").remove();
  53.  
  54. // Cria o container Geral.
  55. var cssEditForm = document.createElement("div");
  56. cssEditForm.setAttribute("id", "containerCSSEditor");
  57.  
  58. // Cria o titulo do css;
  59. var cssTitle = document.createElement("h3");
  60. cssTitle.setAttribute("id", "cssEditorTitle");
  61. cssTitle.append("CSS Aplicados");
  62.  
  63. // Cria a lista e vamos comecar a tacar as coisa ali. (TODO)
  64. var cssULContainer = document.createElement("ul");
  65. cssULContainer.setAttribute("id", "CSSEditorUlContainer");
  66.  
  67. // Agora comeca a adicionar os elementos da lista.
  68.  
  69. for(var i = 0; i < elements.length; i++){
  70. var cssEditorLi = document.createElement("li");
  71. cssEditorLi.setAttribute("class", "cssEditorLi");
  72. cssEditorLi.setAttribute("id", "EditorLi"+i);
  73. cssEditorLi.setAttribute("onclick", "abreEditorCSS(" + i + ")");
  74. var classe = elements[i].className;
  75. var idElemento = elements[i].id;
  76.  
  77. if(classe != ""){
  78. classe = "."+classe;
  79. }
  80. if(idElemento != ""){
  81. idElemento = "#"+idElemento;
  82. }
  83.  
  84. if(!verdade){
  85. if(classe != "" && classe != ""){
  86. cssEditorLi.innerHTML = elements[i].tagName.toLowerCase() + classe + " " + idElemento;
  87. cssULContainer.append(cssEditorLi);
  88. }
  89. }else{
  90. cssEditorLi.innerHTML = elements[i].tagName.toLowerCase() + classe + " " + idElemento;
  91. cssULContainer.append(cssEditorLi);
  92. }
  93. }
  94.  
  95. cssEditForm.append(cssTitle);
  96. cssEditForm.append(cssULContainer);
  97. if(!verdade){
  98. var voltarCSSEditorNode = document.createElement("article");
  99. voltarCSSEditorNode.setAttribute("class", "button-voltar");
  100. voltarCSSEditorNode.setAttribute("id", "carregar");
  101. voltarCSSEditorNode.setAttribute("onclick", "criarListaCSS(true)");
  102. voltarCSSEditorNode.innerHTML = "Carregar todos os elementos";
  103. cssEditForm.append(voltarCSSEditorNode);
  104. }
  105.  
  106. $("body").append(cssEditForm);
  107. $("#containerCSSEditor").css("top", posicaoY).css("left", posicaoX);
  108. }
  109.  
  110.  
  111. function abreEditorCSS(index){
  112.  
  113. var top = $("#containerCSSEditor").css("top");
  114. var left = $("#containerCSSEditor").css("left");
  115. $("#containerCSSEditor").remove();
  116. // Cria um novo editor, dessa vez com base em um form.
  117. var containerCSSEditorNode = document.createElement("div");
  118. containerCSSEditorNode.setAttribute("id", "containerCSSEditor");
  119.  
  120. var voltarCSSEditorNode = document.createElement("article");
  121. voltarCSSEditorNode.setAttribute("class", "button-voltar");
  122. voltarCSSEditorNode.setAttribute("id", "voltarButton");
  123. voltarCSSEditorNode.setAttribute("onclick", "criarListaCSS(false)");
  124. voltarCSSEditorNode.innerHTML = "Voltar"
  125. containerCSSEditorNode.append(voltarCSSEditorNode);
  126.  
  127. var quebraLinha = document.createElement("br");
  128. containerCSSEditorNode.append(quebraLinha);
  129.  
  130. // Botar um titulo pra ficar mais bonitin
  131. var cssTitleNode = document.createElement("h3");
  132. cssTitleNode.setAttribute("id", "cssEditorTitle");
  133. cssTitleNode.append("Alterar CSS");
  134. containerCSSEditorNode.append(cssTitleNode);
  135.  
  136. // Cria o form.
  137. var formCSSEditorNode = document.createElement("form");
  138. formCSSEditorNode.setAttribute("id", "formCSSEditor");
  139. formCSSEditorNode.setAttribute("method", "post");
  140. formCSSEditorNode.setAttribute("action", "google.com"); // TODO.
  141. // Agora cria os inputs do form
  142. // Nome do elemento.
  143. var inputNameCSSEditorNode = document.createElement("input");
  144. inputNameCSSEditorNode.setAttribute("readonly", "");
  145. inputNameCSSEditorNode.setAttribute("name", "divName");
  146. inputNameCSSEditorNode.setAttribute("id", "divName");
  147. inputNameCSSEditorNode.setAttribute("type", "text");
  148. inputNameCSSEditorNode.setAttribute("value", "< " + elements[index].tagName.toLowerCase() + " class='" + elements[index].className + "' id='" + elements[index].id + "' >");
  149. formCSSEditorNode.append(inputNameCSSEditorNode);
  150.  
  151.  
  152. var inputCssCSSEditorNode = document.createElement("textarea");
  153. inputCssCSSEditorNode.setAttribute("rows", "30")
  154. inputCssCSSEditorNode.setAttribute("name", "inputCSSEditorCSS");
  155. inputCssCSSEditorNode.setAttribute("id", "inputCSSEditorCSS");
  156. inputCssCSSEditorNode.setAttribute("type", "text");
  157. inputCssCSSEditorNode.setAttribute("placeholder", "Carregando...");
  158. formCSSEditorNode.append(inputCssCSSEditorNode);
  159.  
  160. // Botao de submit;
  161. var submitCSSEditorNode = document.createElement("button");
  162. submitCSSEditorNode.setAttribute("class", "button");
  163. submitCSSEditorNode.setAttribute("id", "saveButtonCSSEditor");
  164. submitCSSEditorNode.setAttribute("onclick", "removeFormCSSEditor");
  165. submitCSSEditorNode.innerHTML = "Enviar Alterações"
  166. // Agora comeca a putaria de juntar tudo.
  167. formCSSEditorNode.append(submitCSSEditorNode);
  168. containerCSSEditorNode.append(formCSSEditorNode);
  169. $("body").append(containerCSSEditorNode);
  170. // Aparentemente jquery so funciona se ele ja ta appended.
  171. $("#containerCSSEditor").css("top", top).css("left", left);
  172. // Por enquanto, nao quero nenhum submit.
  173. document.addEventListener("submit", function(e){
  174. e.preventDefault();
  175. })
  176. }
  177.  
  178. function getAllStyles(elem) {
  179. if (!elem) return []; // Element does not exist, empty list.
  180. var win = document.defaultView || window, style, styleNode = [];
  181. if (win.getComputedStyle) { /* Modern browsers */
  182. style = win.getComputedStyle(elem, '');
  183. for (var i=0; i<style.length; i++) {
  184. styleNode.push( style[i] + ':' + style.getPropertyValue(style[i]) );
  185. // ^name ^ ^ value ^
  186. }
  187. } else if (elem.currentStyle) { /* IE */
  188. style = elem.currentStyle;
  189. for (var name in style) {
  190. styleNode.push( name + ':' + style[name] );
  191. }
  192. } else { /* Ancient browser..*/
  193. style = elem.style;
  194. for (var i=0; i<style.length; i++) {
  195. styleNode.push( style[i] + ':' + style[style[i]] );
  196. }
  197. }
  198. return styleNode;
  199. }
  200.  
  201.  
  202.  
  203.  
  204.  
  205. function removeFormCSSEditor(){
  206. $("#containerCSSEditor").remove();
  207. }
  208.  
  209. var sheet = (function(){
  210. var style = document.createElement("style");
  211. style.appendChild(document.createTextNode(""));
  212. document.head.appendChild(style);
  213.  
  214. return style.sheet;
  215. });
  216. var v = sheet();
  217. v.insertRule(
  218. "#containerCSSEditor{" +
  219. "position: absolute;" +
  220. "display: table;" +
  221. "height: 600px;" +
  222. "width: 450px;" +
  223. "background: #e6e6e6;" +
  224. "overflow-x: hidden;" +
  225. "overflow-y: scroll;" +
  226. "border-radius: 10px;" +
  227. "border: 1px solid black;" +
  228. "padding-top: 10px;" +
  229. "}"
  230. );
  231. v.insertRule(
  232. "#containerCSSEditor input, #containerCSSEditor button, #containerCSSEditor textarea{" +
  233. "width: 80%; " +
  234. "box-sizing: border-box; " +
  235. "background: #616161; " +
  236. "margin-left: 10%;" +
  237. "margin-bottom: 4px; " +
  238. "color: #FFF; " +
  239. "font-family: monospace;" +
  240. "border-radius: 5px;" +
  241. "height: 20px;" +
  242. "z-index: 10;" +
  243. "}"
  244. );
  245. v.insertRule(
  246. "#cssEditorTitle{" +
  247. "margin-top: 0;" +
  248. "text-align: center;" +
  249. "padding-bottom: 10px;" +
  250. "border-bottom: 1px solid black;"+
  251. "}"
  252. )
  253. v.insertRule(
  254. "#CSSEditorUlContainer{" +
  255. "max-height: 450px;" +
  256. "overflow-x: hidden;" +
  257. "overflow-y: scroll;" +
  258. "margin-left: -40px" +
  259. "}"
  260. );
  261. v.insertRule(
  262. ".cssEditorLi{" +
  263. "padding-top: 15px;" +
  264. "padding-bottom: 7px;" +
  265. "padding-left: 25px;" +
  266. "height: 25px;" +
  267. "width: 100%;" +
  268. "background: #e6e6e6;" +
  269. "font-size: 14px;" +
  270. " transition: transform .2s;" +
  271. "border-bottom: 1px solid black;" +
  272. "cursor: pointer;" +
  273. "list-style-type: none;" +
  274. "}"
  275. );
  276. v.insertRule(
  277. ".cssEditorLi:hover{" +
  278. "background: #b3b3b3;" +
  279. "transform: scale(1.1);" +
  280. "}"
  281. );
  282. v.insertRule(
  283. ".button-voltar{" +
  284. "color: black;" +
  285. "cursor: pointer;" +
  286. "margin-left: 20px;" +
  287. "padding: 7px;" +
  288. "border: 1px solid black;" +
  289. "border-radius: 10px;" +
  290. "background-color: #5692b0;" +
  291. "}"
  292. );
  293.  
  294. v.insertRule(
  295. "#divName{"+
  296. "display: block;" +
  297. "text-align: center;" +
  298. "font-size: 14px;" +
  299. "}"
  300. );
  301.  
  302. v.insertRule(
  303. "#inputCSSEditorCSS{" +
  304. "overflow-x: hidden;" +
  305. "overflow-y: scroll;" +
  306. "height: 100%!important;" +
  307. "max-height: 360px!important;" +
  308. "margin-top: 10px!important;" +
  309. "margin-bottom: 10px!important;" +
  310. "}"
  311. );
  312. $("html").unbind().mousedown(rightclick);
  313.  
  314. //window.onload = function() {
  315. document.addEventListener("contextmenu", function(e){
  316. if(e.which == 3 || e.button == 2){
  317. e.preventDefault();
  318. }
  319. }, false);
  320. //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement