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

add html5 DND events for simulation #24

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion jquery.simulate.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
;(function( $, undefined ) {

var rkeyEvent = /^key/,
rmouseEvent = /^(?:mouse|contextmenu)|click/;
rmouseEvent = /^(?:mouse|contextmenu)|click|drag(?:start|end|over|leave|enter)|drop/;

$.fn.simulate = function( type, options ) {
return this.each(function() {
Expand Down
63 changes: 63 additions & 0 deletions test/unit/simulate.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,69 @@ test( "click on radio triggers change", function() {
notEqual( checked, firstRadio.prop( "checked" ), "radio state changed" );
});

test( "accept dragstart event", function() {
var bindCalled = false
jQuery('<div></div>').bind('dragstart', function(e) {
bindCalled = true
}).simulate('dragstart',{})
equal(bindCalled, true)
});

test( "accept dragenter event", function() {
var bindCalled = false
jQuery('<div></div>').bind('dragenter', function(e) {
bindCalled = true
}).simulate('dragenter',{})
equal(bindCalled, true)
});

test( "accept drageleave event", function() {
var bindCalled = false
jQuery('<div></div>').bind('dragleave', function(e) {
bindCalled = true
}).simulate('dragleave',{})
equal(bindCalled, true)
});

test( "accept drageover event", function() {
var bindCalled = false
jQuery('<div></div>').bind('dragover', function(e) {
bindCalled = true
}).simulate('dragover',{})
equal(bindCalled, true)
});

test( "accept dragend event", function() {
var bindCalled = false
jQuery('<div></div>').bind('dragend', function(e) {
bindCalled = true
}).simulate('dragend',{})
equal(bindCalled, true)
});

test( "accept drop event", function() {
var bindCalled = false
jQuery('<div></div>').bind('drop', function(e) {
bindCalled = true
}).simulate('drop',{})
equal(bindCalled, true)
});

test( "do not accept dragunknown event", function() {
var bindCalled = false
var expectException = false
try {
jQuery('<div></div>').bind('dragunknown', function(e) {
bindCalled = true
}).simulate('dragunknown',{})
} catch (e) {
expectException = true
}
notEqual(bindCalled, true)
equal(expectException, true)
});


var key = jQuery.simulate.keyCode,
keyEvents = [ "keydown", "keyup", "keypress" ],
i = 0;
Expand Down