| 1 |
define( [ |
| 2 |
"qunit", |
| 3 |
"jquery", |
| 4 |
"lib/helper", |
| 5 |
"./helper", |
| 6 |
"ui/widgets/resizable" |
| 7 |
], function( QUnit, $, helper, testHelper ) { |
| 8 |
"use strict"; |
| 9 |
|
| 10 |
QUnit.module( "resizable: core", { afterEach: helper.moduleAfterEach } ); |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
QUnit.test( "n", function( assert ) { |
| 32 |
assert.expect( 4 ); |
| 33 |
|
| 34 |
var handle = ".ui-resizable-n", target = $( "#resizable1" ).resizable( { handles: "all" } ); |
| 35 |
|
| 36 |
testHelper.drag( handle, 0, -50 ); |
| 37 |
assert.equal( target.height(), 150, "compare height" ); |
| 38 |
|
| 39 |
testHelper.drag( handle, 0, 50 ); |
| 40 |
assert.equal( target.height(), 100, "compare height" ); |
| 41 |
|
| 42 |
assert.equal( target[ 0 ].style.left, "", "left should not be modified" ); |
| 43 |
assert.equal( target[ 0 ].style.width, "", "width should not be modified" ); |
| 44 |
} ); |
| 45 |
|
| 46 |
QUnit.test( "s", function( assert ) { |
| 47 |
assert.expect( 5 ); |
| 48 |
|
| 49 |
var handle = ".ui-resizable-s", target = $( "#resizable1" ).resizable( { handles: "all" } ); |
| 50 |
|
| 51 |
testHelper.drag( handle, 0, 50 ); |
| 52 |
assert.equal( target.height(), 150, "compare height" ); |
| 53 |
|
| 54 |
testHelper.drag( handle, 0, -50 ); |
| 55 |
assert.equal( target.height(), 100, "compare height" ); |
| 56 |
|
| 57 |
assert.equal( target[ 0 ].style.top, "", "top should not be modified" ); |
| 58 |
assert.equal( target[ 0 ].style.left, "", "left should not be modified" ); |
| 59 |
assert.equal( target[ 0 ].style.width, "", "width should not be modified" ); |
| 60 |
} ); |
| 61 |
|
| 62 |
QUnit.test( "e", function( assert ) { |
| 63 |
assert.expect( 5 ); |
| 64 |
|
| 65 |
var handle = ".ui-resizable-e", target = $( "#resizable1" ).resizable( { handles: "all" } ); |
| 66 |
|
| 67 |
testHelper.drag( handle, 50 ); |
| 68 |
assert.equal( target.width(), 150, "compare width" ); |
| 69 |
|
| 70 |
testHelper.drag( handle, -50 ); |
| 71 |
assert.equal( target.width(), 100, "compare width" ); |
| 72 |
|
| 73 |
assert.equal( target[ 0 ].style.height, "", "height should not be modified" ); |
| 74 |
assert.equal( target[ 0 ].style.top, "", "top should not be modified" ); |
| 75 |
assert.equal( target[ 0 ].style.left, "", "left should not be modified" ); |
| 76 |
} ); |
| 77 |
|
| 78 |
QUnit.test( "w", function( assert ) { |
| 79 |
assert.expect( 4 ); |
| 80 |
|
| 81 |
var handle = ".ui-resizable-w", target = $( "#resizable1" ).resizable( { handles: "all" } ); |
| 82 |
|
| 83 |
testHelper.drag( handle, -50 ); |
| 84 |
assert.equal( target.width(), 150, "compare width" ); |
| 85 |
|
| 86 |
testHelper.drag( handle, 50 ); |
| 87 |
assert.equal( target.width(), 100, "compare width" ); |
| 88 |
|
| 89 |
assert.equal( target[ 0 ].style.height, "", "height should not be modified" ); |
| 90 |
assert.equal( target[ 0 ].style.top, "", "top should not be modified" ); |
| 91 |
} ); |
| 92 |
|
| 93 |
QUnit.test( "ne", function( assert ) { |
| 94 |
assert.expect( 5 ); |
| 95 |
|
| 96 |
var handle = ".ui-resizable-ne", target = $( "#resizable1" ).css( { overflow: "hidden" } ).resizable( { handles: "all" } ); |
| 97 |
|
| 98 |
testHelper.drag( handle, -50, -50 ); |
| 99 |
assert.equal( target.width(), 50, "compare width" ); |
| 100 |
assert.equal( target.height(), 150, "compare height" ); |
| 101 |
|
| 102 |
testHelper.drag( handle, 50, 50 ); |
| 103 |
assert.equal( target.width(), 100, "compare width" ); |
| 104 |
assert.equal( target.height(), 100, "compare height" ); |
| 105 |
|
| 106 |
assert.equal( target[ 0 ].style.left, "", "left should not be modified" ); |
| 107 |
} ); |
| 108 |
|
| 109 |
QUnit.test( "se", function( assert ) { |
| 110 |
assert.expect( 6 ); |
| 111 |
|
| 112 |
var handle = ".ui-resizable-se", target = $( "#resizable1" ).resizable( { handles: "all" } ); |
| 113 |
|
| 114 |
testHelper.drag( handle, 50, 50 ); |
| 115 |
assert.equal( target.width(), 150, "compare width" ); |
| 116 |
assert.equal( target.height(), 150, "compare height" ); |
| 117 |
|
| 118 |
testHelper.drag( handle, -50, -50 ); |
| 119 |
assert.equal( target.width(), 100, "compare width" ); |
| 120 |
assert.equal( target.height(), 100, "compare height" ); |
| 121 |
|
| 122 |
assert.equal( target[ 0 ].style.top, "", "top should not be modified" ); |
| 123 |
assert.equal( target[ 0 ].style.left, "", "left should not be modified" ); |
| 124 |
} ); |
| 125 |
|
| 126 |
QUnit.test( "sw", function( assert ) { |
| 127 |
assert.expect( 5 ); |
| 128 |
|
| 129 |
var handle = ".ui-resizable-sw", target = $( "#resizable1" ).resizable( { handles: "all" } ); |
| 130 |
|
| 131 |
testHelper.drag( handle, -50, -50 ); |
| 132 |
assert.equal( target.width(), 150, "compare width" ); |
| 133 |
assert.equal( target.height(), 50, "compare height" ); |
| 134 |
|
| 135 |
testHelper.drag( handle, 50, 50 ); |
| 136 |
assert.equal( target.width(), 100, "compare width" ); |
| 137 |
assert.equal( target.height(), 100, "compare height" ); |
| 138 |
|
| 139 |
assert.equal( target[ 0 ].style.top, "", "top should not be modified" ); |
| 140 |
} ); |
| 141 |
|
| 142 |
QUnit.test( "nw", function( assert ) { |
| 143 |
assert.expect( 4 ); |
| 144 |
|
| 145 |
var handle = ".ui-resizable-nw", target = $( "#resizable1" ).resizable( { handles: "all" } ); |
| 146 |
|
| 147 |
testHelper.drag( handle, -50, -50 ); |
| 148 |
assert.equal( target.width(), 150, "compare width" ); |
| 149 |
assert.equal( target.height(), 150, "compare height" ); |
| 150 |
|
| 151 |
testHelper.drag( handle, 50, 50 ); |
| 152 |
assert.equal( target.width(), 100, "compare width" ); |
| 153 |
assert.equal( target.height(), 100, "compare height" ); |
| 154 |
} ); |
| 155 |
|
| 156 |
QUnit.test( "handle with complex markup (#8756)", function( assert ) { |
| 157 |
assert.expect( 2 ); |
| 158 |
|
| 159 |
$( "#resizable1" ) |
| 160 |
.append( |
| 161 |
$( "<div>" ) |
| 162 |
.addClass( "ui-resizable-handle" ) |
| 163 |
.addClass( "ui-resizable-w" ) |
| 164 |
.append( $( "<div>" ) ) |
| 165 |
); |
| 166 |
|
| 167 |
var handle = ".ui-resizable-w div", target = $( "#resizable1" ).resizable( { handles: "all" } ); |
| 168 |
|
| 169 |
testHelper.drag( handle, -50 ); |
| 170 |
assert.equal( target.width(), 150, "compare width" ); |
| 171 |
|
| 172 |
testHelper.drag( handle, 50 ); |
| 173 |
assert.equal( target.width(), 100, "compare width" ); |
| 174 |
} ); |
| 175 |
|
| 176 |
QUnit.test( "resizable accounts for scroll position correctly (#3815)", function( assert ) { |
| 177 |
assert.expect( 4 ); |
| 178 |
|
| 179 |
var position, top, left, |
| 180 |
container = $( "<div style='overflow:scroll;height:300px;width:300px;position:relative;'></div>" ).appendTo( "#qunit-fixture" ), |
| 181 |
overflowed = $( "<div style='width: 1000px; height: 1000px;'></div>" ).appendTo( container ), |
| 182 |
el = $( "<div style='height:100px;width:100px;position:absolute;top:10px;left:10px;'></div>" ).appendTo( overflowed ).resizable( { handles: "all" } ), |
| 183 |
handle = ".ui-resizable-e", |
| 184 |
handlePosition = $( handle ).position().left; |
| 185 |
|
| 186 |
container.scrollLeft( 100 ).scrollTop( 100 ); |
| 187 |
|
| 188 |
position = el.position(); |
| 189 |
left = el.css( "left" ); |
| 190 |
top = el.css( "top" ); |
| 191 |
|
| 192 |
testHelper.drag( handle, 50, 50 ); |
| 193 |
assert.deepEqual( el.position(), position, "position stays the same when resized" ); |
| 194 |
assert.equal( el.css( "left" ), left, "css('left') stays the same when resized" ); |
| 195 |
assert.equal( el.css( "top" ), top, "css('top') stays the same when resized" ); |
| 196 |
assert.equal( $( handle ).position().left, handlePosition + 50, "handle also moved" ); |
| 197 |
} ); |
| 198 |
|
| 199 |
QUnit.test( "resizable stores correct size when using helper and grid (#9547)", function( assert ) { |
| 200 |
assert.expect( 2 ); |
| 201 |
|
| 202 |
var handle = ".ui-resizable-se", |
| 203 |
target = $( "#resizable1" ).resizable( { |
| 204 |
handles: "all", |
| 205 |
helper: "ui-resizable-helper", |
| 206 |
grid: [ 10, 10 ] |
| 207 |
} ); |
| 208 |
|
| 209 |
testHelper.drag( handle, 1, 1 ); |
| 210 |
assert.equal( target.width(), 100, "compare width" ); |
| 211 |
assert.equal( target.height(), 100, "compare height" ); |
| 212 |
} ); |
| 213 |
|
| 214 |
QUnit.test( "nested resizable", function( assert ) { |
| 215 |
assert.expect( 4 ); |
| 216 |
|
| 217 |
var outer = $( "<div id='outer' style='width:50px'></div>" ), |
| 218 |
inner = $( "<div id='inner' style='width:30px'></div>" ), |
| 219 |
target = $( "#resizable1" ), |
| 220 |
innerHandle, |
| 221 |
outerHandle; |
| 222 |
|
| 223 |
outer.appendTo( target ); |
| 224 |
inner.appendTo( outer ); |
| 225 |
|
| 226 |
inner.resizable( { handles: "e" } ); |
| 227 |
outer.resizable( { handles: "e" } ); |
| 228 |
target.resizable( { handles: "e" } ); |
| 229 |
|
| 230 |
innerHandle = $( "#inner > .ui-resizable-e" ); |
| 231 |
outerHandle = $( "#outer > .ui-resizable-e" ); |
| 232 |
|
| 233 |
testHelper.drag( innerHandle, 10 ); |
| 234 |
assert.equal( inner.width(), 40, "compare width of inner element" ); |
| 235 |
testHelper.drag( innerHandle, -10 ); |
| 236 |
assert.equal( inner.width(), 30, "compare width of inner element" ); |
| 237 |
|
| 238 |
testHelper.drag( outerHandle, 10 ); |
| 239 |
assert.equal( outer.width(), 60, "compare width of outer element" ); |
| 240 |
testHelper.drag( outerHandle, -10 ); |
| 241 |
assert.equal( outer.width(), 50, "compare width of outer element" ); |
| 242 |
|
| 243 |
inner.remove(); |
| 244 |
outer.remove(); |
| 245 |
} ); |
| 246 |
|
| 247 |
QUnit.test( "Resizable with scrollbars and box-sizing: border-box", function( assert ) { |
| 248 |
assert.expect( 4 ); |
| 249 |
testResizableWithBoxSizing( assert, { |
| 250 |
isBorderBox: true, |
| 251 |
applyScaleTransform: false |
| 252 |
} ); |
| 253 |
} ); |
| 254 |
|
| 255 |
QUnit.test( "Resizable with scrollbars and box-sizing: content-box", function( assert ) { |
| 256 |
assert.expect( 4 ); |
| 257 |
testResizableWithBoxSizing( assert, { |
| 258 |
isBorderBox: false, |
| 259 |
applyScaleTransform: false |
| 260 |
} ); |
| 261 |
} ); |
| 262 |
|
| 263 |
QUnit.test( "Resizable with scrollbars, a transform and box-sizing: border-box", function( assert ) { |
| 264 |
assert.expect( 4 ); |
| 265 |
testResizableWithBoxSizing( assert, { |
| 266 |
isBorderBox: true, |
| 267 |
applyScaleTransform: true |
| 268 |
} ); |
| 269 |
} ); |
| 270 |
|
| 271 |
QUnit.test( "Resizable with scrollbars, a transform and box-sizing: content-box", function( assert ) { |
| 272 |
assert.expect( 4 ); |
| 273 |
testResizableWithBoxSizing( assert, { |
| 274 |
isBorderBox: false, |
| 275 |
applyScaleTransform: true |
| 276 |
} ); |
| 277 |
} ); |
| 278 |
|
| 279 |
function testResizableWithBoxSizing( assert, options ) { |
| 280 |
var widthBefore, heightBefore, |
| 281 |
cssBoxSizing = options.isBorderBox ? "border-box" : "content-box", |
| 282 |
cssTransform = options.applyScaleTransform ? "scale(1.5)" : "", |
| 283 |
elementContent = $( "<div>" ) |
| 284 |
.css( { |
| 285 |
width: "200px", |
| 286 |
height: "200px", |
| 287 |
padding: "10px", |
| 288 |
border: "5px", |
| 289 |
borderStyle: "solid", |
| 290 |
margin: "20px" |
| 291 |
} ) |
| 292 |
.appendTo( "#resizable1" ), |
| 293 |
element = $( "#resizable1" ).css( { overflow: "auto", transform: cssTransform } ).resizable(), |
| 294 |
handle = ".ui-resizable-se"; |
| 295 |
|
| 296 |
$( "<style> * { box-sizing: " + cssBoxSizing + "; } </style>" ).appendTo( "#qunit-fixture" ); |
| 297 |
|
| 298 |
|
| 299 |
widthBefore = element.innerWidth(); |
| 300 |
heightBefore = element.innerHeight(); |
| 301 |
|
| 302 |
|
| 303 |
testHelper.drag( handle, 10, 10 ); |
| 304 |
assert.equal( parseFloat( element.innerWidth() ), widthBefore + 10, "element width (both scrollbars)" ); |
| 305 |
assert.equal( parseFloat( element.innerHeight() ), heightBefore + 10, "element height (both scrollbars)" ); |
| 306 |
|
| 307 |
|
| 308 |
elementContent.css( "width", "50px" ); |
| 309 |
|
| 310 |
testHelper.drag( handle, 10, 10 ); |
| 311 |
assert.equal( parseFloat( element.innerWidth() ), widthBefore + 20, "element width (only vertical scrollbar)" ); |
| 312 |
assert.equal( parseFloat( element.innerHeight() ), heightBefore + 20, "element height (only vertical scrollbar)" ); |
| 313 |
} |
| 314 |
|
| 315 |
} ); |