[ Index ]

PHP Cross Reference of phpwcms V1.5.0 _r431 (28.01.12)

title

Body

[close]

/template/lib/mootools/more/Interface/ -> HtmlTable.Sort.js (source)

   1  HtmlTable=Class.refactor(HtmlTable,{options:{sortIndex:0,sortReverse:false,parsers:[],defaultParser:"string",classSortable:"table-sortable",classHeadSort:"table-th-sort",classHeadSortRev:"table-th-sort-rev",classNoSort:"table-th-nosort",classGroupHead:"table-tr-group-head",classGroup:"table-tr-group",classCellSort:"table-td-sort",classSortSpan:"table-th-sort-span",sortable:false},initialize:function(){this.previous.apply(this,arguments);if(this.occluded){return this.occluded}this.sorted={index:null,dir:1};this.bound={headClick:this.headClick.bind(this)};this.sortSpans=new Elements();if(this.options.sortable){this.enableSort();if(this.options.sortIndex!=null){this.sort(this.options.sortIndex,this.options.sortReverse)}}},attachSorts:function(a){this.element.removeEvents("click:relay(th)");this.element[$pick(a,true)?"addEvent":"removeEvent"]("click:relay(th)",this.bound.headClick)},setHeaders:function(){this.previous.apply(this,arguments);if(this.sortEnabled){this.detectParsers()}},detectParsers:function(c){if(!this.head){return}var a=this.options.parsers,b=this.body.rows;this.parsers=$$(this.head.cells).map(function(d,e){if(!c&&(d.hasClass(this.options.classNoSort)||d.retrieve("htmltable-parser"))){return d.retrieve("htmltable-parser")}var f=new Element("div");$each(d.childNodes,function(j){f.adopt(j)});f.inject(d);var h=new Element("span",{html:"&#160;","class":this.options.classSortSpan}).inject(f,"top");this.sortSpans.push(h);var i=a[e],g;switch($type(i)){case"function":i={convert:i};g=true;break;case"string":i=i;g=true;break}if(!g){HtmlTable.Parsers.some(function(o){var m=o.match;if(!m){return false}for(var n=0,l=b.length;n<l;n++){var k=document.id(b[n].cells[e]);var p=k?k.get("html").clean():"";if(p&&m.test(p)){i=o;return true}}})}if(!i){i=this.options.defaultParser}d.store("htmltable-parser",i);return i},this)},headClick:function(c,b){if(!this.head||b.hasClass(this.options.classNoSort)){return}var a=Array.indexOf(this.head.cells,b);this.sort(a);return false},sort:function(f,h,m){if(!this.head){return}m=!!(m);var l=this.options.classCellSort;var o=this.options.classGroup,t=this.options.classGroupHead;if(!m){if(f!=null){if(this.sorted.index==f){this.sorted.reverse=!(this.sorted.reverse)}else{if(this.sorted.index!=null){this.sorted.reverse=false;this.head.cells[this.sorted.index].removeClass(this.options.classHeadSort).removeClass(this.options.classHeadSortRev)}else{this.sorted.reverse=true}this.sorted.index=f}}else{f=this.sorted.index}if(h!=null){this.sorted.reverse=h}var d=document.id(this.head.cells[f]);if(d){d.addClass(this.options.classHeadSort);if(this.sorted.reverse){d.addClass(this.options.classHeadSortRev)}else{d.removeClass(this.options.classHeadSortRev)}}this.body.getElements("td").removeClass(this.options.classCellSort)}var c=this.parsers[f];if($type(c)=="string"){c=HtmlTable.Parsers.get(c)}if(!c){return}if(!Browser.Engine.trident){var b=this.body.getParent();this.body.dispose()}var s=Array.map(this.body.rows,function(v,j){var u=c.convert.call(document.id(v.cells[f]));return{position:j,value:u,toString:function(){return u.toString()}}},this);s.reverse(true);s.sort(function(j,i){if(j.value===i.value){return 0}return j.value>i.value?1:-1});if(!this.sorted.reverse){s.reverse(true)}var p=s.length,k=this.body;var n,r,a,g;while(p){var q=s[--p];r=q.position;var e=k.rows[r];if(e.disabled){continue}if(!m){if(g===q.value){e.removeClass(t).addClass(o)}else{g=q.value;e.removeClass(o).addClass(t)}if(this.options.zebra){this.zebra(e,p)}e.cells[f].addClass(l)}k.appendChild(e);for(n=0;n<p;n++){if(s[n].position>r){s[n].position--}}}s=null;if(b){b.grab(k)}return this.fireEvent("sort",[k,f])},reSort:function(){if(this.sortEnabled){this.sort.call(this,this.sorted.index,this.sorted.reverse)}return this},enableSort:function(){this.element.addClass(this.options.classSortable);this.attachSorts(true);this.detectParsers();this.sortEnabled=true;return this},disableSort:function(){this.element.removeClass(this.options.classSortable);this.attachSorts(false);this.sortSpans.each(function(a){a.destroy()});this.sortSpans.empty();this.sortEnabled=false;return this}});HtmlTable.Parsers=new Hash({date:{match:/^\d{2}[-\/ ]\d{2}[-\/ ]\d{2,4}$/,convert:function(){var a=Date.parse(this.get("text").stripTags());return $type(a)=="date"?a.format("db"):""},type:"date"},"input-checked":{match:/ type="(radio|checkbox)" /,convert:function(){return this.getElement("input").checked}},"input-value":{match:/<input/,convert:function(){return this.getElement("input").value}},number:{match:/^\d+[^\d.,]*$/,convert:function(){return this.get("text").stripTags().toInt()},number:true},numberLax:{match:/^[^\d]+\d+$/,convert:function(){return this.get("text").replace(/[^-?^0-9]/,"").stripTags().toInt()},number:true},"float":{match:/^[\d]+\.[\d]+/,convert:function(){return this.get("text").replace(/[^-?^\d.]/,"").stripTags().toFloat()},number:true},floatLax:{match:/^[^\d]+[\d]+\.[\d]+$/,convert:function(){return this.get("text").replace(/[^-?^\d.]/,"").stripTags()},number:true},string:{match:null,convert:function(){return this.get("text").stripTags()}},title:{match:null,convert:function(){return this.title}}});HtmlTable.defineParsers=function(a){HtmlTable.Parsers=new Hash(a).combine(HtmlTable.Parsers)};


Generated: Sun Jan 29 16:31:14 2012 Cross-referenced by PHPXref 0.7.1