Skip to content

Instantly share code, notes, and snippets.

@cld-santos
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cld-santos/11005494 to your computer and use it in GitHub Desktop.
Save cld-santos/11005494 to your computer and use it in GitHub Desktop.
This sample shows how to implement a quick insert panel to able users to quickly register information using desktop, smartphone and tablets devices.
.prompt{
padding:5px;
background-color:black;
height:28px;
color:white;
font-family:courier;
}
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta name="description" content="quick edit panel" />
<meta name="viewport" content="width=device-width">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
</head>
<body>
<br><br>
<div class="prompt" contentEditable=true>
write the html code <span style="background-color:blue;">here</span>
</div>
<div class="result">
</div>
</body>
</html>
console.clear();
var makeMarked = function(pStr){
function replaceMarked(match,a,b,c){
return '<span style="background-color:yellow;">' + b + '</span>';
}
return pStr.replace(/(\*)([\sa-zÃ-ú]*)(\*)/gi, replaceMarked);
}
var extrairNota = function(texto){
texto = texto.replace(/\n/g,'');
var Nota = {};
var textoValido = /^(\@[a-z]{4}\s){0,1}([\sa-zÃ-ú0-9\"\*\#]+)$/i.exec(texto);
if (textoValido!=null){
Nota.tipo = (textoValido[1]!=null) ? /\@([a-zÃ-ú]{4})/i.exec(textoValido[1])[1] : "info";
Nota.descricao = textoValido[2];
Nota.descricaoHtml = makeMarked(textoValido[2]);
Nota.markers = textoValido[2].match(/(\*)([\sa-zÃ-ú]*)(\*)/gi);
}else{
throw {tipo:"falhaConversao", mensagem:"texto mal formado"};
}
return Nota;
}
$('.prompt').focus();
$('.prompt').keypress(function(event){
if ( event.which == 13 ) {
event.preventDefault();//stop the enter action on the div content
var textoDaCaixaDeEntrada = $('.prompt').text();
try{
var NotaExtraida = extrairNota(textoDaCaixaDeEntrada);
}catch(erro){
alert(erro.mensagem);
return ;
}
console.log(NotaExtraida);
$('.result').append("<br>");
$('.result').append(NotaExtraida.descricaoHtml);
$('.prompt').text('');
$('.prompt').html('');
$('.prompt').focus();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment