Skip to content
Permalink
Browse files

Dialog: Use _trigger for drag and resize events instead of executing …

…callbacks directly. Fixed #4629 - Dialog events not being triggered.
  • Loading branch information
scottgonzalez committed Jul 10, 2009
1 parent e155039 commit 2ebc73e2b74556466bb36e2f37abf6488bf5f9bc
Showing with 77 additions and 39 deletions.
  1. +64 −26 tests/unit/dialog/dialog_events.js
  2. +13 −13 ui/ui.dialog.js
@@ -38,91 +38,129 @@ test("open", function() {
});

test("dragStart", function() {
expect(2);
expect(7);

el = $("<div></div>");
el.dialog({
el = $('<div></div>').dialog({
dragStart: function(ev, ui) {
ok(true, 'dragging fires dragStart 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());
drag(handle, 50, 50);
el.remove();
});

test("drag", function() {
var fired = false;

el = $("<div></div>");
el.dialog({
expect(7);
var hasDragged = false;

el = $('<div></div>').dialog({
drag: function(ev, ui) {
fired = true;
equals(this, el[0], "context of callback");
if (!hasDragged) {
ok(true, 'dragging fires drag 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());
drag(handle, 50, 50);
ok(fired, "drag fired");
el.remove();
});

test("dragStop", function() {
expect(2);
expect(7);

el = $("<div></div>");
el.dialog({
dragStop: function(ev, ui) {
el = $('<div></div>').dialog({
dragStart: function(ev, ui) {
ok(true, 'dragging fires dragStop 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());
drag(handle, 50, 50);
el.remove();
});

test("resizeStart", function() {
expect(2);
expect(7);

el = $("<div></div>");
el.dialog({
el = $('<div></div>').dialog({
resizeStart: function(ev, ui) {
ok(true, 'resizing fires resizeStart 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());
drag(handle, 50, 50);
el.remove();
});

test("resize", function() {
var fired = false;
expect(7);
var hasResized = false;

el = $("<div></div>");
el.dialog({
el = $('<div></div>').dialog({
resize: function(ev, ui) {
fired = true;
equals(this, el[0], "context of callback");
if (!hasResized) {
ok(true, 'resizing fires resize 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());
drag(handle, 50, 50);
ok(fired, "resize fired");
el.remove();
});

test("resizeStop", function() {
expect(2);
expect(7);

el = $("<div></div>");
el.dialog({
el = $('<div></div>').dialog({
resizeStop: function(ev, ui) {
ok(true, 'resizing fires resizeStop 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());
drag(handle, 50, 50);
@@ -320,17 +320,17 @@ $.widget("ui.dialog", {
cancel: '.ui-dialog-content',
handle: '.ui-dialog-titlebar',
containment: 'document',
start: function() {
start: function(event) {
heightBeforeDrag = options.height;
$(this).height($(this).height()).addClass("ui-dialog-dragging");
(options.dragStart && options.dragStart.apply(self.element[0], arguments));
self._trigger('dragStart', event);
},
drag: function() {
(options.drag && options.drag.apply(self.element[0], arguments));
drag: function(event) {
self._trigger('drag', event);
},
stop: function() {
stop: function(event) {
$(this).removeClass("ui-dialog-dragging").height(heightBeforeDrag);
(options.dragStop && options.dragStop.apply(self.element[0], arguments));
self._trigger('dragStop', event);
$.ui.dialog.overlay.resize();
}
});
@@ -351,19 +351,19 @@ $.widget("ui.dialog", {
maxHeight: options.maxHeight,
minWidth: options.minWidth,
minHeight: self._minHeight(),
start: function() {
handles: resizeHandles,
start: function(event) {
$(this).addClass("ui-dialog-resizing");
(options.resizeStart && options.resizeStart.apply(self.element[0], arguments));
self._trigger('resizeStart', event);
},
resize: function() {
(options.resize && options.resize.apply(self.element[0], arguments));
resize: function(event) {
self._trigger('resize', event);
},
handles: resizeHandles,
stop: function() {
stop: function(event) {
$(this).removeClass("ui-dialog-resizing");
options.height = $(this).height();
options.width = $(this).width();
(options.resizeStop && options.resizeStop.apply(self.element[0], arguments));
self._trigger('resizeStop', event);
$.ui.dialog.overlay.resize();
}
})

0 comments on commit 2ebc73e

Please sign in to comment.
You can’t perform that action at this time.