Jump to content

User:PerfektesChaos/js/tableXpander/r.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/// tableXpander.js
/// 2023-04-19 PerfektesChaos@de.wikipedia
/// Documentation:[[w:en:User:PerfektesChaos/js/tableXpander]]
/// Fingerprint:#0#7ACC3CB4#
/// @license:CC-by-sa/4.0 GPLv3
///<nowiki>
(function(mw,$){
"use strict";
var Version=2.2,Signature="tableXpander",API={Api:false},PAGE={show:Signature+"@PerfektesChaos",sign:"|}===={|",support:"https://en.wikipedia.org/wiki/Special:MyLanguage/User:PerfektesChaos/js/"+Signature,$textarea:false},CSS={background:"FFF8DC",color:"006400"},NUM={structure:"dot;comma"},TABLE={},REPO={};
CSS.design={"background":"#"+CSS.background,
"color":"#"+CSS.color};
CSS.def={"active":
{"background-color":CSS.design.background+"!important"},
"box":{"background-color":CSS.design.background,
"border-color":CSS.design.color,
"border-radius":"6px",
"border-style":"solid",
"border-width":"3px",
"clear":"both",
"margin-bottom":"2em",
"margin-left":"1%",
"margin-right":"1%",
"margin-top":"1em",
"padding":"0.5em",
"width":"95%"},"caption":
{},
"cell":{"display":"table-cell",
"vertical-align":"middle"},"chosen":
{"background-color":CSS.design.color,
"color":CSS.design.background,
"font-weight":"bold",
"padding":"0.1em"},
"clickable":
{"color":CSS.design.color,
"text-decoration":"none"},
"clickable::link":
{"color":CSS.design.color},"doclink":
{"font-size":"120%",
"font-weight":"bolder"},
"grouping":
{"background-color":CSS.design.color,
"color":CSS.design.background,
"font-weight":"bold",
"padding":"0.3em"},
"handle":
{"background-color":CSS.design.background,
"border-color":CSS.design.color,
"border-radius":"3px",
"border-style":"solid",
"border-width":"2px",
"color":CSS.design.color,
"font-size":"100%",
"font-style":"normal",
"font-weight":"normal",
"padding":"0.2em"},
"icon":{"border-radius":"0.4em",
"border-style":"solid",
"border-width":"0.15em",
"display":"inline-block",
"font-size":"150%",
"font-weight":"bolder",
"margin":"0.5em",
"padding":"0.3em"},
"include":
{"background-color":CSS.design.background},
"info":{"border-color":CSS.design.color,
"border-radius":"3px",
"border-style":"solid",
"border-width":"1px",
"font-family":"monospace",
"font-size":"100%",
"font-style":"normal",
"font-weight":"normal",
"padding-left":"0.1em",
"padding-right":"0.1em"
},
"quit":{"color":"#FF0000",
"font-size":"150%",
"font-weight":"700",
"text-align":"center",
"vertical-align":"middle"},
"td":{"background-color":CSS.design.background,
"color":CSS.design.color,
"font-size":"100%",
"font-style":"normal",
"font-weight":"normal",
"text-align":"center"},
"textarea":
{"background-color":CSS.design.background,
"margin-bottom":"2em",
"margin-top":"1em",
"width":"95%"},
"toggle":
{"display":"inline-block",
"font-size":"80%",
"font-style":"normal",
"font-weight":"normal",
"margin":"0.2em"},
"ul":{"list-style-image":"none",
"list-style-position":"outside",
"list-style-type":"none",
"margin-bottom":"0.2em",
"margin-left":"0",
"margin-right":"0",
"margin-top":"0.2em",
"padding":"0"},"ul > li":
{"display":"inline",
"margin-right":"0.7em",
"padding":"0"},"ul > li::after":
{"content":" \n"},"ul > li:last-child":
{"margin-right":"0"},"version":
{"font-size":"80%"},"widget":
{"margin-left":"0.8em",
"margin-right":"0.8em"}
};
NUM.call={"#":"forward",
"+":"full",
"~":"fair",
"%":"fraction",
"?":"fruits"};
NUM.codes={apos:0x27,comma:0x2C,dot:0x2E,nbsp:0xA0,nnbsp:0x202F};
NUM.entities={apos:0x27,nbsp:0xA0,lrm:false,rlm:false,zwj:false};
NUM.min=0.0001;
NUM.offer=["dot;comma","comma;dot","comma;apos","comma;nbsp","dot;nbsp","comma;nnbsp","dot;nnbsp"];
NUM.patterns={"dot;comma":"0,000.00",
"dot;nbsp":"0&#x25AF;000.00",
"dot;nnbsp":"0&#x25A1;000.00",
"comma;apos":"0'000,00",
"comma;dot":"0.000,00",
"comma;nbsp":"0&#x25AF;000,00",
"comma;nnbsp":"0&#x25A1;000,00"};
NUM.translate={0x2D:45,0x2212:45,0x2B:43,0xFF0B:43,0xFF0D:45};
NUM.seek=NUM.structure;
NUM.sep=".";
NUM.spaces=[0xA0,0x1680,0x2000,0x2001,0x2002,0x2003,0x2004,0x2005,0x2006,0x2007,0x2008,0x2009,0x200A,0x200B,0x200C,0x200D,0x200E,0x200F,0x202F,0x205F,0x3000,0x303F];
NUM.starts="#+~%?";
NUM.variants={apos:[0x2019,0xFF07],comma:[0xFF0C],dot:[0xFF0E]};
NUM.zero=[0x30,0x0660,0x06F0,0x07C0,0x0966,0x09E6,0x0A66,0x0AE6,0x0B66,0x0BE6,0x0C66,0x0CE6,0x0D66,0x0DE6,0x0E50,0x0ED0,0x0F20,0x102E,0x1040,0x1369,0x17E0,0x1810,0x1946,0x19D0,0x1A80,0x1A90,0x1B50,0x1BB0,0x1C40,0x1C50,0xA620,0xA8D0,0xA900,0xA9D0,0xA9F0,0xAA50,0xABF0,0xFF10,0x1104A,0x110D3,0x110E6,0x11106,0x1110F,0x11113,0x1111D,0x1112F,0x11145,0x1114D,0x11165,0x1116C,0x11173,0x1118E,0x111C5,0x111D5,0x111DA,0x116A6,0x116B5,0x116E8,0x11E14,0x11E2F,0x11E8C,0x11E95,0x1D7F6,0xE0030];
TABLE.title={"#":"#",
"+":String.fromCharCode(0x03A3),
"~":String.fromCharCode(0x00F8),
"%":"%",
"?":"^",
"h":String.fromCharCode(0x2194),
"v":String.fromCharCode(0x2195),
"X":"X"
};
function fire(){
if($){
if(typeof $==="function"){
$(PAGE.fire);}}}
API.fail=function(arrived,add){
if(typeof window.console==="object"&&typeof arrived==="string"){
if(typeof window.console.log==="function"){
window.console.log(arrived);}
if(typeof add==="object"&&add&&typeof window.console.dir==="function"){
window.console.dir(add);}}
};
API.formatnum=function(){
var o={action:"expandtemplates",prop:"wikitext",text:"{{formatnum:1234567.89}}"};
if(typeof API.Api!=="object"){
API.Api=new mw.Api();}
API.Api.get(o).done(API.formattednum).fail(API.fail);
};
API.formattednum=function(arrived){
if(typeof arrived==="object"&&arrived&&typeof arrived.expandtemplates==="object"&&typeof arrived.expandtemplates.wikitext==="string"){
NUM.formatting(arrived.expandtemplates.wikitext);}
};
NUM.faculty=function(attempt,array){
var i,r;
if(array){
for(i=0;i<array.length;i++){
if(array[i]===attempt){
r=true;
break;}}}
return r;
};
NUM.fair=function($all,$actives,$about){
var n=$actives.length,g;
if(n){
g=NUM.full($all,$actives,$about);
if(g[0]&&g[1]){
n=g[0]/  g[1];
}else{
n=0;}}
$about.text(n);
};
NUM.fetch=function($at){
var s=$at.data(Signature+"-parsed"),skipped=":hidden,[style*='visibility']",r,store,$dup;
if(s){
if(s!=="!"){
r=parseInt(s,10);
s=false;}
}else{
s=$at.data(Signature+"-raw");
if(!s){
s=$at.data("sort-value");
if(s){
$at.attr({title:s});
}else{
if($at.find(skipped).length>1){
$dup=$at.clone();
$dup.find(":hidden").remove();
s=$dup.text();
}else{
s=$at.text();}}
if(s){
s=NUM.fill(s);
if(s){
if(NUM.reInteger.test(s)){
store="-parsed";
}else{
store="-raw";}
$at.data(Signature+store,s);}}}
if(s){
s=NUM.filter(s);
if(s){
r=parseFloat(s);
if(isNaN(r)){
r=false;}}
}else{
$at.data(Signature+"-parsed","!");}}
return r;
};
NUM.figure=function(analyze){
var i,j,r;
for(i=0;i<NUM.zero.length;i++){
j=NUM.zero[i];
if(analyze<j){
break;
}else{
if(analyze<=j+9){
r=j;
break;}}}
return r;
};
NUM.fill=function(analyze){
var i=analyze.indexOf("[-]"),s=analyze,j,k,less,r;
if(i>=0){
s=s.substr(0,i);}
s=PAGE.flat(s);
s=NUM.flat(s);
k=NUM.translate[s.charCodeAt(0)];
if(k===45||k===43){
less=(k===45);
s=NUM.flat(s.substr(1));}
j=NUM.figure(s.charCodeAt(0));
if(!j){
j=NUM.figure(s.charCodeAt(1));}
if(j){
if(j===0x30){
r=s;
}else{
r=NUM.foreign(s,j);}
for(i=1;i<r.length;i++){
if(r.charCodeAt(i)<=32){
r=r.substr(0,i);
break;}}
if(less){
r="-"+r;}}
return r;
};
NUM.filter=function(attempt){
var fill,i,k,large,left,less,m,r,seg,sep;
if(!NUM.dec&&typeof NUM.seek==="string"){
i=NUM.seek.indexOf(";");
if(i>0){
sep=NUM.seek.substr(0,i);
seg=NUM.seek.substr(i+1);
}else{
sep=NUM.seek;
seg=false;}
NUM.omit=false;
if(sep&&typeof NUM.codes[sep]==="number"){
fill=function(array,assigned){
var i,v;
NUM[array]=[NUM.codes[assigned]];
if(typeof NUM.variants[assigned]==="object"){
v=NUM.variants[assigned];
for(i=0;i<v.length;i++){
NUM[array].push(v[i]);}}
};
fill("dec",sep);
if(seg&&typeof NUM.codes[seg]==="number"){
fill("omit",seg);}}}
if(NUM.dec){
i=0;
if(attempt.charCodeAt(0)===0x2D){
less=true;
i=1;}
do{
k=attempt.charCodeAt(i);
if(k>=0x30&&k<=0x39){
r=(r||"")+String.fromCharCode(k);
}else if(NUM.faculty(k,NUM.omit)){
k=attempt.charCodeAt(i+1);
if(!r||k<0x30||k>0x39){
break;}
}else if(NUM.faculty(k,NUM.dec)){
if(left){
break;
}else{
if(r){
r=r+".";
}else{
k=attempt.charCodeAt(i+1);
if(k===0x45||k===0x65){
r="0.";
}else{
break;}}
left=true;}
}else if(k===0x45||k===0x65){
if(large){
break;
}else{
k=attempt.charCodeAt(i+1);
if(k>=0x30&&k<=0x39){
large=true;
r=r+"e";
}else if(k===0x2B||k===0x2D||k===0x2E||k===NUM.dec[0]){
m=k;
k=attempt.charCodeAt(i+2);
if(k>=0x30&&k<=0x39){
large=true;
switch(m){
case 0x2D:
r=r+"e-";
break;
case 0x2E:
r=r+"e0.";
break;
default:
r=r+"e";}
i++;}}
if(large){
left=false;
}else{
break;}}
}else{
break;}
i++;
}while(k);
if(r&&less){
r="-"+r;}}
return r;
};
NUM.find=function(assign){
var k,r,s;
if(assign.length===1){
k=assign.charCodeAt(0);
for(s in NUM.codes){
if(NUM.codes[s]===k){
r=s;
break;}}}
return r;
};
NUM.fire=function($all){
var $div=$all.find("."+Signature+"-result"),s=$div.data("query");
NUM.first($all,s,$div);
};
NUM.first=function($all,activity,$at){
var s=NUM.call[activity],$code=$at.find("code"),$active;
$code.empty();
if(activity==="?"){
$code.hide();
}else{
$code.text("0").show();}
NUM.fore($all);
if(s){
$active=$all.find("tbody").find("."+Signature+"-active")
.not("."+Signature+"-td");
if($active.length){
NUM[s]($all,$active,$code);}}
};
NUM.flat=function(adjust){
var i=0,j,k;
do{
k=adjust.charCodeAt(i);
if(k>32){
for(j=0;j<NUM.spaces.length;j++){
if(NUM.spaces[j]===k){
k=32;
break;}}}
i++;
}while(k<=32&&i<adjust.length);
return(i>1?adjust.substr(i-1):adjust);
};
NUM.flip=function(action,$at){
var sign=Signature+"-grouping",i,seek,$li,$ul;
NUM.$group.find("."+sign).removeClass(sign);
if(typeof action==="object"&&action&&typeof action.data==="object"&&action.data){
seek=action.data[0];
if(typeof action.data[1]==="object"){
$li=action.data[1];}
}else if(typeof action==="string"){
seek=action;
$li=$at;}
if(seek){
NUM.seek=seek;
NUM.dec=false;
if(!$li){
$ul=NUM.$group.children("li");
for(i=NUM.offer.length-1;i>=0;i--){
$li=$ul.eq(i);
if(NUM.offer[i]===NUM.seek){
break;}}}
$li.addClass(Signature+"-grouping");}
};
NUM.fore=function($all,$active,assign){
var sign=Signature+"-info",r,$e;
if($active){
$e=$active.find("."+sign);
if($e.length){
$e.show();
}else{
$e=$("<div>");
$e.addClass(sign);
$active.prepend($e);}
if(assign){
$e.empty().text(assign);
}else{
r=$e.text();}
}else{
$all.find("."+sign).hide().empty();}
return r;
};
NUM.foreign=function(adjust,align){
var r="",m=align-0x30,n=align+9,i,k;
for(i=0;i<adjust.length;i++){
k=adjust.charCodeAt(i);
if(k>=align&&k<=n){
k-=m;
}else if(align===0xFF10&&(k===0xFF0E||k===0xFF0C)){
k-=0xFEE0;}
r=r+String.fromCharCode(k);}
return r;
};
NUM.formatting=function(analyze){
var got,s,start,struct;
if(typeof NUM.reSeparator!=="object"){
NUM.reSeparator=new RegExp("^(.+)67(.+)89$");}
got=NUM.reSeparator.exec(analyze);
if(got){
start=got[1];
struct=NUM.find(got[2]);
if(struct){
if(typeof NUM.codes[struct]==="number"){
NUM.sep=String.fromCharCode(NUM.codes[struct]);}
if(typeof NUM.reSegment!=="object"){
NUM.reSegment=new RegExp("[1-4]([^2-4&]+)[2-5]");}
got=NUM.reSegment.exec(start);
if(got){
s=NUM.find(got[1]);
if(s){
struct=struct+";"+s;}}
NUM.flip(struct);
REPO.feed("seek",struct);}}
};
NUM.forward=function($all,$actives,$about){
var n=$actives.length,s=$about.parent().parent().data("row"),i,m,row,table,$t;
$about.text(n);
if(s){
table=TABLE.factory($all);
row=table[parseInt(s,10)];
m=0;
for(i=0;i<row.length;i++){
$t=row[i];
if($t&&$t.is($actives)){
s=NUM.fore(false,$t);
if(!s){
m++;
NUM.fore(false,$t,m);}}}
}else{
for(i=0;i<n;i++){
NUM.fore(false,$actives.eq(i),i+1);}}
};
NUM.fraction=function($all,$actives,$about){
var n=$actives.length,i,k,less,lesser,m,q,total,$td;
if(n){
total=NUM.full($all,$actives,$about);
n=total[1];}
if(n){
total=total[0];
lesser=(total<NUM.min);
if(lesser){
if(total>-1*NUM.min){
total=false;
}else{
total=-1*total;}}
if(total){
q=1 / total;
for(i=0;i<$actives.length;i++){
$td=$actives.eq(i);
k=NUM.fetch($td);
if(typeof k==="number"){
less=(k<0);
if(less){
k=-1*k;}
k=Math.round(10000*k*q);
if(k){
m=k%100;
k=Math.floor(k*0.01);
if(less!==lesser){
k=-1*k;}
if(m){
k=k+NUM.sep;
if(m<10){
k=k+"0";}
k=k+m;}}
NUM.fore(false,$td,k+"%");}}}}
};
NUM.fruits=function($all,$actives,$about){
var send="",i,k,s,$t;
$about.empty();
if(typeof NUM.reWhite!=="object"){
NUM.reWhite=new RegExp("[\t\n\r]","g");
NUM.reSpaces=new RegExp(" +","g");}
for(i=0;i<$actives.length;i++){
$t=$actives.eq(i);
NUM.fore($t);
s=$t.text();
k=s.indexOf("[-][+]");
if(k>=0&&k===s.length-6){
s=s.substr(0,k);}
s=s.replace(NUM.reWhite," ").replace(NUM.reSpaces," ");
if(s===" "){
s="";}
if(s.substr(0,1)===" "){
s=s.substr(1);}
if(s.substr(s.length-1)===" "){
s=s.substr(0,s.length-1);}
send=send+(send?"\n":"")+s;}
if(send){
PAGE.fruit(send);}
};
NUM.full=function($all,$actives,$about){
var n=$actives.length,m=n,v=0,got,i,k,$t;
if(typeof NUM.reEntitiy!=="object"){
NUM.reInteger=new RegExp("^-?[0-9]+$");
NUM.re0000000=new RegExp("^(.*\\..*)00000000[1-9]$");
NUM.re9999999=new RegExp("\\.(.*99999999)([1-9])$");}
for(i=0;i<n;i++){
$t=$actives.eq(i);
k=NUM.fetch($t);
if(typeof k==="number"){
v+=k;
}else{
TABLE.flipper({data:[$all,$t,false]},true);
m--;}}
if(v!==Math.floor(v)){
k=""+v;
got=NUM.re0000000.exec(k);
if(got){
v=parseFloat(got[1]);
}else{
got=NUM.re9999999.exec(k);
if(got){
k="0.";
n=got[1].length;
for(i=0;i<n;i++){
k=k+"0";}
k=k+(12-parseInt(got[2],10));
v=v+parseFloat(k);
got=NUM.re0000000.exec(""+v);
if(got){
v=parseFloat(got[1]);}}}}
$about.text(v);
return[v,m];
};
NUM.furnish=function(){
var s=REPO.fetch("seek"),i;
if(s){
NUM.flip(s);
i=s.indexOf(";");
if(i>0){
s=s.substr(0,i);}
if(typeof NUM.codes[s]==="number"){
NUM.sep=String.fromCharCode(NUM.codes[s]);}
}else if(mw){
API.formatnum();}
};
PAGE.fire=function(){
var $content;
if(!$("#"+Signature).length){
PAGE.$box=$("<div>");
PAGE.$box.attr({id:Signature});
$content=$("#content");
if(!$content.length){
$content=$("body");}
$content.prepend(PAGE.$box);
if(!mw||typeof mw!=="object"){
mw=false;}
PAGE.first();
if(mw&&typeof mw.hook==="function"){
mw.hook(Signature+".ready").fire(PAGE.support);}}
};
PAGE.first=function(){
var def,i,s,side,sided,single,style,$a,$icon,$li,$style,$survey,$tables,$text,$version;
if(mw&&mw.loader){
mw.loader.using(["mediawiki.storage"],REPO.format);}
PAGE.dir=$("html").attr("dir")||"ltr";
PAGE.ltr=(PAGE.dir==="ltr");
side=(PAGE.ltr?"left":"right");
sided=(PAGE.ltr?"right":"left");
CSS.def.caption["text-align"]=side;
CSS.def.handle["float"]=side;
CSS.def.icon["margin-"+sided]="1em";
CSS.def.info["float"]=side;
CSS.def.info["margin-"+sided]="1em";
CSS.def.toggle["float"]=sided;
CSS.def.toggle["margin-"+side]="1em";
CSS.def.version["margin-"+side]="4em";
$style=$("<style>");
style="";
for(s in CSS.def){
def=CSS.def[s];
style=style+"."+Signature+"-"+s+"{\n";
for(single in def){
style=style+single+":"+def[single]+";\n";}
style=style+"}\n";}
$("head").after($style.text(style));
$a=$("<a>");
$a.addClass(Signature+"-icon "+Signature+"-clickable").attr({href:PAGE.support,target:"_blank"}).text(PAGE.sign);
$icon=$("<div>");
$icon.append($a).addClass(Signature+"-cell").attr({"aria-hidden":"true"});
PAGE.$box.addClass(Signature+"-box");
PAGE.$box.append($icon);
$text=$("<div>");
$a=$("<a>");
$a.addClass(Signature+"-doclink "+Signature+"-clickable").attr({href:PAGE.support,target:"_blank"}).text(PAGE.show);
$text.append($a);
$version=$("<span>");
$version.addClass(Signature+"-version").text(Version);
$text.append($version);
$tables=$("table").not(":hidden");
if($tables.length){
PAGE.$details=$("<ul>");
PAGE.id=0;
$tables.each(PAGE.furnish);
if(PAGE.id){
PAGE.$details.addClass(Signature+"-ul");
$survey=$("<div>");
$survey.addClass(Signature+"-cell");
$survey.append($text);
NUM.$group=$("<ul>");
NUM.$group.addClass(Signature+"-ul");
for(i=0;i<NUM.offer.length;i++){
s=NUM.offer[i];
$li=$("<li>");
$li.addClass(Signature+"-ul").on("click",[s,$li],NUM.flip)
.text(PAGE.flat(NUM.patterns[s]));
if(i){
$li.prepend($("<wbr>"));}
NUM.$group.append($li);
if(!i){
NUM.flip(s,$li);}}
NUM.furnish();
$survey.append(NUM.$group);
$survey.append(PAGE.$details);
PAGE.$box.append($survey);
}else{
$text.addClass(Signature+"-cell");
PAGE.$box.append($text);}
}else{
$text.addClass(Signature+"-cell");
PAGE.$box.append($text);}
};
PAGE.flat=function(adjust){
var r=(adjust||"ERROR"),fun10,fun16,s,seek,sign,shift;
if(r.indexOf("&#")>=0){
fun10=function(all,adapt){
return String.fromCharCode(parseInt(adapt,10));
};
fun16=function(all,adapt){
return String.fromCharCode(parseInt(adapt,16));
};
if(typeof PAGE.reEntitiy!=="object"){
PAGE.reEntitiy=new RegExp("&#([0-9]+);","g");
PAGE.reEntitiyX=new RegExp("&#x([0-9A-F]+);","gi");}
r=r.replace(PAGE.reEntitiy,fun10);
if(r.indexOf("&#x")>=0){
r=r.replace(PAGE.reEntitiyX,fun16);}}
if(r.indexOf("&")>=0){
for(s in NUM.entities){
seek="&"+s+";";
if(r.indexOf(seek)>=0){
shift=NUM.entities[s];
sign="re_"+s;
if(typeof PAGE[sign]!=="object"){
PAGE[sign]=new RegExp(seek,"g");}
if(shift){
shift=String.fromCharCode(shift);
}else{
shift="";}
r=r.replace(PAGE[sign],shift);
break;}}}
return r;
};
PAGE.fruit=function(assign){
if(!PAGE.$textarea){
PAGE.$textarea=$("<textarea>");
PAGE.$textarea.addClass(Signature+"-textarea").attr({id:Signature+"-copy",readonly:"readonly",rows:"5"});
PAGE.$box.after(PAGE.$textarea);}
PAGE.$textarea.val(assign);
};
PAGE.furnish=function(i,e){
var $table=$(e).eq(0),s,$a,$caption,$handle,$li;
if($table.find("thead").length||$table.find("th").length){
$a=$("<a>");
$li=$("<li>");
if(PAGE.id){
$li.append($("<wbr>"));}++PAGE.id;
s=Signature+"-"+PAGE.id;
$a.attr({href:"#"+s}).text(PAGE.id);
$li.append($a);
PAGE.$details.append($li);
TABLE.fiat($table,PAGE.id);
$caption=$table.find("caption").eq(0);
$handle=$("<div>");
if(!$caption.length){
$caption=$("<caption>");
$table.prepend($caption);}
$handle.addClass(Signature+"-handle").attr({id:s,title:Signature}).text(PAGE.sign).on("click",$table,TABLE.furnish);
$caption.addClass(Signature+"-caption");
$caption.append($handle);}
return true;
};
REPO.feed=function(sign,val){
var webSs;
if(typeof REPO.o!=="object"){
REPO.fetch("");}
REPO.o[sign]=val;
if(typeof window.localStorage==="object"){
webSs=window.localStorage;
if(webSs&&typeof webSs.setItem==="function"){
try{
webSs.setItem(REPO.full(),JSON.stringify(REPO.o));
}catch(e){
}}}
};
REPO.fetch=function(sign){
var got,r,webSs;
if(typeof REPO.o!=="object"&&typeof window.localStorage==="object"){
webSs=window.localStorage;
if(webSs&&typeof webSs.getItem==="function"){
try{
got=JSON.parse(webSs.getItem(REPO.full()));
if(typeof got==="object"&&got){
REPO.o=got;}
}catch(e){
}}}
if(typeof REPO.o!=="object"){
REPO.o={};}
if(typeof REPO.o[sign]!=="undefined"){
r=REPO.o[sign];}
return r;
};
REPO.first=function(){
var stored;
if(typeof REPO.repo==="undefined"&&typeof mw==="object"&&mw&&typeof mw.storage==="object"&&mw.storage&&typeof mw.storage.get==="function"){
REPO.repo=false;
stored=mw.storage.get(Signature);
if(stored){
try{
REPO.repo=JSON.parse(stored);
if(typeof REPO.repo!=="object"||!REPO.repo){
REPO.repo=false;}
}catch(ex){
}}}
};
REPO.full=function(){
if(typeof REPO.sign!=="string"){
REPO.sign=Signature+"."+mw.config.get("wgDBname");}
return REPO.sign;
};
TABLE.facilitate=function($all,$at){
var s="."+Signature,$w=$at.find(s+"-exclude");
if($w.length){
$w.show();
$at.find(s+"-include").hide();
}else{
$w=$("<div>");
$w.addClass(Signature+"-exclude "+Signature+"-toggle").on("click",[$all,$at,false],TABLE.flipper).text("[-]");
$at.append($w);
$w=$("<div>");
$w.addClass(Signature+"-include "+Signature+"-toggle").hide().on("click",[$all,$at,true],TABLE.flipper).text("[+]");
$at.append($w);}
};
TABLE.factory=function($all){
var r=TABLE.fiat($all),e,i,j,k,m,n,s,tmp,ts,$row,$rows,$t;
if(!r.d){
if(typeof TABLE.reInteger!=="object"){
TABLE.reInteger=new RegExp("^[0-9]+$");}
$rows=r["$rows"];
for(i=0;i<r.nR;i++){
n=$rows.eq(i).children().length-1;
if(n>r.nC){
r.nC=n;}}
r.d=[];
tmp=[];
for(i=0;i<r.nR;i++){
ts=[];
r.d.push(new Array(r.nC));
$row=$rows.eq(i).children();
for(k=1;k<$row.length;k++){
ts.push($row.eq(k));}
tmp.push(ts);}
delete r["$rows"];
do{
i=0;
$t=false;
do{
ts=tmp[i];
if(ts){
$t=ts[0];
if(ts.length<=1){
tmp[i]=false;
}else{
tmp[i].splice(0,1);}
s=$t.attr("colspan");
if(s&&TABLE.reInteger.test(s)){
j=(parseInt(s,10)||1);
}else{
j=1;}
s=$t.attr("rowspan");
if(s&&TABLE.reInteger.test(s)){
n=(parseInt(s,10)||1);
}else{
n=1;}
n=Math.min(i+n,r.nR);
for(;i<n;i++){
e=r.d[i];
m=0;
do{
if(!e[m]){
k=Math.min(m+j,r.nC);
for(;m<k;m++){
r.d[i][m]=$t;}
break;}
m++;
}while(m<r.nC);}
}else{
i++;}
}while(i<r.nR);
}while($t);
TABLE.fiat($all,false,r);}
return r.d;
};
TABLE.fiat=function($all,assign,apply){
var r;
if(typeof assign==="number"){
$all.data(Signature,""+assign);
}else{
r=$all.data(Signature);
if(apply){
TABLE.t[r]=apply;
r=apply;
}else{
if(typeof TABLE.t!=="object"){
TABLE.t={};}
if(typeof TABLE.t[r]!=="object"){
TABLE.t[r]={d:false};}
r=TABLE.t[r];}}
return r;
};
TABLE.flat=function($assembly){
var $row=$assembly.children(),r=$row.length,fine=function(){
if(typeof TABLE.reInteger!=="object"){
TABLE.reInteger=new RegExp("^[0-9]+$");}
},i,m,s,$t;
for(i=r-1;i>=0;i--){
$t=$row.eq(i);
s=$t.attr("rowspan");
if(s){
fine();
if(TABLE.reInteger.test(s)){
m=parseInt(s,10);
}else{
m=0;}
if(m<2){
$t.attr({rowspan:null});}}
s=$t.attr("colspan");
if(s){
fine();
if(TABLE.reInteger.test(s)){
m=parseInt(s,10);
if(m>1){
r=r+m-1;}
}else{
m=0;}
if(m<2){
$t.attr({colspan:null});}}}
return r;
};
TABLE.flatten=function($all){
var $clickable;
if($all.hasClass("sortable")){
$all.removeClass("sortable jquery-tablesorter");
$clickable=$all.children("thead").find("th");
$clickable.off("click").off("keypress")
.off("mousedown");}
$all.removeClass("mw-datatable");
};
TABLE.flip=function(action){
var k,line,query,s,s1,s2,$active,$table,$tbody,$td,$thead,$tr;
if(typeof action==="object"&&action&&typeof action.data==="object"&&action.data){
s="."+Signature;
$table=action.data[0];
line=action.data[1];
k=action.data[2];
query=action.data[3];
$tbody=$table.find("tbody");
if(line){
$tr=$tbody.children("tr").eq(k);
$tr=$tr.children();
$td=$tr.eq(0);
}else{
$thead=$table.find("thead");
$tr=$thead.children("tr").eq(0);
$td=$tr.children("td").eq(k);}
$table.find(s+"-result").remove();
NUM.fore($tbody);
s1=Signature+"-chosen";
$table.find("."+s1).removeClass(s1);
if(typeof query==="boolean"){
s1=Signature+"-active";
$active=$tbody.find("."+s1);
$active.removeClass(s1);
$tbody.find(s+"-exclude").hide();
$tbody.find(s+"-include").hide();
s1=s+"-menu";
s2=s+"-widget";
$table.find(s1).hide();
$table.find(s2).css({visibility:"visible"});
$active=$table.find(s+"-quit").children();
if(query){
$td.find(s2).css({visibility:"hidden"});
$td.find(s1).show();
TABLE.focus($table,$tbody,line,k);
$active.show();
}else{
$active.hide();}
}else{
$td.find("."+Signature+"-"+NUM.call[query]).addClass(s1);
$active=$("<div>");
$active.addClass(Signature+"-result").data("query",query)
.append($("<code>"));
$td.append($active);
NUM.first($table,query,$active);}}
};
TABLE.flipper=function(action,abort){
var less,s,sub,$ex,$in,$t,$table;
if(typeof action==="object"&&action&&typeof action.data==="object"&&action.data){
$table=action.data[0];
$t=action.data[1];
less=action.data[2];
s="."+Signature;
sub=Signature+"-active";
$ex=$t.find(s+"-exclude");
$in=$t.find(s+"-include");
if(less){
$t.addClass(sub);
$in.hide();
$ex.show();
}else{
$t.removeClass(sub);
$ex.hide();
$in.show();
NUM.fore($t);}
if(!abort){
NUM.fire($table);}}
};
TABLE.focus=function($all,$area,align,at){
var s=Signature+"-active",table=TABLE.factory($all),i,k,row,$cells,$t;
if(align){
row=table[at];
for(i=0;i<row.length;i++){
$t=row[i];
if($t){
$t.addClass(s);}}
}else{
k=at-1;
for(i=0;i<table.length;i++){
$t=table[i][k];
if($t){
$t.addClass(s);}}}
$cells=$area.find("."+s);
for(k=0;k<$cells.length;k++){
TABLE.facilitate($all,$cells.eq(k));}
};
TABLE.$fold=function($all,align,at){
var $r=$("<td>"),$widget=$("<div>"),$menu=$("<div>"),$space=$("<span>").text(" "),i,s,$e;
$menu.addClass(Signature+"-menu").hide();
for(i=0;i<NUM.starts.length;i++){
s=NUM.starts.substr(i,1);
$e=$("<span>");
$e.addClass(Signature+"-"+NUM.call[s]).on("click",[$all,align,at,s],TABLE.flip);
if(s==="?"){
s=(align?"h":"v");}
$e.text(TABLE.title[s]);
$menu.append($e).append($space.clone());}
if(align){
$r.data("row",""+at);}
$widget.addClass(Signature+"-widget").on("click",[$all,align,at,true],TABLE.flip).text(PAGE.sign);
$r.append($widget).append($menu).addClass(Signature+"-td");
return $r;
};
TABLE.furnish=function(action){
var e,i,k,n,sign,table,$caption,$handle,$rows,$table,$tbody,$td,$tfoot,$thead,$tr,$x;
if(typeof action==="object"&&action&&typeof action.target==="object"&&action.target){
$handle=$(action.target);
sign=$handle.attr("id");
$caption=$handle.parent();
$table=$caption.parent();
$handle.remove();}
if($table){
TABLE.flatten($table);
$thead=$table.find("thead");
if(!$thead.length){
$thead=$("<thead>");
$rows=$table.find("tr");
for(i=0;i<$rows.length;i++){
$tr=$rows.eq(i);
$x=$tr.children();
for(k=0;k<$x.length;k++){
e=$x.eq(k).get(0);
if(e.tagName.toUpperCase()!=="TH"){
$tr=false;
break;}}
if($tr){
$tr.detach();
$thead.append($tr);
}else{
break;}}
$caption.after($thead);}
$tfoot=$table.find("tfoot");
if($tfoot.length){
$rows=$tfoot.find("tr");
$td=$("<td>");
$td.addClass(Signature+"-active");
if($rows.length>1){
$td.attr({rowspan:$rows.length});}
$rows.eq(0).prepend($td);}
$tbody=$table.find("tbody");
if(!$tbody.length){
$tbody=$("<tbody>");
$rows=$table.children("tr");
for(i=0;i<$rows.length;i++){
$tr=$rows.eq(i);
$tr.detach();
$tbody.append($tr);}
$thead.after($tbody);}
$rows=$tbody.children();
n=$rows.length;
if(n){
table=TABLE.fiat($table);
table["$rows"]=$rows;
table.nR=n;
$rows=$thead.children();
k=TABLE.flat($rows.eq(0));
table.nC=k;
k++;
$td=$("<td>");
$x=$("<span>");
$x.hide().on("click",[$table,true,0,false],TABLE.flip).text(TABLE.title.X);
$td.addClass(Signature+"-active "+Signature+"-quit").attr({id:sign,rowspan:$rows.length+1}).append($x);
$tr=$("<tr>");
$tr.append($td);
for(i=1;i<k;i++){
$tr.append(TABLE.$fold($table,false,i));}
$thead.prepend($tr);
for(i=0;i<n;i++){
$tr=table["$rows"].eq(i);
$tr.prepend(TABLE.$fold($table,true,i));}
}else{
PAGE.$details.find("a[href$=\"#"+sign+"\"]").parent().remove();}}
};
fire();
}(window.mediaWiki,window.jQuery));
/// EOF</nowiki>tableXpander.js