From abb367f8fd3dfc6edf321c436a59bbf3f92a87e3 Mon Sep 17 00:00:00 2001 From: Edmar Moretti Date: Thu, 10 Feb 2011 21:38:25 +0000 Subject: [PATCH] Otimização de código com JSlint. Remoção de variáveis inúteis. Correções no IE. --- classesjs/classe_ajuda.js | 10 +++++++--- classesjs/classe_arvoredecamadas.js | 20 ++++++++++---------- classesjs/classe_barradebotoes.js | 14 +++++++------- classesjs/classe_calculo.js | 6 +++--- classesjs/classe_configura.js | 2 +- classesjs/classe_eventos.js | 3 ++- classesjs/classe_i3geo.js | 9 +++++++-- classesjs/classe_navega.js | 12 +++++++----- classesjs/classe_selecao.js | 4 ++-- classesjs/classe_social.js | 6 +++--- classesjs/classe_util.js | 17 +++++++++++------ css/geral.css | 2 +- ferramentas/inserexy2/index.js.php | 1 + ferramentas/selecao/index.js.php | 73 ++++++++++++++++++++++++++++++------------------------------------------- guia_de_migracao.txt | 6 ++++++ interface/geral.htm | 2 +- 16 files changed, 99 insertions(+), 88 deletions(-) diff --git a/classesjs/classe_ajuda.js b/classesjs/classe_ajuda.js index 499b87c..c85a5ce 100644 --- a/classesjs/classe_ajuda.js +++ b/classesjs/classe_ajuda.js @@ -185,6 +185,7 @@ i3GEO.ajuda = { */ ativaCookie: function(){ i3GEO.util.insereCookie("g_janelaMen","sim"); + i3GEO.util.insereCookie("botoesAjuda","sim"); }, /* Function: ativaLetreiro @@ -273,17 +274,20 @@ i3GEO.ajuda = { jm = $i("i3geo_janelaMensagens"), h = parseInt(YAHOO.util.Dom.getStyle(jm,"height"),10), temp; + if(j){ j.innerHTML = texto === "" ? "-" : texto; } else{ - YAHOO.util.Dom.setY("i3geo_janelaMensagens",YAHOO.util.Dom.getY(jm) + h); + if(h) + {YAHOO.util.Dom.setY("i3geo_janelaMensagens",YAHOO.util.Dom.getY(jm) + h);} if(k){k.innerHTML = texto;} if(i3GEO.ajuda.TRANSICAOSUAVE){ temp = texto !== "" ? YAHOO.util.Dom.setStyle(jm,"opacity","1") : YAHOO.util.Dom.setStyle(jm,"opacity",(i3GEO.ajuda.OPACIDADE / 100)); } h = parseInt(YAHOO.util.Dom.getStyle(jm,"height"),10); - YAHOO.util.Dom.setY(jm,YAHOO.util.Dom.getY(jm) - h); + if(h) + {YAHOO.util.Dom.setY(jm,YAHOO.util.Dom.getY(jm) - h);} } }, /* @@ -307,7 +311,7 @@ i3GEO.ajuda = { {$i(i3GEO.ajuda.DIVLETREIRO).value = BSpaces + BMessage;} BPos-=BSpeed; if (BQuantas < 2) - {i3GEO.ajuda.tempoLetreiro = setTimeout('i3GEO.ajuda.mostraLetreiro();', 140);} + {i3GEO.ajuda.tempoLetreiro = setTimeout(function(){i3GEO.ajuda.mostraLetreiro();}, 140);} }, /* Function: redesSociais diff --git a/classesjs/classe_arvoredecamadas.js b/classesjs/classe_arvoredecamadas.js index c5cc6e6..a50f6bc 100644 --- a/classesjs/classe_arvoredecamadas.js +++ b/classesjs/classe_arvoredecamadas.js @@ -343,19 +343,19 @@ i3GEO.arvoreDeCamadas = { if(!YAHOO.lang.isUndefined(funcaoTema)){ i3GEO.arvoreDeCamadas.ATIVATEMA = funcaoTema; } - this.SID = typeof(g_sid) !== 'undefined' ? g_sid : i3GEO.configura.sid; - this.LOCAPLIC = typeof(g_locaplic) !== 'undefined' ? g_locaplic : i3GEO.configura.locaplic; + i3GEO.arvoreDeCamadas.SID = typeof(g_sid) !== 'undefined' ? g_sid : i3GEO.configura.sid; + i3GEO.arvoreDeCamadas.LOCAPLIC = typeof(g_locaplic) !== 'undefined' ? g_locaplic : i3GEO.configura.locaplic; if(onde !== "") - {this.IDHTML = onde;} - if(this.IDHTML === "") + {i3GEO.arvoreDeCamadas.IDHTML = onde;} + if(i3GEO.arvoreDeCamadas.IDHTML === "") {return;} - if(!$i(this.IDHTML)) + if(!$i(i3GEO.arvoreDeCamadas.IDHTML)) {return;} if(YAHOO.lang.isUndefined(temas)) {return;} - this.atualiza(temas); - if(this.finaliza !== ""){ - eval(this.finaliza); + i3GEO.arvoreDeCamadas.atualiza(temas); + if(i3GEO.arvoreDeCamadas.finaliza !== ""){ + eval(i3GEO.arvoreDeCamadas.finaliza); } }, /* @@ -1325,7 +1325,7 @@ i3GEO.arvoreDeCamadas = { do{ ltema = camadas[i]; if(ltema.escondido !== "sim"){ - temp = eval("ltema."+propriedade); + temp = ltema[propriedade]; if(operador === "igual"){ if(temp === valor) {resultado.push(ltema);} @@ -1365,7 +1365,7 @@ i3GEO.arvoreDeCamadas = { do{ ltema = i3GEO.arvoreDeCamadas.CAMADAS[i]; if(ltema.name === camada){ - eval("ltema."+propriedade+"='"+valor+"';"); + ltema[propriedade] = valor; } i += 1; } diff --git a/classesjs/classe_barradebotoes.js b/classesjs/classe_barradebotoes.js index 9ff2355..3274e22 100644 --- a/classesjs/classe_barradebotoes.js +++ b/classesjs/classe_barradebotoes.js @@ -324,9 +324,9 @@ i3GEO.barraDeBotoes = { BOTAOCLICADO: "", ativaPadrao: function(){ try{ - $i(i3GEO.barraDeBotoes.BOTAOPADRAO).onclick.call(); + $i(i3GEO.barraDeBotoes.BOTAOPADRAO).onclick.apply(); //call não funciona no IE } - catch(e){} + catch(e){alert(e)} }, /* Function: ativaIcone @@ -447,7 +447,7 @@ i3GEO.barraDeBotoes = { */ ativaBotoes:function(padrao){ if(typeof(console) !== 'undefined'){console.info("i3GEO.barraDeBotoes.ativaBotoes()");} - var l,b; + var l,b,d; if(arguments.length === 0) {padrao = i3GEO.barraDeBotoes.BOTAOPADRAO;} i3GEO.barraDeBotoes.BOTAOCLICADO = padrao; @@ -464,7 +464,7 @@ i3GEO.barraDeBotoes = { } if(l[b].funcaoonclick){ $i(l[b].iddiv).onclick = l[b].funcaoonclick; - if(l[b].iddiv === padrao) + if(l[b].iddiv == padrao) {l[b].funcaoonclick();} } if(l[b].constroiconteudo) @@ -539,7 +539,7 @@ i3GEO.barraDeBotoes = { chaves = i3GEO.util.listaChaves(i3GEO.barraDeBotoes.INCLUIBOTAO); n = chaves.length; for(i=0;i";} if(tipo === "semtotal") - {return "";} + {return "";} }, publicarTwitter: function(url,tipo){ if(tipo === "comtotal") @@ -89,9 +89,9 @@ i3GEO.social = { tabela += ""+i3GEO.social.publicarTwitter(urlpt,tipo)+""; } if(urlcf !== ""){ + //tabela += ""; tabela += ""+i3GEO.social.curtirFacebook(urlcf,tipo)+""; - tabela += ""; - } + } tabela += ""; if(id !== "") {onde.innerHTML = tabela;} diff --git a/classesjs/classe_util.js b/classesjs/classe_util.js index df1fcc0..c46dd8a 100644 --- a/classesjs/classe_util.js +++ b/classesjs/classe_util.js @@ -1,4 +1,4 @@ -/*jslint plusplus:false,white:false,undef: false, rhino: true, onevar: true, evil: true */ +/*jslint plusplus:false,white:false,undef: false, rhino: true, onevar: true, evil: false */ /* Title: Utilitários @@ -104,6 +104,7 @@ Quando o usuário clica no mapa, essa variável é pesquisada para definir o tipo d */ g_tipoacao = "zoomli"; +/* g_postpx = "px"; g_tipotop = "top"; g_tipoleft = "left"; @@ -113,7 +114,7 @@ if (navm) g_tipotop = "pixelTop"; //utilizado para crossbrowser g_tipoleft = "pixelLeft"; //utilizado para crossbrowser } - +*/ /* Function: $i @@ -279,13 +280,17 @@ i3GEO.util = { */ criaBotaoAplicar: function (nomeFuncao,titulo,classe,obj) { if(typeof(console) !== 'undefined'){console.info("i3GEO.util.criaBotaoAplicar()");} - try - {clearTimeout(tempoBotaoAplicar);} + try{ + if(typeof(tempoBotaoAplicar) !== 'undefined') + {clearTimeout(tempoBotaoAplicar);} + } catch(e){ if(typeof(console) !== 'undefined'){console.error(e);} } - var novoel,xy; - tempoBotaoAplicar = eval("setTimeout('"+nomeFuncao+"\(\)',(i3GEO.configura.tempoAplicar))"); + var executar = new Function(nomeFuncao+"().call;clearTimeout(tempoBotaoAplicar);"), + novoel,xy; + //tempoBotaoAplicar = eval("setTimeout('"+nomeFuncao+"\(\)',(i3GEO.configura.tempoAplicar))"); + tempoBotaoAplicar = setTimeout(executar,(i3GEO.configura.tempoAplicar)); autoRedesenho("reinicia"); if(arguments.length === 1) {titulo = "Aplicar";} diff --git a/css/geral.css b/css/geral.css index 38442a5..7661e61 100644 --- a/css/geral.css +++ b/css/geral.css @@ -66,7 +66,7 @@ select .executar {cursor:pointer;color:white;text-align:left;background-color:gray;background-image:URL('../imagens/tic.png');background-repeat:no-repeat;border-style:outset;background-position: right;font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 10px;} .inputsb -{font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 10px;color: #2F4632;background-color: #FFFFFF;padding: 0;border: 1px solid gray;text-align: center;cursor: text;} +{font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 10px;color: #2F4632;background-color: #FFFFFF;padding: 0;border: 0px solid gray;text-align: center;cursor: text;} .legendatemas {cursor:pointer;text-align:left;background-color:none;vertical-align: top;border: 0px solid gray;margin:0;padding:0;font-family: Verdana, Arial, Helvetica, sans-serif;} .legendatemas td diff --git a/ferramentas/inserexy2/index.js.php b/ferramentas/inserexy2/index.js.php index e76485c..c737fb2 100644 --- a/ferramentas/inserexy2/index.js.php +++ b/ferramentas/inserexy2/index.js.php @@ -288,6 +288,7 @@ i3GEOF.inserexy = { i3GEO.eventos.MOUSECLIQUE.remove("i3GEOF.inserexy.adicionaClique()"); }; YAHOO.util.Event.addListener(janela[0].close, "click", temp); + i3GEO.util.mudaCursor(i3GEO.configura.cursores,"crosshair",i3GEO.Interface.IDMAPA,i3GEO.configura.locaplic); }, /* Function: ativaFoco diff --git a/ferramentas/selecao/index.js.php b/ferramentas/selecao/index.js.php index 26e9d02..143fa45 100644 --- a/ferramentas/selecao/index.js.php +++ b/ferramentas/selecao/index.js.php @@ -218,6 +218,7 @@ i3GEOF.selecao = { if(i3GEO.eventos.MOUSECLIQUE.toString().search("i3GEOF.selecao.clique()") < 0) {i3GEO.eventos.MOUSECLIQUE.push("i3GEOF.selecao.clique()");} temp = function(){ + i3GEO.barraDeBotoes.ativaPadrao(); i3GEO.eventos.MOUSECLIQUE.remove("i3GEOF.selecao.clique()"); try{ i3GEO.desenho.richdraw.fecha; @@ -228,6 +229,7 @@ i3GEOF.selecao = { if($i("pontosins")){document.body.removeChild($i("pontosins"));} }; YAHOO.util.Event.addListener(janela[0].close, "click", temp); + i3GEO.util.mudaCursor(i3GEO.configura.cursores,"crosshair",i3GEO.Interface.IDMAPA,i3GEO.configura.locaplic); }, /* Function: ativaFoco @@ -235,7 +237,7 @@ i3GEOF.selecao = { Refaz a interface da ferramenta quando a janela flutuante tem seu foco ativado */ ativaFoco: function(){ - i3GEO.util.mudaCursor(i3GEO.configura.cursores,"pointer",i3GEO.Interface.IDMAPA,i3GEO.configura.locaplic); + i3GEO.util.mudaCursor(i3GEO.configura.cursores,"crosshair",i3GEO.Interface.IDMAPA,i3GEO.configura.locaplic); i3GEO.barraDeBotoes.ativaIcone("selecao"); i3GEOF.selecao.pegaTemasSel(); g_tipoacao='selecao'; @@ -262,10 +264,6 @@ i3GEOF.selecao = { if($i("i3GEOselecaopoli")) {$i("i3GEOselecaopoli").style.border = "1px solid RGB(230,230,230)";} i3GEO.desenho.richdraw.fecha; - if($i(i3GEO.Interface.IDMAPA)){ - $i(i3GEO.Interface.IDMAPA).title = ""; - i3GEO.util.mudaCursor(i3GEO.configura.cursores,"identifica",i3GEO.Interface.IDMAPA,i3GEO.configura.locaplic); - } }, /* Function: pegaTemasSel @@ -380,22 +378,21 @@ i3GEOF.selecao = { */ inicia: function(){ if($i("i3GEOselecaotemasLigados").value === "") - {alert("Escolha um tema");return;} + {alert("Escolha um tema");return;} if(g_tipoacao !== 'selecaobox') {return;} + i3geoOL.removeControl(OLpanel); i3GEOF.selecao.box.criaBox(); adicionaxyBox = i3GEO.util.pegaPosicaoObjeto($i(i3GEO.Interface.IDCORPO)); var i = $i("i3geoboxSel").style; - i.width=0; - i.height=0; + i.width="10px"; + i.height="10px"; i.visibility="visible"; i.display="block"; - i.left = objposicaocursor.imgx + adicionaxyBox[0] + g_postpx; - i.top = objposicaocursor.imgy + adicionaxyBox[1] + g_postpx; + i.left = objposicaocursor.imgx + adicionaxyBox[0] - 5; + i.top = objposicaocursor.imgy + adicionaxyBox[1] - 5; boxxini = objposicaocursor.imgx + adicionaxyBox[0]; boxyini = objposicaocursor.imgy + adicionaxyBox[1]; - tamanhox = 0; - tamanhoy = 0; if(i3GEO.eventos.MOUSEMOVE.toString().search("i3GEOF.selecao.box.desloca()") < 0) {i3GEO.eventos.MOUSEMOVE.push("i3GEOF.selecao.box.desloca()");} if(i3GEO.eventos.MOUSEUP.toString().search("i3GEOF.selecao.box.termina()") < 0) @@ -407,55 +404,46 @@ i3GEOF.selecao = { Cria o DIV que será utilizado para desenhar o box no mapa */ criaBox: function(){ - try{i3GEO.desenho.richdraw.fecha;} - catch(e){ - if(typeof(console) !== 'undefined'){console.error(e);} + if(i3GEO.Interface.ATUAL !== "openlayers"){ + try{i3GEO.desenho.richdraw.fecha;} + catch(e){ + if(typeof(console) !== 'undefined'){console.error(e);} + } + i3GEO.desenho.criaContainerRichdraw(); + i3GEO.desenho.richdraw.lineColor = "red"; + i3GEO.desenho.richdraw.lineWidth = "2px"; } - i3GEO.desenho.criaContainerRichdraw(); - i3GEO.desenho.richdraw.lineColor = "red"; - i3GEO.desenho.richdraw.lineWidth = "2px"; var novoel,temp; if(!$i("i3geoboxSel")){ novoel = document.createElement("div"); - novoel.style.width = "0px"; - novoel.style.height = "0px"; + novoel.style.width = "10px"; + novoel.style.height = "10px"; novoel.id = "i3geoboxSel"; - novoel.style.display = "none"; + novoel.style.display = "block"; novoel.style.fontSize = "0px"; - if(navn) - {novoel.style.opacity = 0.25;} + YAHOO.util.Dom.setStyle(novoel,"opacity",0.25); novoel.style.backgroundColor = "yellow"; novoel.style.position="absolute"; novoel.style.border = "2px solid #ff0000"; - if (navm) - {novoel.style.filter = "alpha(opacity=25)";} novoel.onmousemove = function(){ var b,wb,hb; b = $i("i3geoboxSel").style; wb = parseInt(b.width,10); hb = parseInt(b.height,10); - if (navm){ - if(wb > 2) - {b.width = wb - 2;} - if(hb > 2) - {b.height = hb - 2;} - } - else{ - b.width = wb - 2 + "px"; - b.height = hb - 2 + "px"; - } + if(wb > 2) + {b.width = wb - 2;} + if(hb > 2) + {b.height = hb - 2;} }; novoel.onmouseup = function() {i3GEOF.selecao.box.termina();}; document.body.appendChild(novoel); } - i3GEO.util.mudaCursor(i3GEO.configura.cursores,"zoom","i3geoboxSel",i3GEO.configura.locaplic); if($i("img")){ $i("img").title = ""; temp = "zoom"; if(i3GEO.Interface.ATIVAMENUCONTEXTO) {temp = "zoom_contexto";} - i3GEO.util.mudaCursor(i3GEO.configura.cursores,temp,"img",i3GEO.configura.locaplic); } }, /* @@ -472,7 +460,7 @@ i3GEOF.selecao = { {return;} ppx = objposicaocursor.imgx + adicionaxyBox[0]; py = objposicaocursor.imgy + adicionaxyBox[1]; - if (navm){ + if (navn){ if ((ppx > boxxini) && ((ppx - boxxini - 2) > 0)) {bxs.width = ppx - boxxini - 2;} if ((py > boxyini) && ((py - boxyini - 2) > 0)) @@ -511,8 +499,8 @@ i3GEOF.selecao = { var bxs = $i("i3geoboxSel").style; bxs.display="none"; bxs.visibility="hidden"; - bxs.width = 0; - bxs.height = 0; + bxs.width = "0px"; + bxs.height = "0px"; }; if((x1 === x2) || (y1 === y2)) {limpa.call();return;} @@ -611,9 +599,8 @@ i3GEOF.selecao = { inicia: function(){ try {i3GEO.desenho.richdraw.fecha;} - catch(e){ - if(typeof(console) !== 'undefined'){console.error(e);} - } + catch(e) + {if(typeof(console) !== 'undefined'){console.error(e);}} pontosdistobj = []; i3GEO.util.insereMarca.limpa(); g_tipoacao = "selecaopoli"; diff --git a/guia_de_migracao.txt b/guia_de_migracao.txt index d178edb..09126ca 100644 --- a/guia_de_migracao.txt +++ b/guia_de_migracao.txt @@ -37,6 +37,12 @@ Para a versão 4.5 css/i3geo_ferramentas45.css Testado o uso de zlib.output_compression = On no php.ini + + Variáveis ou funções removidas + i3GEO.interface (utilize i3GEO.Interface, com "I" maiúsculo) + g_postpx + g_tipotop + g_tipoleft ------------------------------------------------------------------------------------------------- Para a versão 4.4 diff --git a/interface/geral.htm b/interface/geral.htm index 83b93eb..c3c70bf 100644 --- a/interface/geral.htm +++ b/interface/geral.htm @@ -213,7 +213,7 @@ i3GEO.barraDeBotoes.COMPORTAMENTO = "laranja" i3GEO.barraDeBotoes.AUTO = true //as barras de botões serão construídas automaticamente i3GEO.idioma.IDSELETOR = "seletorIdiomas" -i3GEO.interface.ATIVAMENUCONTEXTO = true; +i3GEO.Interface.ATIVAMENUCONTEXTO = true; //i3GEO.gadgets.PARAMETROS.mostraCoordenadasUTM.idhtml = ""; -- libgit2 0.21.2