User:PerfektesChaos/js/preferencesGadgetOptions/r.js

/// User:PerfektesChaos/js/preferencesGadgetOptions/r.js /// 2021-10-08 PerfektesChaos@de.wikipedia /// Fingerprint:#0#C75EA0A3# /// @license GPL [//www.mediawiki.org/w/COPYING](+GFDL,LGPL,CC-BY-SA) /// (function(mw,$){ "use strict"; var Version=2.1,Signature="preferencesGadgetOptions",PREGO={signature:"ext.gadget."+Signature,special:"Blankpage",type:Signature,vsn:Version,api:{},cache:{},date:{},dialog:{},hook:{},lang:{},option:{},page:{}}; function fire{ PREGO.doc="w:en:User:PerfektesChaos/js/"+PREGO.type+""; PREGO.lang.user={"als":["de","fr"], "bar":["de"], "br":["fr"], "cel":["fr"], "dsb":["hsb","de"], "fro":["fr"], "frp":["fr"], "frr":["de","nl"], "fur":["it"], "fy":["nl"], "gsw":["de"], "hsb":["dsb","de"], "ksh":["de"], "lb":["de"], "li":["nl"], "lij":["it"], "lld":["it"], "lmo":["it"], "nap":["it"], "nds":["de","nl"], "nn":["no","da","sv"], "no":["nn","da","sv"], "oc":["fr"], "pdc":["de"], "pdt":["de"], "pfl":["de"], "pms":["it"], "sc":["it"], "sli":["de"], "stq":["de"], "vec":["it"], "vls":["nl"], "vmf":["de"], "wa":["fr"] }; PREGO.local=mw.user.isAnon; if(PREGO.local){ mw.loader.using(["mediawiki.storage"],PREGO.cache.first); }else{ PREGO.finalize;} PREGO.hook.fire;} function first{ var launch,prev,rls; if(mw.loader.getState(PREGO.signature)!=="ready"){ rls={}; rls[PREGO.signature]="ready"; mw.loader.state(rls); if(typeof mw.libs[PREGO.type]!=="object"||!mw.libs[PREGO.type]){ mw.libs[PREGO.type]=PREGO; launch=true; }else{ prev=mw.libs[PREGO.type]; launch=(typeof prev.vsn==="undefined"); if(launch){ $.extend(prev,PREGO); PREGO=prev;}} if(launch){ mw.loader.using(["user","user.options","mediawiki.user"],fire);}}} PREGO.api.failed=function(about,add,aborted){ var s="API error"; if(about){ s=s+"\n\n"+about;} if(add){ if(add.error){ if(add.error.info){ s=s+":\n"+add.error.info;}}} s=s+"\n\n* Login session might have been expired."; if(typeof aborted==="function"){ aborted.call(PREGO,s);} mw.hook("wikipage.content").add(function{ PREGO.api.flop(s); }); }; PREGO.api.fiat=function(api,apply){ var pars={"action":"options", "token":mw.user.tokens.get("csrfToken"), "optionname":apply[0]}; if(apply[1]!==null){ pars.optionvalue=apply[1];} api.post(pars).done(function(d,t,j){ PREGO.api.follow(true,apply[4]); if(apply[2]){ apply[2].call(null,d,t,j);} }).fail(function(d,t,j){ PREGO.api.failed(d); PREGO.api.follow(false,apply[4]); if(apply[3]){ apply[3].call(null,d,t,j);} }); }; PREGO.api.fire=function(assign,apply,any,after,aborted,at){ var $api=false,r,s,task; if(typeof assign==="string"){ if(/[^a-zA-Z0-9_-]/.test(assign)){ r="invalid character in key 'assign'"; }else if(apply===null||typeof apply==="string"){ r=false; }else{ r="invalid type for value 'apply'";} }else{ r="key 'assign' not a string";} if(!r){ if(at){ s="#"+PREGO.page.fragment(assign); $api=mw.util.$content.find(s); if($api.length){ $api.empty; if(!PREGO.page.$throbber){ PREGO.page.factory("$throbber");} $api.append(PREGO.page.$throbber.clone);}} task=[(any?assign:"userjs-"+assign),apply,false,false,$api]; if(typeof after==="function"){ task[2]=after;} if(typeof aborted==="function"){ task[3]=aborted;} if(this.queue){ this.queue.push(task); }else{ this.queue=[task];} mw.loader.using(["mediawiki.api"],this.forward);} return r; }; PREGO.api.fix=function(arrived,assign,advanced,after,assume){ var q=arrived.query,s; if(q){ q=q.userinfo; if(q){ q=q.options; if(q){ s=(advanced?"userjs-"+assign:assign); q=q[s]; mw.user.options.set(s,q); if(typeof after==="function"){ switch(advanced){ case 1: q=PREGO.get(assign,assume); break; case 2: q=PREGO.fetch(assign,assume); break;} after.call(PREGO,q);}}}} }; PREGO.api.flop=function(about){ var $div=$(" "),$span=$(" "); $div.attr("class","error"); $span.text(" "+PREGO.type+" "+about+" "); $div.append($span); mw.util.$content.prepend($div); }; PREGO.api.follow=function(achieved,$apply){ var src; if($apply&&$apply.length){ src=(achieved?"$stored":"$denied"); $apply.empty; if(!PREGO.page[src]){ PREGO.page.factory(src);} $apply.append(PREGO.page[src].clone);} }; PREGO.api.forward=function{ var i,n,request; if(PREGO.api.queue){ n=PREGO.api.queue.length; if(n>0){ request=new mw.Api; for(i=0;i<n;i++){ PREGO.api.fiat(request,PREGO.api.queue[i]);}} PREGO.api.queue=false;} }; PREGO.api.fresh=function(assign,advanced,assume,after,aborted){ var q=new mw.Api; q.get({"action":"query", "meta":"userinfo", "uiprop":"options"}).done(function(arrived){ PREGO.api.fix(arrived,assign,advanced,after,assume); }).fail(function(about,add){ PREGO.api.failed(about,add,aborted); }); }; PREGO.cache.first=function{ var s=mw.storage.get(PREGO.type); if(s){ try{ PREGO.cache.data=JSON.parse(s); }catch(e){ PREGO.cache.data=false;} if(typeof PREGO.cache.data==="object"&&PREGO.cache.data){ if(typeof PREGO.cache.data.userjs==="object"&&PREGO.cache.data.userjs){ for(s in PREGO.cache.data.userjs){ mw.user.options.set("userjs-"+s,PREGO.cache.data.userjs[s]);} }else{ PREGO.cache.data.userjs=false;} }else{ PREGO.cache.data={};}} PREGO.finalize; }; PREGO.cache.fill=function(assign,apply){ var r=this.data,s; if(r){ if(typeof this.data.userjs!=="object"||!this.data.userjs){ this.data.userjs={};} this.data.userjs[assign]=apply; r=mw.storage.set(PREGO.type,JSON.stringify(this.data)); s="#"+PREGO.page.fragment(assign); PREGO.api.follow(r,mw.util.$content.find(s));} return r; }; PREGO.cache.free=function(assign){ var r=this.data; if(r){ if(typeof r.userjs==="object"&&typeof r.userjs[assign]!=="undefined"){ delete this.data.userjs.assign; r=mw.storage.set(PREGO.type,JSON.stringify(this.data)); }else{ r=true;} }else{ r=false;} return r; }; PREGO.date.format8601=function(age){ var jY=age.getUTCFullYear,jM=age.getUTCMonth+1,jD=age.getUTCDate,kH=age.getUTCHours,kM=age.getUTCMinutes,kS=age.getUTCSeconds,kX=age.getUTCMilliseconds; if(jM<10){ jM="0"+jM;} if(jD<10){ jD="0"+jD;} if(kH<10){ kH="0"+kH;} if(kM<10){ kM="0"+kM;} if(kS<10){ kS="0"+kS;} if(kX<100){ if(kX<10){ kX="00"+kX; }else{ kX="0"+kX;}} return jY+"-"+jM+"-"+jD+" "+kH+":"+kM+":"+kS+"."+kX+"Z"; }; PREGO.date.from8601=function(age){ return new Date(parseInt(age.substr(0,4),10),parseInt(age.substr(5,2),10)-1,parseInt(age.substr(8,2),10),parseInt(age.substr(11,2),10),parseInt(age.substr(14,2),10),parseInt(age.substr(17,2),10),parseInt(age.substr(20,3),10)); }; PREGO.dialog.factory=function(about){ var i,n,$e; if(typeof about.opts==="object"&&about.opts){ n=about.opts.length; if(n){ about.selector=PREGO.type+"-form_"+about.script; if(!PREGO.page.$optsForm){ PREGO.page.factory("$optsForm");} about.$pop=PREGO.page.$optsForm.clone; about.$pop.attr("id",about.selector); if(!PREGO.page.$btnClose){ PREGO.page.factory("$btnClose");} $e=PREGO.page.$btnClose.clone; $e.click(function{PREGO.dialog.flat(about); }); about.$pop.append($e); for(i=0;i<n;i++){ PREGO.option.factory(about.selector,about.opts[i],about.$pop);} if(!PREGO.page.$btnSubmit){ PREGO.page.factory("$btnSubmit");} about.$submit=PREGO.page.$btnSubmit.clone; about.$submit.click(function{ PREGO.dialog.forward(about); }); $e=$(" "); $e.append(about.$submit); about.$pop.append($e); $e=$(" "); $e.attr({"class":PREGO.page.fragment, "id":PREGO.page.fragment(about.script)}); if(PREGO.page.ltr){ $e.css("margin-left","2em"); about.$submit.after($e); }else{ $e.css("margin-right","2em"); about.$submit.before($e);} if(typeof about.fiat==="function"){ about.fiat.call(about,about.$submit);} }else{ $e=$(" "); $e.attr("class","error"); $e.text("empty .opts in config"); about.$pop.append($e);}} about.$item.append(about.$pop); }; PREGO.dialog.fetch=function(about){ var i,n,o,v,r; if(about.opts){ r={}; n=about.opts.length; for(i=0;i<n;i++){ o=about.opts[i]; v=undefined; switch(o.type){ case "checkbox": v=o.$checkbox.prop("checked"); break; case "radio": case "multi": case "select": v=PREGO.option.fetch(o); break; case "text": v=$.trim(o.$text.val); break;} if(v!==undefined){ r[o.signature]=v;}} }else{ r=null;} return r; }; PREGO.dialog.fired=function(about){ if(about.opts&&typeof about.opts==="object"){ PREGO.dialog.fresh(about);} if(about.$pop){ about.$pop.css("display","block"); }else{ PREGO.dialog.factory(about);} about.$button.css("display","none"); }; PREGO.dialog.flat=function(about){ about.$pop.css("display","none"); about.$button.css("display","inline"); about.$pop.find("."+PREGO.page.fragment).empty; }; PREGO.dialog.forward=function(about){ var failure,fed,values; values=PREGO.dialog.fetch(about); if(values){ if(typeof about.fed==="function"){ fed=about.fed; }else{ fed=false;} if(typeof about.failure==="function"){ failure=about.failure; }else{ failure=false;} PREGO.forward(about.script,values,fed,failure); if(typeof about.filled==="function"){ about.filled.call(about,values);}} }; PREGO.dialog.fresh=function(about){ var userjs=PREGO.fetch(about.script),i,k,n,o,p,v; if(userjs){ n=about.opts.length; for(i=0;i<n;i++){ o=about.opts[i]; v=userjs[o.signature]; if(v!==undefined){ switch(o.type){ case "checkbox": case "radio": case "text": o.val=v; break; case "multi": if(typeof o.poly==="object"&&o.poly&&typeof v==="object"&&v){ for(k=0;k<p.length;k++){ p[k].val=v[k];}} break;}}}} }; PREGO.dialog.further=function(about){ if(about.$item&&about.opts&&!about.$button){ if(!PREGO.page.$btnOpts){ PREGO.page.factory("$btnOpts");} about.$button=PREGO.page.$btnOpts.clone; about.$button.attr("id",PREGO.type+"-opt_"+about.script); about.$button.click(function{ PREGO.dialog.fired(about); }); if(window.location.hash==="#"+about.script){ window.location.hash=""; this.fired(about);} about.$item.append(about.$button);} }; PREGO.hook.fetch=function(assigned,action,assume){ if(typeof action==="function"){ action(PREGO.fetch(assigned,assume));} }; PREGO.hook.fire=function{ mw.hook(PREGO.type+".fetch").add(PREGO.hook.fetch); mw.hook(PREGO.type+".form").add(PREGO.form); mw.hook(PREGO.type+".forward").add(PREGO.forward); mw.hook(PREGO.type+".$button").add(PREGO.hook.$button); }; PREGO.hook.$button=function(action,assign){ if(typeof action==="function"){ action(PREGO.$button(assign));} }; PREGO.lang.factory=function{ var i,s,u; if(typeof this.polyglott!=="object"){ s=mw.config.get("wgUserLanguage").toLowerCase; this.polyglott=[s]; if(s.length>4){ if(s.charCodeAt(2)===45){ this.polyglott.push(s.substr(0,2));}} if(typeof this.user[s]==="object"){ u=this.user[s]; for(i=0;i<u.length;i++){ s=u[i]; if($.inArray(s,this.polyglott)<0){ this.polyglott.push(s);}}} if($.inArray("en",this.polyglott)<0){ this.polyglott.push("en");} this.multi=this.polyglott.length;} }; PREGO.lang.fetch=function(apply){ var r="??????????????",i,s; switch(typeof apply){ case "string": r=apply; break; case "object": if(apply){ this.factory; for(i=0;i<this.multi;i++){ s=this.polyglott[i]; if(typeof apply[s]==="string"){ r=apply[s]; break;}}} break; case "undefined": break; default: r=apply+"";} return r; }; PREGO.option.factory=function(assigned,access,$append){ var $div,$opt; if(access.signature){ access.selector=assigned+"_"+access.signature; $opt=$(" "); $opt.attr("id",access.selector); switch(access.type){ case "html": $opt.append($(access.source)); break; case "checkbox": this.flag(access,$opt); break; case "radio": case "multi": this.faculty(access,$opt); break; case "select": this.flipper(access,$opt); break; case "text": this.field(access,$opt); break; default: $div=$(" "); $div.attr("class","error"); $div.text("Invalid type: "+access.type); $opt.append($div);} $append.append($opt); }else{ $div=$(" "); $div.attr("class","error"); $div.text("Invalid ID"); $append.append($div);} }; PREGO.option.faculty=function(access,$append){ var lone=(access.type==="radio"),sel=access.selector+"_multiple",$div=$(" "),$label=$(" "),$sub=$(" "),live,i,k,n,o,v,$group; if(typeof access.show==="undefined"){ $sub.attr("class","error"); $sub.text(access.selector); }else{ $sub.text(PREGO.lang.fetch(access.show));} $label.attr("for",sel).append($sub); $div.append($label); if(typeof access.poly==="object"){ n=access.poly.length; if(n){ $group=$(" "); $group.css("margin-"+(PREGO.page.ltr?"left":"right"),"3em"); if(lone||typeof access.val==="object"){ v=access.val; }else{ v=[access.val];} for(i=0;i<n;i++){ o=access.poly[i]; if(typeof o==="object"&&o){ sel=access.selector+"_"+i; o.$item=$(" "); o.$item.attr({type:access.type,id:sel,name:access.selector}); if(lone){ live=(o.val===v); }else{ live=false; for(k=0;k<v.length;k++){ if(o.val===v[k]){ live=true; break;}}} if(live){ o.$item.prop("checked",true);} $group.append(o.$item); $sub=$(" "); if(typeof o.show==="undefined"){ $sub.attr("class","error").text(".poly["+i+"].show missing"); }else{ $sub.text(PREGO.lang.fetch(o.show));} $label=$(" "); $label.attr("for",sel).append($sub).css("margin-"+(PREGO.page.ltr?"left":"right"),".5em").append($(" ")); }else{ $label=$(" "); $label.attr("class","error").text(".poly["+i+"] is not an object");} $group.append($label);} $div.append($group); }else{ $sub=$(" "); $sub.attr("class","error").text("empty .poly"); $div.append($sub);} }else{ $sub=$(" "); $sub.attr("class","error").text("missing/invalid .poly"); $div.append($sub);} $append.append($div); }; PREGO.option.fetch=function(access){ var i,lone,n,o,swing,r; if(typeof access.poly==="object"){ n=access.poly.length; if(n){ switch(access.type){ case "radio": lone=true; case "multi": swing="checked"; break; case "select": lone=access.lone; swing="selected"; break; default: mw.log({loud:true},PREGO.type+" *** Error .option.fetch "+access.type,3,access);} if(!lone){ r=[];} for(i=0;i<n;i++){ o=access.poly[i]; if(o&&typeof o==="object"){ if(o.$item){ if(o.$item.prop(swing)){ if(lone){ r=o.val; break; }else{ r.push(o.val);}}}}}}} return r; }; PREGO.option.field=function(access,$append){ var sel=access.selector+"_text",$div=$(" "),shift,style,$label,$span; access.$text=$(" "); access.$text.addClass("mw-ui-input").attr({id:sel,type:"text"}).css({"width":"auto"}); access.backup=(access.val?$.trim(access.val):""); if(access.backup){ access.$text.val(access.backup);} if(!access.ime){ access.$text.addClass("noime");} if(typeof access.minimum==="number"){ if(access.minimum>0){ access.$text.attr("size",access.minimum);}} if(typeof access.maxlength==="number"){ if(access.maxlength>0){ access.$text.attr("maxlength",access.maxlength);}} if(typeof access.field==="function"){ access.field.call(access,access.$text);} if(typeof access.show!=="undefined"){ $span=PREGO.page.fiat(PREGO.lang.fetch(access.show)); style="margin-"+(PREGO.page.ltr?"right":"left"); shift=$span.css(style); if(typeof shift==="string"){ if(/^0*[a-z]*$/.test(shift)){ shift=false;}} if(!shift){ $span.css(style,"1em");} $label=$(" "); $label.attr("for",sel).append($span); $div.append($label);} $div.append(access.$text); if(typeof access.suffix!=="undefined"){ $span=PREGO.page.fiat(PREGO.lang.fetch(access.suffix)); style="margin-"+(PREGO.page.ltr?"left":"right"); shift=$span.css(style); if(typeof shift==="string"){ if(/^0*[a-z]*$/.test(shift)){ shift=false;}} if(!shift){ $span.css(style,"1em");} $label=$(" "); $label.attr("for",sel).append($span); $div.append($label);} $append.append($div); }; PREGO.option.find=function(about,ask){ var r=false,i,n,o; if(about.opts){ n=about.opts.length; for(i=0;i<n;i++){ o=about.opts[i]; if(o&&o.script===ask){ r=o; break;}}} return r; }; PREGO.option.flag=function(access,$append){ var sel=access.selector+"_checkbox",$label=$(" "); access.$checkbox=$(" "); access.$checkbox.attr({id:sel,type:"checkbox"}); access.backup=(access.val?true:false); if(access.backup){ access.$checkbox.prop("checked",true);} $append.append(access.$checkbox); $label.attr("for",sel).css("margin-"+(PREGO.page.ltr?"left":"right"),".5em"); if(typeof access.show==="undefined"){ $label.text(access.signature); }else{ $label.text(PREGO.lang.fetch(access.show));} $append.append($label); }; PREGO.option.flipper=function(access,$append){ var errs=false,sel=access.selector+"_poly",$div=$(" "),$label=$(" "),$sub=$(" "),live,i,k,n,o,s,v,$select; if(typeof access.show==="undefined"){ $sub.attr("class","error").text(access.selector); }else{ $sub.text(PREGO.lang.fetch(access.show));} $label.attr("for",sel).append($sub); $div.append($label); if(typeof access.poly==="object"){ n=access.poly.length; if(n){ $select=$(" "); $select.attr("id",sel).css("margin-"+(PREGO.page.ltr?"left":"right"),"3em"); if(typeof access.max==="number"&&access.max){ $select.attr("size",access.max);} if(access.lone){ v=access.val; }else{ $select.attr("multiple",true); if(typeof access.val==="object"){ v=access.val; }else{ v=[access.val];}} for(i=0;i1?" ":""); for(i=0;i1){ s=s+", ";} s=s+i;} if(n===1){ s=s+"] is not an object"; }else{ s=s+" ] are no objects";} $sub.text(s); $div.append($sub);} }else{ $sub=$(" "); $sub.attr("class","error"); $sub.text("empty .poly"); $div.append($sub);} }else{ $sub=$(" "); $sub.attr("class","error"); $sub.text("missing/invalid .poly"); $div.append($sub);} $append.append($div); }; PREGO.page.factory=function(acquire){ var i,permit,q,s,$e,$v; if(!this.gallery){ this.gallery={ "$btnOpts":["Nuvola_apps_kcmsystem.svg", "7a",true,true], "$throbber":["Ajax-loader.gif", "de",false,false,"API..."], "$stored":["Symbol_OK.png", "62",true,false,"Okay"], "$denied":["Boos.png", "38",true,false,":-("] };} switch(acquire){ case false: if(typeof this.ltr!=="boolean"){ if(typeof PREGO.config==="object"&&PREGO.config){ permit=["$btnClose","$btnOpts","$btnSubmit","$optsForm","$sectionUser"]; for(i=0;i<permit.length;i++){ s=permit[i]; $e=PREGO.config[s]; if($e&&typeof $e==="object"&&typeof $e.clone==="function"){ this[s]=PREGO.config[s].clone;}}} this.ltr=($(window.document).find("html").attr("dir")!=="rtl");} break; case "Blankpage": q=mw.config.get("wgFormattedNamespaces"); $v=$("#firstHeading,#section_0"); if(!$v.length){ $v=$("h1");} $v.eq(0).text(q["2"]+": "+q["2300"]).attr("title",Version); $v=mw.util.$content.find("#mw-content-text"); $v.empty; $e=$(" "); $e.attr({"id":PREGO.type+"-user"}); $v.prepend($e); this.$sectionUser=$e; $v=$("head"); $e=$v.find("title"); $e.remove; $e=$(" "); $e.text(PREGO.type); $v.prepend($e); break; case "$btnClose": case "$btnOpts": case "$btnSubmit": if(!this[acquire]){ $e=$(" "); $e.attr("type","button"); switch(acquire){ case "$btnClose": $e.css({"background-color":"#FF0000", "color":"#FFFFFF", "font-size":"8px", "font-weight":"bolder", "float":(this.ltr?"right": "left"), "height":"16px", "padding":"0", "text-align":"center", "vertical-align":"middle", "width":"16px" }); $v=$(" "); $v.text("X"); break; case "$btnOpts": $e.css({"background-color":"#80FFFF", "margin-bottom":".5em"}); $e.css("margin-"+(this.ltr?"left":"right"),"1em"); $e.attr("title","Option..."); $v=this.fancy(acquire,20); break; case "$btnSubmit": $e.css({"color":"#00A000", "font-size":"200%", "font-weight":"bolder", "margin-top":"5px"}); $e.attr("title","...API...>>"); $v=$(" "); $v.text("+"); break;} $e.append($v); this[acquire]=$e;} break; case "$optsForm": if(!this.$optsForm){ $e=$(" "); $e.attr("class",PREGO.type+"-optsForm").css({"border":"solid 1px #80FFFF", "margin":".5em", "padding":".5em"}); this.$optsForm=$e;} break; case "$throbber": case "$stored": case "$denied": if(!this[acquire]){ this[acquire]=this.fancy(acquire,18);} break;} }; PREGO.page.fancy=function(access,amount){ var src="//upload.wikimedia.org/wikipedia/commons/",picture=this.gallery[access],s,$r; if(picture){ if(picture[2]){ src=src+"thumb/";} s=picture[1]; src=src+s.substr(0,1)+"/"+s+"/"+picture[0]; if(picture[2]){ src=src+"/"+amount+"px-"+picture[0]; if(picture[3]){ src=src+".png";}} $r=$(" "); $r.attr("src",src); if(picture[4]){ $r.attr("alt",picture[4]);} }else{ $r=$(" "); $r.text("???"+access+"???");} return $r; }; PREGO.page.feature=function(about){ var e,i,n,p,say,$a,$span,$span2; if(typeof this.$sectionUser==="undefined"){ this.first;} if(typeof this.$list==="object"){ if(typeof about.show==="undefined"){ say=about.script; }else{ say=PREGO.lang.fetch(about.show);} $span=$(" "); $span2=$(" "); $span2.html(say); if(typeof about.support==="undefined"){ $span.append($span2); }else{ $a=$(""); $a.attr({href:PREGO.lang.fetch(about.support),target:"_blank"}).append($span2); $span.append($a);} if(typeof about.suffix!=="undefined"){ $span2=$(" "); $span2.html(PREGO.lang.fetch(about.suffix)); $span.append("&#160;"); $span.append($span2);} about.$item=$(""); about.$item.attr("id",about.script); about.$item.append($span); say=say.toLowerCase.replace(/-_.,;/," "); p=[say,about.$item]; if(this.gadgets){ n=this.gadgets.length; for(i=0;i<n;i++){ e=this.gadgets[i]; if(say<e[0]){ e[1].before(about.$item); break;}} e=[say,about.$item]; if(i===n){ this.$list.append(about.$item); this.gadgets.push(p); }else{ this.gadgets.splice(i,0,p);} }else{ this.$list.append(about.$item); this.gadgets=[p];} }else{ about.$item=true;} }; PREGO.page.features=function{ var gadget,i,n; if(!PREGO.page.launched){ PREGO.page.launched=true; PREGO.page.factory(false);} n=PREGO.page.queue.length; for(i=0;i<n;i++){ gadget=PREGO.page.queue[i]; if(gadget&&typeof gadget==="object"){ if(typeof gadget.script==="string"){ PREGO.page.queue[i]=gadget.script; }else{ PREGO.page.queue[i]=i;} if(typeof gadget.$item!=="object"){ PREGO.page.feature(gadget); if(gadget.$item&&gadget.$item!==true&&gadget.opts&&typeof gadget.opts==="object"){ PREGO.dialog.further(gadget);}}}} }; PREGO.page.fiat=function(adjust){ var $r; if(adjust.charCodeAt(0)===60){ $r=$(adjust); }else{ $r=$(" "); $r.text(adjust);} return $r; }; PREGO.page.first=function{ this.factory(PREGO.special); if(typeof this.$sectionUser==="object"){ this.$list=$(" "); this.$list.attr("id",PREGO.type+"-list"); this.$sectionUser.append(this.$list);} }; PREGO.page.fragment=function(assign){ var r=PREGO.type+"-SUBMIT"; if(assign){ r=r+"_"+assign;} return r; }; PREGO.factory=function(apply,adjacent){ var r; if(adjacent){ r=adjacent+"|"; switch(r){ case "boolean|": if(apply){ r="boolean|true";} break; case "Boolean|": if(apply.valueOf){ r="boolean|true";} break; case "number|": case "Number|": case "string|": case "String|": r=r.toLowerCase+apply; break; case "object|": if(r){ r=r+JSON.stringify(apply); }else{ r="null|";} break; case "date|": case "Date|": r="date|"+PREGO.date.format8601(apply); break; default: r="undefined|";} }else if(typeof apply==="string"){ r=apply.indexOf("|"); if(r>0){ switch(apply.substr(0,r)){ case "boolean": r=(apply==="boolean|true"); break; case "number": r=parseInt(apply.substr(r+1),10); break; case "string": r=apply.substr(r+1); break; case "null": r=null; break; case "object": r=JSON.parse(apply.substr(r+1)); break; case "date": r=PREGO.date.from8601(apply.substr(r+1)); break; case "undefined": r=undefined; break; default: r=apply;} }else{ r=apply;} }else{ r=undefined;} return r; }; PREGO.fetch=function(assign,assume,again,aborted){ var o,r,s; if(typeof assign==="string"){ if(again&&!this.local){ this.api.fresh(assign,2,assume,again,aborted);} r=mw.user.options.get("userjs-"+assign); if(r){ if(typeof r==="string"){ o=JSON.parse(r); if(assume&&typeof assume==="object"){ r={}; for(s in assume){ r[s]=assume[s];} for(s in o){ r[s]=o[s];} }else{ r=o;}} }else if(r===undefined){ r=(assume?assume:null);} }else{ r=(assume?assume:null);} return r; }; PREGO.finalize=function{ mw.hook(this.type+".ready").fire(this); }; PREGO.form=function(about){ var r=false,s=mw.config.get("wgCanonicalSpecialPageName"); if(s===PREGO.special){ if(s==="Blankpage"){ s=mw.config.get("wgTitle"); r=(s.indexOf("/"+PREGO.type,3)>0);} if(r&&typeof about==="object"){ if(typeof PREGO.page.queue==="object"){ PREGO.page.queue.push(about); if(PREGO.page.launched){ PREGO.page.features;} }else{ PREGO.page.queue=[about]; PREGO.page.launched=false; mw.loader.load(["mediawiki.ui.input"]); mw.hook("wikipage.content").add(PREGO.page.features);}}} return r; }; PREGO.forward=function(assign,apply,after,aborted){ var r,store; if(typeof assign==="string"&&typeof apply==="object"&&apply){ store=JSON.stringify(apply); if(PREGO.local){ PREGO.cache.fill(assign,store); }else{ PREGO.api.fire(assign,store,false,after,aborted,true);} mw.user.options.set("userjs-"+assign,store); r=false; }else{ r="ERROR * mw.libs."+PREGO.type+".forward * invalid arg";} return r; }; PREGO.get=function(assign,assume,again,aborted){ var r; if(typeof assign==="string"){ r=mw.user.options.get("userjs-"+assign); if(this.local){ if(typeof r!=="string"){ r=undefined;} }else if(again){ this.api.fresh(assign,1,assume,again,aborted);} if(r){ r=this.factory(r,false);}} if(r===undefined){ r=assume;} return r; }; PREGO.put=function(assign,apply,after,aborted){ var s=$.type(apply),r; if(!apply&&s==="object"){ s="null";} s=this.factory(apply,s); if(this.local){ this.cache.fill(assign,s); r=false; }else{ r=this.api.fire(assign,s,false,after,aborted); if(r&&s==="object"){ r=false;}} mw.user.options.set("userjs-"+assign,s); return r; }; PREGO.remove=function(assign,after,aborted){ var r,s,v; if(this.local){ this.cache.free(assign); }else{ r=this.api.fire(assign,null,false,after,aborted);} if(!r){ s="userjs-"+assign; v=mw.user.options.get(s); if(v!==null&&v!==undefined){ mw.user.options.set(s,null);}} return r; }; PREGO.string=function(assign,apply,after,aborted){ var r; if(typeof assign==="string"&&typeof apply==="string"){ r=this.api.fire(assign,apply,true,after,aborted); mw.user.options.set(assign,apply); }else{ r="ERROR * mw.libs."+PREGO.type+".string * invalid arg";} return r; }; PREGO.translation=function(available){ var r=false,i,slang; if(typeof this.lang.polyglott!=="object"){ this.lang.factory;} if(typeof available==="object"&&available){ for(i=0;i<this.lang.multi;i++){ slang=this.lang.polyglott[i]; if(typeof available[slang]!=="undefined"){ r=available[slang]; break;}}} return r; }; PREGO.translator=function{ if(typeof this.lang.polyglott!=="object"){ this.lang.factory;} return this.lang.polyglott; }; PREGO.update=function(assign,after,aborted){ var r; if(typeof assign==="string"){ this.api.fresh(assign,0,mw.user.options.get(assign),after,aborted); r=false; }else{ r="ERROR * mw.libs."+PREGO.type+".update * invalid arg";} return r; }; PREGO.$button=function(assign){ var shift=mw.config.get("wgDBname")+"Gadgets",special=(PREGO.special==="Blankpage"?"Blankpage/"+PREGO.type: PREGO.special),src=window.location.protocol+"//"+window.location.host+mw.util.getUrl("Special:"+special),$btn; if(assign){ src=src+"#"+assign;} if(!PREGO.page.$btnOpts){ PREGO.page.factory("$btnOpts");} $btn=PREGO.page.$btnOpts.clone; $btn.click(function{ window.open(src,shift); return false; }); return $btn; }; first; }(window.mediaWiki,window.jQuery)); /// EOF preferencesGadgetOptions/r.js