Jump to content

User talk:Philosopher/vector.js

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia

Suggest changes

[edit]
// Please leave the following line
// [[user:Where/usertabs]]
 
jQuery(document).ready(function() {
  if (wgTitle.indexOf("/") != -1 || document.title.indexOf("- History -") != -1)  //no subpages or history
     return;
  if (wgCanonicalNamespace == "User" || wgCanonicalNamespace == "User_talk") {
     var username = encodeURIComponent( wgTitle );
     addPortletLink("p-cactions", "http://toolserver.org/~soxred93/count/index.php?name=" + username + "&lang=en&wiki=wikipedia", "Edit count", "ca-editcount", "Edit count");
     addPortletLink("p-cactions", wgServer + "/w/index.php?title=Special:Log&type=move&user=" + username, "Page moves", "ca-pagemoves", "Page moves by this user");
     addPortletLink("p-cactions", wgServer + "/w/index.php?title=Special:Log&type=block&page=User:" + username, "Blocks received", "ca-blog", "Blocks received by this user");
     addPortletLink("p-cactions", wgServer + "/w/index.php?title=Special:Log&type=rights&page=User:" + username, "User rights log", "", "User rights log");
     addPortletLink("p-cactions", wgServer + "/w/index.php?title=Special:Prefixindex&from=" + username + "/&namespace=2", "Userspace", "", "List of pages in this user's userspace");
  }
});


//
importScript('User:TheDJ/qui.js');

//
importScript('User:Alex Smotrov/wlunwatch.js');

//
function embedFeedbackDashboard() {
	var embed_feedback_dashboard_div = document.getElementById( 'fg-test-feedback-dashboard-embed' );
	if (embed_feedback_dashboard_div) {
		var embed_feedback_dashboard_req;
		if(window.XMLHttpRequest) {
			embed_feedback_dashboard_req = new XMLHttpRequest();
		} else {
			embed_feedback_dashboard_req = new ActiveXObject( 'Microsoft.XMLHTTP' );
		}
		embed_feedback_dashboard_req.onreadystatechange=function() {
			if((embed_feedback_dashboard_req.readyState == 4) && (embed_feedback_dashboard_req.status == 200)) {
				var embed_feedback_dashboard_str = embed_feedback_dashboard_req.responseText;

				//////////// Not entirely certain about this style of quoting. Should be ok though. ////////////
				var embed_feedback_dashboard_pos = embed_feedback_dashboard_str.indexOf( 'id="bodyContent"' )+17;

				embed_feedback_dashboard_str = embed_feedback_dashboard_str.substr(embed_feedback_dashboard_pos);
				embed_feedback_dashboard_pos = embed_feedback_dashboard_str.indexOf( '<!-- /bodyContent -->' );
				embed_feedback_dashboard_str = embed_feedback_dashboard_str.substr(0, embed_feedback_dashboard_pos);
				embed_feedback_dashboard_div.innerHTML = embed_feedback_dashboard_str;
			}
		}
		embed_feedback_dashboard_req.open('GET', '/wiki/Special:FeedbackDashboard', true);
		embed_feedback_dashboard_req.send();
	}
}
jQuery(document).ready(embedFeedbackDashboard);

Not entirely sure about the marked quotes. But I thought you might prefer it styled how WMF advise (for their devs etc). The most important changes are to use jQuery(document).ready() instead of addOnloadHook() or document.addEventListener("DOMContentLoaded",functionName,false). The former is being deprecated, and the latter can be a little temperamental (depending on where and how used). fredgandt 05:56, 7 January 2012 (UTC)[reply]

Well, since I really don't know what either command means - I just used "addOnloadHook" because that's what I saw in the instructions for the code at the time - I'll make the changes, thanks. --Philosopher Let us reason together. 03:44, 8 January 2012 (UTC)[reply]
No probs. "addOnloadHook" (in simple terms) will trigger when the page elements are finished loading. So lets say we want to add some text to the text inside an element of the page. We first have to tell the script to get the element, so it knows which to add the text to. If the script starts to run before the page has finished loading, the element we are looking for might not exist (yet), and the script will crash. With the on load hook, the script waits until it's told that all the DOM elements of the page are ready. Now though, "addOnloadHook" is being deprecated and we should all be using f***ing jQuery instead. You'll still see all kinds of code being used that is deprecated. Standards historically take many years to pass fully into common use. Best to try to keep up though. Let me know if anything goes wrong, and I'll do my best to help. fredgandt 04:10, 8 January 2012 (UTC)[reply]
Thanks for the explanation. --Philosopher Let us reason together. 04:23, 8 January 2012 (UTC)[reply]