Changeset 497

Show
Ignore:
Timestamp:
01/14/06 03:46:38 (3 years ago)
Author:
therve@gmail.com
Message:

Add selectClass option to Draggable

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • mochikit/branches/scriptaculous/MochiKit/DragAndDrop.js

    r494 r497  
    247247            }, 
    248248            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}); 
    251253            }, 
    252254            endeffect: function (element) { 
     
    255257            zindex: 1000, 
    256258            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 
    258261        }, options || {}); 
    259262 
     
    261264 
    262265        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]; 
    264268        } 
    265269        if (!this.handle) { 
     
    270274        } 
    271275 
    272         MochiKit.DOM.makePositioned(this.element); // fix IE 
     276        MochiKit.DOM.makePositioned(this.element); // fix IE 
    273277 
    274278        this.delta = this.currentDelta(); 
     
    276280        this.dragging = false; 
    277281 
    278         this.eventMouseDown = MochiKit.DOM.bindAsEventListener(this.initDrag, this); 
     282        this.eventMouseDown = MochiKit.DOM.bindAsEventListener(this.initDrag, 
     283                                                               this); 
    279284        MochiKit.Event.observe(this.handle, 'mousedown', this.eventMouseDown); 
    280  
    281285        DragAndDrop.Draggables.register(this); 
    282286    }, 
    283287 
    284288    destroy: function () { 
    285         MochiKit.Event.stopObserving(this.handle, 'mousedown', this.eventMouseDown); 
     289        MochiKit.Event.stopObserving(this.handle, 'mousedown', 
     290                                     this.eventMouseDown); 
    286291        DragAndDrop.Draggables.unregister(this); 
    287292    }, 
     
    294299 
    295300    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); 
    321328    }, 
    322329 
    323330    startDrag: function (event) { 
    324331        this.dragging = true; 
    325  
     332        if (this.options.selectClass) { 
     333            MochiKit.DOM.addElementClass(this.element, 
     334                                         this.options.selectClass); 
     335        } 
    326336        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'); 
    328339            this.element.style.zIndex = this.options.zindex; 
    329340        } 
     
    362373    finishDrag: function (event, success) { 
    363374        this.dragging = false; 
     375        if (this.options.selectClass) { 
     376            MochiKit.DOM.removeElementClass(this.element, 
     377                                            this.options.selectClass); 
     378        } 
    364379 
    365380        if (this.options.ghosting) {