ಸದಸ್ಯ:Teju2friends/define-it.js
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
/*javascript:
document.write('<script src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js\" type=\"text/javascript\" charset=\"utf-8\"></script>');
*/
var myDiv;
function requestCrossDomain(e, site, callback )
{
if ( !site ||typeof callback !== 'function') {
throw new Error('URL not found!');
return false;
}
var yql = 'http://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent('select * from html where url="' + site + '" and xpath=\'//*[@id="bodyContent"]\'') + '&format=xml&callback=?';
$.getJSON( yql, function (data) {
if ( data.results[0] )
{
data = data.results[0].replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '');
callback(data);
}
else displayMeaning(e,"ಪದ ಸಿಕ್ಕಿಲ್ಲ");
});
}
function getSelText(e)
{
var text = document.getElementById("wpTextbox1");
if (document.selection) // For IE
{
sl = document.selection.createRange().text;
}
else // Non-IE
{
sl = text.value.substring(text.selectionStart,text.selectionEnd);
}
if(sl.replace(/^\s*/g,"") === "") return; // Trim & return if empty
else return "http://kn.wiktionary.org/wiki/"+ sl; // Return URL
}
function setDispPosition(e)
{
sX = e.pageX;
sY = e.pageY;
}
function hideDiv()
{
myDiv.style["display"] = "none";
}
function displayMeaning(e,meaning)
{
setDispPosition(e);
if(myDiv == undefined) // If popup not yet created
{
myDiv = document.createElement("div");
document.body.appendChild(myDiv);
myDiv.style["position"] = 'absolute';
myDiv.style["background"] = "#FFFFA8";
myDiv.style["border"] = "2px solid Gainsboro";
myDiv.style["font-size"] = "larger";
}
myDiv.style["left"] = sX + "px";
myDiv.style["top"] = (sY + 20) + "px"; // Be the position of popup below selected text
myDiv.style["z-index"] = "1015"; // Make the popup above all elements
myDiv.innerHTML = '<div onclick="hideDiv();" style="color:blue; font-size: small;">[ಮುಚ್ಚು / Close]</div>' + meaning;
myDiv.style["display"] = "inline";
}
function getMeaning(e)
{
requestCrossDomain(e,getSelText(e), function(results) {
results = results.replace(/<div class=\"printfooter[\s\S]*?<\/div>/gi,''); //remove footer
results = results.replace(/<table class=\"toc[\s\S]*?<\/table>/gi,''); //remove Index
results = results.replace(/<div class=\"catlinks[\s\S]*?<\/div>/gi,''); //remove Category
results = results.replace(/<[/]*a[^>]*>/gi,''); //remove all links
results = results.replace(/contentSub/gi,''); //remove contentSub, for style issue
displayMeaning(e,results.replace(/<span[^>]*>[\s\S]*?<\/span>/gi,'')); // Remove any edit options
});
return false;
}
var textbox = document.getElementById("wpTextbox1");
if(textbox)textbox.setAttribute('ondblclick',"getMeaning(event)");
//void(0);