Difference between revisions of "Text lookup"

From Wikidocumentaries
Jump to navigation Jump to search
(Created page with "Red links can be selected or any text can be highlighted in a Wikipedia article or image description field to bring up a contextual search menu. The menu will in the first pha...")
 
 
Line 1: Line 1:
 
Red links can be selected or any text can be highlighted in a Wikipedia article or image description field to bring up a contextual search menu. The menu will in the first phase direct the user to that topic page. Later on it can be modified to make annotations that can be consumed by different projects.
 
Red links can be selected or any text can be highlighted in a Wikipedia article or image description field to bring up a contextual search menu. The menu will in the first phase direct the user to that topic page. Later on it can be modified to make annotations that can be consumed by different projects.
  
<code>
+
<pre>
 
var getSelectedText = function () {
 
var getSelectedText = function () {
 
   var selectedText = '';
 
   var selectedText = '';
Line 21: Line 21:
 
   // Now you can do whatever you want with your selected text  
 
   // Now you can do whatever you want with your selected text  
 
});
 
});
</code>
+
</pre>

Latest revision as of 11:38, 10 January 2019

Red links can be selected or any text can be highlighted in a Wikipedia article or image description field to bring up a contextual search menu. The menu will in the first phase direct the user to that topic page. Later on it can be modified to make annotations that can be consumed by different projects.

var getSelectedText = function () {
  var selectedText = '';

  if (window.getSelection()) {
    selectedText = window.getSelection();
  } else if (document.getSelection()) {
    selectedText = document.getSelection();
  } else if (document.selection) {
    selectedText = document.selection.createRange().text;
  }

  return selectedText;
};

window.addEventListener('mouseup', function () {
  var result = getSelectedText();

  // Now you can do whatever you want with your selected text 
});