Browse files

copy text from iframe upon selection

  • Loading branch information...
1 parent 974654d commit e6fcbdbbb9ce2e3cf33db4c4ece0730d0d11157f @gkovacs committed Apr 17, 2012
Showing with 28 additions and 0 deletions.
  1. +28 −0 views/index.ejs
View
28 views/index.ejs
@@ -576,6 +576,27 @@ function showOrHide(elem) {
}
}
+/** Copy selected text into suggestions input textbox */
+function copySelectedText() {
+ var txt = '';
+ var iframe = document.getElementById('frameConts');
+ if (window.getSelection) {
+ var iwindow = iframe.contentWindow || iframe.contentDocument.defaultView;
+ txt = ''+iwindow.getSelection();
+ }
+ else if (document.getSelection) {
+ var idocument = iframe.contentDocument || iframe.contentWindow.document;
+ txt = ''+idocument.getSelection();
+ }
+ else if (document.selection) {
+ var idocument = iframe.contentDocument || iframe.contentWindow.document;
+ txt = idocument.selection.createRange().text;
+ }
+ else return;
+ $('#text_to_be_translated_suggestion').val(txt);
+}
+
+
function getFrameHTML() {
return frames['frameConts'].document.body.innerHTML;
}
@@ -786,6 +807,13 @@ collapseOrExpand($('#scoreBoardRegion'));
//$("#notificationContainer").notify();
+/** When user releases mouse over iframe, copy highlighted selection into textbox */
+$('#frameConts').load(function() {
+ $(document.getElementById('frameConts').contentWindow.document).mouseup(function(){
+ copySelectedText();
+ });
+});
+
});
</script>
<body id='mainBody'>

0 comments on commit e6fcbdb

Please sign in to comment.