Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resizable: Modified to allow jquery objects as handles. Fixed #9658: #1377

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tests/unit/resizable/resizable.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@

<div id="container">
<div id="resizable1">I'm a resizable.</div>
<div id="resizer1" class="ui-resizable-handle ui-resizable-s"></div>
</div>

<div id="container2">
Expand Down
27 changes: 27 additions & 0 deletions tests/unit/resizable/resizable_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,33 @@ test("ui-resizable-nw { handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 1
equal( target.height(), 100, "compare maxHeight" );
});


test("custom handles { handles: { 's': $('#resizer1'), containment: 'parent' }", function () {
expect(2);

var handle = "#resizer1", target = $("#resizable1").resizable({ handles: { "s": $("#resizer1") }, containment: "parent" });

TestHelpers.resizable.drag(handle, 0, 70);
equal(target.height(), 170, "compare height");

TestHelpers.resizable.drag(handle, 0, -70);
equal(target.height(), 100, "compare height");
});


test("custom handles { handles: { 's': $('#resizer1')[0], containment: 'parent' }", function () {
expect(2);

var handle = "#resizer1", target = $("#resizable1").resizable({ handles: { "s": $("#resizer1")[0] }, containment: "parent" });

TestHelpers.resizable.drag(handle, 0, 70);
equal(target.height(), 170, "compare height");

TestHelpers.resizable.drag(handle, 0, -70);
equal(target.height(), 100, "compare height");
});


test("zIndex, applied to all handles", function() {
expect(8);

Expand Down
26 changes: 18 additions & 8 deletions ui/resizable.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ $.widget("ui.resizable", $.ui.mouse, {
nw: ".ui-resizable-nw"
} );

if (this.handles.constructor === String) {
this._handles = $();
if(this.handles.constructor === String) {

if ( this.handles === "all") {
this.handles = "n,e,s,w,se,sw,ne,nw";
Expand Down Expand Up @@ -190,7 +191,11 @@ $.widget("ui.resizable", $.ui.mouse, {

this._renderAxis = function(target) {

var i, axis, padPos, padWrapper;
var i, axis, padPos, padWrapper, mouseDownHandlers = {
mousedown: function (event) {
return that._mouseDown(event);
}
};

target = target || this.element;

Expand All @@ -199,6 +204,10 @@ $.widget("ui.resizable", $.ui.mouse, {
if (this.handles[i].constructor === String) {
this.handles[i] = this.element.children( this.handles[ i ] ).first().show();
}
else if (this.handles[i] && (this.handles[i].jquery || this.handles[i].nodeType)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first check here this.handles[i].jquery is unnecessary. The previous check is already looking at this.handles[i].constructor.

this.handles[i] = $(this.handles[i]);
this._on(this.handles[i], mouseDownHandlers);
}

if (this.elementIsWrapper && this.originalElement[0].nodeName.match(/textarea|input|select|button/i)) {

Expand All @@ -217,18 +226,20 @@ $.widget("ui.resizable", $.ui.mouse, {

}

// TODO: What's that good for? There's not anything to be executed left
if (!$(this.handles[i]).length) {
this._handles = this._handles.add(this.handles[i]);

//TODO: What's that good for? There's not anything to be executed left
if(!$(this.handles[i]).length) {
continue;
}
}
};

// TODO: make renderAxis a prototype function
this._renderAxis(this.element);

this._handles = $(".ui-resizable-handle", this.element)
.disableSelection();
this._handles = this._handles.add($(".ui-resizable-handle", this.element));
this._handles.disableSelection();

this._handles.mouseover(function() {
if (!that.resizing) {
Expand Down Expand Up @@ -262,7 +273,6 @@ $.widget("ui.resizable", $.ui.mouse, {
}

this._mouseInit();

},

_destroy: function() {
Expand Down