Changeset 5435
- Timestamp:
- 02/01/08 08:45:02 (10 months ago)
- Files:
-
- spinelz/trunk/compress/javascripts/spinelz/selectableTable.js (modified) (14 diffs)
- spinelz/trunk/compress/javascripts/spinelz/spinelz_for_rubricks.js (modified) (14 diffs)
- spinelz/trunk/src/javascripts/spinelz/selectableTable.js (modified) (9 diffs)
- spinelz/trunk/test/selectableTable.html (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
spinelz/trunk/compress/javascripts/spinelz/selectableTable.js
r5322 r5435 9 9 },functionSubmit:Prototype.emptyFunction,initialSelected:null,prefixTrId:"selectable_table_",prefixCSS:"custom_"}; 10 10 this.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(); 11 Object.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:{}}); 18 12 this.build(); 19 13 if(this.options.initialSelected){ … … 87 81 _6.cmdPressed=false; 88 82 },true); 83 },addMouseEvent:function(){ 84 Event.observe(this.element,"mousedown",this.eventMouseDown.bindAsEventListener(this)); 85 Event.observe(document,"mouseup",this.eventMouseUp.bindAsEventListener(this)); 89 86 },build:function(){ 90 87 this.addKeyboardEvent(); 88 this.addMouseEvent(); 91 89 if(this.options.build){ 92 90 Element.setStyle(this.element,{visibility:"hidden"}); … … 95 93 for(var i=0;i<_8.length;i++){ 96 94 this.buildTr(_8[i]); 95 this.lineIdArray.push(_8[i].id); 97 96 } 98 97 this.options.functionPostBuild(this); 99 98 Element.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{ 100 this.lineIdArray=$A(this.element.tBodies[0].rows).collect(function(el){ 101 return el.id; 102 }); 103 } 104 },buildTr:function(_b){ 105 _b.id=this.buildTrId(_b.id); 106 this.classNames.addClassNames(_b,"tr"); 107 Event.observe(_b,"click",this.eventClick.bindAsEventListener(this),true); 108 Event.observe(_b,"dblclick",this.eventDoubleClick.bindAsEventListener(this),true); 109 Event.observe(_b,"mouseout",this.eventFocusOut.bindAsEventListener(this),true); 110 Event.observe(_b,"mouseover",this.eventFocusOver.bindAsEventListener(this),true); 111 },buildTrId:function(_c){ 112 return this.options.prefixTrId+_c; 110 113 },deleteAll:function(){ 111 114 if(!this.flagAvailable){ … … 115 118 return; 116 119 } 117 for(var _ cin this.selected){118 this.element.tBodies[0].removeChild($(_ c));119 delete this.selected[_ c];120 for(var _d in this.selected){ 121 this.element.tBodies[0].removeChild($(_d)); 122 delete this.selected[_d]; 120 123 } 121 124 this.focused=null; … … 126 129 } 127 130 this.cmdManager.destroy(); 128 },eventClick:function(_ d){131 },eventClick:function(_e){ 129 132 if(!this.flagAvailable){ 130 133 return; … … 132 135 if(this.options.functionClickCallback.constructor==Function){ 133 136 if(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){137 this.options.functionClickCallback(Event.findElement(_e,"tr").id.replace(this.options.prefixTrId,"")); 138 } 139 } 140 if(_e.shiftKey){ 141 this.selectOrUnselectRange(Event.findElement(_e,"tr").id); 142 }else{ 143 this.selectOrUnselect(Event.findElement(_e,"tr").id,_e.ctrlKey||this.cmdPressed); 144 } 145 },eventDoubleClick:function(_f){ 143 146 if(!this.flagAvailable){ 144 147 return; … … 146 149 if(this.options.functionDoubleClickCallback.constructor==Function){ 147 150 if(this.options.functionDoubleClickCallback!=Prototype.emptyFunction){ 148 this.options.functionDoubleClickCallback(Event.findElement(_ e,"tr").id.replace(this.options.prefixTrId,""));151 this.options.functionDoubleClickCallback(Event.findElement(_f,"tr").id.replace(this.options.prefixTrId,"")); 149 152 } 150 153 } 151 154 if(this.flagAllowMultiple){ 152 this.select(Event.findElement(_ e,"tr").id,false);155 this.select(Event.findElement(_f,"tr").id,false); 153 156 this.submit(); 154 157 } 155 },eventFocusOut:function(_ f){158 },eventFocusOut:function(_10){ 156 159 if(!this.flagAvailable){ 157 160 return; 158 161 } 159 162 this.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){ 164 if(!this.flagAvailable){ 165 return; 166 } 167 this.focusOn(Event.findElement(_11,"tr").id); 168 SpinelzUtil.clearBrowserSelection(); 169 },eventMouseDown:function(_12){ 170 if(!_12.shiftKey&&!_12.ctrlKey){ 171 this.onMouseDown(Event.findElement(_12,"tr").id); 172 } 173 },eventMouseUp:function(_13){ 174 var st=this; 175 setTimeout(function(){ 176 st.onMouseUp(); 177 },10); 178 },focusMove:function(_15){ 167 179 if(!this.flagAvailable){ 168 180 return; … … 173 185 } 174 186 }else{ 175 var _1 2=$(this.focused).rowIndex;176 var _1 3,_14;177 switch(_1 1){187 var _16=$(this.focused).rowIndex; 188 var _17,_18; 189 switch(_15){ 178 190 case "down": 179 _1 3=1;180 _1 4=this.isBottom(_12);191 _17=1; 192 _18=this.isBottom(_16); 181 193 break; 182 194 case "up": 183 _1 3=-1;184 _1 4=this.isTop(_12);195 _17=-1; 196 _18=this.isTop(_16); 185 197 break; 186 198 } 187 if(!_1 4){188 this.focusOn(this.element.rows[_1 2+_13].id);199 if(!_18){ 200 this.focusOn(this.element.rows[_16+_17].id); 189 201 } 190 202 } … … 194 206 } 195 207 if(this.focused!=null){ 196 var _1 5=$(this.focused);197 this.classNames.removeClassNames(_1 5,"trHover");208 var _19=$(this.focused); 209 this.classNames.removeClassNames(_19,"trHover"); 198 210 this.focused=null; 199 211 } 200 },focusOn:function(_1 6){201 if(!this.flagAvailable){ 202 return; 203 } 204 if($(_1 6)!=null){212 },focusOn:function(_1a){ 213 if(!this.flagAvailable){ 214 return; 215 } 216 if($(_1a)!=null){ 205 217 this.focusOff(); 206 this.classNames.addClassNames($(_16),"trHover"); 207 this.focused=_16; 218 if(this.flagAllowMultiple&&this.mouseDown){ 219 this.mouseSelect(_1a); 220 }else{ 221 this.classNames.addClassNames($(_1a),"trHover"); 222 this.focused=_1a; 223 } 208 224 } 209 225 },getSelected:function(){ 210 var _1 7=new Array();211 for(var _1 8in this.selected){212 _1 7.push(_18.replace(this.options.prefixTrId,""));213 } 214 return _1 7;226 var _1b=new Array(); 227 for(var _1c in this.selected){ 228 _1b.push(_1c.replace(this.options.prefixTrId,"")); 229 } 230 return _1b; 215 231 },getSelectedElement:function(id){ 216 var _1 a=this.options.prefixTrId+id;217 return $(_1 a);218 },isBottom:function(_1 b){219 return (_1 b==this.element.rows.length-1)?true:false;220 },isTop:function(_ 1c){221 return (_ 1c==this.element.tBodies[0].rows[0].rowIndex)?true:false;232 var _1e=this.options.prefixTrId+id; 233 return $(_1e); 234 },isBottom:function(_1f){ 235 return (_1f==this.element.rows.length-1)?true:false; 236 },isTop:function(_20){ 237 return (_20==this.element.tBodies[0].rows[0].rowIndex)?true:false; 222 238 },makeAvailable:function(){ 223 239 this.flagAvailable=true; … … 235 251 } 236 252 this.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){ 254 if(!this.flagAvailable){ 255 return; 256 } 257 if(this.mouseDownCurrent==_21){ 258 return; 259 } 260 this.mouseDownCurrent=_21; 261 var _22=[]; 262 if(_21==this.mouseDownBase){ 263 _22.push(_21); 264 }else{ 265 var _23=false; 266 var _24=this; 267 this.lineIdArray.each(function(_25){ 268 if(_23){ 269 _22.push(_25); 270 } 271 if(_25==_24.mouseDownBase||_25==_24.mouseDownCurrent){ 272 _23=(_23!=true); 273 _22.push(_25); 274 } 275 }); 276 _22.uniq(); 277 } 278 this.unselectAll(); 279 var _24=this; 280 _22.each(function(_26){ 281 _24.select(_26,true); 282 }); 283 },onMouseDown:function(_27){ 284 if(!this.flagAvailable){ 285 return; 286 } 287 this.unselectAll(); 288 if(_27){ 289 Object.extend(this,{mouseDown:true,mouseDownBase:_27,mouseDownCurrent:null}); 290 this.mouseSelect(_27); 291 } 292 },onMouseUp:function(){ 293 if(!this.flagAvailable){ 294 return; 295 } 296 if(this.mouseDown){ 297 this.mouseDown=false; 298 } 299 },select:function(_28,_29){ 300 if(!this.flagAvailable){ 301 return; 302 } 303 this.selectEffect(_28,_29); 304 this.lastSelected=_28; 243 305 this.options.functionPostSelect(this); 244 306 if(!this.flagAllowMultiple){ … … 253 315 } 254 316 this.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(_2 1,_22){260 if($(_2 1)){261 if(!this.flagAllowMultiple||!_2 2){317 var _2a=this.element.tBodies[0].rows; 318 for(var i=0;i<_2a.length;i++){ 319 this.select(_2a[i].id,true); 320 } 321 },selectEffect:function(_2c,_2d){ 322 if($(_2c)){ 323 if(!this.flagAllowMultiple||!_2d){ 262 324 this.unselectAll(); 263 325 } 264 this.classNames.addClassNames($(_2 1),"trSelected");265 this.selected[_2 1]=true;266 } 267 },selectOrUnselect:function(_2 3,_24){268 if(!this.flagAvailable){ 269 return; 270 } 271 if(_2 3==null){272 return; 273 } 274 if(_2 4&&this.selected[_23]){326 this.classNames.addClassNames($(_2c),"trSelected"); 327 this.selected[_2c]=true; 328 } 329 },selectOrUnselect:function(_2e,_2f){ 330 if(!this.flagAvailable){ 331 return; 332 } 333 if(_2e==null){ 334 return; 335 } 336 if(_2f&&this.selected[_2e]){ 275 337 if(!this.flagAllowMultiple&&!this.options.flagAllowUnselect){ 276 338 return; 277 339 } 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){ 340 this.unselect(_2e); 341 }else{ 342 this.select(_2e,_2f); 343 if(_2f){ 344 SpinelzUtil.clearBrowserSelection(); 345 } 346 } 347 },selectOrUnselectRange:function(_30){ 348 if(!this.flagAvailable){ 349 return; 350 } 351 if(_30==null){ 352 return; 353 } 354 if(this.lastSelected==null||this.lastSelected==_30){ 355 this.selectOrUnselect(_30); 356 return; 357 } 358 var _31=false; 359 var _32=this.element.tBodies[0].rows; 360 var _33=this.lastSelected; 361 for(var i=0;i<_32.length;i++){ 362 if(_32[i].id==_30||_32[i].id==_33){ 363 _31=(_31)?false:true; 364 }else{ 365 if(!_31){ 301 366 continue; 302 367 } 303 368 } 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; 369 if(this.selected[_33]){ 370 this.select(_32[i].id,true); 371 }else{ 372 this.unselect(_32[i].id); 373 } 374 } 375 SpinelzUtil.clearBrowserSelection(); 376 },submit:function(_35){ 377 if(!this.flagAvailable){ 378 return; 379 } 380 var _36=this.getSelected(); 381 this.options.functionSubmit(_36[0]); 382 },unselect:function(_37){ 383 if(!this.flagAvailable){ 384 return; 385 } 386 this.classNames.removeClassNames($(_37),"trSelected"); 387 delete this.selected[_37]; 388 this.lastSelected=_37; 323 389 this.options.functionPostUnselect(this); 324 390 },unselectAll:function(){ … … 326 392 return; 327 393 } 328 var _ 2d=this.element.tBodies[0].rows;329 for(var i=0;i<_ 2d.length;i++){330 this.unselect(_ 2d[i].id);394 var _38=this.element.tBodies[0].rows; 395 for(var i=0;i<_38.length;i++){ 396 this.unselect(_38[i].id); 331 397 } 332 398 }}; 333 var SelectableTableLib={navi:function(_ 2f,_30){334 var _3 1=_30||(SelectableTableManager.active||"")+"_navigation_top";335 var _3 0=$(_31+"_"+_2f);336 if(_3 0!=null){399 var SelectableTableLib={navi:function(_3a,_3b){ 400 var _3c=_3b||(SelectableTableManager.active||"")+"_navigation_top"; 401 var _3b=$(_3c+"_"+_3a); 402 if(_3b!=null){ 337 403 if(UserAgent.isIE()){ 338 _3 0.fireEvent("onclick");404 _3b.fireEvent("onclick"); 339 405 }else{ 340 406 var evt=document.createEvent("MouseEvents"); 341 407 evt.initEvent("click",true,true); 342 _3 0.dispatchEvent(evt);408 _3b.dispatchEvent(evt); 343 409 } 344 410 } … … 346 412 var SelectableTableCreator={create:function(){ 347 413 var key=arguments[0]; 348 var _3 4=arguments[1]||{};349 var _ 35=arguments[2]||null;350 var _ 36=arguments[3]||false;351 if(_ 35){414 var _3f=arguments[1]||{}; 415 var _40=arguments[2]||null; 416 var _41=arguments[3]||false; 417 if(_40){ 352 418 try{ 353 _ 35.destroy();419 _40.destroy(); 354 420 } 355 421 catch(e){ 356 422 } 357 423 } 358 var _ 37=new SelectableTable(key,_34);359 if(_ 36){360 SelectableTableManager.push(key,_ 37);361 } 362 return _ 37;424 var _42=new SelectableTable(key,_3f); 425 if(_41){ 426 SelectableTableManager.push(key,_42); 427 } 428 return _42; 363 429 }}; 364 430 var SelectableTableManager={active:null,list:$H({}),activate:function(key){ … … 376 442 this.deactivate(); 377 443 this.list=$H({}); 378 },push:function(key,_ 3a){444 },push:function(key,_45){ 379 445 if(this.list[key]){ 380 446 this.list[key].makeUnavailable(); 381 447 } 382 this.list[key]=_ 3a;448 this.list[key]=_45; 383 449 this.activate(key); 384 450 },start:function(){ 385 var _ 3b=this.active;386 if(_ 3b){387 this.list[_ 3b].makeAvailable();451 var _46=this.active; 452 if(_46){ 453 this.list[_46].makeAvailable(); 388 454 } 389 455 },stop:function(){ spinelz/trunk/compress/javascripts/spinelz/spinelz_for_rubricks.js
r5418 r5435 3240 3240 },functionSubmit:Prototype.emptyFunction,initialSelected:null,prefixTrId:"selectable_table_",prefixCSS:"custom_"}; 3241 3241 this.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(); 3242 Object.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:{}}); 3249 3243 this.build(); 3250 3244 if(this.options.initialSelected){ … … 3318 3312 _6.cmdPressed=false; 3319 3313 },true); 3314 },addMouseEvent:function(){ 3315 Event.observe(this.element,"mousedown",this.eventMouseDown.bindAsEventListener(this)); 3316 Event.observe(document,"mouseup",this.eventMouseUp.bindAsEventListener(this)); 3320 3317 },build:function(){ 3321 3318 this.addKeyboardEvent(); 3319 this.addMouseEvent(); 3322 3320 if(this.options.build){ 3323 3321 Element.setStyle(this.element,{visibility:"hidden"}); … … 3326 3324 for(var i=0;i<_8.length;i++){ 3327 3325 this.buildTr(_8[i]); 3326 this.lineIdArray.push(_8[i].id); 3328 3327 } 3329 3328 this.options.functionPostBuild(this); 3330 3329 Element.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{ 3331 this.lineIdArray=$A(this.element.tBodies[0].rows).collect(function(el){ 3332 return el.id; 3333 }); 3334 } 3335 },buildTr:function(_b){ 3336 _b.id=this.buildTrId(_b.id); 3337 this.classNames.addClassNames(_b,"tr"); 3338 Event.observe(_b,"click",this.eventClick.bindAsEventListener(this),true); 3339 Event.observe(_b,"dblclick",this.eventDoubleClick.bindAsEventListener(this),true); 3340 Event.observe(_b,"mouseout",this.eventFocusOut.bindAsEventListener(this),true); 3341 Event.observe(_b,"mouseover",this.eventFocusOver.bindAsEventListener(this),true); 3342 },buildTrId:function(_c){ 3343 return this.options.prefixTrId+_c; 3341 3344 },deleteAll:function(){ 3342 3345 if(!this.flagAvailable){ … … 3346 3349 return; 3347 3350 } 3348 for(var _ cin this.selected){3349 this.element.tBodies[0].removeChild($(_ c));3350 delete this.selected[_ c];3351 for(var _d in this.selected){ 3352 this.element.tBodies[0].removeChild($(_d)); 3353 delete this.selected[_d]; 3351 3354 } 3352 3355 this.focused=null; … … 3357 3360 } 3358 3361 this.cmdManager.destroy(); 3359 },eventClick:function(_ d){3362 },eventClick:function(_e){ 3360 3363 if(!this.flagAvailable){ 3361 3364 return; … … 3363 3366 if(this.options.functionClickCallback.constructor==Function){ 3364 3367 if(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){3368 this.options.functionClickCallback(Event.findElement(_e,"tr").id.replace(this.options.prefixTrId,"")); 3369 } 3370 } 3371 if(_e.shiftKey){ 3372 this.selectOrUnselectRange(Event.findElement(_e,"tr").id); 3373 }else{ 3374 this.selectOrUnselect(Event.findElement(_e,"tr").id,_e.ctrlKey||this.cmdPressed); 3375 } 3376 },eventDoubleClick:function(_f){ 3374 3377 if(!this.flagAvailable){ 3375 3378 return; … … 3377 3380 if(this.options.functionDoubleClickCallback.constructor==Function){ 3378 3381 if(this.options.functionDoubleClickCallback!=Prototype.emptyFunction){ 3379 this.options.functionDoubleClickCallback(Event.findElement(_ e,"tr").id.replace(this.options.prefixTrId,""));3382 this.options.functionDoubleClickCallback(Event.findElement(_f,"tr").id.replace(this.options.prefixTrId,"")); 3380 3383 } 3381 3384 } 3382 3385 if(this.flagAllowMultiple){ 3383 this.select(Event.findElement(_ e,"tr").id,false);3386 this.select(Event.findElement(_f,"tr").id,false); 3384 3387 this.submit(); 3385 3388 } 3386 },eventFocusOut:function(_ f){3389 },eventFocusOut:function(_10){ 3387 3390 if(!this.flagAvailable){ 3388 3391 return; 3389 3392 } 3390 3393 this.focusOff(); 3391 },eventFocusOver:function(_1 0){3394 },eventFocusOver:function(_11){ 3392 3395 if(!this.flagAvailable){ 3393 3396 return; 3394 3397 } 3395 this.focusOn(Event.findElement(_10,"tr").id); 3396 Event.findElement(_10,"tr").focus(); 3397 },focusMove:function(_11){ 3398 this.focusOn(Event.findElement(_11,"tr").id); 3399 SpinelzUtil.clearBrowserSelection(); 3400 },eventMouseDown:function(_12){ 3401 if(!_12.shiftKey&&!_12.ctrlKey){ 3402 this.onMouseDown(Event.findElement(_12,"tr").id); 3403 } 3404 },eventMouseUp:function(_13){ 3405 var st=this; 3406 setTimeout(function(){ 3407 st.onMouseUp(); 3408 },10); 3409 },focusMove:function(_15){ 3398 3410 if(!this.flagAvailable){ 3399 3411 return; … … 3404 3416 } 3405 3417 }else{ 3406 var _1 2=$(this.focused).rowIndex;3407 var _1 3,_14;3408 switch(_1 1){3418 var _16=$(this.focused).rowIndex; 3419 var _17,_18; 3420 switch(_15){ 3409 3421 case "down": 3410 _1 3=1;3411 _1 4=this.isBottom(_12);3422 _17=1; 3423 _18=this.isBottom(_16); 3412 3424 break; 3413 3425 case "up": 3414 _1 3=-1;3415 _1 4=this.isTop(_12);3426 _17=-1; 3427 _18=this.isTop(_16); 3416 3428 break; 3417 3429 } 3418 if(!_1 4){3419 this.focusOn(this.element.rows[_1 2+_13].id);3430 if(!_18){ 3431 this.focusOn(this.element.rows[_16+_17].id); 3420 3432 } 3421 3433 } … … 3425 3437 } 3426 3438 if(this.focused!=null){ 3427 var _1 5=$(this.focused);3428 this.classNames.removeClassNames(_1 5,"trHover");3439 var _19=$(this.focused); 3440 this.classNames.removeClassNames(_19,"trHover"); 3429 3441 this.focused=null; 3430 3442 } 3431 },focusOn:function(_1 6){3443 },focusOn:function(_1a){ 3432 3444 if(!this.flagAvailable){ 3433 3445 return; 3434 3446 } 3435 if($(_1 6)!=null){3447 if($(_1a)!=null){ 3436 3448 this.focusOff(); 3437 this.classNames.addClassNames($(_16),"trHover"); 3438 this.focused=_16; 3449 if(this.flagAllowMultiple&&this.mouseDown){ 3450 this.mouseSelect(_1a); 3451 }else{ 3452 this.classNames.addClassNames($(_1a),"trHover"); 3453 this.focused=_1a; 3454 } 3439 3455 } 3440 3456 },getSelected:function(){ 3441 var _1 7=new Array();3442 for(var _1 8in this.selected){3443 _1 7.push(_18.replace(this.options.prefixTrId,""));3444 } 3445 return _1 7;3457 var _1b=new Array(); 3458 for(var _1c in this.selected){ 3459 _1b.push(_1c.replace(this.options.prefixTrId,"")); 3460 } 3461 return _1b; 3446 3462 },getSelectedElement:function(id){ 3447 var _1 a=this.options.prefixTrId+id;3448 return $(_1 a);3449 },isBottom:function(_1 b){3450 return (_1 b==this.element.rows.length-1)?true:false;3451 },isTop:function(_ 1c){3452 return (_ 1c==this.element.tBodies[0].rows[0].rowIndex)?true:false;3463 var _1e=this.options.prefixTrId+id; 3464 return $(_1e); 3465 },isBottom:function(_1f){ 3466 return (_1f==this.element.rows.length-1)?true:false; 3467 },isTop:function(_20){ 3468 return (_20==this.element.tBodies[0].rows[0].rowIndex)?true:false; 3453 3469 },makeAvailable:function(){ 3454 3470 this.flagAvailable=true; … … 3466 3482 } 3467 3483 this.flagAvailable=false; 3468 }, select:function(_1d,_1e){3484 },mouseSelect:function(_21){ 3469 3485 if(!this.flagAvailable){ 3470 3486 return; 3471 3487 } 3472 this.selectEffect(_1d,_1e); 3473 this.lastSelected=_1d; 3488 if(this.mouseDownCurrent==_21){ 3489 return; 3490 } 3491 this.mouseDownCurrent=_21; 3492 var _22=[]; 3493 if(_21==this.mouseDownBase){ 3494 _22.push(_21); 3495 }else{ 3496 var _23=false; 3497 var _24=this; 3498 this.lineIdArray.each(function(_25){ 3499 if(_23){ 3500 _22.push(_25); 3501 } 3502 if(_25==_24.mouseDownBase||_25==_24.mouseDownCurrent){ 3503 _23=(_23!=true); 3504 _22.push(_25); 3505 } 3506 }); 3507 _22.uniq(); 3508 } 3509 this.unselectAll(); 3510 var _24=this; 3511 _22.each(function(_26){ 3512 _24.select(_26,true); 3513 }); 3514 },onMouseDown:function(_27){ 3515 if(!this.flagAvailable){ 3516 return; 3517 } 3518 this.unselectAll(); 3519 if(_27){ 3520 Object.extend(this,{mouseDown:true,mouseDownBase:_27,mouseDownCurrent:null}); 3521 this.mouseSelect(_27); 3522 } 3523 },onMouseUp:function(){ 3524 if(!this.flagAvailable){ 3525 return; 3526 } 3527 if(this.mouseDown){ 3528 this.mouseDown=false; 3529 } 3530 },select:function(_28,_29){ 3531 if(!this.flagAvailable){ 3532 return; 3533 } 3534 this.selectEffect(_28,_29); 3535 this.lastSelected=_28; 3474 3536 this.options.functionPostSelect(this); 3475 3537 if(!this.flagAllowMultiple){ … … 3484 3546 } 3485 3547 this.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(_2 1,_22){3491 if($(_2 1)){3492 if(!this.flagAllowMultiple||!_2 2){3548 var _2a=this.element.tBodies[0].rows; 3549 for(var i=0;i<_2a.length;i++){ 3550 this.select(_2a[i].id,true); 3551 } 3552 },selectEffect:function(_2c,_2d){ 3553 if($(_2c)){ 3554 if(!this.flagAllowMultiple||!_2d){ 3493 3555 this.unselectAll(); 3494 3556 } 3495 this.classNames.addClassNames($(_2 1),"trSelected");3496 this.selected[_2 1]=true;3497 } 3498 },selectOrUnselect:function(_2 3,_24){3557 this.classNames.addClassNames($(_2c),"trSelected"); 3558 this.selected[_2c]=true; 3559 } 3560 },selectOrUnselect:function(_2e,_2f){ 3499 3561 if(!this.flagAvailable){ 3500 3562 return; 3501 3563 } 3502 if(_2 3==null){3503 return; 3504 } 3505 if(_2 4&&this.selected[_23]){3564 if(_2e==null){ 3565 return; 3566 } 3567 if(_2f&&this.selected[_2e]){ 3506 3568 if(!this.flagAllowMultiple&&!this.options.flagAllowUnselect){ 3507 3569 return; 3508 3570 } 3509 this.unselect(_23); 3510 }else{ 3511 this.select(_23,_24); 3512 } 3513 },selectOrUnselectRange:function(_25){ 3571 this.unselect(_2e); 3572 }else{ 3573 this.select(_2e,_2f); 3574 if(_2f){ 3575 SpinelzUtil.clearBrowserSelection(); 3576 } 3577 } 3578 },selectOrUnselectRange:function(_30){ 3514 3579 if(!this.flagAvailable){ 3515 3580 return; 3516 3581 } 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){3582 if(_30==null){ 3583 return; 3584 } 3585 if(this.lastSelected==null||this.lastSelected==_30){ 3586 this.selectOrUnselect(_30); 3587 return; 3588 } 3589 var _31=false; 3590 var _32=this.element.tBodies[0].rows; 3591 var _33=this.lastSelected; 3592 for(var i=0;i<_32.length;i++){ 3593 if(_32[i].id==_30||_32[i].id==_33){ 3594 _31=(_31)?false:true; 3595 }else{ 3596 if(!_31){ 3532 3597 continue; 3533 3598 } 3534 3599 } 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){ 3600 if(this.selected[_33]){ 3601 this.select(_32[i].id,true); 3602 }else{ 3603 this.unselect(_32[i].id); 3604 } 3605 } 3606 SpinelzUtil.clearBrowserSelection(); 3607 },submit:function(_35){ 3542 3608 if(!this.flagAvailable){ 3543 3609 return; 3544 3610 } 3545 var _ 2b=this.getSelected();3546 this.options.functionSubmit(_ 2b[0]);3547 },unselect:function(_ 2c){3611 var _36=this.getSelected(); 3612 this.options.functionSubmit(_36[0]); 3613 },unselect:function(_37){ 3548 3614 if(!this.flagAvailable){ 3549 3615 return; 3550 3616 } 3551 this.classNames.removeClassNames($(_ 2c),"trSelected");3552 delete this.selected[_ 2c];3553 this.lastSelected=_ 2c;3617 this.classNames.removeClassNames($(_37),"trSelected"); 3618 delete this.selected[_37]; 3619 this.lastSelected=_37; 3554 3620 this.options.functionPostUnselect(this); 3555 3621 },unselectAll:function(){ … … 3557 3623 return; 3558 3624 } 3559 var _ 2d=this.element.tBodies[0].rows;3560 for(var i=0;i<_ 2d.length;i++){3561 this.unselect(_ 2d[i].id);3625 var _38=this.element.tBodies[0].rows; 3626 for(var i=0;i<_38.length;i++){ 3627 this.unselect(_38[i].id); 3562 3628 } 3563 3629 }}; 3564 var SelectableTableLib={navi:function(_ 2f,_30){3565 var _3 1=_30||(SelectableTableManager.active||"")+"_navigation_top";3566 var _3 0=$(_31+"_"+_2f);3567 if(_3 0!=null){3630 var SelectableTableLib={navi:function(_3a,_3b){ 3631 var _3c=_3b||(SelectableTableManager.active||"")+"_navigation_top"; 3632 var _3b=$(_3c+"_"+_3a); 3633 if(_3b!=null){ 3568 3634 if(UserAgent.isIE()){ 3569 _3 0.fireEvent("onclick");3635 _3b.fireEvent("onclick"); 3570 3636 }else{ 3571 3637 var evt=document.createEvent("MouseEvents"); 3572 3638 evt.initEvent("click",true,true); 3573 _3 0.dispatchEvent(evt);3639 _3b.dispatchEvent(evt); 3574 3640 } 3575 3641 } … … 3577 3643 var SelectableTableCreator={create:function(){ 3578 3644 var key=arguments[0]; 3579 var _3 4=arguments[1]||{};3580 var _ 35=arguments[2]||null;3581 var _ 36=arguments[3]||false;3582 if(_ 35){3645 var _3f=arguments[1]||{}; 3646 var _40=arguments[2]||null; 3647 var _41=arguments[3]||false; 3648 if(_40){ 3583 3649 try{ 3584 _ 35.destroy();3650 _40.destroy(); 3585 3651 } 3586 3652 catch(e){ 3587 3653 } 3588 3654 } 3589 var _ 37=new SelectableTable(key,_34);3590 if(_ 36){3591 SelectableTableManager.push(key,_ 37);3592 } 3593 return _ 37;3655 var _42=new SelectableTable(key,_3f); 3656 if(_41){ 3657 SelectableTableManager.push(key,_42); 3658 } 3659 return _42; 3594 3660 }}; 3595 3661 var SelectableTableManager={active:null,list:$H({}),activate:function(key){ … … 3607 3673 this.deactivate(); 3608 3674 this.list=$H({}); 3609 },push:function(key,_ 3a){3675 },push:function(key,_45){ 3610 3676 if(this.list[key]){ 3611 3677 this.list[key].makeUnavailable(); 3612 3678 } 3613 this.list[key]=_ 3a;3679 this.list[key]=_45; 3614 3680 this.activate(key); 3615 3681 },start:function(){ 3616 var _ 3b=this.active;3617 if(_ 3b){3618 this.list[_ 3b].makeAvailable();3682 var _46=this.active; 3683 if(_46){ 3684 this.list[_46].makeAvailable(); 3619 3685 } 3620 3686 },stop:function(){ spinelz/trunk/src/javascripts/spinelz/selectableTable.js
r5322 r5435 56 56 prefixCSS: 'custom_' 57 57 } 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 }); 66 69 this.build(); 67 70 if(this.options.initialSelected) { … … 120 123 //===[for Mac]===========================================================// 121 124 }, 125 addMouseEvent: function() { 126 Event.observe(this.element, 'mousedown', this.eventMouseDown.bindAsEventListener(this)); 127 Event.observe(document, 'mouseup', this.eventMouseUp.bindAsEventListener(this)); 128 }, 122 129 build: function() { 123 130 this.addKeyboardEvent(); 131 this.addMouseEvent(); 124 132 if(this.options.build) { 125 133 Element.setStyle(this.element, {visibility:'hidden'}); … … 128 136 for(var i = 0; i < lines.length; i++) { 129 137 this.buildTr(lines[i]); 138 this.lineIdArray.push(lines[i].id); 130 139 } 131 140 this.options.functionPostBuild(this); 132 141 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 ); 133 146 } 134 147 }, … … 136 149 objTr.id = this.buildTrId(objTr.id); 137 150 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); 142 155 }, 143 156 buildTrId: function(strId) { … … 194 207 if(!this.flagAvailable) {return;} 195 208 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); 197 219 }, 198 220 focusMove: function(direction) { … … 232 254 if($(trId) != null) { 233 255 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 } 236 262 } 237 263 }, … … 271 297 } 272 298 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 } 273 348 }, 274 349 select: function(trId, ctrl) { … … 307 382 } else { 308 383 this.select(trId, ctrl); 384 if(ctrl) { 385 SpinelzUtil.clearBrowserSelection(); 386 } 309 387 } 310 388 }, … … 331 409 } 332 410 } 411 SpinelzUtil.clearBrowserSelection(); 333 412 }, 334 413 submit: function(trId) { spinelz/trunk/test/selectableTable.html
r4178 r5435 27 27 <tbody> 28 28 <tr id="1"> 29 <td>tanaka</td> 29 <td> 30 <div onmouseover="event.cancelBubble=true;">tanaka</div> 31 </td> 30 32 </tr> 31 33 <tr id="2"> 32 <td>suzuki</td> 34 <td> 35 <div onmouseover="event.cancelBubble=true;">suzuki</div> 36 </td> 33 37 </tr> 34 38 <tr id="3"> 35 <td>sato</td> 39 <td> 40 <div onmouseover="event.cancelBubble=true;">sato</div> 41 </td> 36 42 </tr> 37 43 <tr id="4"> 38 <td>yamada</td> 44 <td>
