I've been able to do the View More function, with a StackOverflow code here, but the texts come from the dynamic database, so how do I get this code to get every text?
Code in php:
< div class="box-body" id="texto">
<?php
$texto = htmlentities($row['texto']);
$texto = preg_replace('/[\n\r]{1,}/',"\n\n",$texto);
echo nl2br(emoticons($texto));
?>
</ div>
Jquery code:
var wordLimit = 50;
$(function() {
//trata o conteúdo na inicialização da página
$('#texto').each(function() {
var post = $(this);
var text = post.text();
//encontra palavra limite
var re = /[\s]+/gm, results = null, count = 0;
while ((results = re.exec(text)) !== null && ++count < wordLimit) { }
//resume o texto e coloca o link
if (results !== null && count >= wordLimit) {
var summary = text.substring(0, re.lastIndex - results[0].length);
post.text(summary + '...');
post.data('original-text', text);
post.append('<br/><a href="#" class="read-more">Leia mais</a>');
}
});
//ao clicar num link "Leia mais", mostra o conteúdo original
$('.read-more').on('click', function() {
var post = $(this).closest('#texto');
var text = post.data('original-text');
post.text(text);
});
});