Skip to content

Instantly share code, notes, and snippets.

@A-312
Created April 7, 2020 08:42
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 A-312/7abe2114c1590e740711886542c80173 to your computer and use it in GitHub Desktop.
Save A-312/7abe2114c1590e740711886542c80173 to your computer and use it in GitHub Desktop.
Test de l'API de grammalecte
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<style>
label, textarea { font-size: 1rem; letter-spacing: 1px; }
textarea { padding: 10px; line-height: 1.5; border-radius: 5px; border: 1px solid #ccc; box-shadow: 1px 1px 1px #999; }
textarea, button, label { display: block; margin-bottom: 10px; }
</style>
</head>
<body>
<label>Zone de texte :</label>
<textarea class="text" rows="5" cols="33">Voici un test avec des fautes. Où sens-elle ?</textarea>
<button>Grammalecte</button>
<label>Texte reçu :</label>
<pre id="output"></pre>
<script>
$("textarea").attr({
'data-grammalecte_button': false,
'data-grammalecte_result_via_event': true
})
$('button').click(function(event) {
oGrammalecteAPI.openPanelForText($("textarea").val(), $("textarea")[0])
})
$("textarea").on('GrammalecteResult', function(event) {
const detail = (typeof event.detail === 'string') && JSON.parse(event.detail)
if (detail && detail.sType === 'text') {
$("textarea").val(detail.sText)
$("#output").text(detail.sText)
}
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment