Cómo preservar la selección de texto al abrir un cuadro de diálogo jQuery
Usando el diálogo de jQuery me encontré con el siguiente capricho (probado en FF3):
El usuario selecciona el textoEn código, abra un cuadro de diálogo jQueryBUG: el texto no se selecciona(el texto puede estar en un área de texto o simplemente un HTML en la página)
Entonces, para mí parece un error divertido (y molesto) o un capricho, pero tal vez haya una buena explicación para eso. Y lo que más me interesa es cómo preservar esta selección de texto después de abrir el diálogo.
Aquí hay un código:
function getSelectedText() {
var t;
if (d.getSelection) t = d.getSelection();
else if(d.selection) t = d.selection.createRange();
if (t.text != undefined) t = t.text;
if (!t || t=='') {
var a = d.getElementsByTagName('textarea');
for (var i = 0; i < a.length; ++i) {
if (a[i].selectionStart != undefined && a[i].selectionStart != a[i].selectionEnd) {
t = a[i].value.substring(a[i].selectionStart, a[i].selectionEnd);
break;
}
}
}
return t;
}
$("#dialog").dialog({
autoOpen: false,
bgiframe: false,
height: 60,
width: 80,
modal: false,
show: 'highlight',
title: 'wc'});
alert(getSelectedText()); // Text is here
$("#dialog").dialog("open");
alert(getSelectedText()); // Text is not selected here :( damn!
¡Gracias