User:I9606/swl viewer.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | Documentation for this user script can be added at User:I9606/swl viewer. |
// User scripts
//operates on pages where it can find semantic wiki links
$(document).ready(function(){
var subject = document.title.split("-")[0];
//When you mouse over a SWL indicated by its 'swl' class, get and show the elelements of the link
$(".swl").hover(function() {
console.log("hovering");
//get semantic information out
var predicate = ""; var object = "";
predicate = $("span",this).attr('class');
object = $("a",this).attr('title');
var link = "<a href=\"http://en.wikipedia.org/wiki/Category:SWL/"+predicate+"\">"+predicate+"</a>";
//console.log("embedded triple is "+ subject +" "+ predicate+" " + object);
//render a clickable pop up window
//Fade in Background to hide page
$('body').append('<div id="fade"></div>');
$('#fade').css({'filter' : 'alpha(opacity=50)'}).fadeIn();
//display the information box
$(this).append('<div id="popup_swl" class="popup_block">'+ subject +" "+link+" " + object +' <a href="#" class="close">(close)</a></div>');
$("#popup_swl").css({'filter' : 'alpha(opacity=10)'}).fadeIn();
},
//handle mouse out
function () {
// $("#popup_swl").hide();
}
);
//Close Popups and Fade Layer
$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
$('#fade , .popup_block').fadeOut(function() {
$('#fade, a.close').remove(); //fade them both out
$("#popup_swl").remove();
});
return false;
});
});