User:Anilande/dr.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:Anilande/dr. |
// <pre><nowiki>
// _________________________________________________________________________________________
// | |
// | === WARNING: GLOBAL GADGET FILE === |
// | Changes to this page affect many users. |
// | Please discuss changes on the talk page or on [[Wikipedia_talk:Gadget]] before editing. |
// |_________________________________________________________________________________________|
//
// Imports [[User:Anilande/dRin.js]]
// </nowiki></pre>
// ===UserScript===
// @name DRin
// @namespace DRin
// @include http://*.wikipedia.org/*
// ===/UserScript===
//
// DRin launch helper script.
// Description: this script eases the procedure to launch DRin by instrumenting
// wikipedia pages with links and options to launch the application.
//
// The current options to launch DRin are:
// click the 'View Visually' option in the left side toolbox menu and 'View Visually' tab on top tabs list.
var ajaxRequest = {
createXMLHTTPObject : function (){
var activexmodes=["Msxml2.XMLHTTP", "Msxml3.XMLHTTP", "Microsoft.XMLHTTP"] //activeX versions to check for in IE
if (window.ActiveXObject){ //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
for (var i=0; i<activexmodes.length; i++){
try{
return new ActiveXObject(activexmodes[i])
}
catch(e){
continue;
}
break;
}
}else if (window.XMLHttpRequest){
return new XMLHttpRequest();
}else{
return false;
}
},
sendAjaxRequest : function(url, callback, method) {
var req = ajaxRequest.createXMLHTTPObject();
if (!req) {
return;
}
req.open("GET","http://msri-digitalpro/rin/Cache/Foobar.xml",true);
req.setRequestHeader("Cache-Control", "no-cache");
req.setRequestHeader("Pragma", "no-cache");
req.onreadystatechange = function () {
var response = {
status: req.status,
statusText: req.statusText,
readyState: req.readyState,
responseText: req.responseText,
responseHeaders: req.responseHeaders,
finalUrl: url
};
if ((req.status !== 200 && req.status !== 304) || req.readyState !== 4) {
return;
}
//callback(response);
};
if (req.readyState === 4) {
return;
}
req.send(null);
}
};
var drGadget = {
drUrl: null,
ulEle: null,
// wbLoadGadget is executed after the page finishes loading. It looks for specific
// indicators and determines how to instrument the page with different options to launch the application
drLoadGadget : function()
{
drGadget.naritiveViewTab();
// looks for the Toolbar on edit pages, creates and appends a simple button in the format expected by the toolbar
if(document.getElementById('p-views') || document.getElementById('p-cactions'))
{
if(document.getElementById('p-views')){
drGadget.ulEle = document.getElementById('p-views').getElementsByTagName("ul")[0];
}else if(document.getElementById('p-cactions')){
drGadget.ulEle = document.getElementById('p-cactions').getElementsByTagName("ul")[0];
}
drGadget.showNaritiveEditTab();
drGadget.showNaritiveViewTab();
}
},
showNaritiveViewTab : function(){
var liVElem = document.createElement('li');
liVElem.id = 'tabVDRin';
var anchorVElem = document.createElement('a');
anchorVElem.title = "View Narrative";
anchorVElem.id = "toolbarLinkDRin";
anchorVElem.innerHTML = "<span>View Narrative</span>";
anchorVElem.href = drGadget.drUrl;
liVElem.appendChild(anchorVElem);
drGadget.ulEle.insertBefore(liVElem, drGadget.ulEle.firstChild);
return true;
},
showNaritiveEditTab : function(){
var liEElem = document.createElement('li');
liEElem.id = 'tabEDRin';
var anchorEElem = document.createElement('a');
anchorEElem.title = "Edit Narrative";
anchorEElem.id = "toolbarLinkDRin";
anchorEElem.innerHTML = "<span>Edit Narrative</span>";
anchorEElem.href = "javascript:editNaritive(rinXMLData);";
liEElem.appendChild(anchorEElem);
if(document.getElementById('p-views')){
var liElem = document.getElementById('p-views').getElementsByTagName("ul")[0].getElementsByTagName("li")[2];
}else if(document.getElementById('p-cactions')){
var liElem = document.getElementById('p-cactions').getElementsByTagName("ul")[0].getElementsByTagName("li")[2];
}
drGadget.ulEle.insertBefore(liEElem, liElem);
//ajaxRequest.sendAjaxRequest("http://msri-digitalpro/rin/Cache/Foobar.xml", drGadget.populateRTEditor, 'GET');
return true;
},
getCurrentArticleTitle: function() {
if (typeof wgTitle !== "undefined") {
if (wgAction === "view" && wgArticleId === 0 && wgIsArticle === false) {
return false;
}
//in addition to the page title, get the name space also if it exists.
if (typeof wgCanonicalNamespace !== "undefined" && wgCanonicalNamespace.length > 0) {
return wgCanonicalNamespace + ":" + wgTitle;
}
return wgTitle;
}
},
naritiveViewTab : function(){
var title = drGadget.getCurrentArticleTitle();
if(title){
docHeight = ((document.height - 100)<700)?(document.height - 100):700;
drGadget.drUrl = 'javascript:(function(){ document.getElementById("content").innerHTML = "<iframe src=\'http://msri-digitalpro/rin/?PlayerMode=Dynamic&NarrativeId='+title+'\' width=\'100%\' height=\''+docHeight+'px\'></iframe>"; selectTab("tabVDRin");})();';
return true;
}else{
return false;
}
},
populateRTEditor : function(responce){
rinXMLData = responce.responseText;
}
};
var rinXMLData = '';
selectTab = function(tabObj) {
document.getElementById("tabEDRin").className="";
document.getElementById("tabVDRin").className="";
document.getElementById("ca-view").className="";
document.getElementById("ca-edit").className="";
document.getElementById("ca-history").className="";
document.getElementById(tabObj).className="selected";
};
editNaritive = function(rinXMLData){
document.getElementById("content").innerHTML = "<textarea>"+rinXMLData+"</textarea>";
selectTab('tabEDRin');
};
setTimeout(drGadget.drLoadGadget,1000);