This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// padrão módulo | |
var MYAPP = { | |
// definição dos namespaces | |
models: {}, | |
views: {}, | |
controllers: {}, | |
utils: {} | |
} | |
MYAPP.models.User = function (name, email, gender) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// INPUT EVENT | |
var texto = document.getElementById("texto"); | |
// evento input é disparado depois de o texto ser inserido em um elemento (não é possível cancelar) | |
texto.addEventListener("input", function () { | |
this.value = this.value.toUpperCase(); | |
}); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var obj = { | |
id: 11, nome: 'Julio', | |
test: {id: 1, nome: 'test'} | |
}; | |
var arrayFromObject = function (obj) { | |
var arr = []; | |
for (var i in obj) { | |
arr[i] = (typeof obj[i] === 'object') ? | |
arrayFromObject(obj[i]) : arr[i] = obj[i]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ajax(method, url, callback) { | |
var xmlhttp; | |
if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari | |
try { xmlhttp = new XMLHttpRequest(); } catch (e) { xmlhttp = false; } | |
} else { // code for IE6, IE5 | |
try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { | |
try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { xmlhttp = false; } | |
} | |
} | |
if (!xmlhttp) { alert("Erro ao criar o objeto XMLHttpRequest"); return; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
<input type="text" id="txtFind" placeholder="Buscar"> | |
<div> | |
<p class="name">Bruno</p> | |
<p class="name">Sara</p> | |
<p class="name">Bernardo</p> | |
<p class="name">Kennedy</p> | |
<p class="name">Bianca</p> | |
<p class="name">Alex</p> | |
<p class="name">Jessica</p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Permite apenas números, vírgula e ponto (000.000.000,00) | |
* Ideal para o evento keypress de um input por exemplo | |
*/ | |
function onlyMonetary(event) { | |
var character = String.fromCharCode(event.keyCode); | |
var regex1 = new RegExp(/[\d.,]/); | |
if (!regex1.test(character)) { | |
if (event.preventDefault) event.preventDefault(); | |
event.returnValue = false; // caso o navegador não aceite preventDefault |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Testa se o valor está no formato 000.000.000,00 | |
* @param value | |
* @return {boolean} | |
*/ | |
function isMonetary(value) { | |
var regex = new RegExp(/^\d+((\d{0,3}(\.\d(\d{0,2}))+)?,\d+)?$/); | |
return regex.test(value); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
<style> #div1 { width: 350px; height: 70px; padding: 10px; border: 1px solid #aaaaaa; } </style> | |
<div id="div1"></div><br> | |
<img id="drag1" src="https://www.w3schools.com/html/img_logo.gif" width="336" height="69"> | |
*/ | |
function allowDrop(ev) { ev.preventDefault(); } | |
function drag(ev) { ev.dataTransfer.setData("text", ev.target.id); } | |
function drop(ev) { | |
ev.preventDefault(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*<style> span#relogio { font: bold 24pt sans-serif; background: #ddf; padding: 10px; border: solid black 2px; border-radius: 10px; } </style> | |
<span id="relogio"></span> | |
<textarea cols="40" rows="20"></textarea>*/ | |
var relogio = document.getElementById("relogio"); | |
function exibeHora() { | |
var agora = new Date(); | |
var hrs = agora.getHours(), mins = agora.getMinutes(); | |
if (mins < 10) mins = "0" + mins; | |
relogio.innerHTML = hrs + ":" + mins; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// COORDENADAS | |
// o objeto Event possui as propriedades clientX e clientY que especificam as | |
// coordenadas do cursor do mouse em relação à janela contêiner | |
function coordenadas(event) { | |
console.log("Coordenadas de X: " + event.clientX + | |
", coordenadas de Y: " + event.clientY); | |
} | |
window.addEventListener("click", coordenadas); |