User:PerfektesChaos/js/resultListSort/r.js

/// mw:User:PerfektesChaos/js/resultListSort/?.js /// 2012-07-19 PerfektesChaos@de.wikipedia /// Fingerprint:#0#4B11167E# /// @license GPL [//www.mediawiki.org/w/COPYING](+GFDL,LGPL,CC-BY-SA) /// (function(mw,$){ "use strict"; if(typeof mw.libs.resultListSort!=="object"){ mw.libs.resultListSort={opt:{}};} mw.libs.resultListSort.vsn=1.1; mw.libs.resultListSort.type="resultListSort"; if(typeof mw.libs.resultListSort.opt!=="object"){ mw.libs.resultListSort.opt={};} mw.libs.resultListSort.modeDirect=0; mw.libs.resultListSort.modeSRH=1; mw.libs.resultListSort.fair=function($access){ var g; var m=0; var n=0; var p; var s=this.fetch($access); if(s){ if(this.joint){ s=s.substr(this.joint);} g=this.reNS.exec(s); if(g){ p=g[1]; n=this.space2num[p]; s=s.substr(p.length+1); if(mw.libs.resultListSort.opt.group){ m=n%2; n=(n-m)/ 2;}} if(mw.libs.resultListSort.opt.casing){ s=s.toLowerCase;} }else{ s="";} return[$access,n,s,m]; }; mw.libs.resultListSort.fetch=function($access){ var $d=false; var r=false; switch(this.mode){ case this.modeDirect: $d=$access; break; case this.modeSRH: $d=$access.children(".mw-search-result-heading"); break;} if($d){ if($d.length){ r=$d.children("a").attr("href");}} return r; }; mw.libs.resultListSort.fiat=function($alike){ var re,s; if(!this.reNS){ this.space2num=mw.config.get("wgNamespaceIds"); re=""; for(s in this.space2num){ if(this.space2num.hasOwnProperty(s)){ if(this.space2num[s]){ re=re+(re?"|":"")+s;}}} this.reNS=new RegExp("^("+re+"):","i");} this.joint=0; if($alike){ if(!this.start){ s=mw.config.get("wgArticlePath"); this.start=s.replace(/\$1/,"");} s=this.fetch($alike); if(s){ if(s.charCodeAt(0)===47){ if(s.charCodeAt(1)===47){ re="//"+window.location.host+this.start; }else{ re=this.start;} }else{ re=window.location.protocol+"//"+ window.location.host+this.start;} if(s.indexOf(re)===0){ this.joint=re.length;}}} }; mw.libs.resultListSort.find=function(album,ask){ var i; var r=false; switch(typeof album){ case "number": case "string": r=(album===ask); break; case "object": if(album){ if(typeof album.length==="number"){ for(i=0;i<album.length;i++){ r=(album[i]===ask); if(r){ break;}} }else{ r=album[ask];}} break;} return r; }; mw.libs.resultListSort.fire=function{ var RLS=mw.libs.resultListSort; if(RLS.opt.auto){ if(RLS.find(RLS.opt.auto,RLS.specialPage)){ RLS.fresh;}} if(RLS.opt.portlet===undefined){ switch(RLS.specialPage){ case "Contributions": case "Search": case "Whatlinkshere": RLS.furnish;} }else if(RLS.opt.portlet){ if(RLS.find(RLS.opt.portlet,RLS.specialPage)){ RLS.furnish;}} }; mw.libs.resultListSort.first=function(arg1,arg2){ var r=arg1[1]-arg2[1]; if(!r){ if(arg1[2]===arg2[2]){ r=arg1[3]-arg2[3]; }else if(arg1[2]<arg2[2]){ r=-1; }else{ r=1;}} return r; }; mw.libs.resultListSort.fresh=function{ var g,i,k,n,$lis; var $ul=false; switch(mw.libs.resultListSort.specialPage){ case "Contributions": k=mw.libs.resultListSort.modeDirect; $ul="#mw-content-text ul"; break; case "Recentchangeslinked": k=mw.libs.resultListSort.modeDirect; $ul=".special"; break; case "Search": k=mw.libs.resultListSort.modeSRH; $ul=".mw-search-results"; break; case "Whatlinkshere": k=mw.libs.resultListSort.modeDirect; $ul="#mw-whatlinkshere-list"; break;} if($ul){ $ul=mw.util.$content.find($ul); if($ul.length){ $lis=$ul.children("li"); n=$lis.length; if(n>1){ mw.libs.resultListSort.mode=k; g=new Array(n); mw.libs.resultListSort.fiat($lis.eq(0)); for(i=0;i<n;i++){ g[i]=mw.libs.resultListSort.fair($lis.eq(i));} g.sort(mw.libs.resultListSort.first); $lis.detach; for(i=0;i<n;i++){ $ul.append(g[i][0]);}}}} }; mw.libs.resultListSort.furnish=function{ var show="Sort results"; switch(mw.config.get("wgUserLanguage")){ case "de": case "de-at": case "de-ch": case "de-formal": case "als": case "nds": show="Sortiere Ergebnisse"; break;} mw.util.addPortletLink("p-cactions","javascript:mw.libs.resultListSort.fresh;void(0);", show,"ca-sort",show,null,"ca-sort", "#ca-history"); }; if(!mw.libs.resultListSort.loaded){ mw.libs.resultListSort.loaded=true; if(mw.config.get("wgNamespaceNumber")===-1){ $(document).ready(function{ mw.libs.resultListSort.specialPage=mw.config.get("wgCanonicalSpecialPageName"); mw.loader.using(["user","mediawiki.util"], mw.libs.resultListSort.fire); });}} mw.loader.state("ext.gadget.resultListSort","ready"); }(mediaWiki,jQuery)); /// EOF resultListSort/r.js