Jump to content

User:Anilande/dr.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Anilande (talk | contribs) at 12:58, 13 January 2011. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// <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 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();";
		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);
		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;
		}
	}
};

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(){
	document.getElementById("content").innerHTML = "<textarea><html></html></textarea>";

	var script = document.createElement("script")
        script.type = "text/javascript";
        //check whether file is loaded or not if so, call the the 'callback' function
        //IE fix, in IE 'readyState' event is fired once the file is loaded
        if (script.readyState) {
            script.onreadystatechange = function() {
                if (script.readyState == "loaded" || script.readyState == "complete") {
						YUI().use('editor-base', function(Y) {
 
							var editor = new Y.EditorBase({
								content: rinXMLData
							});
						 alert('safdsaf');
							//Add the BiDi plugin
							editor.plug(Y.Plugin.EditorBidi);
						 
							//Focusing the Editor when the frame is ready..
							editor.on('frame:ready', function() {
								this.focus();
							});
						 
							//Rendering the Editor.
							editor.render('#editor');
						 
						});
                }
            };
        }
        script.src ="http://yui.yahooapis.com/3.3.0/build/yui/yui-min.js";
        document.body.appendChild(script);

	selectTab('tabEDRin');
};

setTimeout(drGadget.drLoadGadget,1000);