User:Quadratus/myskin.js

/** * jQuery cookie plugin * Copyright (c) 2006 Klaus Hartl (stilbuero.de) * Dual licensed under the MIT and GPL licenses: */

jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value=;options.expires=-1}var expires=;if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString)){var date;if(typeof options.expires=='number'){date=new Date;date.setTime(date.getTime+(options.expires*24*60*60*1000))}else{date=options.expires}expires='; expires='+date.toUTCString}var path=options.path?'; path='+options.path:;var domain=options.domain?'; domain='+options.domain:;var secure=options.secure?'; secure':;document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join()}else{var cookieValue=null;if(document.cookie&&document.cookie!=''){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'=')){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break}}}return cookieValue}};

/*** * Auto-complete: http://en.wikipedia.org/wiki/User:Zocky/AutoComplete.js * Link to stylesheet removed and integrated into myskin.css */

String.prototype.parseJSON=function{try{return!(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(this.replace(/"(\\.|[^"\\])*"/g,)))&&eval('('+this+')')}catch(e){return false}};function ac$query(cb,what){if(ac$query.arguments.length>1&&ac$x){var i=2;var url="/w/query.php?format=json&what="+what;while(i<ac$query.arguments.length){url=url+"&"+ac$query.arguments[i]+"="+ac$query.arguments[i+1];i+=2}ac$x.onreadystatechange=function{if(ac$x.readyState==4)return ac$x.status==200?cb(ac$x.responseText.parseJSON):cb(false)};ac$x.open("GET",url,true);ac$x.setRequestHeader('Accept','text/*');ac$x.send(null)}else return false}function ac$$e(id){return document.getElementById(id)}function ac$$c(name,id){var el=document.createElement(name);el.id=id;return el};function ac$$ia(node,newnode){return node.parentNode.insertBefore(newnode,node.nextSibling)}function ac$$uc(s){return s.substring(0,1).toUpperCase+s.substring(1)};function ac$inputKeyDown(e){if(e.which==40&&ac$b.style.visibility=="visible"){ac$b.focus}else{try{clearTimeout(ac$t)}catch(e){};ac$t=setTimeout("ac$timeOut",500)}}function ac$boxKeyPress(e){if(e.which==13){ac$s.value=ac$b.options[ac$b.selectedIndex].value;ac$b.style.visibility="hidden";ac$b.selectedIndex=-1;ac$s.focus}else if(e.which==27){ac$b.style.visibility="hidden";ac$b.selectedIndex=-1;ac$s.focus}else if(e.which){ac$s.value+=String.fromCharCode(e.which);ac$s.focus;ac$b.selectedIndex=-1;ac$s.selectionStart=ac$s.selectionEnd=ac$s.value.length;try{clearTimeout(ac$t)}catch(e){};ac$t=setTimeout("ac$timeOut",500)}}function ac$boxClick(e){ac$s.value=ac$b.options[ac$b.selectedIndex].value;ac$b.style.visibility="hidden";ac$b.selectedIndex=-1;ac$s.focus}function ac$blur(e){if(e.target==ac$b){if(ac$b.style.visibility=="hidden")ac$b.blur}else if(e.target!=ac$s&&e.target!=document&&e.target!=window){ac$b.style.visibility="hidden";ac$b.selectedIndex=-1}}function ac$timeOut{if(ac$s.value.length>0){try{ac$x.abort}catch(e){};cb=function(obj){ac$b.innerHTML=;for(var i in obj.meta.namespaces){try{var ns=obj.meta.namespaces[i]['*'];ac$n[ns]=i;if(ac$s.value.toUpperCase==ns.substring(0,ac$s.value.length).toUpperCase){ac$b.innerHTML+=''+ns+': '}}catch(e){}}for(var i in obj.pages){if(ac$s.value.toUpperCase==obj.pages[i].title.substring(0,ac$s.value.length).toUpperCase)ac$b.innerHTML+=(obj.pages[i].redirect!=""?' ':'')+obj.pages[i].title+' '}ac$b.options.length||(ac$b.innerHTML='(no pages found) ');ac$b.style.visibility="visible"};var ns=ac$s.value.match(/^.*?(?=:)/);if(ns in ac$n){var apns=ac$n[ns];var apfrom=ac$s.value.replace(/^.*?:/,'')}else{var apns=0;var apfrom=ac$s.value}ac$query(cb,"allpages|namespaces","apfrom",ac$$uc(apfrom.replace(/ /g,'_')),"aplimit","50","apnamespace",apns)}else{ac$b.style.visibility="hidden"}}var ac$s;var ac$b;var ac$t;var ac$n=[];var ac$x=window.XMLHttpRequest?new XMLHttpRequest:window.ActiveXObject?new ActiveXObject("Microsoft.XMLHTTP"):false;function ac$init{ac$s=ac$$e("searchInput");if(ac$s){ac$b=ac$$c('select','autocompletebox');ac$b.size=8;ac$b.style.visibility="hidden";ac$$ia(ac$s,ac$b);ac$s.setAttribute('autocomplete','off');ac$s.addEventListener('keydown',ac$inputKeyDown,true);ac$b.addEventListener('keypress',ac$boxKeyPress,true);ac$b.addEventListener('click',ac$boxClick,true);document.addEventListener('focus',ac$blur,true)}}addOnloadHook(ac$init);

/*** * Own code starts here */

$(document).ready(function{ /*** * Reorganize the content */

$("#column-one").prependTo("body"); // Switch the columns

$("body").prepend("Wikipedia, the free encyclopedia "); // Add a new header

$("#column-one").prepend(" Wikipedia: "); $("#p-tb").before(" This page: "); // Add explanations for the menu $("#p-interaction h5").replaceWith(" Interaction "); // interaction -> Interaction

$("#column-content").prepend(" "); // Add the sidebar $("#p-personal").prependTo("#sidebar"); // Add the personal menu to the sidebar $("#p-search").prependTo("#sidebar"); // Add the search to the sidebar $("#p-cactions").prependTo("#sidebar"); // Add the view menu to the sidebar $("#column-content").append(" "); // Clear the float of the sidebar

$("#p-personal").after(" Toolbox  "); $("#t-upload").appendTo("#p-tb2 ul"); $("#t-specialpages").appendTo("#p-tb2 ul");

$("#p-logo").remove; // Remove the old logo $("#p-cactions > h5").remove; // Remove the views header $("#p-search > h5").remove; // Remove the search header

/*** * Making the top drop-down menu */

$("#column-one .portlet").hover(	function {		$(this).find(".pBody").fadeIn;	},	function  {		$(this).find(".pBody").fadeOut;	} );

/*** * If two adjacent items in the sidebar are selected, assign new classes for styling */

$("li.selected + li.selected").prev.addClass("selected-first"); $("li.selected + li.selected").addClass("selected-second");

/*** * Favorites */

$("#p-cactions ul").append("Add to favorites"); // Add the link to the views menu $("#p-search").after(" Favorites <ul></ul> "); // Add the portlet to the sidebar /* * A function to make list items and links for favorites */

function makeFavoriteLink(pageTitle, pageLink) { var pageTitle = (pageTitle == null) ? wgTitle : pageTitle; // Default pageTitle is the current page title var pageLink = (pageLink == null) ? wgScript + "?title=" + encodeURIComponent(mw.config.get('wgPageName')) : pageLink; // Default link is the current page link return "<li class=\"favorite\"><a href=\"" + pageLink + "\">" + pageTitle + "</a> <a href=\"#\" class=\"remove-favorite\"><img src=\"http://home.planet.nl/~merri033/delete.png\" alt=\"-\" /></a></li>"; }

/* * A function to remove the favorite from the sidebar and also from the cookie */

function removeFavorite(pageTitle, removeLink) { removeLink.parent.remove; // Remove the link from the sidebar

if($("#p-favorites ul").is(":empty")) { // If there are no more favorites... $("#p-favorites ul").append("<li id=\"no-favorites\">No favorites</li>"); }

var favorites = $.cookie('wikipedia-favorites').split("\n"); // All the cookie lines in a variable var cookie = ''; // Now we add all the lines back to the cookie, except the one we want removed for(var i = 0; i < (favorites.length - 1); i++) { // -1 because we don't want the last line if(favorites[i].split("|")[0] != pageTitle) { cookie += (favorites[i] + "\n"); }	}	$.cookie('wikipedia-favorites', cookie, { expires: 30 }); }

/* * Add favorites that were already in the cookie */

if(!$.cookie('wikipedia-favorites') || $.cookie('wikipedia-favorites') == '') { $("#p-favorites ul").append("<li id=\"no-favorites\">No favorites</li>"); // There is no cookie } else { var favorites = $.cookie('wikipedia-favorites').split("\n"); for(var i = 0; i < (favorites.length - 1); i++) { // -1 because we don't want the last line $("#p-favorites ul").append(makeFavoriteLink(favorites[i].split("|")[0],favorites[i].split("|")[1])); // Make links of the cookie }	$("a.remove-favorite").click(function { // The remove links of the cookie favorites are enabled		removeFavorite($(this).prev.text,$(this));		return false; // So the page doesn't scroll to the top	}); }

/* * A favorite is added... */

$("#ca-favorites a").click(function {	$("#no-favorites").remove; // Remove the 'no favorites' text (if it is there)

var j = 0; if($.cookie('wikipedia-favorites')) { // If there is a cookie... var favorites = $.cookie('wikipedia-favorites').split("\n"); for(var i = 0; i < (favorites.length - 1); i++) { // -1 because we don't want the last line if(favorites[i].split("|")[0] == wgTitle) { j++; // If the page is already in the cookie, and thus a favorite, j becomes greater than 0 }		}	}	if(j == 0) { // If j > 0 then the page was already a favorite $("#p-favorites ul").append(makeFavoriteLink); // Add the page to the list, no arguments for makeFavoriteLink because the defaults are used $.cookie('wikipedia-favorites', (($.cookie('wikipedia-favorites')) ? $.cookie('wikipedia-favorites') : '') + wgTitle + '|' + wgScript + "?title=" + encodeURIComponent(mw.config.get('wgPageName')) + "\n", { expires: 30 }); // Add the link to the cookie $("a.remove-favorite").click(function { // Call this event again because new links were added			removeFavorite($(this).prev.text,$(this));			return false; // So the page doesn't scroll to the top		}); }	return false; });

/*** * Making the sidebar portlets tools collapsible */

$("#sidebar .portlet h5").append(" [<a href=\"#\">-</a><a href=\"#\" style=\"display: none\">+</a>]"); $("#sidebar .portlet h5 a").click(function {	$(this).parent.next.slideToggle;	$(this).siblings.addBack.toggle;	return false; });

});