Changeset 5435

Show
Ignore:
Timestamp:
02/01/08 08:45:02 (10 months ago)
Author:
uta
Message:

2349

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • spinelz/trunk/compress/javascripts/spinelz/selectableTable.js

    r5322 r5435  
    99},functionSubmit:Prototype.emptyFunction,initialSelected:null,prefixTrId:"selectable_table_",prefixCSS:"custom_"}; 
    1010this.options=Object.extend(_2,arguments[1]||{}); 
    11 this.classNames=new CssUtil([SelectableTable.classNames,CssUtil.appendPrefix(this.options.prefixCSS,SelectableTable.classNames)]); 
    12 this.flagAllowMultiple=this.options.flagInitialAllowMultiple; 
    13 this.flagAvailable=true; 
    14 this.focused=null; 
    15 this.lastSelected=null; 
    16 this.newNumber=1; 
    17 this.selected=new Object(); 
     11Object.extend(this,{classNames:new CssUtil([SelectableTable.classNames,CssUtil.appendPrefix(this.options.prefixCSS,SelectableTable.classNames)]),flagAllowMultiple:this.options.flagInitialAllowMultiple,flagAvailable:true,focused:null,lastSelected:null,lineIdArray:[],newNumber:1,selected:{}}); 
    1812this.build(); 
    1913if(this.options.initialSelected){ 
     
    8781_6.cmdPressed=false; 
    8882},true); 
     83},addMouseEvent:function(){ 
     84Event.observe(this.element,"mousedown",this.eventMouseDown.bindAsEventListener(this)); 
     85Event.observe(document,"mouseup",this.eventMouseUp.bindAsEventListener(this)); 
    8986},build:function(){ 
    9087this.addKeyboardEvent(); 
     88this.addMouseEvent(); 
    9189if(this.options.build){ 
    9290Element.setStyle(this.element,{visibility:"hidden"}); 
     
    9593for(var i=0;i<_8.length;i++){ 
    9694this.buildTr(_8[i]); 
     95this.lineIdArray.push(_8[i].id); 
    9796} 
    9897this.options.functionPostBuild(this); 
    9998Element.setStyle(this.element,{visibility:"visible"}); 
    100 
    101 },buildTr:function(_a){ 
    102 _a.id=this.buildTrId(_a.id); 
    103 this.classNames.addClassNames(_a,"tr"); 
    104 Event.observe(_a,"click",this.eventClick.bindAsEventListener(this)); 
    105 Event.observe(_a,"dblclick",this.eventDoubleClick.bindAsEventListener(this)); 
    106 Event.observe(_a,"mouseout",this.eventFocusOut.bindAsEventListener(this)); 
    107 Event.observe(_a,"mouseover",this.eventFocusOver.bindAsEventListener(this)); 
    108 },buildTrId:function(_b){ 
    109 return this.options.prefixTrId+_b; 
     99}else{ 
     100this.lineIdArray=$A(this.element.tBodies[0].rows).collect(function(el){ 
     101return el.id; 
     102}); 
     103
     104},buildTr:function(_b){ 
     105_b.id=this.buildTrId(_b.id); 
     106this.classNames.addClassNames(_b,"tr"); 
     107Event.observe(_b,"click",this.eventClick.bindAsEventListener(this),true); 
     108Event.observe(_b,"dblclick",this.eventDoubleClick.bindAsEventListener(this),true); 
     109Event.observe(_b,"mouseout",this.eventFocusOut.bindAsEventListener(this),true); 
     110Event.observe(_b,"mouseover",this.eventFocusOver.bindAsEventListener(this),true); 
     111},buildTrId:function(_c){ 
     112return this.options.prefixTrId+_c; 
    110113},deleteAll:function(){ 
    111114if(!this.flagAvailable){ 
     
    115118return; 
    116119} 
    117 for(var _c in this.selected){ 
    118 this.element.tBodies[0].removeChild($(_c)); 
    119 delete this.selected[_c]; 
     120for(var _d in this.selected){ 
     121this.element.tBodies[0].removeChild($(_d)); 
     122delete this.selected[_d]; 
    120123} 
    121124this.focused=null; 
     
    126129} 
    127130this.cmdManager.destroy(); 
    128 },eventClick:function(_d){ 
     131},eventClick:function(_e){ 
    129132if(!this.flagAvailable){ 
    130133return; 
     
    132135if(this.options.functionClickCallback.constructor==Function){ 
    133136if(this.options.functionClickCallback!=Prototype.emptyFunction){ 
    134 this.options.functionClickCallback(Event.findElement(_d,"tr").id.replace(this.options.prefixTrId,"")); 
    135 } 
    136 } 
    137 if(_d.shiftKey){ 
    138 this.selectOrUnselectRange(Event.findElement(_d,"tr").id); 
    139 }else{ 
    140 this.selectOrUnselect(Event.findElement(_d,"tr").id,_d.ctrlKey||this.cmdPressed); 
    141 } 
    142 },eventDoubleClick:function(_e){ 
     137this.options.functionClickCallback(Event.findElement(_e,"tr").id.replace(this.options.prefixTrId,"")); 
     138} 
     139} 
     140if(_e.shiftKey){ 
     141this.selectOrUnselectRange(Event.findElement(_e,"tr").id); 
     142}else{ 
     143this.selectOrUnselect(Event.findElement(_e,"tr").id,_e.ctrlKey||this.cmdPressed); 
     144} 
     145},eventDoubleClick:function(_f){ 
    143146if(!this.flagAvailable){ 
    144147return; 
     
    146149if(this.options.functionDoubleClickCallback.constructor==Function){ 
    147150if(this.options.functionDoubleClickCallback!=Prototype.emptyFunction){ 
    148 this.options.functionDoubleClickCallback(Event.findElement(_e,"tr").id.replace(this.options.prefixTrId,"")); 
     151this.options.functionDoubleClickCallback(Event.findElement(_f,"tr").id.replace(this.options.prefixTrId,"")); 
    149152} 
    150153} 
    151154if(this.flagAllowMultiple){ 
    152 this.select(Event.findElement(_e,"tr").id,false); 
     155this.select(Event.findElement(_f,"tr").id,false); 
    153156this.submit(); 
    154157} 
    155 },eventFocusOut:function(_f){ 
     158},eventFocusOut:function(_10){ 
    156159if(!this.flagAvailable){ 
    157160return; 
    158161} 
    159162this.focusOff(); 
    160 },eventFocusOver:function(_10){ 
    161 if(!this.flagAvailable){ 
    162 return; 
    163 
    164 this.focusOn(Event.findElement(_10,"tr").id); 
    165 Event.findElement(_10,"tr").focus(); 
    166 },focusMove:function(_11){ 
     163},eventFocusOver:function(_11){ 
     164if(!this.flagAvailable){ 
     165return; 
     166
     167this.focusOn(Event.findElement(_11,"tr").id); 
     168SpinelzUtil.clearBrowserSelection(); 
     169},eventMouseDown:function(_12){ 
     170if(!_12.shiftKey&&!_12.ctrlKey){ 
     171this.onMouseDown(Event.findElement(_12,"tr").id); 
     172
     173},eventMouseUp:function(_13){ 
     174var st=this; 
     175setTimeout(function(){ 
     176st.onMouseUp(); 
     177},10); 
     178},focusMove:function(_15){ 
    167179if(!this.flagAvailable){ 
    168180return; 
     
    173185} 
    174186}else{ 
    175 var _12=$(this.focused).rowIndex; 
    176 var _13,_14
    177 switch(_11){ 
     187var _16=$(this.focused).rowIndex; 
     188var _17,_18
     189switch(_15){ 
    178190case "down": 
    179 _13=1; 
    180 _14=this.isBottom(_12); 
     191_17=1; 
     192_18=this.isBottom(_16); 
    181193break; 
    182194case "up": 
    183 _13=-1; 
    184 _14=this.isTop(_12); 
     195_17=-1; 
     196_18=this.isTop(_16); 
    185197break; 
    186198} 
    187 if(!_14){ 
    188 this.focusOn(this.element.rows[_12+_13].id); 
     199if(!_18){ 
     200this.focusOn(this.element.rows[_16+_17].id); 
    189201} 
    190202} 
     
    194206} 
    195207if(this.focused!=null){ 
    196 var _15=$(this.focused); 
    197 this.classNames.removeClassNames(_15,"trHover"); 
     208var _19=$(this.focused); 
     209this.classNames.removeClassNames(_19,"trHover"); 
    198210this.focused=null; 
    199211} 
    200 },focusOn:function(_16){ 
    201 if(!this.flagAvailable){ 
    202 return; 
    203 } 
    204 if($(_16)!=null){ 
     212},focusOn:function(_1a){ 
     213if(!this.flagAvailable){ 
     214return; 
     215} 
     216if($(_1a)!=null){ 
    205217this.focusOff(); 
    206 this.classNames.addClassNames($(_16),"trHover"); 
    207 this.focused=_16; 
     218if(this.flagAllowMultiple&&this.mouseDown){ 
     219this.mouseSelect(_1a); 
     220}else{ 
     221this.classNames.addClassNames($(_1a),"trHover"); 
     222this.focused=_1a; 
     223
    208224} 
    209225},getSelected:function(){ 
    210 var _17=new Array(); 
    211 for(var _18 in this.selected){ 
    212 _17.push(_18.replace(this.options.prefixTrId,"")); 
    213 } 
    214 return _17
     226var _1b=new Array(); 
     227for(var _1c in this.selected){ 
     228_1b.push(_1c.replace(this.options.prefixTrId,"")); 
     229} 
     230return _1b
    215231},getSelectedElement:function(id){ 
    216 var _1a=this.options.prefixTrId+id; 
    217 return $(_1a); 
    218 },isBottom:function(_1b){ 
    219 return (_1b==this.element.rows.length-1)?true:false; 
    220 },isTop:function(_1c){ 
    221 return (_1c==this.element.tBodies[0].rows[0].rowIndex)?true:false; 
     232var _1e=this.options.prefixTrId+id; 
     233return $(_1e); 
     234},isBottom:function(_1f){ 
     235return (_1f==this.element.rows.length-1)?true:false; 
     236},isTop:function(_20){ 
     237return (_20==this.element.tBodies[0].rows[0].rowIndex)?true:false; 
    222238},makeAvailable:function(){ 
    223239this.flagAvailable=true; 
     
    235251} 
    236252this.flagAvailable=false; 
    237 },select:function(_1d,_1e){ 
    238 if(!this.flagAvailable){ 
    239 return; 
    240 
    241 this.selectEffect(_1d,_1e); 
    242 this.lastSelected=_1d; 
     253},mouseSelect:function(_21){ 
     254if(!this.flagAvailable){ 
     255return; 
     256
     257if(this.mouseDownCurrent==_21){ 
     258return; 
     259
     260this.mouseDownCurrent=_21; 
     261var _22=[]; 
     262if(_21==this.mouseDownBase){ 
     263_22.push(_21); 
     264}else{ 
     265var _23=false; 
     266var _24=this; 
     267this.lineIdArray.each(function(_25){ 
     268if(_23){ 
     269_22.push(_25); 
     270
     271if(_25==_24.mouseDownBase||_25==_24.mouseDownCurrent){ 
     272_23=(_23!=true); 
     273_22.push(_25); 
     274
     275}); 
     276_22.uniq(); 
     277
     278this.unselectAll(); 
     279var _24=this; 
     280_22.each(function(_26){ 
     281_24.select(_26,true); 
     282}); 
     283},onMouseDown:function(_27){ 
     284if(!this.flagAvailable){ 
     285return; 
     286
     287this.unselectAll(); 
     288if(_27){ 
     289Object.extend(this,{mouseDown:true,mouseDownBase:_27,mouseDownCurrent:null}); 
     290this.mouseSelect(_27); 
     291
     292},onMouseUp:function(){ 
     293if(!this.flagAvailable){ 
     294return; 
     295
     296if(this.mouseDown){ 
     297this.mouseDown=false; 
     298
     299},select:function(_28,_29){ 
     300if(!this.flagAvailable){ 
     301return; 
     302
     303this.selectEffect(_28,_29); 
     304this.lastSelected=_28; 
    243305this.options.functionPostSelect(this); 
    244306if(!this.flagAllowMultiple){ 
     
    253315} 
    254316this.selected=new Object(); 
    255 var _1f=this.element.tBodies[0].rows; 
    256 for(var i=0;i<_1f.length;i++){ 
    257 this.select(_1f[i].id,true); 
    258 } 
    259 },selectEffect:function(_21,_22){ 
    260 if($(_21)){ 
    261 if(!this.flagAllowMultiple||!_22){ 
     317var _2a=this.element.tBodies[0].rows; 
     318for(var i=0;i<_2a.length;i++){ 
     319this.select(_2a[i].id,true); 
     320} 
     321},selectEffect:function(_2c,_2d){ 
     322if($(_2c)){ 
     323if(!this.flagAllowMultiple||!_2d){ 
    262324this.unselectAll(); 
    263325} 
    264 this.classNames.addClassNames($(_21),"trSelected"); 
    265 this.selected[_21]=true; 
    266 } 
    267 },selectOrUnselect:function(_23,_24){ 
    268 if(!this.flagAvailable){ 
    269 return; 
    270 } 
    271 if(_23==null){ 
    272 return; 
    273 } 
    274 if(_24&&this.selected[_23]){ 
     326this.classNames.addClassNames($(_2c),"trSelected"); 
     327this.selected[_2c]=true; 
     328} 
     329},selectOrUnselect:function(_2e,_2f){ 
     330if(!this.flagAvailable){ 
     331return; 
     332} 
     333if(_2e==null){ 
     334return; 
     335} 
     336if(_2f&&this.selected[_2e]){ 
    275337if(!this.flagAllowMultiple&&!this.options.flagAllowUnselect){ 
    276338return; 
    277339} 
    278 this.unselect(_23); 
    279 }else{ 
    280 this.select(_23,_24); 
    281 
    282 },selectOrUnselectRange:function(_25){ 
    283 if(!this.flagAvailable){ 
    284 return; 
    285 
    286 if(_25==null){ 
    287 return; 
    288 
    289 if(this.lastSelected==null||this.lastSelected==_25){ 
    290 this.selectOrUnselect(_25); 
    291 return; 
    292 
    293 var _26=false; 
    294 var _27=this.element.tBodies[0].rows; 
    295 var _28=this.lastSelected; 
    296 for(var i=0;i<_27.length;i++){ 
    297 if(_27[i].id==_25||_27[i].id==_28){ 
    298 _26=(_26)?false:true; 
    299 }else{ 
    300 if(!_26){ 
     340this.unselect(_2e); 
     341}else{ 
     342this.select(_2e,_2f); 
     343if(_2f){ 
     344SpinelzUtil.clearBrowserSelection(); 
     345
     346
     347},selectOrUnselectRange:function(_30){ 
     348if(!this.flagAvailable){ 
     349return; 
     350
     351if(_30==null){ 
     352return; 
     353
     354if(this.lastSelected==null||this.lastSelected==_30){ 
     355this.selectOrUnselect(_30); 
     356return; 
     357
     358var _31=false; 
     359var _32=this.element.tBodies[0].rows; 
     360var _33=this.lastSelected; 
     361for(var i=0;i<_32.length;i++){ 
     362if(_32[i].id==_30||_32[i].id==_33){ 
     363_31=(_31)?false:true; 
     364}else{ 
     365if(!_31){ 
    301366continue; 
    302367} 
    303368} 
    304 if(this.selected[_28]){ 
    305 this.select(_27[i].id,true); 
    306 }else{ 
    307 this.unselect(_27[i].id); 
    308 
    309 
    310 },submit:function(_2a){ 
    311 if(!this.flagAvailable){ 
    312 return; 
    313 
    314 var _2b=this.getSelected(); 
    315 this.options.functionSubmit(_2b[0]); 
    316 },unselect:function(_2c){ 
    317 if(!this.flagAvailable){ 
    318 return; 
    319 
    320 this.classNames.removeClassNames($(_2c),"trSelected"); 
    321 delete this.selected[_2c]; 
    322 this.lastSelected=_2c; 
     369if(this.selected[_33]){ 
     370this.select(_32[i].id,true); 
     371}else{ 
     372this.unselect(_32[i].id); 
     373
     374
     375SpinelzUtil.clearBrowserSelection(); 
     376},submit:function(_35){ 
     377if(!this.flagAvailable){ 
     378return; 
     379
     380var _36=this.getSelected(); 
     381this.options.functionSubmit(_36[0]); 
     382},unselect:function(_37){ 
     383if(!this.flagAvailable){ 
     384return; 
     385
     386this.classNames.removeClassNames($(_37),"trSelected"); 
     387delete this.selected[_37]; 
     388this.lastSelected=_37; 
    323389this.options.functionPostUnselect(this); 
    324390},unselectAll:function(){ 
     
    326392return; 
    327393} 
    328 var _2d=this.element.tBodies[0].rows; 
    329 for(var i=0;i<_2d.length;i++){ 
    330 this.unselect(_2d[i].id); 
     394var _38=this.element.tBodies[0].rows; 
     395for(var i=0;i<_38.length;i++){ 
     396this.unselect(_38[i].id); 
    331397} 
    332398}}; 
    333 var SelectableTableLib={navi:function(_2f,_30){ 
    334 var _31=_30||(SelectableTableManager.active||"")+"_navigation_top"; 
    335 var _30=$(_31+"_"+_2f); 
    336 if(_30!=null){ 
     399var SelectableTableLib={navi:function(_3a,_3b){ 
     400var _3c=_3b||(SelectableTableManager.active||"")+"_navigation_top"; 
     401var _3b=$(_3c+"_"+_3a); 
     402if(_3b!=null){ 
    337403if(UserAgent.isIE()){ 
    338 _30.fireEvent("onclick"); 
     404_3b.fireEvent("onclick"); 
    339405}else{ 
    340406var evt=document.createEvent("MouseEvents"); 
    341407evt.initEvent("click",true,true); 
    342 _30.dispatchEvent(evt); 
     408_3b.dispatchEvent(evt); 
    343409} 
    344410} 
     
    346412var SelectableTableCreator={create:function(){ 
    347413var key=arguments[0]; 
    348 var _34=arguments[1]||{}; 
    349 var _35=arguments[2]||null; 
    350 var _36=arguments[3]||false; 
    351 if(_35){ 
     414var _3f=arguments[1]||{}; 
     415var _40=arguments[2]||null; 
     416var _41=arguments[3]||false; 
     417if(_40){ 
    352418try{ 
    353 _35.destroy(); 
     419_40.destroy(); 
    354420} 
    355421catch(e){ 
    356422} 
    357423} 
    358 var _37=new SelectableTable(key,_34); 
    359 if(_36){ 
    360 SelectableTableManager.push(key,_37); 
    361 } 
    362 return _37
     424var _42=new SelectableTable(key,_3f); 
     425if(_41){ 
     426SelectableTableManager.push(key,_42); 
     427} 
     428return _42
    363429}}; 
    364430var SelectableTableManager={active:null,list:$H({}),activate:function(key){ 
     
    376442this.deactivate(); 
    377443this.list=$H({}); 
    378 },push:function(key,_3a){ 
     444},push:function(key,_45){ 
    379445if(this.list[key]){ 
    380446this.list[key].makeUnavailable(); 
    381447} 
    382 this.list[key]=_3a
     448this.list[key]=_45
    383449this.activate(key); 
    384450},start:function(){ 
    385 var _3b=this.active; 
    386 if(_3b){ 
    387 this.list[_3b].makeAvailable(); 
     451var _46=this.active; 
     452if(_46){ 
     453this.list[_46].makeAvailable(); 
    388454} 
    389455},stop:function(){ 
  • spinelz/trunk/compress/javascripts/spinelz/spinelz_for_rubricks.js

    r5418 r5435  
    32403240},functionSubmit:Prototype.emptyFunction,initialSelected:null,prefixTrId:"selectable_table_",prefixCSS:"custom_"}; 
    32413241this.options=Object.extend(_2,arguments[1]||{}); 
    3242 this.classNames=new CssUtil([SelectableTable.classNames,CssUtil.appendPrefix(this.options.prefixCSS,SelectableTable.classNames)]); 
    3243 this.flagAllowMultiple=this.options.flagInitialAllowMultiple; 
    3244 this.flagAvailable=true; 
    3245 this.focused=null; 
    3246 this.lastSelected=null; 
    3247 this.newNumber=1; 
    3248 this.selected=new Object(); 
     3242Object.extend(this,{classNames:new CssUtil([SelectableTable.classNames,CssUtil.appendPrefix(this.options.prefixCSS,SelectableTable.classNames)]),flagAllowMultiple:this.options.flagInitialAllowMultiple,flagAvailable:true,focused:null,lastSelected:null,lineIdArray:[],newNumber:1,selected:{}}); 
    32493243this.build(); 
    32503244if(this.options.initialSelected){ 
     
    33183312_6.cmdPressed=false; 
    33193313},true); 
     3314},addMouseEvent:function(){ 
     3315Event.observe(this.element,"mousedown",this.eventMouseDown.bindAsEventListener(this)); 
     3316Event.observe(document,"mouseup",this.eventMouseUp.bindAsEventListener(this)); 
    33203317},build:function(){ 
    33213318this.addKeyboardEvent(); 
     3319this.addMouseEvent(); 
    33223320if(this.options.build){ 
    33233321Element.setStyle(this.element,{visibility:"hidden"}); 
     
    33263324for(var i=0;i<_8.length;i++){ 
    33273325this.buildTr(_8[i]); 
     3326this.lineIdArray.push(_8[i].id); 
    33283327} 
    33293328this.options.functionPostBuild(this); 
    33303329Element.setStyle(this.element,{visibility:"visible"}); 
    3331 
    3332 },buildTr:function(_a){ 
    3333 _a.id=this.buildTrId(_a.id); 
    3334 this.classNames.addClassNames(_a,"tr"); 
    3335 Event.observe(_a,"click",this.eventClick.bindAsEventListener(this)); 
    3336 Event.observe(_a,"dblclick",this.eventDoubleClick.bindAsEventListener(this)); 
    3337 Event.observe(_a,"mouseout",this.eventFocusOut.bindAsEventListener(this)); 
    3338 Event.observe(_a,"mouseover",this.eventFocusOver.bindAsEventListener(this)); 
    3339 },buildTrId:function(_b){ 
    3340 return this.options.prefixTrId+_b; 
     3330}else{ 
     3331this.lineIdArray=$A(this.element.tBodies[0].rows).collect(function(el){ 
     3332return el.id; 
     3333}); 
     3334
     3335},buildTr:function(_b){ 
     3336_b.id=this.buildTrId(_b.id); 
     3337this.classNames.addClassNames(_b,"tr"); 
     3338Event.observe(_b,"click",this.eventClick.bindAsEventListener(this),true); 
     3339Event.observe(_b,"dblclick",this.eventDoubleClick.bindAsEventListener(this),true); 
     3340Event.observe(_b,"mouseout",this.eventFocusOut.bindAsEventListener(this),true); 
     3341Event.observe(_b,"mouseover",this.eventFocusOver.bindAsEventListener(this),true); 
     3342},buildTrId:function(_c){ 
     3343return this.options.prefixTrId+_c; 
    33413344},deleteAll:function(){ 
    33423345if(!this.flagAvailable){ 
     
    33463349return; 
    33473350} 
    3348 for(var _c in this.selected){ 
    3349 this.element.tBodies[0].removeChild($(_c)); 
    3350 delete this.selected[_c]; 
     3351for(var _d in this.selected){ 
     3352this.element.tBodies[0].removeChild($(_d)); 
     3353delete this.selected[_d]; 
    33513354} 
    33523355this.focused=null; 
     
    33573360} 
    33583361this.cmdManager.destroy(); 
    3359 },eventClick:function(_d){ 
     3362},eventClick:function(_e){ 
    33603363if(!this.flagAvailable){ 
    33613364return; 
     
    33633366if(this.options.functionClickCallback.constructor==Function){ 
    33643367if(this.options.functionClickCallback!=Prototype.emptyFunction){ 
    3365 this.options.functionClickCallback(Event.findElement(_d,"tr").id.replace(this.options.prefixTrId,"")); 
    3366 } 
    3367 } 
    3368 if(_d.shiftKey){ 
    3369 this.selectOrUnselectRange(Event.findElement(_d,"tr").id); 
    3370 }else{ 
    3371 this.selectOrUnselect(Event.findElement(_d,"tr").id,_d.ctrlKey||this.cmdPressed); 
    3372 } 
    3373 },eventDoubleClick:function(_e){ 
     3368this.options.functionClickCallback(Event.findElement(_e,"tr").id.replace(this.options.prefixTrId,"")); 
     3369} 
     3370} 
     3371if(_e.shiftKey){ 
     3372this.selectOrUnselectRange(Event.findElement(_e,"tr").id); 
     3373}else{ 
     3374this.selectOrUnselect(Event.findElement(_e,"tr").id,_e.ctrlKey||this.cmdPressed); 
     3375} 
     3376},eventDoubleClick:function(_f){ 
    33743377if(!this.flagAvailable){ 
    33753378return; 
     
    33773380if(this.options.functionDoubleClickCallback.constructor==Function){ 
    33783381if(this.options.functionDoubleClickCallback!=Prototype.emptyFunction){ 
    3379 this.options.functionDoubleClickCallback(Event.findElement(_e,"tr").id.replace(this.options.prefixTrId,"")); 
     3382this.options.functionDoubleClickCallback(Event.findElement(_f,"tr").id.replace(this.options.prefixTrId,"")); 
    33803383} 
    33813384} 
    33823385if(this.flagAllowMultiple){ 
    3383 this.select(Event.findElement(_e,"tr").id,false); 
     3386this.select(Event.findElement(_f,"tr").id,false); 
    33843387this.submit(); 
    33853388} 
    3386 },eventFocusOut:function(_f){ 
     3389},eventFocusOut:function(_10){ 
    33873390if(!this.flagAvailable){ 
    33883391return; 
    33893392} 
    33903393this.focusOff(); 
    3391 },eventFocusOver:function(_10){ 
     3394},eventFocusOver:function(_11){ 
    33923395if(!this.flagAvailable){ 
    33933396return; 
    33943397} 
    3395 this.focusOn(Event.findElement(_10,"tr").id); 
    3396 Event.findElement(_10,"tr").focus(); 
    3397 },focusMove:function(_11){ 
     3398this.focusOn(Event.findElement(_11,"tr").id); 
     3399SpinelzUtil.clearBrowserSelection(); 
     3400},eventMouseDown:function(_12){ 
     3401if(!_12.shiftKey&&!_12.ctrlKey){ 
     3402this.onMouseDown(Event.findElement(_12,"tr").id); 
     3403
     3404},eventMouseUp:function(_13){ 
     3405var st=this; 
     3406setTimeout(function(){ 
     3407st.onMouseUp(); 
     3408},10); 
     3409},focusMove:function(_15){ 
    33983410if(!this.flagAvailable){ 
    33993411return; 
     
    34043416} 
    34053417}else{ 
    3406 var _12=$(this.focused).rowIndex; 
    3407 var _13,_14
    3408 switch(_11){ 
     3418var _16=$(this.focused).rowIndex; 
     3419var _17,_18
     3420switch(_15){ 
    34093421case "down": 
    3410 _13=1; 
    3411 _14=this.isBottom(_12); 
     3422_17=1; 
     3423_18=this.isBottom(_16); 
    34123424break; 
    34133425case "up": 
    3414 _13=-1; 
    3415 _14=this.isTop(_12); 
     3426_17=-1; 
     3427_18=this.isTop(_16); 
    34163428break; 
    34173429} 
    3418 if(!_14){ 
    3419 this.focusOn(this.element.rows[_12+_13].id); 
     3430if(!_18){ 
     3431this.focusOn(this.element.rows[_16+_17].id); 
    34203432} 
    34213433} 
     
    34253437} 
    34263438if(this.focused!=null){ 
    3427 var _15=$(this.focused); 
    3428 this.classNames.removeClassNames(_15,"trHover"); 
     3439var _19=$(this.focused); 
     3440this.classNames.removeClassNames(_19,"trHover"); 
    34293441this.focused=null; 
    34303442} 
    3431 },focusOn:function(_16){ 
     3443},focusOn:function(_1a){ 
    34323444if(!this.flagAvailable){ 
    34333445return; 
    34343446} 
    3435 if($(_16)!=null){ 
     3447if($(_1a)!=null){ 
    34363448this.focusOff(); 
    3437 this.classNames.addClassNames($(_16),"trHover"); 
    3438 this.focused=_16; 
     3449if(this.flagAllowMultiple&&this.mouseDown){ 
     3450this.mouseSelect(_1a); 
     3451}else{ 
     3452this.classNames.addClassNames($(_1a),"trHover"); 
     3453this.focused=_1a; 
     3454
    34393455} 
    34403456},getSelected:function(){ 
    3441 var _17=new Array(); 
    3442 for(var _18 in this.selected){ 
    3443 _17.push(_18.replace(this.options.prefixTrId,"")); 
    3444 } 
    3445 return _17
     3457var _1b=new Array(); 
     3458for(var _1c in this.selected){ 
     3459_1b.push(_1c.replace(this.options.prefixTrId,"")); 
     3460} 
     3461return _1b
    34463462},getSelectedElement:function(id){ 
    3447 var _1a=this.options.prefixTrId+id; 
    3448 return $(_1a); 
    3449 },isBottom:function(_1b){ 
    3450 return (_1b==this.element.rows.length-1)?true:false; 
    3451 },isTop:function(_1c){ 
    3452 return (_1c==this.element.tBodies[0].rows[0].rowIndex)?true:false; 
     3463var _1e=this.options.prefixTrId+id; 
     3464return $(_1e); 
     3465},isBottom:function(_1f){ 
     3466return (_1f==this.element.rows.length-1)?true:false; 
     3467},isTop:function(_20){ 
     3468return (_20==this.element.tBodies[0].rows[0].rowIndex)?true:false; 
    34533469},makeAvailable:function(){ 
    34543470this.flagAvailable=true; 
     
    34663482} 
    34673483this.flagAvailable=false; 
    3468 },select:function(_1d,_1e){ 
     3484},mouseSelect:function(_21){ 
    34693485if(!this.flagAvailable){ 
    34703486return; 
    34713487} 
    3472 this.selectEffect(_1d,_1e); 
    3473 this.lastSelected=_1d; 
     3488if(this.mouseDownCurrent==_21){ 
     3489return; 
     3490
     3491this.mouseDownCurrent=_21; 
     3492var _22=[]; 
     3493if(_21==this.mouseDownBase){ 
     3494_22.push(_21); 
     3495}else{ 
     3496var _23=false; 
     3497var _24=this; 
     3498this.lineIdArray.each(function(_25){ 
     3499if(_23){ 
     3500_22.push(_25); 
     3501
     3502if(_25==_24.mouseDownBase||_25==_24.mouseDownCurrent){ 
     3503_23=(_23!=true); 
     3504_22.push(_25); 
     3505
     3506}); 
     3507_22.uniq(); 
     3508
     3509this.unselectAll(); 
     3510var _24=this; 
     3511_22.each(function(_26){ 
     3512_24.select(_26,true); 
     3513}); 
     3514},onMouseDown:function(_27){ 
     3515if(!this.flagAvailable){ 
     3516return; 
     3517
     3518this.unselectAll(); 
     3519if(_27){ 
     3520Object.extend(this,{mouseDown:true,mouseDownBase:_27,mouseDownCurrent:null}); 
     3521this.mouseSelect(_27); 
     3522
     3523},onMouseUp:function(){ 
     3524if(!this.flagAvailable){ 
     3525return; 
     3526
     3527if(this.mouseDown){ 
     3528this.mouseDown=false; 
     3529
     3530},select:function(_28,_29){ 
     3531if(!this.flagAvailable){ 
     3532return; 
     3533
     3534this.selectEffect(_28,_29); 
     3535this.lastSelected=_28; 
    34743536this.options.functionPostSelect(this); 
    34753537if(!this.flagAllowMultiple){ 
     
    34843546} 
    34853547this.selected=new Object(); 
    3486 var _1f=this.element.tBodies[0].rows; 
    3487 for(var i=0;i<_1f.length;i++){ 
    3488 this.select(_1f[i].id,true); 
    3489 } 
    3490 },selectEffect:function(_21,_22){ 
    3491 if($(_21)){ 
    3492 if(!this.flagAllowMultiple||!_22){ 
     3548var _2a=this.element.tBodies[0].rows; 
     3549for(var i=0;i<_2a.length;i++){ 
     3550this.select(_2a[i].id,true); 
     3551} 
     3552},selectEffect:function(_2c,_2d){ 
     3553if($(_2c)){ 
     3554if(!this.flagAllowMultiple||!_2d){ 
    34933555this.unselectAll(); 
    34943556} 
    3495 this.classNames.addClassNames($(_21),"trSelected"); 
    3496 this.selected[_21]=true; 
    3497 } 
    3498 },selectOrUnselect:function(_23,_24){ 
     3557this.classNames.addClassNames($(_2c),"trSelected"); 
     3558this.selected[_2c]=true; 
     3559} 
     3560},selectOrUnselect:function(_2e,_2f){ 
    34993561if(!this.flagAvailable){ 
    35003562return; 
    35013563} 
    3502 if(_23==null){ 
    3503 return; 
    3504 } 
    3505 if(_24&&this.selected[_23]){ 
     3564if(_2e==null){ 
     3565return; 
     3566} 
     3567if(_2f&&this.selected[_2e]){ 
    35063568if(!this.flagAllowMultiple&&!this.options.flagAllowUnselect){ 
    35073569return; 
    35083570} 
    3509 this.unselect(_23); 
    3510 }else{ 
    3511 this.select(_23,_24); 
    3512 
    3513 },selectOrUnselectRange:function(_25){ 
     3571this.unselect(_2e); 
     3572}else{ 
     3573this.select(_2e,_2f); 
     3574if(_2f){ 
     3575SpinelzUtil.clearBrowserSelection(); 
     3576
     3577
     3578},selectOrUnselectRange:function(_30){ 
    35143579if(!this.flagAvailable){ 
    35153580return; 
    35163581} 
    3517 if(_25==null){ 
    3518 return; 
    3519 } 
    3520 if(this.lastSelected==null||this.lastSelected==_25){ 
    3521 this.selectOrUnselect(_25); 
    3522 return; 
    3523 } 
    3524 var _26=false; 
    3525 var _27=this.element.tBodies[0].rows; 
    3526 var _28=this.lastSelected; 
    3527 for(var i=0;i<_27.length;i++){ 
    3528 if(_27[i].id==_25||_27[i].id==_28){ 
    3529 _26=(_26)?false:true; 
    3530 }else{ 
    3531 if(!_26){ 
     3582if(_30==null){ 
     3583return; 
     3584} 
     3585if(this.lastSelected==null||this.lastSelected==_30){ 
     3586this.selectOrUnselect(_30); 
     3587return; 
     3588} 
     3589var _31=false; 
     3590var _32=this.element.tBodies[0].rows; 
     3591var _33=this.lastSelected; 
     3592for(var i=0;i<_32.length;i++){ 
     3593if(_32[i].id==_30||_32[i].id==_33){ 
     3594_31=(_31)?false:true; 
     3595}else{ 
     3596if(!_31){ 
    35323597continue; 
    35333598} 
    35343599} 
    3535 if(this.selected[_28]){ 
    3536 this.select(_27[i].id,true); 
    3537 }else{ 
    3538 this.unselect(_27[i].id); 
    3539 
    3540 
    3541 },submit:function(_2a){ 
     3600if(this.selected[_33]){ 
     3601this.select(_32[i].id,true); 
     3602}else{ 
     3603this.unselect(_32[i].id); 
     3604
     3605
     3606SpinelzUtil.clearBrowserSelection(); 
     3607},submit:function(_35){ 
    35423608if(!this.flagAvailable){ 
    35433609return; 
    35443610} 
    3545 var _2b=this.getSelected(); 
    3546 this.options.functionSubmit(_2b[0]); 
    3547 },unselect:function(_2c){ 
     3611var _36=this.getSelected(); 
     3612this.options.functionSubmit(_36[0]); 
     3613},unselect:function(_37){ 
    35483614if(!this.flagAvailable){ 
    35493615return; 
    35503616} 
    3551 this.classNames.removeClassNames($(_2c),"trSelected"); 
    3552 delete this.selected[_2c]; 
    3553 this.lastSelected=_2c
     3617this.classNames.removeClassNames($(_37),"trSelected"); 
     3618delete this.selected[_37]; 
     3619this.lastSelected=_37
    35543620this.options.functionPostUnselect(this); 
    35553621},unselectAll:function(){ 
     
    35573623return; 
    35583624} 
    3559 var _2d=this.element.tBodies[0].rows; 
    3560 for(var i=0;i<_2d.length;i++){ 
    3561 this.unselect(_2d[i].id); 
     3625var _38=this.element.tBodies[0].rows; 
     3626for(var i=0;i<_38.length;i++){ 
     3627this.unselect(_38[i].id); 
    35623628} 
    35633629}}; 
    3564 var SelectableTableLib={navi:function(_2f,_30){ 
    3565 var _31=_30||(SelectableTableManager.active||"")+"_navigation_top"; 
    3566 var _30=$(_31+"_"+_2f); 
    3567 if(_30!=null){ 
     3630var SelectableTableLib={navi:function(_3a,_3b){ 
     3631var _3c=_3b||(SelectableTableManager.active||"")+"_navigation_top"; 
     3632var _3b=$(_3c+"_"+_3a); 
     3633if(_3b!=null){ 
    35683634if(UserAgent.isIE()){ 
    3569 _30.fireEvent("onclick"); 
     3635_3b.fireEvent("onclick"); 
    35703636}else{ 
    35713637var evt=document.createEvent("MouseEvents"); 
    35723638evt.initEvent("click",true,true); 
    3573 _30.dispatchEvent(evt); 
     3639_3b.dispatchEvent(evt); 
    35743640} 
    35753641} 
     
    35773643var SelectableTableCreator={create:function(){ 
    35783644var key=arguments[0]; 
    3579 var _34=arguments[1]||{}; 
    3580 var _35=arguments[2]||null; 
    3581 var _36=arguments[3]||false; 
    3582 if(_35){ 
     3645var _3f=arguments[1]||{}; 
     3646var _40=arguments[2]||null; 
     3647var _41=arguments[3]||false; 
     3648if(_40){ 
    35833649try{ 
    3584 _35.destroy(); 
     3650_40.destroy(); 
    35853651} 
    35863652catch(e){ 
    35873653} 
    35883654} 
    3589 var _37=new SelectableTable(key,_34); 
    3590 if(_36){ 
    3591 SelectableTableManager.push(key,_37); 
    3592 } 
    3593 return _37
     3655var _42=new SelectableTable(key,_3f); 
     3656if(_41){ 
     3657SelectableTableManager.push(key,_42); 
     3658} 
     3659return _42
    35943660}}; 
    35953661var SelectableTableManager={active:null,list:$H({}),activate:function(key){ 
     
    36073673this.deactivate(); 
    36083674this.list=$H({}); 
    3609 },push:function(key,_3a){ 
     3675},push:function(key,_45){ 
    36103676if(this.list[key]){ 
    36113677this.list[key].makeUnavailable(); 
    36123678} 
    3613 this.list[key]=_3a
     3679this.list[key]=_45
    36143680this.activate(key); 
    36153681},start:function(){ 
    3616 var _3b=this.active; 
    3617 if(_3b){ 
    3618 this.list[_3b].makeAvailable(); 
     3682var _46=this.active; 
     3683if(_46){ 
     3684this.list[_46].makeAvailable(); 
    36193685} 
    36203686},stop:function(){ 
  • spinelz/trunk/src/javascripts/spinelz/selectableTable.js

    r5322 r5435  
    5656      prefixCSS:                    'custom_' 
    5757    } 
    58     this.options            = Object.extend(defaultOptions, arguments[1] || {}); 
    59     this.classNames         = new CssUtil([SelectableTable.classNames, CssUtil.appendPrefix(this.options.prefixCSS, SelectableTable.classNames)]); 
    60     this.flagAllowMultiple  = this.options.flagInitialAllowMultiple; 
    61     this.flagAvailable      = true; 
    62     this.focused            = null; 
    63     this.lastSelected       = null; 
    64     this.newNumber          = 1; 
    65     this.selected           = new Object(); 
     58    this.options = Object.extend(defaultOptions, arguments[1] || {}); 
     59    Object.extend(this, { 
     60      classNames:           new CssUtil([SelectableTable.classNames, CssUtil.appendPrefix(this.options.prefixCSS, SelectableTable.classNames)]), 
     61      flagAllowMultiple:    this.options.flagInitialAllowMultiple, 
     62      flagAvailable:        true, 
     63      focused:              null, 
     64      lastSelected:         null, 
     65      lineIdArray:          [], 
     66      newNumber:            1, 
     67      selected:             {} 
     68    }); 
    6669    this.build(); 
    6770    if(this.options.initialSelected) { 
     
    120123    //===[for Mac]===========================================================// 
    121124  }, 
     125  addMouseEvent: function() { 
     126    Event.observe(this.element, 'mousedown', this.eventMouseDown.bindAsEventListener(this)); 
     127    Event.observe(document,     'mouseup',   this.eventMouseUp.bindAsEventListener(this)); 
     128  }, 
    122129  build: function() { 
    123130    this.addKeyboardEvent(); 
     131    this.addMouseEvent(); 
    124132    if(this.options.build) { 
    125133      Element.setStyle(this.element, {visibility:'hidden'}); 
     
    128136      for(var i = 0; i < lines.length; i++) { 
    129137        this.buildTr(lines[i]); 
     138        this.lineIdArray.push(lines[i].id); 
    130139      } 
    131140      this.options.functionPostBuild(this); 
    132141      Element.setStyle(this.element, {visibility:'visible'}); 
     142    } else { 
     143      this.lineIdArray = $A(this.element.tBodies[0].rows).collect( 
     144        function(el) {return el.id;} 
     145      ); 
    133146    } 
    134147  }, 
     
    136149    objTr.id = this.buildTrId(objTr.id); 
    137150    this.classNames.addClassNames(objTr, 'tr'); 
    138     Event.observe(objTr, 'click',     this.eventClick.bindAsEventListener(this)); 
    139     Event.observe(objTr, 'dblclick',  this.eventDoubleClick.bindAsEventListener(this)); 
    140     Event.observe(objTr, 'mouseout',  this.eventFocusOut.bindAsEventListener(this)); 
    141     Event.observe(objTr, 'mouseover', this.eventFocusOver.bindAsEventListener(this)); 
     151    Event.observe(objTr, 'click',     this.eventClick.bindAsEventListener(this),       true); 
     152    Event.observe(objTr, 'dblclick',  this.eventDoubleClick.bindAsEventListener(this), true); 
     153    Event.observe(objTr, 'mouseout',  this.eventFocusOut.bindAsEventListener(this),    true); 
     154    Event.observe(objTr, 'mouseover', this.eventFocusOver.bindAsEventListener(this),   true); 
    142155  }, 
    143156  buildTrId: function(strId) { 
     
    194207    if(!this.flagAvailable) {return;} 
    195208    this.focusOn(Event.findElement(event, 'tr').id); 
    196     Event.findElement(event, 'tr').focus(); 
     209    SpinelzUtil.clearBrowserSelection(); 
     210  }, 
     211  eventMouseDown: function(event) { 
     212    if(!event.shiftKey && !event.ctrlKey) { 
     213      this.onMouseDown(Event.findElement(event, 'tr').id); 
     214    } 
     215  }, 
     216  eventMouseUp: function(event) { 
     217    var st = this; 
     218    setTimeout(function() {st.onMouseUp();}, 10); 
    197219  }, 
    198220  focusMove: function(direction) { 
     
    232254    if($(trId) != null) { 
    233255      this.focusOff(); 
    234       this.classNames.addClassNames($(trId), 'trHover'); 
    235       this.focused = trId; 
     256      if(this.flagAllowMultiple && this.mouseDown) { 
     257        this.mouseSelect(trId); 
     258      } else { 
     259        this.classNames.addClassNames($(trId), 'trHover'); 
     260        this.focused = trId; 
     261      } 
    236262    } 
    237263  }, 
     
    271297    } 
    272298    this.flagAvailable = false; 
     299  }, 
     300  mouseSelect: function(trId) { 
     301    if(!this.flagAvailable) {return;} 
     302    if(this.mouseDownCurrent == trId) {return;} 
     303    this.mouseDownCurrent = trId; 
     304    var trIdArray = []; 
     305    if(trId == this.mouseDownBase) { 
     306      trIdArray.push(trId); 
     307    } else { 
     308      var flag = false; 
     309      var self = this; 
     310      this.lineIdArray.each( 
     311        function(lineId) { 
     312          if(flag) { 
     313            trIdArray.push(lineId); 
     314          } 
     315          if(lineId == self.mouseDownBase || lineId == self.mouseDownCurrent) { 
     316            flag = (flag != true); 
     317            trIdArray.push(lineId); 
     318          } 
     319        } 
     320      ); 
     321      trIdArray.uniq(); 
     322    } 
     323    this.unselectAll(); 
     324    var self = this; 
     325    trIdArray.each( 
     326      function(trId) { 
     327        self.select(trId, true); 
     328      } 
     329    ); 
     330  }, 
     331  onMouseDown: function(trId) { 
     332    if(!this.flagAvailable) {return;} 
     333    this.unselectAll(); 
     334    if(trId) { 
     335      Object.extend(this, { 
     336        mouseDown:          true, 
     337        mouseDownBase:      trId, 
     338        mouseDownCurrent:   null 
     339      }); 
     340      this.mouseSelect(trId); 
     341    } 
     342  }, 
     343  onMouseUp: function() { 
     344    if(!this.flagAvailable) {return;} 
     345    if(this.mouseDown) { 
     346      this.mouseDown = false; 
     347    } 
    273348  }, 
    274349  select: function(trId, ctrl) { 
     
    307382    } else { 
    308383      this.select(trId, ctrl); 
     384      if(ctrl) { 
     385        SpinelzUtil.clearBrowserSelection(); 
     386      } 
    309387    } 
    310388  }, 
     
    331409      } 
    332410    } 
     411    SpinelzUtil.clearBrowserSelection(); 
    333412  }, 
    334413  submit: function(trId) { 
  • spinelz/trunk/test/selectableTable.html

    r4178 r5435  
    2727                <tbody> 
    2828                        <tr id="1"> 
    29                                 <td>tanaka</td> 
     29                                <td> 
     30                                        <div onmouseover="event.cancelBubble=true;">tanaka</div> 
     31                                </td> 
    3032                        </tr> 
    3133                        <tr id="2"> 
    32                                 <td>suzuki</td> 
     34                                <td> 
     35                                        <div onmouseover="event.cancelBubble=true;">suzuki</div> 
     36                                </td> 
    3337                        </tr> 
    3438                        <tr id="3"> 
    35                                 <td>sato</td> 
     39                                <td> 
     40                                        <div onmouseover="event.cancelBubble=true;">sato</div> 
     41                                </td> 
    3642                        </tr> 
    3743                        <tr id="4"> 
    38                                 <td>yamada</td> 
     44                                <td>