[ Index ]

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

title

Body

[close]

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

   1  HtmlTable=Class.refactor(HtmlTable,{options:{useKeyboard:true,classRowSelected:"table-tr-selected",classRowHovered:"table-tr-hovered",classSelectable:"table-selectable",shiftForMultiSelect:true,allowMultiSelect:true,selectable:false},initialize:function(){this.previous.apply(this,arguments);if(this.occluded){return this.occluded}this._selectedRows=new Elements();this._bound={mouseleave:this._mouseleave.bind(this),clickRow:this._clickRow.bind(this)};if(this.options.selectable){this.enableSelect()}},enableSelect:function(){this._selectEnabled=true;this._attachSelects();this.element.addClass(this.options.classSelectable)},disableSelect:function(){this._selectEnabled=false;this._attachSelects(false);this.element.removeClass(this.options.classSelectable)},push:function(){var a=this.previous.apply(this,arguments);this._updateSelects();return a},toggleRow:function(a){return this.isSelected(a)?this.deselectRow.apply(this,arguments):this.selectRow.apply(this,arguments)},selectRow:function(b,a){if(this.isSelected(b)||(!a&&!this.body.getChildren().contains(b))){return}if(!this.options.allowMultiSelect){this.selectNone()}if(!this.isSelected(b)){this._selectedRows.push(b);b.addClass(this.options.classRowSelected);this.fireEvent("rowFocus",[b,this._selectedRows])}this._focused=b;document.clearSelection();return this},isSelected:function(a){return this._selectedRows.contains(a)},deselectRow:function(b,a){if(!this.isSelected(b)||(!a&&!this.body.getChildren().contains(b))){return}this._selectedRows.erase(b);b.removeClass(this.options.classRowSelected);this.fireEvent("rowUnfocus",[b,this._selectedRows]);return this},selectAll:function(a){if(!a&&!this.options.allowMultiSelect){return}this.selectRange(0,this.body.rows.length,a);return this},selectNone:function(){return this.selectAll(true)},selectRange:function(b,a,f){if(!this.options.allowMultiSelect&&!f){return}var g=f?"deselectRow":"selectRow",e=$A(this.body.rows);if($type(b)=="element"){b=e.indexOf(b)}if($type(a)=="element"){a=e.indexOf(a)}a=a<e.length-1?a:e.length-1;if(a<b){var d=b;b=a;a=d}for(var c=b;c<=a;c++){this[g](e[c],true)}return this},deselectRange:function(b,a){this.selectRange(b,a,true)},_enterRow:function(a){if(this._hovered){this._hovered=this._leaveRow(this._hovered)}this._hovered=a.addClass(this.options.classRowHovered)},_leaveRow:function(a){a.removeClass(this.options.classRowHovered)},_updateSelects:function(){Array.each(this.body.rows,function(a){var b=a.retrieve("binders");if((b&&this._selectEnabled)||(!b&&!this._selectEnabled)){return}if(!b){b={mouseenter:this._enterRow.bind(this,[a]),mouseleave:this._leaveRow.bind(this,[a])};a.store("binders",b).addEvents(b)}else{a.removeEvents(b)}},this)},_shiftFocus:function(b,a){if(!this._focused){return this.selectRow(this.body.rows[0],a)}var c=this._getRowByOffset(b);if(c===null||this._focused==this.body.rows[c]){return this}this.toggleRow(this.body.rows[c],a)},_clickRow:function(a,b){var c=(a.shift||a.meta||a.control)&&this.options.shiftForMultiSelect;if(!c&&!(a.rightClick&&this.isSelected(b)&&this.options.allowMultiSelect)){this.selectNone()}if(a.rightClick){this.selectRow(b)}else{this.toggleRow(b)}if(a.shift){this.selectRange(this._rangeStart||this.body.rows[0],b,this._rangeStart?!this.isSelected(b):true);this._focused=b}this._rangeStart=b},_getRowByOffset:function(b){if(!this._focused){return 0}var a=Array.indexOf(this.body.rows,this._focused)+b;if(a<0){a=null}if(a>=this.body.rows.length){a=null}return a},_attachSelects:function(d){d=$pick(d,true);var g=d?"addEvents":"removeEvents";this.element[g]({mouseleave:this._bound.mouseleave});this.body[g]({"click:relay(tr)":this._bound.clickRow,"contextmenu:relay(tr)":this._bound.clickRow});if(this.options.useKeyboard||this.keyboard){if(!this.keyboard){var f,e;var c=function(i){var h=function(j){$clear(f);j.preventDefault();var k=this.body.rows[this._getRowByOffset(i)];if(j.shift&&k&&this.isSelected(k)){this.deselectRow(this._focused);this._focused=k}else{if(k&&(!this.options.allowMultiSelect||!j.shift)){this.selectNone()}this._shiftFocus(i,j)}if(e){f=h.delay(100,this,j)}else{f=(function(){e=true;h(j)}).delay(400)}}.bind(this);return h}.bind(this);var b=function(){$clear(f);e=false};this.keyboard=new Keyboard({events:{"keydown:shift+up":c(-1),"keydown:shift+down":c(1),"keyup:shift+up":b,"keyup:shift+down":b,"keyup:up":b,"keyup:down":b},active:true});var a="";if(this.options.allowMultiSelect&&this.options.shiftForMultiSelect&&this.options.useKeyboard){a=" (Shift multi-selects)."}this.keyboard.addShortcuts({"Select Previous Row":{keys:"up",shortcut:"up arrow",handler:c(-1),description:"Select the previous row in the table."+a},"Select Next Row":{keys:"down",shortcut:"down arrow",handler:c(1),description:"Select the next row in the table."+a}})}this.keyboard[d?"activate":"deactivate"]()}this._updateSelects()},_mouseleave:function(){if(this._hovered){this._leaveRow(this._hovered)}}});


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