Created
April 10, 2014 06:33
-
-
Save AlexMocioi/10348145 to your computer and use it in GitHub Desktop.
Funcție ajutătoare să faci ceva cu un text selectat prin dublu-click într-o fereastră HTML
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getSelectedText() { | |
if (window.getSelection) return window.getSelection().toString(); | |
if (document.getSelection) return document.getSelection().toString(); | |
if (document.selection) return document.selection.createRange().text.toString(); | |
return ""; | |
} | |
//În altă parte vrei să se declanșeze ceva când utilizatorul a selectat un cuvânt: | |
//- merge pe selecție prin drag peste text, când termini, pe mouseUp | |
//- merge când faci dublu-click, că face și selecția și apoi la mouseUp declanșează acțiunea | |
// pun acum evenimentul pe mouseUp și dacă am selecție de cuvânt, caut cabinetul după acel cuvânt | |
$('#tabelaIncasariParserate td').mouseup(function(evt) { | |
// Dacă nu-i în TD, abandonez | |
if ( evt.target.tagName!="TD" ) return; | |
var crtTR = $(evt.target).closest("tr")[0]; | |
var cuvant = trim(getSelectedText()); | |
if (cuvant=="") return; | |
// de aici înseamnă că am text selectat, fac ceva cu el, lookup, display ... | |
... | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment