Add JS files

This commit is contained in:
2025-05-12 15:45:17 +00:00
parent 7ddd15c4fa
commit 967007b0c7
3239 changed files with 1157078 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
TestHelpers.commonWidgetTests( "draggable", {
defaults: {
appendTo: "parent",
axis: false,
cancel: "input,textarea,button,select,option",
connectToSortable: false,
containment: false,
cursor: "auto",
cursorAt: false,
disabled: false,
grid: false,
handle: false,
helper: "original",
opacity: false,
refreshPositions: false,
revert: false,
revertDuration: 500,
scroll: true,
scrollSensitivity: 20,
scrollSpeed: 20,
scope: "default",
snap: false,
snapMode: "both",
snapTolerance: 20,
stack: false,
zIndex: false,
//todo: remove the following option checks when interactions are rewritten:
addClasses: true,
delay: 0,
distance: 1,
iframeFix: false,
// callbacks
create: null,
drag: null,
start: null,
stop: null
}
});

View File

@@ -0,0 +1,168 @@
/*
* draggable_core.js
*/
(function( $ ) {
module( "draggable: core" );
test( "element types", function() {
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"
).split(",");
expect( typeNames.length * 2 );
$.each( typeNames, function( i ) {
var offsetBefore, offsetAfter,
typeName = typeNames[ i ],
el = $( document.createElement( typeName ) ).appendTo("#qunit-fixture");
if ( typeName === "table" ) {
el.append("<tr><td>content</td></tr>");
}
el.draggable({ cancel: "" });
offsetBefore = el.offset();
el.simulate( "drag", {
dx: 50,
dy: 50
});
offsetAfter = el.offset();
// Support: FF, Chrome, and IE9,
// there are some rounding errors in so we can't say equal, we have to settle for close enough
closeEnough( offsetBefore.left, offsetAfter.left - 50, 1, "dragged[50, 50] " + "<" + typeName + ">" );
closeEnough( offsetBefore.top, offsetAfter.top - 50, 1, "dragged[50, 50] " + "<" + typeName + ">" );
el.draggable("destroy");
el.remove();
});
});
test( "No options, relative", function() {
expect( 1 );
TestHelpers.draggable.shouldMove( $( "#draggable1" ).draggable() );
});
test( "No options, absolute", function() {
expect( 1 );
TestHelpers.draggable.shouldMove( $( "#draggable2" ).draggable() );
});
test( "resizable handle with complex markup (#8756 / #8757)", function() {
expect( 2 );
$( "#draggable1" )
.append(
$("<div>")
.addClass("ui-resizable-handle ui-resizable-w")
.append( $("<div>") )
);
var handle = $(".ui-resizable-w div"),
target = $( "#draggable1" ).draggable().resizable({ handles: "all" });
// todo: fix resizable so it doesn't require a mouseover
handle.simulate("mouseover").simulate( "drag", { dx: -50 } );
equal( target.width(), 250, "compare width" );
// todo: fix resizable so it doesn't require a mouseover
handle.simulate("mouseover").simulate( "drag", { dx: 50 } );
equal( target.width(), 200, "compare width" );
});
test( "#8269: Removing draggable element on drop", function() {
expect( 1 );
var element = $( "#draggable1" ).wrap( "<div id='wrapper' />" ).draggable(),
dropOffset = $( "#droppable" ).offset();
$( "#droppable" ).droppable({
drop: function() {
$( "#wrapper" ).remove();
ok( true, "element removed from DOM on drop" );
}
});
// Support: Opera 12.10, Safari 5.1, jQuery <1.8
if ( TestHelpers.draggable.unreliableContains ) {
ok( true, "Opera <12.14 and Safari <6.0 report wrong values for $.contains in jQuery < 1.8" );
ok( true, "Opera <12.14 and Safari <6.0 report wrong values for $.contains in jQuery < 1.8" );
} else {
element.simulate( "drag", {
handle: "corner",
x: dropOffset.left,
y: dropOffset.top
});
}
});
test( "#6258: not following mouse when scrolled and using overflow-y: scroll", function() {
expect( 2 );
var element = $( "#draggable1" ).draggable({
stop: function( event, ui ) {
equal( ui.position.left, 1, "left position is correct despite overflow on HTML" );
equal( ui.position.top, 1, "top position is correct despite overflow on HTML" );
$( "html" )
.css( "overflow-y", oldOverflowY )
.css( "overflow-x", oldOverflowX )
.scrollTop( 0 )
.scrollLeft( 0 );
}
}),
contentToForceScroll = $( "<div>" ).css({
height: "10000px",
width: "10000px"
}),
oldOverflowY = $( "html" ).css( "overflow-y" ),
oldOverflowX = $( "html" ).css( "overflow-x" );
contentToForceScroll.appendTo( "#qunit-fixture" );
$( "html" )
.css( "overflow-y", "scroll" )
.css( "overflow-x", "scroll" )
.scrollTop( 300 )
.scrollLeft( 300 );
element.simulate( "drag", {
dx: 1,
dy: 1,
moves: 1
});
});
test( "#5009: scroll not working with parent's position fixed", function() {
expect( 2 );
var startValue = 300,
element = $( "#draggable1" ).wrap( "<div id='wrapper' />" ).draggable({
drag: function() {
startValue += 100;
$( document ).scrollTop( startValue ).scrollLeft( startValue );
},
stop: function( event, ui ) {
equal( ui.position.left, 10, "left position is correct when parent position is fixed" );
equal( ui.position.top, 10, "top position is correct when parent position is fixed" );
$( document ).scrollTop( 0 ).scrollLeft( 0 );
}
}),
contentToForceScroll = $( "<div>" ).css({
height: "20000px",
width: "20000px"
});
$( "#qunit-fixture" ).append( contentToForceScroll );
$( "#wrapper" ).css( "position", "fixed" );
element.simulate( "drag", {
dx: 10,
dy: 10,
moves: 3
});
});
})( jQuery );

View File

@@ -0,0 +1,125 @@
/*
* draggable_events.js
*/
(function( $ ) {
var element;
module( "draggable: events", {
setup: function() {
element = $("<div>").appendTo("#qunit-fixture");
},
teardown: function() {
element.draggable("destroy");
}
});
test( "callbacks occurrence count", function() {
expect( 3 );
var start = 0,
stop = 0,
dragc = 0;
element.draggable({
start: function() {
start++;
},
drag: function() {
dragc++;
},
stop: function() {
stop++;
}
});
element.simulate( "drag", {
dx: 10,
dy: 10
});
equal( start, 1, "start callback should happen exactly once" );
equal( dragc, 3, "drag callback should happen exactly once per mousemove" );
equal( stop, 1, "stop callback should happen exactly once" );
});
test( "stopping the start callback", function() {
expect( 3 );
var start = 0,
stop = 0,
dragc = 0;
element.draggable({
start: function() {
start++;
return false;
},
drag: function() {
dragc++;
},
stop: function() {
stop++;
}
});
element.simulate( "drag", {
dx: 10,
dy: 10
});
equal( start, 1, "start callback should happen exactly once" );
equal( dragc, 0, "drag callback should not happen at all" );
equal( stop, 0, "stop callback should not happen if there wasnt even a start" );
});
test( "stopping the drag callback", function() {
expect( 2 );
var start = 0,
stop = 0,
dragc = 0;
element.draggable({
start: function() {
start++;
},
drag: function() {
dragc++;
return false;
},
stop: function() {
stop++;
}
});
element.simulate( "drag", {
dx: 10,
dy: 10
});
equal( start, 1, "start callback should happen exactly once" );
equal( stop, 1, "stop callback should happen, as we need to actively stop the drag" );
});
test( "stopping the stop callback", function() {
expect( 1 );
element.draggable({
helper: "clone",
stop: function() {
return false;
}
});
element.simulate( "drag", {
dx: 10,
dy: 10
});
ok( element.data("ui-draggable").helper, "the clone should not be deleted if the stop callback is stopped" );
});
})( jQuery );

View File

