Skip to content

Commit effa323

Browse files
authored
Position: Make sure of is treated as a CSS selector
Closes gh-1955
1 parent 3285086 commit effa323

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

tests/unit/position/core.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ QUnit.test( "positions", function( assert ) {
113113
} );
114114

115115
QUnit.test( "of", function( assert ) {
116-
assert.expect( 9 + ( scrollTopSupport() ? 1 : 0 ) );
116+
assert.expect( 10 + ( scrollTopSupport() ? 1 : 0 ) );
117+
118+
var done = assert.async();
117119

118120
var event;
119121

@@ -225,6 +227,21 @@ QUnit.test( "of", function( assert ) {
225227
top: 600,
226228
left: 400
227229
}, "event - left top, right bottom" );
230+
231+
try {
232+
$( "#elx" ).position( {
233+
my: "left top",
234+
at: "right bottom",
235+
of: "<img onerror='window.globalOf=true' src='/404' />",
236+
collision: "none"
237+
} );
238+
} catch ( e ) {}
239+
240+
setTimeout( function() {
241+
assert.equal( window.globalOf, undefined, "of treated as a selector" );
242+
delete window.globalOf;
243+
done();
244+
}, 500 );
228245
} );
229246

230247
QUnit.test( "offsets", function( assert ) {
@@ -334,6 +351,7 @@ QUnit.test( "using", function( assert ) {
334351
assert.deepEqual( position, expectedPosition, "correct position for call #" + count );
335352
assert.deepEqual( feedback.element.element[ 0 ], elems[ count ] );
336353
delete feedback.element.element;
354+
delete feedback.target.element.prevObject;
337355
assert.deepEqual( feedback, expectedFeedback );
338356
count++;
339357
}

ui/position.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,12 @@ $.fn.position = function( options ) {
148148
options = $.extend( {}, options );
149149

150150
var atOffset, targetWidth, targetHeight, targetOffset, basePosition, dimensions,
151-
target = $( options.of ),
151+
152+
// Make sure string options are treated as CSS selectors
153+
target = typeof options.of === "string" ?
154+
$( document ).find( options.of ) :
155+
$( options.of ),
156+
152157
within = $.position.getWithinInfo( options.within ),
153158
scrollInfo = $.position.getScrollInfo( within ),
154159
collision = ( options.collision || "flip" ).split( " " ),

0 commit comments

Comments
 (0)