MediaWiki:Common.js/Clases/TableManager-min.js

// Versión comprimida. Véase MediaWiki:Common.js/Clases/TableManager.js function TableManager(d,e){e=e||{};this.cfg={unsortable:false,emptysort:0};YAHOO.lang.augmentObject(this.cfg,e,true);this.table=d;this.tableInit=false;this.reloadDlg=true;this.dlg=null;this.sortCfg={number:{testFn:function(c,t){return(t==)||(t=='-')||/^([-]\s*)?(\d+|\d{1,3}([.]\d{3})+)(,\d+)?(\s*[%\u00a3$\u20ac])?$/.test(t)},sortFn:function(a,b){var A=a[1],B=b[1];if(A==)return B==?0:-1;else if(B==)return 1;if(A=='-')A='0';if(B=='-')B='0';var c=parseFloat(A.replace(/[.\s%\u00a3$\u20ac]/g,).replace(',','.')),bb=parseFloat(B.replace(/[.\s%\u00a3$\u20ac]/g,).replace(',','.'));return(isNaN(c)?0:c)-(isNaN(bb)?0:bb)},priority:1,title:'numérico'},text:{testFn:null,sortFn:function(a,b){var A=a[1].toLowerCase,B=b[1].toLowerCase;return(AB?1:0)},priority:99,title:'alfabético'}};if(e.sortCfg)this.sortCfg=YAHOO.lang.augmentObject(this.sortCfg,e.sortCfg,true);this.init}TableManager.prototype={version:'1.1',init:function(a){var b=$T.create('span',{'class':'menubtn'},'opciones de tabla');var c=$T.create('div',{'class':'tm-ctrl noprint'},[b]);this.table.parentNode.insertBefore(c,this.table);$E.on(b,'click',this.menuClick,null,this)},menuClick:function(e){if(!this.tableInit)this.initTable;this.showDialog(e)},initTable:function{for(var i=0,cs=this.table.rows[0].cells;i<cs.length;i++){cs[i].tmColDfn={originalIndex:cs[i].cellIndex,newIndex:cs[i].cellIndex,visible:true,sort:null}}if((' '+this.table.className+' ').indexOf(' unsortable ')!=-1)this.cfg.unsortable=true;if(this.cfg.unsortable||!this.sortCfg){this.tableInit=true;return}var c=[];for(var d in this.sortCfg){this.sortCfg[d].name=d;c.push(this.sortCfg[d])}if(!c.length){this.tableInit=true;return}c.sort(function(a,b){return(a.priority||0)-(b.priority||0)});var e=[];for(var i=0,cs=this.table.rows[0].cells;i<cs.length;i++){if((' '+cs[i].className+' ').indexOf(' unsortable ')!=-1){e[i]=-1;continue}for(var j=0;j<c.length;j++){if((' '+cs[i].className+' ').indexOf(' sort'+c[j].name+' ')!=-1){e[i]=j;break}}}for(var i=1,rs=this.table.rows;i<rs.length;i++){var f=0;for(var j=0,cs=rs[i].cells;j<cs.length;j++){e[j]=(e[j]||0);if(e[j]==-1||!c[e[j]].testFn){f++;continue}var t=this.getTextContent(cs[j]);if(this.cfg.emptysort!=0&&t==)continue;for(var k=e[j];k<c.length;k++){if(!c[k].testFn||c[k].testFn(cs[j],t)){e[j]=k;break}if(k==c.length-1)e[j]=-1}}if(f==cs.length)break}for(var i=0,cs=this.table.rows[0].cells;i<cs.length;i++){if(typeof e[i]!='undefined'&&e[i]!=-1){var s=c[e[i]];cs[i].tmColDfn.sort={state:0,oldState:0,sortFn:s.sortFn,title:s.title,name:s.name,priority:0,oldPriority:0}}}this.tableInit=true},getTextContent:function(a){if((a.nodeType==1&&a.getElementsByTagName('img').lenght==0)||a.nodeType!=1)return $T.trim(a.textContent||a.innerText||);var b=,cs=a.childNodes;for(var i=0;i<cs.length;i++){if(cs[i].nodeType==1){if(cs[i].tagName.toLowerCase=='img')b+=cs[i].alt;else b+=this.getTextContent(cs[i])}else if(cs[i].nodeType==3){b+=cs[i].nodeValue}}return $T.trim(b)},showDialog:function(e){$E.stopEvent(e);if(this.reloadDlg)this.genDialog;this.dlg.show;this.dlg.center;this.dlg.cfg.setProperty('constraintoviewport',true)},genDialog:function{if(!this.dlg){var a=$T.create('div');$D.generateId(a,'tm-dlg');document.body.appendChild(a);this.dlg=new YAHOO.widget.Dialog(a,{visible:false,modal:true,dragOnly:true,buttons:[{text:'Aplicar cambios',handler:{fn:this.applyChanges,scope:this}},{text:'Cancelar',handler:function{this.cancel}}]});this.dlg.setHeader('Controles de tabla');this.dlg.subscribe('beforeHide',function{this.cfg.setProperty('constraintoviewport',false);this.moveTo(-10000,-10000)});this.dlg.subscribe('cancel',function{this.discardChanges},null,this);if(!this.dlg.body){this.dlg.subscribe('render',function{$E.addListener(this.dlg.body,'mousedown',this.beginMove,null,this);$E.addListener(this.dlg.body,'click',this.dlgClick,null,this)},null,this)}this.dlg.subscribe('changeBody',function{this.moveArgs.locator=null},null,this);$D.addClass(this.dlg.element,'tm-dialog');this.moveArgs={target:null,proxy:null,locator:null,visible:false,rowRegionCache:null}}var t=$T.create('table');this.dlg.setBody(t);for(var i=0,cs=this.table.rows[0].cells;i<cs.length;i++){var d=cs[i].tmColDfn;if(!d)continue;var r=t.insertRow(t.rows.length);r.tmCell=cs[i];this.dlg.cplTBody=t.tBodies[0];var b=r.insertCell(0);b.className='tm-tc-vis';var e=$T.create('input',{type:'checkbox'});if(cs[i].tmColDfn.visible)e.checked=true;b.appendChild(e);var f=r.insertCell(1);f.className='tm-tc-col';f.appendChild(document.createTextNode(cs[i].innerText?cs[i].innerText:cs[i].textContent));if(!this.cfg.unsortable){var f=r.insertCell(2);f.className='tm-tc-sort';if(!d.sort)f.appendChild($T.create('div',{'class':'tm-unsortable',title:'Sin orden'}));else{f.appendChild($T.create('div',[$T.create('span',{'class':'tm-sortpri'},)]));this.changeSortState(i,0)}}}var g=t.createTHead.insertRow(0);g.insertCell(0).appendChild($T.create('span',{title:'Sólo se mostrarán las columnas que estén marcadas'},'Mostrar'));g.insertCell(1).appendChild($T.create('span',{title:'Puedes mover las columnas de posición con el mouse, haciendo clic y moviéndolo sin soltar el botón'},'Columna'));if(!this.cfg.unsortable){g.insertCell(2).appendChild($T.create('span',{title:'Selecciona la columna por la que se ordenarán las filas'},'Orden'));var c=$T.create('input',{type:'checkbox'});this.dlg.body.appendChild($T.create('div',{'class':'tm-options'},[c,$T.create('label',{'for':$D.generateId(c,'tm-chk')},'Permitir ordenar múltiples columnas')]));this.dlg.multiSort=c}this.reloadDlg=false;this.dlg.render},beginMove:function(e){if(e.button!=0||e.ctrlKey||e.shiftKey||e.altKey)return;$E.stopEvent(e);var a=$E.getTarget(e);if(a.tagName.toLowerCase!='td'||a.className!='tm-tc-col')return;a=a.parentNode;this.moveArgs.target=a;$E.addListener(document.body,'mousemove',this.colMove,null,this);$E.addListener(document.body,'mouseup',this.endMove,null,this);if(!this.moveArgs.proxy){this.moveArgs.proxy=$T.create('div',{'class':'tm-dlg-proxy',style:'display:none;'});this.dlg.element.appendChild(this.moveArgs.proxy)}if(!this.moveArgs.locator){this.moveArgs.locator=$T.create('div',{'class':'tm-dlg-locator',style:'display:none;'});this.dlg.body.appendChild(this.moveArgs.locator)}var b=$D.getRegion(a);$D.setStyle([this.moveArgs.proxy,this.moveArgs.locator],'width',(b.right-b.left).toString+'px');$D.setStyle(this.moveArgs.proxy,'height',(b.bottom-b.top).toString+'px');$D.setStyle(this.moveArgs.proxy,'display','block');$D.setXY(this.moveArgs.proxy,[($E.getXY(e)[0]-(b.right-b.left)/2),($E.getXY(e)[1]-(b.bottom-b.top)/2)]);this.moveArgs.proxy.focus;$D.setX(this.moveArgs.locator,b.left);this.moveArgs.rowRegionCache=new Array;var c=this.dlg.cplTBody;this.moveArgs.rowRegionCache.push([$D.getRegion(c),null]);for(var i=0;i<c.rows.length;i++)this.moveArgs.rowRegionCache.push([$D.getRegion(c.rows[i]),c.rows[i]]);if((' '+a.className+' ').indexOf(' m-selected ')==-1)a.className+=' m-selected'},colMove:function(e){$E.stopEvent(e);var a=$D.getRegion(this.moveArgs.proxy);var b=$E.getXY(e);$D.setXY(this.moveArgs.proxy,[($E.getXY(e)[0]-(a.right-a.left)/2),($E.getXY(e)[1]-(a.bottom-a.top)/2)]);var c=this.getRowByMousePos(e);if(!c){$D.setStyle(this.moveArgs.locator,'display','none');this.moveArgs.visible=false;return}if(!this.moveArgs.visible){$D.setStyle(this.moveArgs.locator,'display','block');this.moveArgs.visible=true}var d=c[0].top+(c[0].bottom-c[0].top)/2;$D.setY(this.moveArgs.locator,((b[1]<d?c[0].top:c[0].bottom)-1))},endMove:function(e){$E.removeListener(document.body,'mousemove',this.colMove);$E.removeListener(document.body,'mouseup',this.endMove);var v=this.moveArgs.visible;$D.setStyle([this.moveArgs.proxy,this.moveArgs.locator],'display','none');this.moveArgs.visible=false;if(this.moveArgs.target&&(' '+this.moveArgs.target.className+' ').indexOf(' m-selected ')!=-1)this.moveArgs.target.className=$T.trim((' '+this.moveArgs.target.className+' ').replace(' m-selected ',' '));if(!v)return;var a=this.getRowByMousePos(e);if(!a)return;var b=a[0].top+(a[0].bottom-a[0].top)/2;if($E.getXY(e)[1]eXY[0]||cReg.righteXY[1]||cReg.bottom=eXY[1]){b=a[i];break}}return b},dlgClick:function(e){var a=$E.getTarget(e);if(a.tagName.toLowerCase!='div'||a.parentNode.className!='tm-tc-sort')return;var r=a.parentNode.parentNode,s=r.tmCell.tmColDfn.sort;for(var i=0,rs=this.dlg.cplTBody.rows;i0?'-asc tm-sort-asc':' tm-sort'));c.title=s.state?'Orden '+s.title+' '+(s.state<0?'de mayor a menor':'de menor a mayor'):'Sin ordenar (tipo '+s.title+')';if(!s.state)s.priority=0},rebuildMultiSort:function{var c=[],mc=this.dlg.multiSort.checked;for(var i=0,rs=this.dlg.cplTBody.rows;i<rs.length;i++){var s=rs[i].tmCell.tmColDfn.sort;if(s)c.push([rs[i].cells[2].firstChild.firstChild.firstChild,s])}c.sort(function(a,b){if(!a[1].state)return b[1].state?1:0;else if(!b[1].state)return-1;return a[1].priority?a[1].priority-(b[1].priority||a[1].priority+1):1});for(var i=0;i<c.length;i++){if(c[i][1].state){c[i][1].priority=i+1;c[i][0].data=mc?(i+1).toString:}else c[i][0].data=}},discardChanges:function{var c=this.dlg.cplTBody.rows;var e=[];for(var i=0;i<c.length;i++){var d=c[i].tmCell.tmColDfn,s=d.sort;c[i].cells[0].firstChild.checked=d.visible;if(!this.cfg.unsortable&&s){this.changeSortState(i,s.oldState);s.priority=s.oldPriority}e.push(c[i])}if(!this.cfg.unsortable){this.dlg.multiSort.checked=this.dlg.multiSort.defaultChecked;this.rebuildMultiSort}e.sort(function(a,b){return a.tmCell.cellIndex-b.tmCell.cellIndex});$T.makeChildren(e,this.dlg.cplTBody)},applyChanges:function{$D.setStyle(document.body,'cursor','wait');var a=this.dlg.cplTBody.rows;var b=false,cfgVis=[],tagPos=false,tagSort=false,cfgSort=[];for(var i=0;i<a.length;i++){var c=a[i].tmCell,d=c.tmColDfn;if(a[i].cells[0].firstChild.checked!=d.visible){b=true;cfgVis[c.cellIndex]={changed:true,value:a[i].cells[0].firstChild.checked}}else cfgVis[c.cellIndex]=null;if(c.cellIndex!=i)tagPos=true;d.newIndex=i;if(!this.cfg.unsortable&&d.sort){if(d.sort.state==0){d.sort.oldState=0;d.sort.oldPriority=0}else{cfgSort.push(c);if(d.sort.state!=d.sort.oldState)tagSort=true}}}if(!this.cfg.unsortable)this.dlg.multiSort.defaultChecked=this.dlg.multiSort.checked;$D.setStyle(this.table,'display','none');var f=null;try{if(b)this.applyVisibility(cfgVis);if(tagPos)this.applyColumnPosition;if(tagSort)this.applySort(cfgSort)}catch(e){f=e}$D.setStyle(this.table,'display',);$D.setStyle(document.body,'cursor',);this.dlg.hide;if(f)throw f;},applyVisibility:function(a){for(var i=0,rs=this.table.rows;i=0;i--){var d=[];for(var j=0,cs=rs[i].cells;j<cs.length;j++)d.push(cs[j]);d.sort(function(a,b){var c=a.parentNode.parentNode.parentNode.rows[0];return c.cells[a.cellIndex].tmColDfn.newIndex-c.cells[b.cellIndex].tmColDfn.newIndex});$T.makeChildren(d,rs[i])}},applySort:function(c){var d=[],bottomRows=[];c.sort(function(a,b){return a.tmColDfn.sort.priority-b.tmColDfn.sort.priority});for(var i=1,rs=this.table.rows;i<rs.length;i++){if((' '+rs[i].className+' ').indexOf(' sortbottom ')!=-1)bottomRows.push(rs[i]);else d.push(rs[i])}window.__tm_cfgSort=c;window.__tm_this=this;d.sort(this.rowSortFunction);delete window.__tm_cfgSort;delete window.__tm_this;$T.makeChildren(d,this.table.tBodies[0]);$T.makeChildren(bottomRows,this.table.tBodies[0]);for(var i=0,cs=this.table.rows[0].cells;i<cs.length;i++){var s=cs[i].tmColDfn.sort;if(s){s.oldState=s.state;s.oldPriority=s.priority}}},rowSortFunction:function(a,b){var d=0,cfgSort=window.__tm_cfgSort,thisArg=window.__tm_this;for(var i=0;i<cfgSort.length;i++){var c=cfgSort[i],s=c.tmColDfn.sort,A=thisArg.getTextContent(a.cells[c.cellIndex]),B=thisArg.getTextContent(b.cells[c.cellIndex]);var e=thisArg.cfg.emptysort,ss=s.state;if(e!=0&&(A!=||B!=)){if(A==)return(-1)*e;if(B=='')return e}if(!s.sortFn)continue;d=ss*s.sortFn([a,A,ss*a.rowIndex,a.cells[c.cellIndex]],[b,B,ss*b.rowIndex,b.cells[c.cellIndex]]);if(d)break}return d}};

if (window.postloadFunctionData && postloadFunctionData['tablemanager'] !== null) { for (var i = 0; i < postloadFunctionData['tablemanager'].length; i++) { var t = postloadFunctionData['tablemanager'][i]; if ( $UT.hasClass(t, 'movnivel') ) { new TableManager(t, {emptysort:-1}); } else { new TableManager(t); }	} } //