User:PerfektesChaos/js/resultListSort/r.js

/// mw:User:PerfektesChaos/js/resultListSort/?.js /// 2012-07-22 PerfektesChaos@de.wikipedia /// Fingerprint:#0#9E27B3B1# /// @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.3; mw.libs.resultListSort.type="resultListSort"; if(typeof mw.libs.resultListSort.opt!=="object"){ mw.libs.resultListSort.opt={};} mw.libs.resultListSort.modeDirect=0; mw.libs.resultListSort.modeContr=1; mw.libs.resultListSort.modeLink2=2; mw.libs.resultListSort.modeSRH=3; mw.libs.resultListSort.fair=function($access){ var g; var m=0; var n=0; var p; var s=this.fetch($access); if(s){ g=this.reNS.exec(s); if(g){ p=g[1].toLowerCase; 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 $s=false; var j=0; var r=false; switch(this.mode){ case this.modeContr: case this.modeDirect: $s=$access; break; case this.modeLink2: $s=$access; j=1; break; case this.modeSRH: $s=$access.children(".mw-search-result-heading"); break;} if($s){ if($s.length){ $s=$s.children("a"); if(j){ $s=$s.eq(j);} r=$s.attr("title");}} return r; }; mw.libs.resultListSort.fiat=function{ var k,o,re,s; if(!this.reNS){ o=mw.config.get("wgNamespaceIds"); re=""; this.space2num={}; for(s in o){ if(o.hasOwnProperty(s)){ k=o[s]; if(k){ s=s.replace(/_/," "); this.space2num[s]=k; re=re+(re?"|":"")+s;}}} this.reNS=new RegExp("^("+re+"):","i");} }; 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 "LinkSearch": case "Search": case "Whatlinkshere": RLS.furnish; break;} }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,n,$lis; var RLS=mw.libs.resultListSort; var $l=false; switch(RLS.specialPage){ case "Contributions": RLS.mode=RLS.modeContr; $l="#mw-content-text ul"; break; case "LinkSearch": RLS.mode=RLS.modeLink2; $l="ol.special"; break; case "Recentchangeslinked": RLS.mode=RLS.modeDirect; $l=".special"; break; case "Search": RLS.mode=RLS.modeSRH; $l=".mw-search-results"; break; case "Whatlinkshere": RLS.mode=RLS.modeDirect; $l="#mw-whatlinkshere-list"; break;} if($l){ $l=mw.util.$content.find($l); if($l.length){ $lis=$l.children("li"); n=$lis.length; if(n>1){ g=new Array(n); RLS.fiat; for(i=0;i<n;i++){ g[i]=RLS.fair($lis.eq(i));} g.sort(RLS.first); $lis.detach; for(i=0;i<n;i++){ $l.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