/[projects]/misc/horsensspejder-web/jquery/jquery-ui-1.10.3/tests/unit/draggable/draggable_core.js
ViewVC logotype

Contents of /misc/horsensspejder-web/jquery/jquery-ui-1.10.3/tests/unit/draggable/draggable_core.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2125 - (show annotations) (download) (as text)
Wed Mar 12 19:30:05 2014 UTC (10 years, 3 months ago) by torben
File MIME type: application/javascript
File size: 4593 byte(s)
initial import
1 /*
2 * draggable_core.js
3 */
4
5 (function( $ ) {
6
7 module( "draggable: core" );
8
9 test( "element types", function() {
10 var typeNames = (
11 "p,h1,h2,h3,h4,h5,h6,blockquote,ol,ul,dl,div,form" +
12 ",table,fieldset,address,ins,del,em,strong,q,cite,dfn,abbr" +
13 ",acronym,code,samp,kbd,var,img,hr" +
14 ",input,button,label,select,iframe"
15 ).split(",");
16
17 expect( typeNames.length * 2 );
18
19 $.each( typeNames, function( i ) {
20 var offsetBefore, offsetAfter,
21 typeName = typeNames[ i ],
22 el = $( document.createElement( typeName ) ).appendTo("#qunit-fixture");
23
24 if ( typeName === "table" ) {
25 el.append("<tr><td>content</td></tr>");
26 }
27
28 el.draggable({ cancel: "" });
29 offsetBefore = el.offset();
30 el.simulate( "drag", {
31 dx: 50,
32 dy: 50
33 });
34 offsetAfter = el.offset();
35
36 // Support: FF, Chrome, and IE9,
37 // there are some rounding errors in so we can't say equal, we have to settle for close enough
38 closeEnough( offsetBefore.left, offsetAfter.left - 50, 1, "dragged[50, 50] " + "<" + typeName + ">" );
39 closeEnough( offsetBefore.top, offsetAfter.top - 50, 1, "dragged[50, 50] " + "<" + typeName + ">" );
40 el.draggable("destroy");
41 el.remove();
42 });
43 });
44
45 test( "No options, relative", function() {
46 expect( 1 );
47 TestHelpers.draggable.shouldMove( $( "#draggable1" ).draggable() );
48 });
49
50 test( "No options, absolute", function() {
51 expect( 1 );
52 TestHelpers.draggable.shouldMove( $( "#draggable2" ).draggable() );
53 });
54
55 test( "resizable handle with complex markup (#8756 / #8757)", function() {
56 expect( 2 );
57
58 $( "#draggable1" )
59 .append(
60 $("<div>")
61 .addClass("ui-resizable-handle ui-resizable-w")
62 .append( $("<div>") )
63 );
64
65 var handle = $(".ui-resizable-w div"),
66 target = $( "#draggable1" ).draggable().resizable({ handles: "all" });
67
68 // todo: fix resizable so it doesn't require a mouseover
69 handle.simulate("mouseover").simulate( "drag", { dx: -50 } );
70 equal( target.width(), 250, "compare width" );
71
72 // todo: fix resizable so it doesn't require a mouseover
73 handle.simulate("mouseover").simulate( "drag", { dx: 50 } );
74 equal( target.width(), 200, "compare width" );
75 });
76
77 test( "#8269: Removing draggable element on drop", function() {
78 expect( 1 );
79
80 var element = $( "#draggable1" ).wrap( "<div id='wrapper' />" ).draggable(),
81 dropOffset = $( "#droppable" ).offset();
82
83 $( "#droppable" ).droppable({
84 drop: function() {
85 $( "#wrapper" ).remove();
86 ok( true, "element removed from DOM on drop" );
87 }
88 });
89
90 // Support: Opera 12.10, Safari 5.1, jQuery <1.8
91 if ( TestHelpers.draggable.unreliableContains ) {
92 ok( true, "Opera <12.14 and Safari <6.0 report wrong values for $.contains in jQuery < 1.8" );
93 } else {
94 element.simulate( "drag", {
95 handle: "corner",
96 x: dropOffset.left,
97 y: dropOffset.top
98 });
99 }
100 });
101
102 test( "#6258: not following mouse when scrolled and using overflow-y: scroll", function() {
103 expect( 2 );
104
105 var element = $( "#draggable1" ).draggable({
106 stop: function( event, ui ) {
107 equal( ui.position.left, 1, "left position is correct despite overflow on HTML" );
108 equal( ui.position.top, 1, "top position is correct despite overflow on HTML" );
109 $( "html" )
110 .css( "overflow-y", oldOverflowY )
111 .css( "overflow-x", oldOverflowX )
112 .scrollTop( 0 )
113 .scrollLeft( 0 );
114 }
115 }),
116 contentToForceScroll = $( "<div>" ).css({
117 height: "10000px",
118 width: "10000px"
119 }),
120 oldOverflowY = $( "html" ).css( "overflow-y" ),
121 oldOverflowX = $( "html" ).css( "overflow-x" );
122
123 contentToForceScroll.appendTo( "#qunit-fixture" );
124 $( "html" )
125 .css( "overflow-y", "scroll" )
126 .css( "overflow-x", "scroll" )
127 .scrollTop( 300 )
128 .scrollLeft( 300 );
129
130 element.simulate( "drag", {
131 dx: 1,
132 dy: 1,
133 moves: 1
134 });
135 });
136
137 test( "#5009: scroll not working with parent's position fixed", function() {
138 expect( 2 );
139
140 var startValue = 300,
141 element = $( "#draggable1" ).wrap( "<div id='wrapper' />" ).draggable({
142 drag: function() {
143 startValue += 100;
144 $( document ).scrollTop( startValue ).scrollLeft( startValue );
145 },
146 stop: function( event, ui ) {
147 equal( ui.position.left, 10, "left position is correct when parent position is fixed" );
148 equal( ui.position.top, 10, "top position is correct when parent position is fixed" );
149 $( document ).scrollTop( 0 ).scrollLeft( 0 );
150 }
151 }),
152 contentToForceScroll = $( "<div>" ).css({
153 height: "20000px",
154 width: "20000px"
155 });
156
157 $( "#qunit-fixture" ).append( contentToForceScroll );
158 $( "#wrapper" ).css( "position", "fixed" );
159
160 element.simulate( "drag", {
161 dx: 10,
162 dy: 10,
163 moves: 3
164 });
165 });
166
167 })( jQuery );

  ViewVC Help
Powered by ViewVC 1.1.20