mirror of
https://github.com/jquery/jquery-ui.git
synced 2025-01-07 20:34:24 +00:00
Dialog: Use _trigger for drag and resize events instead of executing callbacks directly. Fixed #4629 - Dialog events not being triggered.
This commit is contained in:
parent
e1550390b1
commit
2ebc73e2b7
@ -38,14 +38,19 @@ test("open", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("dragStart", function() {
|
test("dragStart", function() {
|
||||||
expect(2);
|
expect(7);
|
||||||
|
|
||||||
el = $("<div></div>");
|
el = $('<div></div>').dialog({
|
||||||
el.dialog({
|
|
||||||
dragStart: function(ev, ui) {
|
dragStart: function(ev, ui) {
|
||||||
ok(true, 'dragging fires dragStart callback');
|
ok(true, 'dragging fires dragStart callback');
|
||||||
equals(this, el[0], "context of callback");
|
equals(this, el[0], "context of callback");
|
||||||
|
equals(ev.type, 'dialogdragStart', 'event type in callback');
|
||||||
|
same(ui, {}, 'ui hash in callback');
|
||||||
}
|
}
|
||||||
|
}).bind('dialogdragStart', function(ev, ui) {
|
||||||
|
ok(true, 'dragging fires dialogdragStart event');
|
||||||
|
equals(this, el[0], 'context of event');
|
||||||
|
same(ui, {}, 'ui hash in event');
|
||||||
});
|
});
|
||||||
var handle = $(".ui-dialog-titlebar", dlg());
|
var handle = $(".ui-dialog-titlebar", dlg());
|
||||||
drag(handle, 50, 50);
|
drag(handle, 50, 50);
|
||||||
@ -53,30 +58,44 @@ test("dragStart", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("drag", function() {
|
test("drag", function() {
|
||||||
var fired = false;
|
expect(7);
|
||||||
|
var hasDragged = false;
|
||||||
|
|
||||||
el = $("<div></div>");
|
el = $('<div></div>').dialog({
|
||||||
el.dialog({
|
|
||||||
drag: function(ev, ui) {
|
drag: function(ev, ui) {
|
||||||
fired = true;
|
if (!hasDragged) {
|
||||||
|
ok(true, 'dragging fires drag callback');
|
||||||
equals(this, el[0], "context of callback");
|
equals(this, el[0], "context of callback");
|
||||||
|
equals(ev.type, 'dialogdrag', 'event type in callback');
|
||||||
|
same(ui, {}, 'ui hash in callback');
|
||||||
|
|
||||||
|
hasDragged = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}).one('dialogdrag', function(ev, ui) {
|
||||||
|
ok(true, 'dragging fires dialogdrag event');
|
||||||
|
equals(this, el[0], 'context of event');
|
||||||
|
same(ui, {}, 'ui hash in event');
|
||||||
});
|
});
|
||||||
var handle = $(".ui-dialog-titlebar", dlg());
|
var handle = $(".ui-dialog-titlebar", dlg());
|
||||||
drag(handle, 50, 50);
|
drag(handle, 50, 50);
|
||||||
ok(fired, "drag fired");
|
|
||||||
el.remove();
|
el.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("dragStop", function() {
|
test("dragStop", function() {
|
||||||
expect(2);
|
expect(7);
|
||||||
|
|
||||||
el = $("<div></div>");
|
el = $('<div></div>').dialog({
|
||||||
el.dialog({
|
dragStart: function(ev, ui) {
|
||||||
dragStop: function(ev, ui) {
|
|
||||||
ok(true, 'dragging fires dragStop callback');
|
ok(true, 'dragging fires dragStop callback');
|
||||||
equals(this, el[0], "context of callback");
|
equals(this, el[0], "context of callback");
|
||||||
|
equals(ev.type, 'dialogdragStop', 'event type in callback');
|
||||||
|
same(ui, {}, 'ui hash in callback');
|
||||||
}
|
}
|
||||||
|
}).bind('dialogdragStop', function(ev, ui) {
|
||||||
|
ok(true, 'dragging fires dialogdragStop event');
|
||||||
|
equals(this, el[0], 'context of event');
|
||||||
|
same(ui, {}, 'ui hash in event');
|
||||||
});
|
});
|
||||||
var handle = $(".ui-dialog-titlebar", dlg());
|
var handle = $(".ui-dialog-titlebar", dlg());
|
||||||
drag(handle, 50, 50);
|
drag(handle, 50, 50);
|
||||||
@ -84,14 +103,19 @@ test("dragStop", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("resizeStart", function() {
|
test("resizeStart", function() {
|
||||||
expect(2);
|
expect(7);
|
||||||
|
|
||||||
el = $("<div></div>");
|
el = $('<div></div>').dialog({
|
||||||
el.dialog({
|
|
||||||
resizeStart: function(ev, ui) {
|
resizeStart: function(ev, ui) {
|
||||||
ok(true, 'resizing fires resizeStart callback');
|
ok(true, 'resizing fires resizeStart callback');
|
||||||
equals(this, el[0], "context of callback");
|
equals(this, el[0], "context of callback");
|
||||||
|
equals(ev.type, 'dialogresizeStart', 'event type in callback');
|
||||||
|
same(ui, {}, 'ui hash in callback');
|
||||||
}
|
}
|
||||||
|
}).bind('dialogresizeStart', function(ev, ui) {
|
||||||
|
ok(true, 'resizing fires dialogresizeStart event');
|
||||||
|
equals(this, el[0], 'context of event');
|
||||||
|
same(ui, {}, 'ui hash in event');
|
||||||
});
|
});
|
||||||
var handle = $(".ui-resizable-se", dlg());
|
var handle = $(".ui-resizable-se", dlg());
|
||||||
drag(handle, 50, 50);
|
drag(handle, 50, 50);
|
||||||
@ -99,30 +123,44 @@ test("resizeStart", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("resize", function() {
|
test("resize", function() {
|
||||||
var fired = false;
|
expect(7);
|
||||||
|
var hasResized = false;
|
||||||
|
|
||||||
el = $("<div></div>");
|
el = $('<div></div>').dialog({
|
||||||
el.dialog({
|
|
||||||
resize: function(ev, ui) {
|
resize: function(ev, ui) {
|
||||||
fired = true;
|
if (!hasResized) {
|
||||||
|
ok(true, 'resizing fires resize callback');
|
||||||
equals(this, el[0], "context of callback");
|
equals(this, el[0], "context of callback");
|
||||||
|
equals(ev.type, 'dialogresize', 'event type in callback');
|
||||||
|
same(ui, {}, 'ui hash in callback');
|
||||||
|
|
||||||
|
hasResized = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}).one('dialogresize', function(ev, ui) {
|
||||||
|
ok(true, 'resizing fires dialogresize event');
|
||||||
|
equals(this, el[0], 'context of event');
|
||||||
|
same(ui, {}, 'ui hash in event');
|
||||||
});
|
});
|
||||||
var handle = $(".ui-resizable-se", dlg());
|
var handle = $(".ui-resizable-se", dlg());
|
||||||
drag(handle, 50, 50);
|
drag(handle, 50, 50);
|
||||||
ok(fired, "resize fired");
|
|
||||||
el.remove();
|
el.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("resizeStop", function() {
|
test("resizeStop", function() {
|
||||||
expect(2);
|
expect(7);
|
||||||
|
|
||||||
el = $("<div></div>");
|
el = $('<div></div>').dialog({
|
||||||
el.dialog({
|
|
||||||
resizeStop: function(ev, ui) {
|
resizeStop: function(ev, ui) {
|
||||||
ok(true, 'resizing fires resizeStop callback');
|
ok(true, 'resizing fires resizeStop callback');
|
||||||
equals(this, el[0], "context of callback");
|
equals(this, el[0], "context of callback");
|
||||||
|
equals(ev.type, 'dialogresizeStop', 'event type in callback');
|
||||||
|
same(ui, {}, 'ui hash in callback');
|
||||||
}
|
}
|
||||||
|
}).bind('dialogresizeStop', function(ev, ui) {
|
||||||
|
ok(true, 'resizing fires dialogresizeStop event');
|
||||||
|
equals(this, el[0], 'context of event');
|
||||||
|
same(ui, {}, 'ui hash in event');
|
||||||
});
|
});
|
||||||
var handle = $(".ui-resizable-se", dlg());
|
var handle = $(".ui-resizable-se", dlg());
|
||||||
drag(handle, 50, 50);
|
drag(handle, 50, 50);
|
||||||
|
@ -320,17 +320,17 @@ $.widget("ui.dialog", {
|
|||||||
cancel: '.ui-dialog-content',
|
cancel: '.ui-dialog-content',
|
||||||
handle: '.ui-dialog-titlebar',
|
handle: '.ui-dialog-titlebar',
|
||||||
containment: 'document',
|
containment: 'document',
|
||||||
start: function() {
|
start: function(event) {
|
||||||
heightBeforeDrag = options.height;
|
heightBeforeDrag = options.height;
|
||||||
$(this).height($(this).height()).addClass("ui-dialog-dragging");
|
$(this).height($(this).height()).addClass("ui-dialog-dragging");
|
||||||
(options.dragStart && options.dragStart.apply(self.element[0], arguments));
|
self._trigger('dragStart', event);
|
||||||
},
|
},
|
||||||
drag: function() {
|
drag: function(event) {
|
||||||
(options.drag && options.drag.apply(self.element[0], arguments));
|
self._trigger('drag', event);
|
||||||
},
|
},
|
||||||
stop: function() {
|
stop: function(event) {
|
||||||
$(this).removeClass("ui-dialog-dragging").height(heightBeforeDrag);
|
$(this).removeClass("ui-dialog-dragging").height(heightBeforeDrag);
|
||||||
(options.dragStop && options.dragStop.apply(self.element[0], arguments));
|
self._trigger('dragStop', event);
|
||||||
$.ui.dialog.overlay.resize();
|
$.ui.dialog.overlay.resize();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -351,19 +351,19 @@ $.widget("ui.dialog", {
|
|||||||
maxHeight: options.maxHeight,
|
maxHeight: options.maxHeight,
|
||||||
minWidth: options.minWidth,
|
minWidth: options.minWidth,
|
||||||
minHeight: self._minHeight(),
|
minHeight: self._minHeight(),
|
||||||
start: function() {
|
|
||||||
$(this).addClass("ui-dialog-resizing");
|
|
||||||
(options.resizeStart && options.resizeStart.apply(self.element[0], arguments));
|
|
||||||
},
|
|
||||||
resize: function() {
|
|
||||||
(options.resize && options.resize.apply(self.element[0], arguments));
|
|
||||||
},
|
|
||||||
handles: resizeHandles,
|
handles: resizeHandles,
|
||||||
stop: function() {
|
start: function(event) {
|
||||||
|
$(this).addClass("ui-dialog-resizing");
|
||||||
|
self._trigger('resizeStart', event);
|
||||||
|
},
|
||||||
|
resize: function(event) {
|
||||||
|
self._trigger('resize', event);
|
||||||
|
},
|
||||||
|
stop: function(event) {
|
||||||
$(this).removeClass("ui-dialog-resizing");
|
$(this).removeClass("ui-dialog-resizing");
|
||||||
options.height = $(this).height();
|
options.height = $(this).height();
|
||||||
options.width = $(this).width();
|
options.width = $(this).width();
|
||||||
(options.resizeStop && options.resizeStop.apply(self.element[0], arguments));
|
self._trigger('resizeStop', event);
|
||||||
$.ui.dialog.overlay.resize();
|
$.ui.dialog.overlay.resize();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user