2
2
* draggable_core.js
3
3
*/
4
4
5
- ( function ( $ ) {
5
+ ( function ( $ ) {
6
6
7
- module ( "draggable" ) ;
7
+ var relativeElement , absoluteElement ;
8
8
9
- test ( "element types" , function ( ) {
10
- var typeNames = ( "p,h1,h2,h3,h4,h5,h6,blockquote,ol,ul,dl,div,form" +
11
- ",table,fieldset,address,ins,del,em,strong,q,cite,dfn,abbr" +
12
- ",acronym,code,samp,kbd,var,img,hr" +
13
- ",input,button,label,select,iframe" ) . split ( "," ) ;
9
+ module ( "draggable: core" , {
10
+ setup : function ( ) {
11
+ relativeElement = $ ( "<div style='width: 200px; height: 100px;'>Relative</div>" ) . appendTo ( "#qunit-fixture" ) ;
12
+ absoluteElement = $ ( "<div style='background: green; width: 200px; height: 100px; position: absolute; top: 10px; left: 10px;'><span>Absolute</span></div>" ) . appendTo ( "#qunit-fixture" ) ;
13
+ } ,
14
+ teardown : function ( ) {
15
+ relativeElement . remove ( ) ;
16
+ absoluteElement . remove ( ) ;
17
+ }
18
+ } ) ;
19
+
20
+ test ( "element types" , function ( ) {
21
+ var typeNames = (
22
+ "p,h1,h2,h3,h4,h5,h6,blockquote,ol,ul,dl,div,form" +
23
+ ",table,fieldset,address,ins,del,em,strong,q,cite,dfn,abbr" +
24
+ ",acronym,code,samp,kbd,var,img,hr" +
25
+ ",input,button,label,select,iframe"
26
+ ) . split ( "," ) ;
14
27
15
28
expect ( typeNames . length * 2 ) ;
16
29
17
- $ . each ( typeNames , function ( i ) {
30
+ $ . each ( typeNames , function ( i ) {
18
31
var offsetBefore , offsetAfter ,
19
- typeName = typeNames [ i ] ,
20
- el = $ ( document . createElement ( typeName ) ) . appendTo ( "#qunit-fixture" ) ;
32
+ typeName = typeNames [ i ] ,
33
+ el = $ ( document . createElement ( typeName ) ) . appendTo ( "#qunit-fixture" ) ;
34
+
35
+ if ( typeName === "table" ) {
36
+ el . append ( "<tr><td>content</td></tr>" ) ;
37
+ }
21
38
22
- ( typeName === "table" && el . append ( "<tr><td>content</td></tr>" ) ) ;
23
39
el . draggable ( { cancel : "" } ) ;
24
40
offsetBefore = el . offset ( ) ;
25
41
el . simulate ( "drag" , {
26
42
dx : 50 ,
27
43
dy : 50
28
44
} ) ;
29
45
offsetAfter = el . offset ( ) ;
30
- // there are some rounding errors in FF, Chrome, and IE9, so we can't say equal, we have to settle for close enough
31
- closeEnough ( offsetBefore . left , offsetAfter . left - 50 , 1 , "dragged[50, 50] " + "<" + typeName + ">" ) ;
32
- closeEnough ( offsetBefore . top , offsetAfter . top - 50 , 1 , "dragged[50, 50] " + "<" + typeName + ">" ) ;
46
+
47
+ // Support: FF, Chrome, and IE9,
48
+ // there are some rounding errors in so we can't say equal, we have to settle for close enough
49
+ closeEnough ( offsetBefore . left , offsetAfter . left - 50 , 1 , "dragged[50, 50] " + "<" + typeName + ">" ) ;
50
+ closeEnough ( offsetBefore . top , offsetAfter . top - 50 , 1 , "dragged[50, 50] " + "<" + typeName + ">" ) ;
33
51
el . draggable ( "destroy" ) ;
34
52
el . remove ( ) ;
35
53
} ) ;
36
54
} ) ;
37
55
38
- test ( "No options, relative" , function ( ) {
56
+ test ( "No options, relative" , function ( ) {
39
57
expect ( 1 ) ;
40
- var el = $ ( "#draggable1" ) . draggable ( ) ;
41
- TestHelpers . draggable . shouldMove ( el ) ;
58
+ TestHelpers . draggable . shouldMove ( relativeElement . draggable ( ) ) ;
42
59
} ) ;
43
60
44
- test ( "No options, absolute" , function ( ) {
61
+ test ( "No options, absolute" , function ( ) {
45
62
expect ( 1 ) ;
46
- var el = $ ( "#draggable2" ) . draggable ( ) ;
47
- TestHelpers . draggable . shouldMove ( el ) ;
63
+ TestHelpers . draggable . shouldMove ( absoluteElement . draggable ( ) ) ;
48
64
} ) ;
49
65
50
- test ( "resizable handle with complex markup (#8756 / #8757)" , function ( ) {
66
+ test ( "resizable handle with complex markup (#8756 / #8757)" , function ( ) {
51
67
expect ( 2 ) ;
52
68
53
- $ ( "#draggable1" )
69
+ relativeElement
54
70
. append (
55
71
$ ( "<div>" )
56
- . addClass ( "ui-resizable-handle" )
57
- . addClass ( "ui-resizable-w" )
58
- . append ( $ ( "<div>" ) )
72
+ . addClass ( "ui-resizable-handle ui-resizable-w" )
73
+ . append ( $ ( "<div>" ) )
59
74
) ;
60
75
61
76
var handle = $ ( ".ui-resizable-w div" ) ,
62
- target = $ ( "#draggable1" ) . draggable ( ) . resizable ( { handles : "all" } ) ;
77
+ target = relativeElement . draggable ( ) . resizable ( { handles : "all" } ) ;
63
78
64
79
// todo: fix resizable so it doesn't require a mouseover
65
80
handle . simulate ( "mouseover" ) . simulate ( "drag" , { dx : - 50 } ) ;
@@ -70,4 +85,4 @@ test("resizable handle with complex markup (#8756 / #8757)", function() {
70
85
equal ( target . width ( ) , 200 , "compare width" ) ;
71
86
} ) ;
72
87
73
- } ) ( jQuery ) ;
88
+ } ) ( jQuery ) ;
0 commit comments