Evento Drag Drop no Input (onDrop) (drop)

Como prevenir evento drag drop no input?

<input type="text" (drop)="onDrop($event)"></div>

export class DropComponent {
    onDrop(event) {
        event.preventDefault();
    }
}

prevent drag in input Angular 5

<span class="entry-utility-prep entry-utility-prep-cat-links">Posted in</span> Angular 5, AngularJS, IONIC, JavaScript | <span class="entry-utility-prep entry-utility-prep-tag-links">Tagged</span> , | Leave a comment

Push Envio de Notificação Firebase Para Usuário Específico

Há em nossas aplicações mobile sempre a necessidade de enviar notificações push aos usuários dos nossos app.
O Google vem mudando recentemente o GCM para FCM (Firebase Cloud Messassing).
Neste post mostro como realizar o envio através do PostMan.

  1. Você irá enviar um POST para a URL https://fcm.googleapis.com/fcm/send
  2. Atribuir o Content-Type application/json
  3. Atribuir o Authorization Key=seu key token

  1. Atribuir a mensagem que deseja enviar ao seu usuário

{
 "to": "seu token ou instance id ou device token gerado ao registrar o app do usuário",
 "notification" : {
 "body" : "Um novo post sobre notificação firebase ionic!",
 "title" : "CTASoftware Blog",
 "content_available" : "true",
 "priority" : "high"
 },
 "data" : {
 "body" : "Um novo post sobre notificação firebase ionic!",
 "title" : "CTASoftware Blog",
 "content_available" : true,
 "priority" : "high"
 } 
}

 

Para saber mais sobre todos os parâmetros utilize a documentação do firebase https://firebase.google.com/docs/cloud-messaging/http-server-ref

Abraços.

 

<span class="entry-utility-prep entry-utility-prep-cat-links">Posted in</span> Dicas, IONIC, PHP | <span class="entry-utility-prep entry-utility-prep-tag-links">Tagged</span> , , , , , | Leave a comment

Authorization no PHP

O PHP por default não aceita Authorization enviado no header.
Para utilizar se faz necessário alterar o .htaccess do apache.

RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* – [e=HTTP_AUTHORIZATION:%1]

<span class="entry-utility-prep entry-utility-prep-cat-links">Posted in</span> Sem categoria | Leave a comment

Gerar GUID em JavaScript

Gera GUID em JavaScript.

[js]
function guid() {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
return s4() + s4() + ‘-‘ + s4() + ‘-‘ + s4() + ‘-‘ +
s4() + ‘-‘ + s4() + s4() + s4();
}
[/js]

<span class="entry-utility-prep entry-utility-prep-cat-links">Posted in</span> JavaScript | Leave a comment

Alterar Input File por Imagem

O css e html abaixo alteram o padrão do input file para uma imagem.

css
[css]
.image-upload > input
{
display: none;
}
[/css]

HTML
[html]

[/html]

Resultado

Simples assim…

<span class="entry-utility-prep entry-utility-prep-cat-links">Posted in</span> JavaScript, JQuery | <span class="entry-utility-prep entry-utility-prep-tag-links">Tagged</span> , , | Leave a comment

Formatação de CPF em JavaScript

Formata CPF em JavaScript.
Obs: Não faz validação, apenas formata.

[js]
function formatarCPFExibicaoApenas(v) {
if (v != undefined) {
if (v.length <= 14) { //CPF //Coloca um ponto entre o terceiro e o quarto dígitos v = v.replace(/(\d{3})(\d)/, "$1.$2") //Coloca um ponto entre o terceiro e o quarto dígitos //de novo (para o segundo bloco de números) v = v.replace(/(\d{3})(\d)/, "$1.$2") //Coloca um hífen entre o terceiro e o quarto dígitos v = v.replace(/(\d{3})(\d{1,2})$/, "$1-$2") return v; } } } [/js]

<span class="entry-utility-prep entry-utility-prep-cat-links">Posted in</span> JavaScript | <span class="entry-utility-prep entry-utility-prep-tag-links">Tagged</span> , | Leave a comment

Script Gerar Senha em JavaScript

Script para geração de senha em JavaScript

[js]
// Gera um número aleatório
function returnRand() {
var randomization = Math.random().toString();
var lengthNumbers = randomization.length;
var sort = randomization.substring(lengthNumbers, lengthNumbers – 1);
return sort;
}

// Gera uma senha simples
function generatePasswordEasy() {
var retorno = ‘password’;
var letters = [‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’, ‘h’, ‘i’, ‘j’];

retorno = letters[returnRand()].toUpperCase() + letters[returnRand()] + letters[returnRand()] +
returnRand() + returnRand() + returnRand();

return retorno;
}

// Gera uma senha complexa
function generatePassword(len) {
var pwd = [],
cc = String.fromCharCode,
R = Math.random,
rnd, i;
pwd.push(cc(48 + (0 | R() * 10))); // push a number
pwd.push(cc(65 + (0 | R() * 26))); // push an upper case letter

for (i = 2; i < len; i++) { rnd = 0 | R() * 62; // generate upper OR lower OR number pwd.push(cc(48 + rnd + (rnd > 9 ? 7 : 0) + (rnd > 35 ? 6 : 0)));
}

// shuffle letters in password
return pwd.sort(function() { return R() – .5; }).join(”);
}
[/js]

<span class="entry-utility-prep entry-utility-prep-cat-links">Posted in</span> JavaScript | Leave a comment

Verifica se Email é Válido JavaScript

Faz a verificação se um e-mail é válido em JavaScript

[js]
function emailIsValid(email) {
var regexEmail = new RegExp(“[a-zA-Z0-9][a-zA-Z0-9._-]+@([a-zA-Z0-9._-]+.)[a-zA-Z-0-9]{2,3}”);
if (!regexEmail.test(email)) { return false; }
return true;
}
[/js]

<span class="entry-utility-prep entry-utility-prep-cat-links">Posted in</span> JavaScript, JQuery | Leave a comment

Formatar Telefone em JavaScript

Método para formatar telefone com 8 ou 9 dígitos em JavaScript.

[js]
function formataNumeroTelefone(ddd, numero) {
var length = numero.length;
var telefoneFormatado;

if (length === 8) {
telefoneFormatado = ‘(‘ + ddd + ‘) ‘ + numero.substring(0, 4) + ‘-‘ + numero.substring(4, 8);
} else if (length === 9) {
telefoneFormatado = ‘(‘ + ddd + ‘) ‘ + numero.substring(0, 5) + ‘-‘ + numero.substring(5, 9);
}
return telefoneFormatado;
}
[/js]

Até a próxima

<span class="entry-utility-prep entry-utility-prep-cat-links">Posted in</span> JavaScript | <span class="entry-utility-prep entry-utility-prep-tag-links">Tagged</span> , | Leave a comment

Ler JSON facilmente em C#

Lendo JSON rapidamente em C#

[js]
dynamic array = JsonConvert.DeserializeObject(json);
foreach(var item in array)
{
Console.WriteLine(“{0} – {1}”, item.Nome, item.Telefone);
}
[/js]

<span class="entry-utility-prep entry-utility-prep-cat-links">Posted in</span> .NET | <span class="entry-utility-prep entry-utility-prep-tag-links">Tagged</span> , , | Leave a comment