@@ -0,0 +1,99 @@
/*
* draggable_methods.js
*/
(function( $ ) {
var element;
module( "draggable: methods", {
setup: function() {
element = $("<div style='background: green; width: 200px; height: 100px; position: absolute; top: 10px; left: 10px;'><span>Absolute</span></div>").appendTo("#qunit-fixture");
},
teardown: function() {
element.remove();
}
});
test( "init", function() {
expect( 5 );
element.draggable();
ok( true, ".draggable() called on element" );
$([]).draggable();
ok( true, ".draggable() called on empty collection" );
$("<div></div>").draggable();
ok( true, ".draggable() called on disconnected DOMElement" );
element.draggable( "option", "foo" );
ok( true, "arbitrary option getter after init" );
element.draggable( "option", "foo", "bar" );
ok( true, "arbitrary option setter after init" );
});
test( "destroy", function() {
expect( 4 );
element.draggable().draggable("destroy");
ok( true, ".draggable('destroy') called on element" );
$([]).draggable().draggable("destroy");
ok( true, ".draggable('destroy') called on empty collection" );
element.draggable().draggable("destroy");
ok( true, ".draggable('destroy') called on disconnected DOMElement" );
var expected = element.draggable(),
actual = expected.draggable("destroy");
equal( actual, expected, "destroy is chainable" );
});
test( "enable", function() {
expect( 7 );
element.draggable({ disabled: true });
TestHelpers.draggable.shouldNotMove( element, ".draggable({ disabled: true })" );
element.draggable("enable");
TestHelpers.draggable.shouldMove( element, ".draggable('enable')" );
equal( element.draggable( "option", "disabled" ), false, "disabled option getter" );
element.draggable("destroy");
element.draggable({ disabled: true });
TestHelpers.draggable.shouldNotMove( element, ".draggable({ disabled: true })" );
element.draggable( "option", "disabled", false );
equal(element.draggable( "option", "disabled" ), false, "disabled option setter" );
TestHelpers.draggable.shouldMove( element, ".draggable('option', 'disabled', false)" );
var expected = element.draggable(),
actual = expected.draggable("enable");
equal( actual, expected, "enable is chainable" );
});
test( "disable", function() {
expect( 7 );
element = $("#draggable2").draggable({ disabled: false });
TestHelpers.draggable.shouldMove( element, ".draggable({ disabled: false })" );
element.draggable("disable");
TestHelpers.draggable.shouldNotMove( element, ".draggable('disable')" );
equal( element.draggable( "option", "disabled" ), true, "disabled option getter" );
element.draggable("destroy");
element.draggable({ disabled: false });
TestHelpers.draggable.shouldMove( element, ".draggable({ disabled: false })" );
element.draggable( "option", "disabled", true );
equal( element.draggable( "option", "disabled" ), true, "disabled option setter" );
TestHelpers.draggable.shouldNotMove( element, ".draggable('option', 'disabled', true)" );
var expected = element.draggable(),
actual = expected.draggable("disable");
equal( actual, expected, "disable is chainable" );
});
})( jQuery );

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,79 @@
TestHelpers.draggable = {
// TODO: remove the unreliable offset hacks
unreliableOffset: $.ui.ie && ( !document.documentMode || document.documentMode < 8 ) ? 2 : 0,
// Support: Opera 12.10, Safari 5.1, jQuery <1.8
unreliableContains: (function(){
var element = $( "<div>" );
return $.contains( element[ 0 ].ownerDocument, element[ 0 ] );
})(),
testDrag: function( el, handle, dx, dy, expectedDX, expectedDY, msg ) {
var offsetAfter, actual, expected,
offsetBefore = el.offset();
$( handle ).simulate( "drag", {
dx: dx,
dy: dy
});
offsetAfter = el.offset();
actual = { left: offsetAfter.left, top: offsetAfter.top };
expected = { left: offsetBefore.left + expectedDX, top: offsetBefore.top + expectedDY };
msg = msg ? msg + "." : "";
deepEqual( actual, expected, "dragged[" + dx + ", " + dy + "] " + msg );
},
shouldMove: function( el, why ) {
TestHelpers.draggable.testDrag( el, el, 50, 50, 50, 50, why );
},
shouldNotMove: function( el, why ) {
TestHelpers.draggable.testDrag( el, el, 50, 50, 0, 0, why );
},
testScroll: function( el, position ) {
var oldPosition = $( "#main" ).css( "position" );
$( "#main" ).css( "position", position);
TestHelpers.draggable.shouldMove( el, position + " parent" );
$( "#main" ).css( "position", oldPosition );
},
restoreScroll: function( what ) {
if( what ) {
$( document ).scrollTop( 0 ).scrollLeft( 0 );
} else {
$( "#main" ).scrollTop( 0 ).scrollLeft( 0 );
}
},
setScroll: function( what ) {
if( what ) {
// TODO: currently, the draggable interaction doesn't properly account for scrolled pages,
// uncomment the line below to make the tests fail that should when the page is scrolled
// $( document ).scrollTop( 100 ).scrollLeft( 100 );
} else {
$( "#main" ).scrollTop( 100 ).scrollLeft( 100 );
}
},
border: function( el, side ) {
return parseInt( el.css( "border-" + side + "-width" ), 10 ) || 0;
},
margin: function( el, side ) {
return parseInt( el.css( "margin-" + side ), 10 ) || 0;
},
move: function( el, x, y ) {
$( el ).simulate( "drag", {
dx: x,
dy: y
});
},
trackMouseCss : function( el ) {
el.bind( "drag", function() {
el.data( "last_dragged_cursor", $( "body" ).css( "cursor" ) );
});
},
trackAppendedParent : function( el ) {
// TODO: appendTo is currently ignored if helper is original (see #7044)
el.draggable( "option", "helper", "clone" );
// Get what parent is at time of drag
el.bind( "drag", function(e,ui) {
el.data( "last_dragged_parent", ui.helper.parent()[ 0 ] );
});
}
};