User:PerfektesChaos/js/resultListSort/r.js

/// mw:User:PerfektesChaos/js/resultListSort/?.js /// 2012-07-13 PerfektesChaos@de.wikipedia /// Fingerprint:#0#856A5A9F# /// @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.0; mw.libs.resultListSort.type="resultListSort"; if(typeof mw.libs.resultListSort.opt!=="object"){ mw.libs.resultListSort.opt={};} mw.libs.resultListSort.fair=function($access,aligned){ var g; var m=0; var n=0; var p; var s=this.fetch($access,aligned); 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,aligned){ var $d=false; var r=false; switch(aligned){ case 1: $d=$access; break; case 2: $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,aligned){ 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,aligned); 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){ 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]1){ g=new Array(n); mw.libs.resultListSort.fiat($lis.eq(0),k); for(i=0;i<n;i++){ g[i]=mw.libs.resultListSort.fair($lis.eq(i),k);} 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