Bug Tracker

Changeset 5668

Show
Ignore:
Timestamp:
05/22/08 18:17:30 (8 months ago)
Author:
rdworth
Message:

ui experimental mouse - fixed drag+resize to work together

Location:
branches/ui-experimental/mouse
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • branches/ui-experimental/mouse/ui.core.js

    r5666 r5668  
    183183         
    184184        mouseDown: function(e) { 
     185             
     186            // we may have missed mouseup (out of window) 
     187            (this._mouseStarted 
     188                && this.mouseUp(e)); 
     189             
    185190            this._mouseDownEvent = e; 
    186191             
     
    192197            } 
    193198             
    194             this._mouseDelayMet = false; 
    195             this._mouseDelayTimer = setTimeout(function() { 
    196                 self._mouseDelayMet = true; 
    197             } , this.options.delay); 
    198              
     199            this._mouseDelayMet = (this.options.delay == 0); 
     200            if (!this._mouseDelayMet) { 
     201                this._mouseDelayTimer = setTimeout(function() { 
     202                    self._mouseDelayMet = true; 
     203                }, this.options.delay); 
     204            } 
     205             
     206            // these delegates are required to keep context 
     207            this._mouseMoveDelegate = function(e) { 
     208                return self.mouseMove(e); 
     209            } 
     210            this._mouseUpDelegate = function(e) { 
     211                return self.mouseUp(e); 
     212            } 
    199213            $(document) 
    200                 .bind('mousemove.mouse', function(e) { 
    201                     return self.mouseMove(e); 
    202                 }) 
    203                 .bind('mouseup.mouse', function(e) { 
    204                     return self.mouseUp(e); 
    205                 }); 
     214                .bind('mousemove.mouse', this._mouseMoveDelegate) 
     215                .bind('mouseup.mouse', this._mouseUpDelegate); 
    206216             
    207217            return false; 
     
    209219         
    210220        mouseMove: function(e) { 
     221             
    211222            // IE mouseup check - mouseup happened when mouse was out of window 
    212223            if ($.browser.msie && !e.button) { 
     
    229240         
    230241        mouseUp: function(e) { 
    231             $(document).unbind('.mouse'); 
     242             
     243            $(document) 
     244                .unbind('mousemove.mouse', this._mouseMoveDelegate) 
     245                .unbind('mouseup.mouse', this._mouseUpDelegate); 
    232246             
    233247            if (this._mouseStarted) { 
  • branches/ui-experimental/mouse/ui.draggable.js

    r5665 r5668  
    3030        }, 
    3131        mouseStart: function(e) { 
    32              
    3332            var o = this.options; 
     33             
     34            if (o.disabled) return false; 
     35             
     36            var handle = !this.options.handle || !$(this.options.handle, this.element).length ? true : false; 
     37            if(!handle) $(this.options.handle, this.element).each(function() { 
     38                if(this == e.target) handle = true; 
     39            }); 
     40            if (!handle) return false; 
     41             
    3442            if($.ui.ddmanager) $.ui.ddmanager.current = this; 
    3543             
     
    111119            if ($.ui.ddmanager && !o.dropBehaviour) $.ui.ddmanager.prepareOffsets(this, e); 
    112120             
    113             return !o.disabled; 
     121            return true; 
    114122        }, 
    115123        convertPositionTo: function(d, pos) { 
     
    192200        }, 
    193201        mouseStop: function(e) { 
    194          
     202             
    195203            //If we are using droppables, inform the manager about the drop 
    196204            if ($.ui.ddmanager && !this.options.dropBehaviour) 
  • branches/ui-experimental/mouse/ui.resizable.js

    r5666 r5668  
    3030                knobHandles: o.knobHandles === true ? 'ui-resizable-knob-handle' : o.knobHandles 
    3131            }); 
    32  
     32             
    3333            //Default Theme 
    3434            var aBorder = '1px solid #DEDEDE'; 
    35      
     35             
    3636            o.defaultTheme = { 
    3737                'ui-resizable': { display: 'block' }, 
     
    8181                 
    8282                var oel = this.element; this.element = this.element.parent(); 
    83          
     83                 
    8484                //Move margins to the wrapper 
    8585                this.element.css({ marginLeft: oel.css("marginLeft"), marginTop: oel.css("marginTop"), 
    8686                    marginRight: oel.css("marginRight"), marginBottom: oel.css("marginBottom") 
    8787                }); 
    88          
     88                 
    8989                oel.css({ marginLeft: 0, marginTop: 0, marginRight: 0, marginBottom: 0}); 
    90          
     90                 
    9191                //Prevent Safari textarea resize 
    9292                if ($.browser.safari && o.preventDefault) oel.css('resize', 'none'); 
    93          
     93                 
    9494                o.proportionallyResize = oel.css({ position: 'static', zoom: 1, display: 'block' }); 
    9595                 
     
    103103            if(!o.handles) o.handles = !$('.ui-resizable-handle', this.element).length ? "e,s,se" : { n: '.ui-resizable-n', e: '.ui-resizable-e', s: '.ui-resizable-s', w: '.ui-resizable-w', se: '.ui-resizable-se', sw: '.ui-resizable-sw', ne: '.ui-resizable-ne', nw: '.ui-resizable-nw' }; 
    104104            if(o.handles.constructor == String) { 
    105          
     105                 
    106106                o.zIndex = o.zIndex || 1000; 
    107107                 
    108108                if(o.handles == 'all') o.handles = 'n,e,s,w,se,sw,ne,nw'; 
    109          
     109                 
    110110                var n = o.handles.split(","); o.handles = {}; 
    111111                 
     
    122122                    nw: 'top: 0pt; left: 0px;' 
    123123                }; 
    124          
     124                 
    125125                for(var i = 0; i < n.length; i++) { 
    126126                    var handle = $.trim(n[i]), dt = o.defaultTheme, hname = 'ui-resizable-'+handle, loadDefault = !$.ui.css(hname) && !o.knobHandles, userKnobClass = $.ui.css('ui-resizable-knob-handle'),  
     
    144144                if (o.knobHandles) this.element.addClass('ui-resizable-knob').css( !$.ui.css('ui-resizable-knob') ? { /*border: '1px #fff dashed'*/ } : {} ); 
    145145            } 
    146  
     146             
    147147            this._renderAxis = function(target) { 
    148148                target = target || this.element; 
    149          
     149                 
    150150                for(var i in o.handles) { 
    151151                    if(o.handles[i].constructor == String)  
    152152                        o.handles[i] = $(o.handles[i], this.element).show(); 
    153          
     153                     
    154154                    if (o.transparent) 
    155155                        o.handles[i].css({opacity:0}); 
    156          
     156                     
    157157                    //Apply pad to wrapper element, needed to fix axis position (textarea, inputs, scrolls) 
    158158                    if (this.element.is('.ui-wrapper') &&  
    159159                        o._nodeName.match(/textarea|input|select|button/i)) { 
    160          
     160                         
    161161                        var axis = $(o.handles[i], this.element), padWrapper = 0; 
    162          
     162                         
    163163                        //Checking the correct pad and border 
    164164                        padWrapper = /sw|ne|nw|se|n|s/.test(i) ? axis.outerHeight() : axis.outerWidth(); 
    165          
     165                         
    166166                        //The padding type i have to apply... 
    167167                        var padPos = [ 'padding',  
     
    169169                            /se|sw|s/.test(i) ? 'Bottom' :  
    170170                            /^e$/.test(i) ? 'Right' : 'Left' ].join("");  
    171          
     171                         
    172172                        if (!o.transparent) 
    173173                            target.css(padPos, padWrapper); 
    174          
     174                         
    175175                        this._proportionallyResize(); 
    176176                    } 
     
    194194                } 
    195195            }); 
    196                      
     196             
    197197            //If we want to auto hide the elements 
    198198            if (o.autohide) { 
     
    209209                }); 
    210210            } 
    211          
     211             
    212212            this.mouseInit(); 
    213              
    214213        }, 
    215214        plugins: {}, 
     
    229228             
    230229            this.mouseDestroy(); 
    231  
     230             
    232231            var _destroy = function(exp) { 
    233232                $(exp).removeClass("ui-resizable ui-resizable-disabled") 
    234233                    .removeData("resizable").unbind(".resizable").find('.ui-resizable-handle').remove(); 
    235  
    236234            }; 
    237235             
     
    262260        mouseStart: function(e) { 
    263261            if(this.disabled) return false; 
    264  
     262             
     263            var handle = false; 
     264            for(var i in this.options.handles) { 
     265                if($(this.options.handles[i])[0] == e.target) handle = true; 
     266            } 
     267            if (!handle) return false; 
     268             
    265269            var o = this.options, iniPos = this.element.position(), el = this.element,  
    266270                num = function(v) { return parseInt(v, 10) || 0; }, ie6 = $.browser.msie && $.browser.version < 7; 
    267271            o.resizing = true; 
    268272            o.documentScroll = { top: $(document).scrollTop(), left: $(document).scrollLeft() }; 
    269      
     273             
    270274            // bugfix #1749 
    271275            if (el.is('.ui-draggable') || (/absolute/).test(el.css('position'))) { 
     
    281285            if (/relative/.test(el.css('position')) && $.browser.opera) 
    282286                el.css({ position: 'relative', top: 'auto', left: 'auto' }); 
    283      
     287             
    284288            this._renderProxy(); 
    285      
     289             
    286290            var curleft = num(this.helper.css('left')), curtop = num(this.helper.css('top')); 
    287291             
     
    297301            //Aspect Ratio 
    298302            o.aspectRatio = (typeof o.aspectRatio == 'number') ? o.aspectRatio : ((this.originalSize.height / this.originalSize.width)||1); 
    299      
     303             
    300304            if (o.preserveCursor) 
    301305                $('body').css('cursor', this.axis + '-resize'); 
    302306                 
    303307            this.propagate("start", e); 
    304             for(var i in this.options.handles) { 
    305                 if($(this.options.handles[i])[0] == e.target) return true; 
    306             } 
    307             return false; 
     308            return true; 
    308309        }, 
    309310        mouseDrag: function(e) { 
     311             
    310312            //Increase performance, avoid regex 
    311313            var el = this.helper, o = this.options, props = {}, 
    312314                self = this, smp = this.originalMousePosition, a = this.axis; 
    313  
     315             
    314316            var dx = (e.pageX-smp.left)||0, dy = (e.pageY-smp.top)||0; 
    315317            var trigger = this._change[a]; 
     
    339341        }, 
    340342        mouseStop: function(e) { 
     343             
    341344            this.options.resizing = false; 
    342345            var o = this.options, num = function(v) { return parseInt(v, 10) || 0; }, self = this; 
    343      
     346             
    344347            if(o.proxy) { 
    345348                var pr = o.proportionallyResize, ista = pr && (/textarea/i).test(pr.get(0).nodeName),  
    346349                            soffseth = ista && $.ui.hasScroll(pr.get(0), 'left') /* TODO - jump height */ ? 0 : self.sizeDiff.height, 
    347350                                soffsetw = ista ? 0 : self.sizeDiff.width; 
    348              
     351                 
    349352                var s = { width: (self.size.width - soffsetw), height: (self.size.height - soffseth) }, 
    350353                    left = (parseInt(self.element.css('left'), 10) + (self.position.left - self.originalPosition.left)) || null,  
     
    357360                this.helper.remove(); 
    358361            } 
    359  
     362             
    360363            if (o.preserveCursor) 
    361364            $('body').css('cursor', 'auto'); 
    362      
     365             
    363366            this.propagate("stop", e);   
    364367            return false; 
     
    437440            var el = this.element, o = this.options; 
    438441            this.elementOffset = el.offset(); 
    439      
     442             
    440443            if(o.proxy) { 
    441444                this.helper = this.helper || $('<div style="overflow:hidden;"></div>'); 
    442      
     445                 
    443446                // fix ie6 offset 
    444447                var ie6 = $.browser.msie && $.browser.version < 7, ie6offset = (ie6 ? 1 : 0), 
    445448                pxyoffset = ( ie6 ? 2 : -1 ); 
    446      
     449                 
    447450                this.helper.addClass(o.proxy).css({ 
    448451                    width: el.outerWidth() + pxyoffset, 
     
    455458                 
    456459                this.helper.appendTo("body"); 
    457      
     460                 
    458461                if (o.disableSelection) 
    459462                    $.ui.disableSelection(this.helper.get(0)); 
    460      
     463                 
    461464            } else { 
    462465                this.helper = el;  
     
    498501            distance: 0, 
    499502            delay: 0, 
    500  
    501503            preventDefault: true, 
    502504            transparent: false, 
     
    524526            if (/document/.test(oc) || oc == document) { 
    525527                self.containerOffset = { left: 0, top: 0 }; 
    526  
     528                 
    527529                self.parentData = {  
    528530                    element: $(document), left: 0, top: 0, width: $(document).width(), 
     
    612614        stop: function(e, ui) { 
    613615            var o = ui.options, self = ui.instance; 
    614  
     616             
    615617            var pr = o.proportionallyResize, ista = pr && (/textarea/i).test(pr.get(0).nodeName),  
    616618                            soffseth = ista && $.ui.hasScroll(pr.get(0), 'left') /* TODO - jump height */ ? 0 : self.sizeDiff.height,