User:Yair rand/fastbrowsing.js

// Don't load anything but the new bodyContent from the API when going to a new page

("pushState" in history) && wgAction == 'view' && jQuery(document).ready(function($){	// grab the search box contents and run away with it :) $("#searchform").submit(function(e){		var $sI = $("#searchInput"), val = $sI.val;		if(val.indexOf(":") == -1){			switchpage(val)			$sI.val("")			e.preventDefault		}	}) // hack all mainspace-targeted links on the page $("body").live("click",function(e){		var a = e.target; a = a.nodeName == "A" ? a : a.parentNode;		if(a.href && a.getAttribute('href').indexOf(":") == -1 && a.getAttribute('href').indexOf("?") == -1 && a.href.indexOf(mw.config.get('wgServer')+mw.config.get('wgArticlePath').replace("$1","")) == 0 && a.className != "new" // && a.getAttribute('href').substr(0,1) != "#" && a.href.indexOf(location.pathname+"#") == -1 ){ // mainspace, non-current, existing, internal wiki target				switchpage(a.href.split("/wiki/")[1], false)			if(a.getAttribute('href').substr(0,1) != "#" && a.href.indexOf(location.pathname+"#") == -1){				e.preventDefault;			}		}	},"a") // attach page name data to the current state, so back button will work history.replaceState({target:wgPageName, nonmainspace:wgNamespaceNumber!=0}); onpopstate = function(e){if(!e.state){return}if(e.state.nonmainspace){location.reload(true)}else{switchpage(e.state.target, true)}} var loader = newNode("img",{"src":"http://upload.wikimedia.org/wikipedia/commons/d/de/Ajax-loader.gif","title":"Loading..."})

var switchToMainspace = wgNamespaceNumber == 0 ? $.noop : function{ switchToMainspace = $.noop; wgNamespaceNumber = 0; $("#firstHeading").show; mw.util.addPortletLink('p-tb', 'javascript:addDefinition', 'Add definition'); window.addPOSHeader && mw.util.addPortletLink('p-tb', 'javascript:addPOSHeader', 'Add part of speech'); }	function switchpage(target,cancelpush){try{ if(target.split("#")[0] == wgPageName){ setTimeout(function{history.replaceState({target:wgPageName});},0) return; }		switchToMainspace; mw.util.$content.empty[0].appendChild(loader); var dtarget = decodeURI(target).replace(/\./g, '%').replace(/_/g,' ').split("#")[0]; $("#firstHeading").text(dtarget); JsMwApi({action:'parse',prop:'text|displaytitle|categorieshtml|langlinks',page:dtarget,disablepp:1,smaxage:"30"},function(r){			if(r){				$("#firstHeading").show.text(r.parse.displaytitle)				mw.util.$content.html(r.parse.text['*']+r.parse.categorieshtml['*'])				var newlanglinks=[];$.each(r.parse.langlinks,function{newlanglinks.push(""+interwikinames[this.lang]+"")})				$("ul","#p-lang").html(newlanglinks.join(""))				// do some stuff				cancelpush || history.pushState({target:target},target,mw.config.get('wgServer')+mw.config.get('wgArticlePath').replace("$1", target))				document.title = r.parse.displaytitle + " - " + wgSiteName;				wgPageName = dtarget.split("#")[0]; 				$("#ca-nstab-main a,#ca-view a,#ca-edit a,#ca-history a,#ca-watch a,#ca-unwatch a,#ca-delete a,#ca-move a,#ca-protect a").attr("href",function(e,v){return v.replace(/(\/wiki\/Special:MovePage\/|title=[^:&]+?:|\/wiki\/[^:&]+?:|title=|\/wiki\/)[^&\?]+/g,'$1'+target.split("#")[0])}) $(VisibilityToggles.buttons).empty; VisibilityToggles.toggles = {}; $("ol>li",mw.util.$content).each(function{setupHiddenQuotes(this)}) $("[class=\"NavFrame\"]").each(function{createNavToggle(this)}); window.suppressTargetedTranslations || clarifyTransTable; tabbedLanguages=[];languageContainers=[];currentLanguageTab=0;languageHeaderEditButtons=[]; loadedTabs=false;window.makeLanguageTabs && makeLanguageTabs; window.setupOrangeLinks && setupOrangeLinks; delete Editor.instance; var EditorBox = $("body")[0].firstChild;if(EditorBox&&EditorBox.style&&EditorBox.style.zIndex == 10){EditorBox.parentNode.removeChild(EditorBox)} TranslationAdders(new Editor); $.cookie("DisableYREdit") || window.DisableYREdit || makedefsidebox && $("ol:not(.references)>li").each(function{makedefsidebox(this)}); } else { location.href = mw.config.get('wgServer') + mw.config.get('wgArticlePath').replace("$1", target) }		})		JsMwApi({action:"query",prop:"info",titles:"Talk:"+dtarget+"|Citations:"+dtarget,smaxage:"30"},function(r){r=r.query.pages; (function(whichtab){				var ca = document.getElementById("ca-"+(whichtab=="Talk"?"talk":"nstab-citations"));				ca.getElementsByTagName("a")[0].href = wgArticlePath.replace("$1", whichtab+":"+target) + 											((ca.className = (r[-2] && r[-2].title == whichtab+":"+target || r[-1] && r[-1].title == whichtab+":"+target)?"new":"")?"?action=edit&redlink=1":"")				return arguments.callee;			})("Talk")("Citations") }) }catch(e){window.console && console.log && console.log(e)}	}

var interwikinames = {aa:"Qafár af",ab:"Аҧсуа",af:"Afrikaans",ak:"Akan",als:"Alemannisch",am:"አማርኛ",an:"Aragonés",ang:"Ænglisc",ar:"العربية",as:"অসমীয়া",ast:"Asturianu",av:"Авар",ay:"Aymar aru",az:"Azərbaycanca",ba:"Башҡортса",be:"Беларуская",bg:"Български",bh:"भोजपुरी",bi:"Bislama",bm:"Bamanankan",bn:"বাংলা",bo:"བོད་ཡིག",br:"Brezhoneg",bs:"Bosanski",ca:"Català",ch:"Chamoru",chr:"ᏣᎳᎩ",co:"Corsu",cr:"Nēhiyawēwin / ᓀᐦᐃᔭᐍᐏᐣ",cs:"Česky",csb:"Kaszëbsczi",cy:"Cymraeg",da:"Dansk",de:"Deutsch",dv:"ދިވެހިބަސް",dz:"ཇོང་ཁ",el:"Ελληνικά",eo:"Esperanto",es:"Español",et:"Eesti",eu:"Euskara",fa:"فارسی",fi:"Suomi",fj:"Na Vosa Vakaviti",fo:"Føroyskt",fr:"Français",fy:"Frysk",ga:"Gaeilge",gd:"Gàidhlig",gl:"Galego",gn:"Avañe'ẽ",gu:"ગુજરાતી",gv:"Gaelg",ha:"هَوُسَ",he:"עברית",hi:"हिन्दी",hr:"Hrvatski",hsb:"Hornjoserbsce",ht:"Kreyòl ayisyen",hu:"Magyar",hy:"Հայերեն",ia:"Interlingua",id:"Bahasa Indonesia",ie:"Interlingue",ik:"Iñupiak",io:"Ido",is:"Íslenska",it:"Italiano",iu:"ᐃᓄᒃᑎᑐᑦ/inuktitut",ja:"日本語",jbo:"Lojban",jv:"Basa Jawa",ka:"ქართული",kk:"Қазақша",kl:"Kalaallisut",km:"ភាសាខ្មែរ",kn:"ಕನ್ನಡ",ko:"한국어",ks:"कश्मीरी - (كشميري)",ku:"Kurdî",kw:"Kernowek",ky:"Кыргызча",la:"Latina",lb:"Lëtzebuergesch",li:"Limburgs",ln:"Lingála",lo:"ລາວ",lt:"Lietuvių",lv:"Latviešu",mg:"Malagasy",mh:"Ebon",mi:"Māori",mk:"Македонски",ml:"മലയാളം",mn:"Монгол",mo:"Молдовеняскэ",mr:"मराठी",ms:"Bahasa Melayu",mt:"Malti",my:"မြန်မာဘာသာ",na:"Dorerin Naoero",nah:"Nāhuatl",nds:"Plattdüütsch",ne:"नेपाली",nl:"Nederlands",nn:"‪Norsk (nynorsk)‬",no:"‪Norsk (bokmål)‬",oc:"Occitan",om:"Oromoo",or:"ଓଡ଼ିଆ",pa:"ਪੰਜਾਬੀ",pi:"पािऴ",pl:"Polski",ps:"پښتو",pt:"Português",qu:"Runa Simi",rm:"Rumantsch",rn:"Kirundi",ro:"Română","roa-rup":"Armãneashce",ru:"Русский",rw:"Kinyarwanda",sa:"संस्कृत",sc:"Sardu",scn:"Sicilianu",sd:"سنڌي",sg:"Sängö",sh:"Srpskohrvatski / Српскохрватски",si:"සිංහල",simple:"Simple English",sk:"Slovenčina",sl:"Slovenščina",sm:"Gagana Samoa",sn:"chiShona",so:"Soomaaliga",sq:"Shqip",sr:"Српски / Srpski",ss:"SiSwati",st:"Sesotho",su:"Basa Sunda",sv:"Svenska",sw:"Kiswahili",ta:"தமிழ்",te:"తెలుగు",tg:"Тоҷикӣ",th:"ไทย",ti:"ትግርኛ",tk:"Türkmençe",tl:"Tagalog",tn:"Setswana",to:"lea faka-Tonga",tpi:"Tok Pisin",tr:"Türkçe",ts:"Xitsonga",tt:"Татарча/Tatarça",tw:"Twi",ug:"ئۇيغۇرچە / Uyghurche‎",uk:"Українська",ur:"اردو",uz:"O'zbek",vi:"Tiếng Việt",vo:"Volapük",wa:"Walon",wo:"Wolof",xh:"isiXhosa",yi:"ייִדיש",yo:"Yorùbá",za:"Vahcuengh",zh:"中文","zh-min-nan":"Bân-lâm-gú",zu:"isiZulu"}

})