_create: function() {
var self = this,
- doc = this.element[ 0 ].ownerDocument,
// Some browsers only repeat keydown events, not keypress events,
// so we use the suppressKeyPress flag to determine if we've already
// handled the keydown event. #7269
};
this.menu = $( "<ul></ul>" )
.addClass( "ui-autocomplete" )
- .appendTo( $( this.options.appendTo || "body", doc )[0] )
+ .appendTo( this.document.find( this.options.appendTo || "body" )[0] )
// prevent the close-on-blur in case of a "slow" click on the menu (long mousedown)
.mousedown(function( event ) {
// clicking on the scrollbar causes focus to shift to the body
var menuElement = self.menu.element[ 0 ];
if ( !$( event.target ).closest( ".ui-menu-item" ).length ) {
setTimeout(function() {
- $( document ).one( 'mousedown', function( event ) {
+ self.document.one( 'mousedown', function( event ) {
if ( event.target !== self.element[ 0 ] &&
event.target !== menuElement &&
!$.contains( menuElement, event.target ) ) {
previous = self.previous;
// only trigger when focus was lost (click on menu)
- if ( self.element[0] !== doc.activeElement ) {
+ if ( self.element[0] !== self.document[0].activeElement ) {
self.element.focus();
self.previous = previous;
// #6109 - IE triggers two focus events and the second
// turning off autocomplete prevents the browser from remembering the
// value when navigating through history, so we re-enable autocomplete
// if the page is unloaded before the widget is destroyed. #7790
- this._bind( doc.defaultView, {
+ this._bind( this.window, {
beforeunload: function() {
this.element.removeAttr( "autocomplete" );
}
this._initSource();
}
if ( key === "appendTo" ) {
- this.menu.element.appendTo( $( value || "body", this.element[0].ownerDocument )[0] );
+ this.menu.element.appendTo( this.document.find( value || "body" )[0] );
}
if ( key === "disabled" && value && this.xhr ) {
this.xhr.abort();
}
$( this ).addClass( "ui-state-active" );
lastActive = this;
- $( document ).one( "mouseup", function() {
+ self.document.one( "mouseup", function() {
lastActive = null;
});
})
return;
}
var buttonElement = this.buttonElement.removeClass( typeClasses ),
- buttonText = $( "<span></span>", this.element[0].ownerDocument )
+ buttonText = $( "<span></span>", this.document[0] )
.addClass( "ui-button-text" )
.html( this.options.label )
.appendTo( buttonElement.empty() )
_makeDraggable: function() {
var self = this,
- options = self.options,
- doc = $( document );
+ options = self.options;
function filteredUi( ui ) {
return {
},
stop: function( event, ui ) {
options.position = [
- ui.position.left - doc.scrollLeft(),
- ui.position.top - doc.scrollTop()
+ ui.position.left - self.document.scrollLeft(),
+ ui.position.top - self.document.scrollTop()
];
$( this )
.removeClass( "ui-dialog-dragging" );
},
blur: function( event ) {
this._delay( function() {
- if ( ! $.contains( this.element[0], document.activeElement ) ) {
+ if ( ! $.contains( this.element[0], this.document[0].activeElement ) ) {
this.collapseAll( event );
}
}, 0);
}
});
- this._bind( document, {
+ this._bind( this.document, {
click: function( event ) {
if ( !$( event.target ).closest( ".ui-menu" ).length ) {
this.collapseAll( event );
}
});
- this._bind(document, {
+ this._bind( this.document, {
click: function( event ) {
if ( this.isOpen && !$( event.target ).closest( this.element.add( this.options.trigger ) ).length ) {
this.close( event );
// turning off autocomplete prevents the browser from remembering the
// value when navigating through history, so we re-enable autocomplete
// if the page is unloaded before the widget is destroyed. #7790
- this._bind( this.element[0].ownerDocument.defaultView, {
+ this._bind( this.window, {
beforeunload: function() {
this.element.removeAttr( "autocomplete" );
}
"mousedown .ui-spinner-button": function( event ) {
// ensure focus is on (or stays on) the text field
event.preventDefault();
- if ( document.activeElement !== this.element[ 0 ] ) {
+ if ( this.document[0].activeElement !== this.element[ 0 ] ) {
this.element.focus();
}
// don't close if the element has focus
// this prevents the tooltip from closing if you hover while focused
- if ( !force && document.activeElement === target[0] ) {
+ if ( !force && this.document[0].activeElement === target[0] ) {
return;
}
$( "<div>" )
.addClass( "ui-tooltip-content" )
.appendTo( tooltip );
- tooltip.appendTo( document.body );
+ tooltip.appendTo( this.document[0].body );
if ( $.fn.bgiframe ) {
tooltip.bgiframe();
}
if ( element !== this ) {
$.data( element, this.widgetName, this );
this._bind({ remove: "destroy" });
+ this.document = $( element.ownerDocument );
+ this.window = $( this.document[0].defaultView );
}
this._create();