<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Battisti - Blog &#187; Javascript</title>
	<atom:link href="http://battisti.etc.br/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://battisti.etc.br</link>
	<description>Tecnologia, Web e um pouco de cultura inútil</description>
	<lastBuildDate>Tue, 27 Jul 2010 02:03:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Google API Translate Portugues Para Inglês Javascript</title>
		<link>http://battisti.etc.br/2010/04/09/google-api-translate-portugues-para-ingles-javascript/</link>
		<comments>http://battisti.etc.br/2010/04/09/google-api-translate-portugues-para-ingles-javascript/#comments</comments>
		<pubDate>Fri, 09 Apr 2010 01:29:03 +0000</pubDate>
		<dc:creator>battisti</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://battisti.etc.br/?p=895</guid>
		<description><![CDATA[Precisava fazer um esquema para traduzir o texto que o meu usuário digitava do português para o inglês, este texto estava em um campo de busca pois a APP externa que utilizei não entendia muito bem o português, sendo assim o negócio era mandar tudo em inglês para ela. O google, só pra variar um [...]]]></description>
			<content:encoded><![CDATA[<div class="mwordstext"><p>Precisava fazer um esquema para traduzir o texto que o meu usuário digitava do português para o inglês, este texto estava em um campo de busca pois a APP externa que utilizei não entendia muito bem o português, sendo assim o negócio era mandar tudo em inglês para ela.</p>
<p>O google, só pra variar um pouco, fornece uma <a class="bbli" href="http://sledge.boo-box.com/list/page/QVBJXyMjX2JveF8jI190YWdnaW5nLXRvb2wtd3BfIyNfMTkxMTQ=-52">API<img class="bbic" src="http://boo-box.com/bbli" alt="[bb]" /></a> chamada <a href="http://code.google.com/apis/ajaxlanguage/documentation/reference.html">translate API</a> que pode ser facilmente acoplada nas aplicações web.</p>
<p>Segue abaixo um exemplo de como utilizar a <a class="bbli" href="http://sledge.boo-box.com/list/page/QVBJXyMjX2JveF8jI190YWdnaW5nLXRvb2wtd3BfIyNfMTkxMTQ=-52">API<img class="bbic" src="http://boo-box.com/bbli" alt="[bb]" /></a>:</p>
<p><script src="http://gist.github.com/360765.js?file=sample_googletranslate_api.js"></script></p>
</div><!-- fim mwordstext -->]]></content:encoded>
			<wfw:commentRss>http://battisti.etc.br/2010/04/09/google-api-translate-portugues-para-ingles-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Replace Javascript Várias Ocorrências</title>
		<link>http://battisti.etc.br/2010/04/08/replace-javascript-varias-ocorrencias/</link>
		<comments>http://battisti.etc.br/2010/04/08/replace-javascript-varias-ocorrencias/#comments</comments>
		<pubDate>Thu, 08 Apr 2010 00:23:30 +0000</pubDate>
		<dc:creator>battisti</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://battisti.etc.br/?p=890</guid>
		<description><![CDATA[Estava eu aqui com um Javascript onde eu precisava substituir várias ocorrências de uma string dentro de outra, usei o replace mas para minha surpresa ele apenas substituiu a primeira o ocorrência! E agora, como faço para substituir todas as ocorrências? Como Faz? var a = "teste teste teset"; console.log(a.replace('e','')); // substitui apenas a primeira [...]]]></description>
			<content:encoded><![CDATA[<div class="mwordstext"><p>
  Estava eu aqui com um <i>Javascript</i> onde eu precisava substituir várias ocorrências de uma string dentro de outra, usei o replace mas para minha surpresa ele apenas substituiu a primeira o ocorrência! E agora, como faço para substituir todas as ocorrências?
</p>
<h1>Como Faz? </h1>
<p><span id="more-890"></span></p>
<pre>
var a = "teste teste teset";
console.log(a.replace('e','')); // substitui apenas a primeira ocorrência
console.log(a.replace(/e/g,'')); // substitui todas as ocorrências
</pre>
<p>Grande Abraço</p>
</div><!-- fim mwordstext -->]]></content:encoded>
			<wfw:commentRss>http://battisti.etc.br/2010/04/08/replace-javascript-varias-ocorrencias/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Alterar a Cor da Linha via CSS usando JQuery</title>
		<link>http://battisti.etc.br/2009/07/23/alterar-a-cor-da-linha-via-css-usando-jquery/</link>
		<comments>http://battisti.etc.br/2009/07/23/alterar-a-cor-da-linha-via-css-usando-jquery/#comments</comments>
		<pubDate>Thu, 23 Jul 2009 23:41:05 +0000</pubDate>
		<dc:creator>battisti</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://battisti.etc.br/?p=588</guid>
		<description><![CDATA[Introdução Fazer com que a cor do fundo de uma linha mude de cor quando se passa o mouse por sobre ela. Exemplo $(document).ready( function() { $(".gray_grid tbody tr td table tbody tr").mouseover(function() { $(this).css("background-color","#b7ffcc"); }).mouseout(function() { $(this).css("background-color","#fff"); }) })]]></description>
			<content:encoded><![CDATA[<div class="mwordstext"><h1>Introdução</h1>
<p>Fazer com que a cor do fundo de uma linha mude de cor quando se passa o mouse por sobre ela.<span id="more-588"></span></p>
<h1>Exemplo</h1>
<pre lang="javascript">    $(document).ready( function() {
     	$(".gray_grid tbody tr td table tbody tr").mouseover(function() {
     		$(this).css("background-color","#b7ffcc");
     	}).mouseout(function() {
 		$(this).css("background-color","#fff");
     	})
    })</pre>
</div><!-- fim mwordstext -->]]></content:encoded>
			<wfw:commentRss>http://battisti.etc.br/2009/07/23/alterar-a-cor-da-linha-via-css-usando-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Teclas de Atalho com Javascript</title>
		<link>http://battisti.etc.br/2009/07/19/teclas-de-atalho-com-javascript/</link>
		<comments>http://battisti.etc.br/2009/07/19/teclas-de-atalho-com-javascript/#comments</comments>
		<pubDate>Sun, 19 Jul 2009 18:59:23 +0000</pubDate>
		<dc:creator>battisti</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://battisti.etc.br/?p=579</guid>
		<description><![CDATA[Introdução O uso de teclas de atalho em geral não é muito utilizado em aplicativos Web porém está é um falta grave pois atalhos podem aumentar  signifiicativamente a usabilidade. Mas como criar atalhos em aplicações Web? Biblioteca Existe uma biblioteca muito boa, chamada shortcuts, bem sugestivo não, abaixo eu compilei ela em um exemplo simples [...]]]></description>
			<content:encoded><![CDATA[<div class="mwordstext"><h1>Introdução</h1>
<p>O uso de teclas de atalho em geral não é muito utilizado em aplicativos Web porém está é um falta grave pois atalhos podem aumentar  signifiicativamente a usabilidade. Mas como criar atalhos em aplicações Web?</p>
<p><span id="more-579"></span></p>
<h1>Biblioteca</h1>
<p>Existe uma biblioteca muito boa, chamada <a href="http://www.openjs.com/scripts/events/keyboard_shortcuts/"><em>shortcuts</em></a>, bem sugestivo não, abaixo eu compilei ela em um exemplo simples de ser usado:</p>
<pre lang="javascript">/**********************/
//==UserScript==
//@name           shortcuts
//@namespace      hack
//@description    add shortcuts to call functions
//@include        *
//==/UserScript==

(function() { // intro

function run() {
	shortcut.add("ESC", function()alert('ESC')} );
}

//--------------------------------------------------------------------------------

/**
* http://www.openjs.com/scripts/events/keyboard_shortcuts/
* Version : 2.01.A
* By Binny V A
* License : BSD
*/
shortcut = {
	'all_shortcuts':{},//All the shortcuts are stored in this array
	'add': function(shortcut_combination,callback,opt) {
		//Provide a set of default options
		var default_options = {
			'type':'keydown',
			'propagate':false,
			'disable_in_input':false,
			'target':document,
			'keycode':false
		}
		if(!opt) opt = default_options;
		else {
			for(var dfo in default_options) {
				if(typeof opt[dfo] == 'undefined') opt[dfo] = default_options[dfo];
			}
		}

		var ele = opt.target
		if(typeof opt.target == 'string') ele = document.getElementById(opt.target);
		var ths = this;
		shortcut_combination = shortcut_combination.toLowerCase();

		//The function to be called at keypress
		var func = function(e) {
			e = e || window.event;

			if(opt['disable_in_input']) { //Don't enable shortcut keys in Input, Textarea fields
				var element;
				if(e.target) element=e.target;
				else if(e.srcElement) element=e.srcElement;
				if(element.nodeType==3) element=element.parentNode;

				if(element.tagName == 'INPUT' || element.tagName == 'TEXTAREA') return;
			}

			//Find Which key is pressed
			if (e.keyCode) code = e.keyCode;
			else if (e.which) code = e.which;
			var character = String.fromCharCode(code).toLowerCase();

			if(code == 188) character=","; //If the user presses , when the type is onkeydown
			if(code == 190) character="."; //If the user presses , when the type is onkeydown

			var keys = shortcut_combination.split("+");
			//Key Pressed - counts the number of valid keypresses - if it is same as the number of keys, the shortcut function is invoked
			var kp = 0;

			//Work around for stupid Shift key bug created by using lowercase - as a result the shift+num combination was broken
			var shift_nums = {
				"`":"~",
				"1":"!",
				"2":"@",
				"3":"#",
				"4":"$",
				"5":"%",
				"6":"^",
				"7":"&amp;",
				"8":"*",
				"9":"(",
				"0":")",
				"-":"_",
				"=":"+",
				";":":",
				"'":"\"",
				",":"&lt;", 				".":"&gt;",
				"/":"?",
				"\\":"|"
			}
			//Special Keys - and their codes
			var special_keys = {
				'esc':27,
				'escape':27,
				'tab':9,
				'space':32,
				'return':13,
				'enter':13,
				'backspace':8,

				'scrolllock':145,
				'scroll_lock':145,
				'scroll':145,
				'capslock':20,
				'caps_lock':20,
				'caps':20,
				'numlock':144,
				'num_lock':144,
				'num':144,

				'pause':19,
				'break':19,

				'insert':45,
				'home':36,
				'delete':46,
				'end':35,

				'pageup':33,
				'page_up':33,
				'pu':33,

				'pagedown':34,
				'page_down':34,
				'pd':34,

				'left':37,
				'up':38,
				'right':39,
				'down':40,

				'f1':112,
				'f2':113,
				'f3':114,
				'f4':115,
				'f5':116,
				'f6':117,
				'f7':118,
				'f8':119,
				'f9':120,
				'f10':121,
				'f11':122,
				'f12':123
			}

			var modifiers = {
				shift: { wanted:false, pressed:false},
				ctrl : { wanted:false, pressed:false},
				alt  : { wanted:false, pressed:false},
				meta : { wanted:false, pressed:false}	//Meta is Mac specific
			};

			if(e.ctrlKey)	modifiers.ctrl.pressed = true;
			if(e.shiftKey)	modifiers.shift.pressed = true;
			if(e.altKey)	modifiers.alt.pressed = true;
			if(e.metaKey)   modifiers.meta.pressed = true;

			for(var i=0; k=keys[i],i 1) { //If it is a special key
					if(special_keys[k] == code) kp++;

				} else if(opt['keycode']) {
					if(opt['keycode'] == code) kp++;

				} else { //The special keys did not match
					if(character == k) kp++;
					else {
						if(shift_nums[character] &amp;&amp; e.shiftKey) { //Stupid Shift key bug created by using lowercase
							character = shift_nums[character];
							if(character == k) kp++;
						}
					}
				}
			}

			if(kp == keys.length &amp;&amp;
						modifiers.ctrl.pressed == modifiers.ctrl.wanted &amp;&amp;
						modifiers.shift.pressed == modifiers.shift.wanted &amp;&amp;
						modifiers.alt.pressed == modifiers.alt.wanted &amp;&amp;
						modifiers.meta.pressed == modifiers.meta.wanted) {
				callback(e);

				if(!opt['propagate']) { //Stop the event
					//e.cancelBubble is supported by IE - this will kill the bubbling process.
					e.cancelBubble = true;
					e.returnValue = false;

					//e.stopPropagation works in Firefox.
					if (e.stopPropagation) {
						e.stopPropagation();
						e.preventDefault();
					}
					return false;
				}
			}
		}
		this.all_shortcuts[shortcut_combination] = {
			'callback':func,
			'target':ele,
			'event': opt['type']
		};
		//Attach the function with the event
		if(ele.addEventListener) ele.addEventListener(opt['type'], func, false);
		else if(ele.attachEvent) ele.attachEvent('on'+opt['type'], func);
		else ele['on'+opt['type']] = func;
	},

	//Remove the shortcut - just specify the shortcut and I will remove the binding
	'remove':function(shortcut_combination) {
		shortcut_combination = shortcut_combination.toLowerCase();
		var binding = this.all_shortcuts[shortcut_combination];
		delete(this.all_shortcuts[shortcut_combination])
		if(!binding) return;
		var type = binding['event'];
		var ele = binding['target'];
		var callback = binding['callback'];

		if(ele.detachEvent) ele.detachEvent('on'+type, callback);
		else if(ele.removeEventListener) ele.removeEventListener(type, callback, false);
		else ele['on'+type] = false;
	}
}

run();

})(); // outro</pre>
</div><!-- fim mwordstext -->]]></content:encoded>
			<wfw:commentRss>http://battisti.etc.br/2009/07/19/teclas-de-atalho-com-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Botão Direito do Mouse Javascript</title>
		<link>http://battisti.etc.br/2009/06/11/botao-direito-do-mouse-javascript/</link>
		<comments>http://battisti.etc.br/2009/06/11/botao-direito-do-mouse-javascript/#comments</comments>
		<pubDate>Thu, 11 Jun 2009 19:29:26 +0000</pubDate>
		<dc:creator>battisti</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://battisti.etc.br/?p=502</guid>
		<description><![CDATA[O Problema Executar uma determinada ação quando o botão direito do mouse é pressionado sobre um elemento HTML da página. A Solução function teste(event) { if(event.which == 1){ alert("Esquerdo"); } if(event.which == 2){ alert("Meio"); } if(event.which == 3){ alert("Direito"); } } Veja aqui a demonstração Conclusão Esse pequeno exemplo só foi testado no Firefox, cada [...]]]></description>
			<content:encoded><![CDATA[<div class="mwordstext"><h1>O Problema</h1>
<p>Executar uma determinada ação quando o botão direito do mouse é pressionado sobre um elemento HTML da página.<span id="more-502"></span></p>
<h1>A Solução</h1>
<pre lang="javascript">function teste(event)
{
   if(event.which == 1){
       alert("Esquerdo");
   }

   if(event.which == 2){
       alert("Meio");
   }

   if(event.which == 3){
       alert("Direito");
   }
}
<input onmousedown="teste(event)" type="button" value="clique" /></pre>
<p>Veja aqui a <a href="http://battisti.etc.br/scripts/botaodireito/botao.html" target="_self">demonstração</a></p>
<h1>Conclusão</h1>
<p>Esse pequeno exemplo só foi testado no Firefox, cada navegador possui um tratador de eventos específicos, se alguem conhecer uma biblioteca que abstraia estas coisas posta ai.</p>
<p>Para atalhos do teclado eu uso essa <a href="http://www.openjs.com/scripts/events/keyboard_shortcuts/">lib aqui</a>, muito boa e flexível.</p>
</div><!-- fim mwordstext -->]]></content:encoded>
			<wfw:commentRss>http://battisti.etc.br/2009/06/11/botao-direito-do-mouse-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
