8000 Widget: Added window and document properties. Fixes #7801 - Widget: A… · rorteg/jquery-ui@a0856ef · GitHub
[go: up one dir, main page]

Skip to content

Commit a0856ef

Browse files
committed
Widget: Added window and document properties. Fixes #7801 - Widget: Add document and window properties.
1 parent c145f16 commit a0856ef

8 files changed

+19
-19
lines changed

ui/jquery.ui.autocomplete.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ $.widget( "ui.autocomplete", {
4747

4848
_create: function() {
4949
var self = this,
50-
doc = this.element[ 0 ].ownerDocument,
5150
// Some browsers only repeat keydown events, not keypress events,
5251
// so we use the suppressKeyPress flag to determine if we've already
5352
// handled the keydown event. #7269
@@ -197,7 +196,7 @@ $.widget( "ui.autocomplete", {
197196
};
198197
this.menu = $( "<ul></ul>" )
199198
.addClass( "ui-autocomplete" )
200-
.appendTo( $( this.options.appendTo || "body", doc )[0] )
199+
.appendTo( this.document.find( this.options.appendTo || "body" )[0] )
201200
// prevent the close-on-blur in case of a "slow" click on the menu (long mousedown)
202201
.mousedown(function( event ) {
203202
// clicking on the scrollbar causes focus to shift to the body
@@ -207,7 +206,7 @@ $.widget( "ui.autocomplete", {
207206
var menuElement = self.menu.element[ 0 ];
208207
if ( !$( event.target ).closest( ".ui-menu-item" ).length ) {
209208
setTimeout(function() {
210-
$( document ).one( 'mousedown', function( event ) {
209+
self.document.one( 'mousedown', function( event ) {
211210
if ( event.target !== self.element[ 0 ] &&
212211
event.target !== menuElement &&
213212
!$.contains( menuElement, event.target ) ) {
@@ -239,7 +238,7 @@ $.widget( "ui.autocomplete", {
239238
previous = self.previous;
240239

241240
// only trigger when focus was lost (click on menu)
242-
if ( self.element[0] !== doc.activeElement ) {
241+
if ( self.element[0] !== self.document[0].activeElement ) {
243242
self.element.focus();
244243
self.previous = previous;
245244
// #6109 - IE triggers two focus events and the second
@@ -273,7 +272,7 @@ $.widget( "ui.autocomplete", {
273272
// turning off autocomplete prevents the browser from remembering the
274273
// value when navigating through history, so we re-enable autocomplete
275274
// if the page is unloaded before the widget is destroyed. #7790
276-
this._bind( doc.defaultView, {
275+
this._bind( this.window, {
277276
beforeunload: function() {
278277
this.element.removeAttr( "autocomplete" );
279278
}
@@ -297,7 +296,7 @@ $.widget( "ui.autocomplete", {
297296
this._initSource();
298297
}
299298
if ( key === "appendTo" ) {
300-
this.menu.element.appendTo( $( value || "body", this.element[0].ownerDocument )[0] );
299+
this.menu.element.appendTo( this.document.find( value || "body" )[0] );
301300
}
302301
if ( key === "disabled" && value && this.xhr ) {
303302
this.xhr.abort();

ui/jquery.ui.button.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ $.widget( "ui.button", {
174174
}
175175
$( this ).addClass( "ui-state-active" );
176176
lastActive = this;
177-
$( document ).one( "mouseup", function() {
177+
self.document.one( "mouseup", function() {
178178
lastActive = null;
179179
});
180180
})
@@ -319,7 +319,7 @@ $.widget( "ui.button", {
319319
return;
320320
}
321321
var buttonElement = this.buttonElement.removeClass( typeClasses ),
322-
buttonText = $( "<span></span>", this.element[0].ownerDocument )
322+
buttonText = $( "<span></span>", this.document[0] )
323323
.addClass( "ui-button-text" )
324324
.html( this.options.label )
325325
.appendTo( buttonElement.empty() )

ui/jquery.ui.dialog.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,7 @@ $.widget("ui.dialog", {
372372

373373
_makeDraggable: function() {
374374
var self = this,
375-
options = self.options,
376-
doc = $( document );
375+
options = self.options;
377376

378377
function filteredUi( ui ) {
379378
return {
@@ -396,8 +395,8 @@ $.widget("ui.dialog", {
396395
},
397396
stop: function( event, ui ) {
398397
options.position = [
399-
ui.position.left - doc.scrollLeft(),
400-
ui.position.top - doc.scrollTop()
398+
ui.position.left - self.document.scrollLeft(),
399+
ui.position.top - self.document.scrollTop()
401400
];
402401
$( this )
403402
.removeClass( "ui-dialog-dragging" );

ui/jquery.ui.menu.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ $.widget( "ui.menu", {
8585
},
8686
blur: function( event ) {
8787
this._delay( function() {
88-
if ( ! $.contains( this.element[0], document.activeElement ) ) {
88+
if ( ! $.contains( this.element[0], this.document[0].activeElement ) ) {
8989
this.collapseAll( event );
9090
}
9191
}, 0);
@@ -207,7 +207,7 @@ $.widget( "ui.menu", {
207207
}
208208
});
209209

210-
this._bind( document, {
210+
this._bind( this.document, {
211211
click: function( event ) {
212212
if ( !$( event.target ).closest( ".ui-menu" ).length ) {
213213
this.collapseAll( event );

ui/jquery.ui.popup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ $.widget( "ui.popup", {
187187
}
188188
});
189189

190-
this._bind(document, {
190+
this._bind( this.document, {
191191
click: function( event ) {
192192
if ( this.isOpen && !$( event.target ).closest( this.element.add( this.options.trigger ) ).length ) {
193193
this.close( event );

ui/jquery.ui.spinner.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ $.widget( "ui.spinner", {
5353
// turning off autocomplete prevents the browser from remembering the
5454
// value when navigating through history, so we re-enable autocomplete
5555
// if the page is unloaded before the widget is destroyed. #7790
56-
this._bind( this.element[0].ownerDocument.defaultView, {
56+
this._bind( this.window, {
5757
beforeunload: function() {
5858
this.element.removeAttr( "autocomplete" );
5959
}
@@ -112,7 +112,7 @@ $.widget( "ui.spinner", {
112112
"mousedown .ui-spinner-button": function( event ) {
113113
// ensure focus is on (or stays on) the text field
114114
event.preventDefault();
115-
if ( document.activeElement !== this.element[ 0 ] ) {
115+
if ( this.document[0].activeElement !== this.element[ 0 ] ) {
116116
this.element.focus();
117117
}
118118

ui/jquery.ui.tooltip.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ $.widget( "ui.tooltip", {
166166

167167
// don't close if the element has focus
168168
// this prevents the tooltip from closing if you hover while focused
169-
if ( !force && document.activeElement === target[0] ) {
169+
if ( !force && this.document[0].activeElement === target[0] ) {
170170
return;
171171
}
172172

@@ -200,7 +200,7 @@ $.widget( "ui.tooltip", {
200200
$( "<div>" )
201201
.addClass( "ui-tooltip-content" )
202202
.appendTo( tooltip );
203-
tooltip.appendTo( document.body );
203+
tooltip.appendTo( this.document[0].body );
204204
if ( $.fn.bgiframe ) {
205205
tooltip.bgiframe();
206206
}

ui/jquery.ui.widget.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ $.Widget.prototype = {
195195
if ( element !== this ) {
196196
$.data( element, this.widgetName, this );
197197
this._bind({ remove: "destroy" });
198+
this.document = $( element.ownerDocument );
199+
this.window = $( this.document[0].defaultView );
198200
}
199201

200202
this._create();

0 commit comments

Comments
 (0)
0