Changeset 497
- Timestamp:
- 01/14/06 03:46:38 (3 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
mochikit/branches/scriptaculous/MochiKit/DragAndDrop.js
r494 r497 247 247 }, 248 248 reverteffect: function (element, top_offset, left_offset) { 249 var dur = Math.sqrt(Math.abs(top_offset^2)+Math.abs(left_offset^2))*0.02; 250 element._revert = new Effect.Move(element, {x: -left_offset, y: -top_offset, duration: dur}); 249 var dur = Math.sqrt(Math.abs(top_offset^2) + 250 Math.abs(left_offset^2))*0.02; 251 element._revert = new Effect.Move(element, 252 {x: -left_offset, y: -top_offset, duration: dur}); 251 253 }, 252 254 endeffect: function (element) { … … 255 257 zindex: 1000, 256 258 revert: false, 257 snap: false // false, or xy or [x, y] or function (x, y){return [x, y];} 259 // false, or xy or [x, y] or function (x, y){return [x, y];} 260 snap: false 258 261 }, options || {}); 259 262 … … 261 264 262 265 if (options.handle && (typeof options.handle == 'string')) { 263 this.handle = MochiKit.DOM.getElementsByTagAndClassName(null, options.handle, this.element)[0]; 266 this.handle = MochiKit.DOM.getElementsByTagAndClassName(null, 267 options.handle, this.element)[0]; 264 268 } 265 269 if (!this.handle) { … … 270 274 } 271 275 272 MochiKit.DOM.makePositioned(this.element); // fix IE276 MochiKit.DOM.makePositioned(this.element); // fix IE 273 277 274 278 this.delta = this.currentDelta(); … … 276 280 this.dragging = false; 277 281 278 this.eventMouseDown = MochiKit.DOM.bindAsEventListener(this.initDrag, this); 282 this.eventMouseDown = MochiKit.DOM.bindAsEventListener(this.initDrag, 283 this); 279 284 MochiKit.Event.observe(this.handle, 'mousedown', this.eventMouseDown); 280 281 285 DragAndDrop.Draggables.register(this); 282 286 }, 283 287 284 288 destroy: function () { 285 MochiKit.Event.stopObserving(this.handle, 'mousedown', this.eventMouseDown); 289 MochiKit.Event.stopObserving(this.handle, 'mousedown', 290 this.eventMouseDown); 286 291 DragAndDrop.Draggables.unregister(this); 287 292 }, … … 294 299 295 300 initDrag: function (event) { 296 if (MochiKit.Event.isLeftClick(event)) { 297 // abort on form elements, fixes a Firefox issue 298 var src = MochiKit.Event.element(event); 299 if (src.tagName && ( 300 src.tagName == 'INPUT' || 301 src.tagName == 'SELECT' || 302 src.tagName == 'BUTTON' || 303 src.tagName == 'TEXTAREA')) { 304 return; 305 } 306 307 if (this.element._revert) { 308 this.element._revert.cancel(); 309 this.element._revert = null; 310 } 311 312 var pointer = [MochiKit.Event.pointerX(event), MochiKit.Event.pointerY(event)]; 313 var pos = MochiKit.Position.cumulativeOffset(this.element); 314 this.offset = MochiKit.Base.map(function (i) { 315 return (pointer[i] - pos[i]); 316 }, [0, 1]); 317 318 DragAndDrop.Draggables.activate(this); 319 MochiKit.Event.stop(event); 320 } 301 if (!MochiKit.Event.isLeftClick(event)) { 302 return; 303 } 304 // abort on form elements, fixes a Firefox issue 305 var src = MochiKit.Event.element(event); 306 if (src.tagName && ( 307 src.tagName == 'INPUT' || 308 src.tagName == 'SELECT' || 309 src.tagName == 'BUTTON' || 310 src.tagName == 'TEXTAREA')) { 311 return; 312 } 313 314 if (this.element._revert) { 315 this.element._revert.cancel(); 316 this.element._revert = null; 317 } 318 319 var pointer = [MochiKit.Event.pointerX(event), 320 MochiKit.Event.pointerY(event)]; 321 var pos = MochiKit.Position.cumulativeOffset(this.element); 322 this.offset = MochiKit.Base.map(function (i) { 323 return (pointer[i] - pos[i]); 324 }, [0, 1]); 325 326 DragAndDrop.Draggables.activate(this); 327 MochiKit.Event.stop(event); 321 328 }, 322 329 323 330 startDrag: function (event) { 324 331 this.dragging = true; 325 332 if (this.options.selectClass) { 333 MochiKit.DOM.addElementClass(this.element, 334 this.options.selectClass); 335 } 326 336 if (this.options.zindex) { 327 this.originalZ = parseInt(MochiKit.DOM.getStyle(this.element, 'z-index') || '0'); 337 this.originalZ = parseInt(MochiKit.DOM.getStyle(this.element, 338 'z-index') || '0'); 328 339 this.element.style.zIndex = this.options.zindex; 329 340 } … … 362 373 finishDrag: function (event, success) { 363 374 this.dragging = false; 375 if (this.options.selectClass) { 376 MochiKit.DOM.removeElementClass(this.element, 377 this.options.selectClass); 378 } 364 379 365 380 if (this.options.ghosting) {
