2015-04-06 16:42:49 +00:00
|
|
|
define( [
|
2016-04-03 16:21:57 +00:00
|
|
|
"qunit",
|
2015-04-06 16:42:49 +00:00
|
|
|
"jquery",
|
2020-05-16 07:16:24 +00:00
|
|
|
"lib/helper",
|
2015-04-07 14:55:52 +00:00
|
|
|
"./helper",
|
2015-07-15 01:59:40 +00:00
|
|
|
"ui/widgets/draggable",
|
2015-07-15 02:03:06 +00:00
|
|
|
"ui/widgets/droppable",
|
2015-07-15 02:05:00 +00:00
|
|
|
"ui/widgets/resizable"
|
2020-05-16 07:16:24 +00:00
|
|
|
], function( QUnit, $, helper, testHelper ) {
|
2021-06-06 22:58:12 +00:00
|
|
|
"use strict";
|
2008-06-06 06:34:09 +00:00
|
|
|
|
2020-05-16 07:16:24 +00:00
|
|
|
QUnit.module( "draggable: core", { afterEach: helper.moduleAfterEach } );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "element types", function( assert ) {
|
2013-01-12 05:33:45 +00:00
|
|
|
var typeNames = (
|
|
|
|
"p,h1,h2,h3,h4,h5,h6,blockquote,ol,ul,dl,div,form" +
|
|
|
|
",table,fieldset,address,ins,del,em,strong,q,cite,dfn,abbr" +
|
|
|
|
",acronym,code,samp,kbd,var,img,hr" +
|
|
|
|
",input,button,label,select,iframe"
|
2015-08-24 12:59:44 +00:00
|
|
|
).split( "," );
|
2008-06-07 06:09:04 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.expect( typeNames.length * 2 );
|
2012-10-30 23:12:17 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
$.each( typeNames, function( i ) {
|
2012-11-03 20:17:16 +00:00
|
|
|
var offsetBefore, offsetAfter,
|
2013-01-12 05:33:45 +00:00
|
|
|
typeName = typeNames[ i ],
|
2015-08-24 12:59:44 +00:00
|
|
|
el = $( document.createElement( typeName ) ).appendTo( "#qunit-fixture" );
|
2013-01-12 05:33:45 +00:00
|
|
|
|
|
|
|
if ( typeName === "table" ) {
|
2015-08-24 12:59:44 +00:00
|
|
|
el.append( "<tr><td>content</td></tr>" );
|
2013-01-12 05:33:45 +00:00
|
|
|
}
|
2012-11-03 20:17:16 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
el.draggable( { cancel: "" } );
|
2012-10-30 23:12:17 +00:00
|
|
|
offsetBefore = el.offset();
|
2012-12-09 02:27:37 +00:00
|
|
|
el.simulate( "drag", {
|
|
|
|
dx: 50,
|
|
|
|
dy: 50
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2012-11-03 20:17:16 +00:00
|
|
|
offsetAfter = el.offset();
|
2013-01-12 05:33:45 +00:00
|
|
|
|
2024-04-30 22:54:19 +00:00
|
|
|
// Support: Firefox, Chrome
|
|
|
|
// There are some rounding errors, so we can't say equal, we have to settle for close enough
|
2015-03-31 20:52:28 +00:00
|
|
|
assert.close( offsetBefore.left, offsetAfter.left - 50, 1, "dragged[50, 50] " + "<" + typeName + "> left" );
|
|
|
|
assert.close( offsetBefore.top, offsetAfter.top - 50, 1, "dragged[50, 50] " + "<" + typeName + "> top" );
|
2015-08-24 12:59:44 +00:00
|
|
|
el.draggable( "destroy" );
|
2008-06-07 06:09:04 +00:00
|
|
|
el.remove();
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
|
|
|
} );
|
2008-06-07 06:09:04 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "No options, relative", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
|
|
|
testHelper.shouldMove( assert, $( "#draggable1" ).draggable(), "no options, relative" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2008-06-04 02:34:33 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "No options, absolute", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
|
|
|
testHelper.shouldMove( assert, $( "#draggable2" ).draggable(), "no options, absolute" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2008-06-04 02:34:33 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "resizable handle with complex markup (#8756 / #8757)", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2012-11-19 14:06:36 +00:00
|
|
|
|
2013-03-26 13:18:58 +00:00
|
|
|
$( "#draggable1" )
|
2012-11-19 14:06:36 +00:00
|
|
|
.append(
|
2015-08-24 12:59:44 +00:00
|
|
|
$( "<div>" )
|
|
|
|
.addClass( "ui-resizable-handle ui-resizable-w" )
|
|
|
|
.append( $( "<div>" ) )
|
2012-11-19 14:06:36 +00:00
|
|
|
);
|
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
var handle = $( ".ui-resizable-w div" ),
|
|
|
|
target = $( "#draggable1" ).draggable().resizable( { handles: "all" } );
|
2012-11-19 14:06:36 +00:00
|
|
|
|
2015-08-21 04:11:02 +00:00
|
|
|
// Todo: fix resizable so it doesn't require a mouseover
|
2015-08-24 12:59:44 +00:00
|
|
|
handle.simulate( "mouseover" ).simulate( "drag", { dx: -50 } );
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( target.width(), 250, "compare width" );
|
2012-11-19 14:06:36 +00:00
|
|
|
|
2015-08-21 04:11:02 +00:00
|
|
|
// Todo: fix resizable so it doesn't require a mouseover
|
2015-08-24 12:59:44 +00:00
|
|
|
handle.simulate( "mouseover" ).simulate( "drag", { dx: 50 } );
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( target.width(), 200, "compare width" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2012-11-19 14:06:36 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "#8269: Removing draggable element on drop", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2013-03-26 13:18:00 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
var element = $( "#draggable1" ).wrap( "<div id='wrapper' />" ).draggable( {
|
2013-03-27 20:47:57 +00:00
|
|
|
stop: function() {
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.ok( true, "stop still called despite element being removed from DOM on drop" );
|
2013-03-27 20:47:57 +00:00
|
|
|
}
|
2015-08-24 12:59:44 +00:00
|
|
|
} ),
|
2013-03-26 13:18:00 +00:00
|
|
|
dropOffset = $( "#droppable" ).offset();
|
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
$( "#droppable" ).droppable( {
|
2013-03-26 13:18:00 +00:00
|
|
|
drop: function() {
|
|
|
|
$( "#wrapper" ).remove();
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.ok( true, "element removed from DOM on drop" );
|
2013-03-26 13:18:00 +00:00
|
|
|
}
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-03-26 13:18:00 +00:00
|
|
|
|
2021-04-09 21:36:00 +00:00
|
|
|
element.simulate( "drag", {
|
|
|
|
handle: "corner",
|
|
|
|
x: dropOffset.left,
|
|
|
|
y: dropOffset.top
|
|
|
|
} );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-03-26 13:18:00 +00:00
|
|
|
|
2024-04-26 14:25:34 +00:00
|
|
|
// https://bugs.jqueryui.com/ticket/7778
|
2014-08-19 19:09:28 +00:00
|
|
|
// drag element breaks in IE8 when its content is replaced onmousedown
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "Stray mousemove after mousedown still drags", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2014-08-19 19:09:28 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
var element = $( "#draggable1" ).draggable( { scroll: false } );
|
2014-08-19 19:09:28 +00:00
|
|
|
|
|
|
|
// In IE8, when content is placed under the mouse (e.g. when draggable content is replaced
|
|
|
|
// on mousedown), mousemove is triggered on those elements even though the mouse hasn't moved.
|
2015-05-14 01:57:47 +00:00
|
|
|
element.on( "mousedown", function() {
|
2015-08-24 12:59:44 +00:00
|
|
|
$( document ).simulate( "mousemove", { button: -1 } );
|
|
|
|
} );
|
2014-08-19 19:09:28 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
testHelper.shouldMove( assert, element, "element is draggable" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2014-08-19 19:09:28 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "#6258: not following mouse when scrolled and using overflow-y: scroll", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2013-04-02 13:08:17 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
var element = $( "#draggable1" ).draggable( {
|
2013-04-02 13:08:17 +00:00
|
|
|
stop: function( event, ui ) {
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( ui.position.left, 1, "left position is correct despite overflow on HTML" );
|
|
|
|
assert.equal( ui.position.top, 1, "top position is correct despite overflow on HTML" );
|
2013-04-02 13:08:17 +00:00
|
|
|
$( "html" )
|
|
|
|
.css( "overflow-y", oldOverflowY )
|
|
|
|
.css( "overflow-x", oldOverflowX )
|
|
|
|
.scrollTop( 0 )
|
|
|
|
.scrollLeft( 0 );
|
|
|
|
}
|
2015-08-24 12:59:44 +00:00
|
|
|
} ),
|
2013-04-02 13:08:17 +00:00
|
|
|
oldOverflowY = $( "html" ).css( "overflow-y" ),
|
|
|
|
oldOverflowX = $( "html" ).css( "overflow-x" );
|
|
|
|
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.forceScrollableWindow();
|
2013-10-19 15:12:35 +00:00
|
|
|
|
2013-04-02 13:08:17 +00:00
|
|
|
$( "html" )
|
|
|
|
.css( "overflow-y", "scroll" )
|
|
|
|
.css( "overflow-x", "scroll" )
|
|
|
|
.scrollTop( 300 )
|
|
|
|
.scrollLeft( 300 );
|
|
|
|
|
|
|
|
element.simulate( "drag", {
|
|
|
|
dx: 1,
|
|
|
|
dy: 1,
|
|
|
|
moves: 1
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
|
|
|
} );
|
2013-04-02 13:08:17 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "#9315: jumps down with offset of scrollbar", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2013-08-12 23:31:39 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
var element = $( "#draggable2" ).draggable( {
|
2013-08-12 23:31:39 +00:00
|
|
|
stop: function( event, ui ) {
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( ui.position.left, 11, "left position is correct when position is absolute" );
|
|
|
|
assert.equal( ui.position.top, 11, "top position is correct when position is absolute" );
|
2013-08-12 23:31:39 +00:00
|
|
|
$( "html" ).scrollTop( 0 ).scrollLeft( 0 );
|
|
|
|
}
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-08-12 23:31:39 +00:00
|
|
|
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.forceScrollableWindow();
|
2013-10-19 15:12:35 +00:00
|
|
|
|
2013-08-12 23:31:39 +00:00
|
|
|
$( "html" ).scrollTop( 300 ).scrollLeft( 300 );
|
|
|
|
|
|
|
|
element.simulate( "drag", {
|
|
|
|
dx: 1,
|
|
|
|
dy: 1,
|
|
|
|
moves: 1
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
|
|
|
} );
|
2013-08-12 23:31:39 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "scroll offset with fixed ancestors", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2013-04-03 16:26:39 +00:00
|
|
|
|
|
|
|
var startValue = 300,
|
2014-08-23 19:34:04 +00:00
|
|
|
element = $( "#draggable1" )
|
2015-08-24 12:59:44 +00:00
|
|
|
|
2024-04-26 14:25:34 +00:00
|
|
|
// https://bugs.jqueryui.com/ticket/5009
|
2014-08-23 19:34:04 +00:00
|
|
|
// scroll not working with parent's position fixed
|
|
|
|
.wrap( "<div id='wrapper' />" )
|
2015-08-24 12:59:44 +00:00
|
|
|
|
2024-04-26 14:25:34 +00:00
|
|
|
// https://bugs.jqueryui.com/ticket/9612
|
2014-08-23 19:34:04 +00:00
|
|
|
// abspos elements inside of fixed elements moving away from the mouse when scrolling
|
|
|
|
.wrap( "<div id='wrapper2' />" )
|
2015-08-24 12:59:44 +00:00
|
|
|
.draggable( {
|
2014-08-23 19:34:04 +00:00
|
|
|
drag: function() {
|
|
|
|
startValue += 100;
|
|
|
|
$( document ).scrollTop( startValue ).scrollLeft( startValue );
|
|
|
|
},
|
|
|
|
stop: function( event, ui ) {
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( ui.position.left, 10, "left position is correct when parent position is fixed" );
|
|
|
|
assert.equal( ui.position.top, 10, "top position is correct when parent position is fixed" );
|
2014-08-23 19:34:04 +00:00
|
|
|
$( document ).scrollTop( 0 ).scrollLeft( 0 );
|
|
|
|
}
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-04-03 16:26:39 +00:00
|
|
|
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.forceScrollableWindow();
|
2013-10-19 15:12:35 +00:00
|
|
|
|
2013-04-03 16:26:39 +00:00
|
|
|
$( "#wrapper" ).css( "position", "fixed" );
|
2014-08-23 19:34:04 +00:00
|
|
|
$( "#wrapper2" ).css( "position", "absolute" );
|
2013-04-03 16:26:39 +00:00
|
|
|
|
|
|
|
element.simulate( "drag", {
|
|
|
|
dx: 10,
|
|
|
|
dy: 10,
|
|
|
|
moves: 3
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
|
|
|
} );
|
2013-04-03 16:26:39 +00:00
|
|
|
|
2015-08-24 12:59:44 +00:00
|
|
|
$( [ "hidden", "auto", "scroll" ] ).each( function() {
|
2014-08-10 03:00:58 +00:00
|
|
|
var overflow = this;
|
|
|
|
|
2024-04-26 15:28:11 +00:00
|
|
|
// https://bugs.jqueryui.com/ticket/9379 - position bug in scrollable div
|
2024-04-26 14:25:34 +00:00
|
|
|
// https://bugs.jqueryui.com/ticket/10147 - Wrong position in a parent with "overflow: hidden"
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "position in scrollable parent with overflow: " + overflow, function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2014-08-10 03:00:58 +00:00
|
|
|
|
|
|
|
$( "#qunit-fixture" ).html( "<div id='outer'><div id='inner'></div><div id='dragged'>a</div></div>" );
|
2015-08-24 12:59:44 +00:00
|
|
|
$( "#inner" ).css( { position: "absolute", width: "500px", height: "500px" } );
|
|
|
|
$( "#outer" ).css( { position: "absolute", width: "300px", height: "300px" } );
|
|
|
|
$( "#dragged" ).css( { width: "10px", height: "10px" } );
|
2014-08-10 03:00:58 +00:00
|
|
|
|
|
|
|
var moves = 3,
|
|
|
|
startValue = 0,
|
|
|
|
dragDelta = 20,
|
|
|
|
delta = 100,
|
|
|
|
|
2015-08-21 04:11:02 +00:00
|
|
|
// We scroll after each drag event, so subtract 1 from number of moves for expected
|
2014-08-10 03:00:58 +00:00
|
|
|
expected = delta + ( ( moves - 1 ) * dragDelta ),
|
2015-08-24 12:59:44 +00:00
|
|
|
element = $( "#dragged" ).draggable( {
|
2014-08-10 03:00:58 +00:00
|
|
|
drag: function() {
|
|
|
|
startValue += dragDelta;
|
|
|
|
$( "#outer" ).scrollTop( startValue ).scrollLeft( startValue );
|
|
|
|
},
|
|
|
|
stop: function( event, ui ) {
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( ui.position.left, expected, "left position is correct when grandparent is scrolled" );
|
|
|
|
assert.equal( ui.position.top, expected, "top position is correct when grandparent is scrolled" );
|
2014-08-10 03:00:58 +00:00
|
|
|
}
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2014-08-10 03:00:58 +00:00
|
|
|
|
|
|
|
$( "#outer" ).css( "overflow", overflow );
|
2013-10-29 22:35:42 +00:00
|
|
|
|
2014-08-10 03:00:58 +00:00
|
|
|
element.simulate( "drag", {
|
|
|
|
dy: delta,
|
|
|
|
dx: delta,
|
|
|
|
moves: moves
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
|
|
|
} );
|
|
|
|
} );
|
2013-10-29 22:35:42 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "#5727: draggable from iframe", function( assert ) {
|
|
|
|
assert.expect( 1 );
|
2010-06-14 15:20:03 +00:00
|
|
|
|
2013-12-14 22:38:33 +00:00
|
|
|
var iframeBody, draggable1,
|
|
|
|
iframe = $( "<iframe />" ).appendTo( "#qunit-fixture" ),
|
|
|
|
iframeDoc = ( iframe[ 0 ].contentWindow || iframe[ 0 ].contentDocument ).document;
|
|
|
|
|
|
|
|
iframeDoc.write( "<!doctype html><html><body>" );
|
|
|
|
iframeDoc.close();
|
|
|
|
|
|
|
|
iframeBody = $( iframeDoc.body ).append( "<div style='width: 2px; height: 2px;' />" );
|
|
|
|
draggable1 = iframeBody.find( "div" );
|
2010-06-14 15:20:03 +00:00
|
|
|
|
|
|
|
draggable1.draggable();
|
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.equal( draggable1.closest( iframeBody ).length, 1 );
|
2010-06-14 15:20:03 +00:00
|
|
|
|
2013-10-21 14:59:54 +00:00
|
|
|
// TODO: fix draggable within an IFRAME to fire events on the element properly
|
2015-04-07 14:30:07 +00:00
|
|
|
// and these testHelper.shouldMove relies on events for testing
|
2016-04-03 16:21:57 +00:00
|
|
|
//testHelper.shouldMove( assert, draggable1, "draggable from an iframe" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2010-06-14 15:20:03 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "#8399: A draggable should become the active element after you are finished interacting with it, but not before.", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2013-05-02 19:07:34 +00:00
|
|
|
|
|
|
|
var element = $( "<a href='#'>link</a>" ).appendTo( "#qunit-fixture" ).draggable();
|
|
|
|
|
|
|
|
$( document ).one( "mousemove", function() {
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.notStrictEqual( document.activeElement, element.get( 0 ), "moving a draggable anchor did not make it the active element" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-05-02 19:07:34 +00:00
|
|
|
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.move( element, 50, 50 );
|
2013-05-02 19:07:34 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.strictEqual( document.activeElement, element.get( 0 ), "finishing moving a draggable anchor made it the active element" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-05-02 19:07:34 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "blur behavior - handle is main element", function( assert ) {
|
|
|
|
var ready = assert.async();
|
|
|
|
assert.expect( 3 );
|
2014-08-16 13:44:05 +00:00
|
|
|
|
|
|
|
var element = $( "#draggable1" ).draggable(),
|
|
|
|
focusElement = $( "<div tabindex='1'></div>" ).appendTo( element );
|
|
|
|
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.onFocus( focusElement, function() {
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.strictEqual( document.activeElement, focusElement.get( 0 ), "test element is focused before mousing down on a draggable" );
|
2013-05-01 22:01:32 +00:00
|
|
|
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.move( focusElement, 1, 1 );
|
2013-05-01 22:01:32 +00:00
|
|
|
|
2024-04-26 15:28:11 +00:00
|
|
|
// https://bugs.jqueryui.com/ticket/10527
|
2014-08-16 13:44:05 +00:00
|
|
|
// Draggable: Can't select option in modal dialog (IE8)
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.strictEqual( document.activeElement, focusElement.get( 0 ), "test element is focused after mousing down on itself" );
|
2013-05-01 22:01:32 +00:00
|
|
|
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.move( element, 50, 50 );
|
2013-05-01 22:01:32 +00:00
|
|
|
|
2024-04-26 15:28:11 +00:00
|
|
|
// https://bugs.jqueryui.com/ticket/4261
|
2014-08-16 13:44:05 +00:00
|
|
|
// active element should blur when mousing down on a draggable
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.notStrictEqual( document.activeElement, focusElement.get( 0 ), "test element is no longer focused after mousing down on a draggable" );
|
|
|
|
ready();
|
2015-05-05 13:29:21 +00:00
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "blur behavior - descendant of handle", function( assert ) {
|
|
|
|
var ready = assert.async();
|
|
|
|
assert.expect( 2 );
|
2015-05-05 13:29:21 +00:00
|
|
|
|
|
|
|
var element = $( "#draggable2" ).draggable( { handle: "span" } ),
|
|
|
|
|
|
|
|
// The handle is a descendant, but we also want to grab a descendant of the handle
|
|
|
|
handle = element.find( "span em" ),
|
|
|
|
focusElement = $( "<div tabindex='1'></div>" ).appendTo( element );
|
|
|
|
|
|
|
|
testHelper.onFocus( focusElement, function() {
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.strictEqual( document.activeElement, focusElement.get( 0 ), "test element is focused before mousing down on a draggable" );
|
2015-05-05 13:29:21 +00:00
|
|
|
|
|
|
|
testHelper.move( handle, 50, 50 );
|
|
|
|
|
|
|
|
// Elements outside of the handle should blur (#12472, #14905)
|
2016-04-03 16:21:57 +00:00
|
|
|
assert.notStrictEqual( document.activeElement, focusElement.get( 0 ), "test element is no longer focused after mousing down on a draggable" );
|
|
|
|
ready();
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
|
|
|
} );
|
2013-05-01 22:01:32 +00:00
|
|
|
|
2016-08-16 23:52:15 +00:00
|
|
|
QUnit.test( "blur behavior - off handle", function( assert ) {
|
|
|
|
var ready = assert.async();
|
|
|
|
assert.expect( 3 );
|
|
|
|
|
|
|
|
var element = $( "#draggable2" ).draggable( { handle: "span" } ),
|
|
|
|
focusElement = $( "<div tabindex='1'></div>" ).appendTo( element );
|
|
|
|
|
2024-04-30 22:54:19 +00:00
|
|
|
// Mock $.ui.trigger with a spy
|
|
|
|
var _trigger = $.fn.trigger;
|
2016-08-16 23:52:15 +00:00
|
|
|
var blurCalledCount = 0;
|
2024-04-30 22:54:19 +00:00
|
|
|
$.fn.trigger = function( eventName ) {
|
|
|
|
if ( eventName === "blur" ) {
|
|
|
|
blurCalledCount++;
|
|
|
|
}
|
2016-08-16 23:52:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
testHelper.onFocus( focusElement, function() {
|
|
|
|
assert.strictEqual( document.activeElement, focusElement.get( 0 ), "test element is focused before mousing down on a draggable" );
|
|
|
|
|
|
|
|
testHelper.move( element, 1, 1 );
|
|
|
|
assert.strictEqual( blurCalledCount, 0, "draggable doesn't blur when mousing down off handle" );
|
|
|
|
|
|
|
|
testHelper.move( element.find( "span" ), 1, 1 );
|
|
|
|
assert.strictEqual( blurCalledCount, 1, "draggable blurs when mousing down on handle" );
|
|
|
|
|
2024-04-30 22:54:19 +00:00
|
|
|
// Restore trigger
|
|
|
|
$.fn.trigger = _trigger;
|
2016-08-16 23:52:15 +00:00
|
|
|
|
|
|
|
ready();
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "ui-draggable-handle assigned to appropriate element", function( assert ) {
|
|
|
|
assert.expect( 5 );
|
2013-12-13 03:10:06 +00:00
|
|
|
|
2014-07-15 17:38:00 +00:00
|
|
|
var p = $( "<p>" ).appendTo( "#qunit-fixture" ),
|
|
|
|
element = $( "<div><p></p></div>" ).appendTo( "#qunit-fixture" ).draggable();
|
2015-01-30 14:57:30 +00:00
|
|
|
assert.hasClasses( element, "ui-draggable-handle" );
|
2013-12-13 03:10:06 +00:00
|
|
|
|
|
|
|
element.draggable( "option", "handle", "p" );
|
2015-01-30 14:57:30 +00:00
|
|
|
assert.lacksClasses( element, "ui-draggable-handle" );
|
|
|
|
assert.hasClasses( element.find( "p" ), "ui-draggable-handle",
|
2014-07-15 17:38:00 +00:00
|
|
|
"ensure handle class name is constrained within the draggble (#10212)" );
|
2015-01-30 14:57:30 +00:00
|
|
|
assert.lacksClasses( p, "ui-draggable-handle" );
|
2014-07-15 17:38:00 +00:00
|
|
|
|
2013-12-13 03:10:06 +00:00
|
|
|
element.draggable( "destroy" );
|
2015-01-30 14:57:30 +00:00
|
|
|
assert.lacksClasses( element.find( "p" ), "ui-draggable-handle" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2013-12-13 03:10:06 +00:00
|
|
|
|
2016-04-03 16:21:57 +00:00
|
|
|
QUnit.test( "ui-draggable-handle managed correctly in nested draggables", function( assert ) {
|
|
|
|
assert.expect( 4 );
|
2014-07-15 19:16:26 +00:00
|
|
|
var parent = $( "<div><div></div></div>" ).draggable().appendTo( "#qunit-fixture" ),
|
|
|
|
child = parent.find( "div" ).draggable();
|
|
|
|
|
2015-01-30 14:57:30 +00:00
|
|
|
assert.hasClasses( parent, "ui-draggable-handle", "parent has class name on init" );
|
|
|
|
assert.hasClasses( child, "ui-draggable-handle", "child has class name on init" );
|
2014-07-15 19:16:26 +00:00
|
|
|
|
|
|
|
parent.draggable( "destroy" );
|
2015-01-30 14:57:30 +00:00
|
|
|
assert.lacksClasses( parent, "ui-draggable-handle", "parent loses class name on destroy" );
|
|
|
|
assert.hasClasses( child, "ui-draggable-handle", "child retains class name on destroy" );
|
2015-08-24 12:59:44 +00:00
|
|
|
} );
|
2014-07-15 19:16:26 +00:00
|
|
|
|
2024-04-30 22:54:19 +00:00
|
|
|
QUnit.test( "does not stop propagation to window", function( assert ) {
|
|
|
|
assert.expect( 1 );
|
|
|
|
var element = $( "#draggable1" ).draggable();
|
2015-10-26 19:10:43 +00:00
|
|
|
|
2024-04-30 22:54:19 +00:00
|
|
|
var handler = function() {
|
|
|
|
assert.ok( true, "mouseup propagates to window" );
|
|
|
|
};
|
|
|
|
$( window ).on( "mouseup", handler );
|
2015-10-18 16:36:43 +00:00
|
|
|
|
2024-04-30 22:54:19 +00:00
|
|
|
element.simulate( "drag", {
|
|
|
|
dx: 10,
|
|
|
|
dy: 10
|
|
|
|
} );
|
2015-10-18 16:36:43 +00:00
|
|
|
|
2024-04-30 22:54:19 +00:00
|
|
|
$( window ).off( "mouseup", handler );
|
|
|
|
} );
|
2015-10-18 16:36:43 +00:00
|
|
|
|
2015-04-06 16:42:49 +00:00
|
|
|
} );
|