Skip to content

Commit a78d5ee

Browse files
allproscottgonzalez
authored andcommitted
Resizable: Patched the alsoResize plugin to fix 2 critical bugs. Fixes #5694 - Invalid reference in UI Resizable hack for Opera. Fixes #5662/5695/3842 - When resizing from top or left edge, Dialog adds top/left CSS values to content element. Enhances Dialog - Allows dialog-content to have position:relative to 'contain' floated and positioned elements. Bug Demo for #5662 - http://layout.jquery-dev.net/samples/ui_dialog_bug.html
1 parent a8311f9 commit a78d5ee

File tree

1 file changed

+33
-20
lines changed

1 file changed

+33
-20
lines changed

ui/jquery.ui.resizable.js

+33-20
Original file line numberDiff line numberDiff line change
@@ -528,47 +528,49 @@ $.extend($.ui.resizable, {
528528

529529
$.ui.plugin.add("resizable", "alsoResize", {
530530

531-
start: function(event, ui) {
532-
531+
start: function (event, ui) {
533532
var self = $(this).data("resizable"), o = self.options;
534533

535-
var _store = function(exp) {
534+
var _store = function (exp) {
536535
$(exp).each(function() {
537-
$(this).data("resizable-alsoresize", {
538-
width: parseInt($(this).width(), 10), height: parseInt($(this).height(), 10),
539-
left: parseInt($(this).css('left'), 10), top: parseInt($(this).css('top'), 10)
536+
var el = $(this);
537+
el.data("resizable-alsoresize", {
538+
width: parseInt(el.width(), 10), height: parseInt(el.height(), 10),
539+
left: parseInt(el.css('left'), 10), top: parseInt(el.css('top'), 10),
540+
position: el.css('position') // to reset Opera on stop()
540541
});
541542
});
542543
};
543544

544545
if (typeof(o.alsoResize) == 'object' && !o.alsoResize.parentNode) {
545-
if (o.alsoResize.length) { o.alsoResize = o.alsoResize[0]; _store(o.alsoResize); }
546-
else { $.each(o.alsoResize, function(exp, c) { _store(exp); }); }
546+
if (o.alsoResize.length) { o.alsoResize = o.alsoResize[0]; _store(o.alsoResize); }
547+
else { $.each(o.alsoResize, function (exp) { _store(exp); }); }
547548
}else{
548549
_store(o.alsoResize);
549550
}
550551
},
551552

552-
resize: function(event, ui){
553+
resize: function (event, ui) {
553554
var self = $(this).data("resizable"), o = self.options, os = self.originalSize, op = self.originalPosition;
554555

555556
var delta = {
556557
height: (self.size.height - os.height) || 0, width: (self.size.width - os.width) || 0,
557558
top: (self.position.top - op.top) || 0, left: (self.position.left - op.left) || 0
558559
},
559560

560-
_alsoResize = function(exp, c) {
561+
_alsoResize = function (exp, c) {
561562
$(exp).each(function() {
562-
var el = $(this), start = $(this).data("resizable-alsoresize"), style = {}, css = c && c.length ? c : ['width', 'height', 'top', 'left'];
563+
var el = $(this), start = $(this).data("resizable-alsoresize"), style = {},
564+
css = c && c.length ? c : el.parents(ui.originalElement[0]).length ? ['width', 'height'] : ['width', 'height', 'top', 'left'];
563565

564-
$.each(css || ['width', 'height', 'top', 'left'], function(i, prop) {
566+
$.each(css, function (i, prop) {
565567
var sum = (start[prop]||0) + (delta[prop]||0);
566568
if (sum && sum >= 0)
567569
style[prop] = sum || null;
568570
});
569571

570-
//Opera fixing relative position
571-
if (/relative/.test(el.css('position')) && $.browser.opera) {
572+
// Opera fixing relative position
573+
if ($.browser.opera && /relative/.test(el.css('position'))) {
572574
self._revertToRelativePosition = true;
573575
el.css({ position: 'absolute', top: 'auto', left: 'auto' });
574576
}
@@ -578,22 +580,33 @@ $.ui.plugin.add("resizable", "alsoResize", {
578580
};
579581

580582
if (typeof(o.alsoResize) == 'object' && !o.alsoResize.nodeType) {
581-
$.each(o.alsoResize, function(exp, c) { _alsoResize(exp, c); });
583+
$.each(o.alsoResize, function (exp, c) { _alsoResize(exp, c); });
582584
}else{
583585
_alsoResize(o.alsoResize);
584586
}
585587
},
586588

587-
stop: function(event, ui){
589+
stop: function (event, ui) {
588590
var self = $(this).data("resizable");
589591

590-
//Opera fixing relative position
591-
if (self._revertToRelativePosition && $.browser.opera) {
592+
_reset = function (exp) {
593+
$(exp).each(function() {
594+
var el = $(this);
595+
// reset position for Opera - no need to verify it was changed
596+
el.css({ position: el.data("resizable-alsoresize").position });
597+
});
598+
}
599+
600+
if (self._revertToRelativePosition) {
592601
self._revertToRelativePosition = false;
593-
el.css({ position: 'relative' });
602+
if (typeof(o.alsoResize) == 'object' && !o.alsoResize.nodeType) {
603+
$.each(o.alsoResize, function (exp) { _reset(exp); });
604+
}else{
605+
_reset(o.alsoResize);
606+
}
594607
}
595608

596-
$(this).removeData("resizable-alsoresize-start");
609+
$(this).removeData("resizable-alsoresize");
597610
}
598611
});
599612

0 commit comments

Comments
 (0)