var w = null, text = null, arr = null, max = null;
var current = 0;
var current_id = null;
var palabras = false;
var autoRead = false;
var rendering = false;
var pictures = [];

if (window.level == undefined) {

   level = 3;  // 0-10, higher level, less word replacements.

}

if (window.polite == undefined) {

   polite = 10;  // 0-10, higher level, less jokes added.

}

if (window.pitch == undefined) {

   pitch = 1.0;

}

if (window.speed == undefined) {

   speed = 0.6;

}

$('.pic').hide();

function getRandomSentence() {

  var random = [
"Caca culo pedo pis.",
"Tu culo huele mal.",
"Este cuento es muy tonto.",
"Yo no quiero leer más, déjame en paz.",
"Baila con el culo, baila con el pito."
];
var l = random.length;
var i = dice(l);
return randomi?;

}

function dice(faces) {

   var i = Math.floor((Math.random() * faces));
return i;

}

$('.read').hide()

$('.text').each( function() {

   var title =  $(this).attr('name');
var textId = $(this).attr('id');
var bid = textId + "_btn";
$('#menu').append('<a id="' + bid + '" href="#" class="button menu_btn">' + title +'</a>');
$('#' + bid).click( function() {
openText(textId);
});

});

if ($('.menu_btn').length == 1) {

   $('.menu_btn').click();

}

function openText(cid) {

       w = $("#" + cid);
palabras = w.hasClass('palabras');
autoRead = w.hasClass('autoRead');
useBookmark = w.hasClass('useBookmark');
text = w.text().trim();
arr = text.split(/\.\n?+/gm);
// arr = text.split(/\.\n?+/);
max = arr.length -1 ;
if (arrmax?.trim() != "") {
arr.push("");
max++;
}
// remember last page?
current = 0;
if (useBookmark) {
current = app.Load Number?('pag_' + cid, 0);
}
current_id = cid;
$('#menu').hide();
$('.read').show();
pictures = [];
       for (var i = 0; i <= max; i++) {
var page = i + 1;
var pic = $('.pic').filter('.' + current_id).filter('.p' + page);
pictures.push(pic);
}
       changePage()

}

function changePage() {

   if (current < 0 || current > max) {
current = 0;
$('#menu').show();
$('.read').hide();
return;
}
if (current > max ) {
current = 0;
}
   rendering = true;
if (autoRead) {
$('#control').hide();
}
$('#texto').html('');
setTimeout(setPage, 20);

}

function setPage() {

   var t = arrcurrent?.trim();
if (/.*(a-z?|^\u 0000-\u 007 F?)$/.test(t)) {
// Add a dot if necessary, to sentences ending in a letter:
t = t + '.';
}
   replacements = [];
   if (palabras && current) {
       var words = t.split(/\n\r\t.,:;'\"\+!\?-?+/);
var wl = words.length - 1;
for (var i = 0; i < wl; i++) {
var word = wordsi?;
if (word == "") continue;
var wid = word.toLowerCase();
           var img = $('#' + wid + ".pic");
if (img.length && dice(10) >= level ) {
t = t.replace(word, "<span class='" + wid + "'></span>");
replacements.push(wid);
}
}
}
   if (current == 0) {
t = "<h3>" + t + "</h3>";
   }
   $('#texto').html("<div class='sentence'>" + t + "</div><div id='pic'></div>");
   var wl = replacements.length;
for (var i = 0; i < wl; i++) {
var wid = replacementsi?;
$('#' + wid).clone().appendTo("." + wid).show();
}
   // Show illustration, if existing.
var pic = picturescurrent?;
   if (pic.length == 1) {
pic.clone().appendTo('#pic').show();
if (!palabras) $('.sentence').css({"margin-top": '0.5em'});
} else {
if (!palabras) $('.sentence').css({"margin-top": '1.5em'});
}
app.Save Number?('pag_' + current_id, current);
   var page = current + 1;
if (current == max ) {
$('#texto').html('<hr/><hr/><hr/><hr/><hr/>');
$('#pageCnt').text('Fin');
} else {
$('#pageCnt').text(page + ' de ' + max);
}
if (autoRead) {
setTimeout(function() { rendering = false; $('#control').show(); }, 2000 );
readAloud();
} else {
rendering = false;
}

}

$('#pageCnt').click(function() {

   if (rendering) return;
current = 0;
changePage()

});

$('#next').click(function() {

   if (rendering) return;
current++;
changePage()

});

$('#prev').click(function() {

   if (rendering) return;
current--;
changePage()

});

function readAloud() {

   var read = arrcurrent? + ".";
read = read.replace("- ", "");
if (dice(10) > polite) {
// One in every few cases, we also read a random sentence :-)
read = read + " " + getRandomSentence();
}
app.Text To Speech?( read, pitch, speed );

}

$('#texto').click(function() {

   readAloud();

});


EditThis! (edited 2014-06-15 13:23) [info] [diff] ♦ Print [help]
Search. Links to this page.
Recent changes, Wiki Front Page, What is this wiki?