]> source.dussan.org Git - jquery-ui.git/commitdiff
Widget: Added window and document properties. Fixes #7801 - Widget: Add document...
authorScott González <scott.gonzalez@gmail.com>
Thu, 20 Oct 2011 20:57:47 +0000 (16:57 -0400)
committerScott González <scott.gonzalez@gmail.com>
Thu, 20 Oct 2011 20:57:47 +0000 (16:57 -0400)
ui/jquery.ui.autocomplete.js
ui/jquery.ui.button.js
ui/jquery.ui.dialog.js
ui/jquery.ui.menu.js
ui/jquery.ui.popup.js
ui/jquery.ui.spinner.js
ui/jquery.ui.tooltip.js
ui/jquery.ui.widget.js

index ab2edfdffdaf574b269aa8eb2520de196510bc4a..5dda7d97085dd83f6181c3a510ac87f9b543f71f 100644 (file)
@@ -47,7 +47,6 @@ $.widget( "ui.autocomplete", {
 
        _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
@@ -197,7 +196,7 @@ $.widget( "ui.autocomplete", {
                };
                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
@@ -207,7 +206,7 @@ $.widget( "ui.autocomplete", {
                                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 ) ) {
@@ -239,7 +238,7 @@ $.widget( "ui.autocomplete", {
                                                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
@@ -273,7 +272,7 @@ $.widget( "ui.autocomplete", {
                // 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" );
                        }
@@ -297,7 +296,7 @@ $.widget( "ui.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();
index 63bd1fc73db88ee1166fb7b9c566ddab0f87d1cb..20eb2ca89fe820c8505ab131148d72389509e28d 100644 (file)
@@ -174,7 +174,7 @@ $.widget( "ui.button", {
                                        }
                                        $( this ).addClass( "ui-state-active" );
                                        lastActive = this;
-                                       $( document ).one( "mouseup", function() {
+                                       self.document.one( "mouseup", function() {
                                                lastActive = null;
                                        });
                                })
@@ -319,7 +319,7 @@ $.widget( "ui.button", {
                        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() )
index 46320426a2244014c6a05f15b3f07e30c5416684..9c9a9b6fc74bb52837f23e605de7afff3d751431 100644 (file)
@@ -372,8 +372,7 @@ $.widget("ui.dialog", {
 
        _makeDraggable: function() {
                var self = this,
-                       options = self.options,
-                       doc = $( document );
+                       options = self.options;
 
                function filteredUi( ui ) {
                        return {
@@ -396,8 +395,8 @@ $.widget("ui.dialog", {
                        },
                        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" );
index f2f758d96e0939c6df72ae9f80a59f407c798b5a..bf36a77fe7a1ab369e1b24a9bd565b72ea1e0030 100644 (file)
@@ -85,7 +85,7 @@ $.widget( "ui.menu", {
                        },
                        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);
@@ -207,7 +207,7 @@ $.widget( "ui.menu", {
                        }
                });
 
-               this._bind( document, {
+               this._bind( this.document, {
                        click: function( event ) {
                                if ( !$( event.target ).closest( ".ui-menu" ).length ) {
                                        this.collapseAll( event );
index 70bf84be0b57b732fc6c65e3692439e884683c33..f6585b761d44880a361fc6522f3106ff16313845 100644 (file)
@@ -187,7 +187,7 @@ $.widget( "ui.popup", {
                        }
                });
 
-               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 );
index 7fc291c00e34977be45af4c61958a9b7122b70eb..9c554b2dfe9880c7d3e35b791fc42a3d6b4fcbec 100644 (file)
@@ -53,7 +53,7 @@ $.widget( "ui.spinner", {
                // 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" );
                        }
@@ -112,7 +112,7 @@ $.widget( "ui.spinner", {
                "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();
                        }
 
index 2f8d929692ce030d550efc1a96ca99ad9ed46ba2..35b6f9b5020e289c9165b2e77a8da0f82d9fd6a6 100644 (file)
@@ -166,7 +166,7 @@ $.widget( "ui.tooltip", {
 
                // 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;
                }
 
@@ -200,7 +200,7 @@ $.widget( "ui.tooltip", {
                $( "<div>" )
                        .addClass( "ui-tooltip-content" )
                        .appendTo( tooltip );
-               tooltip.appendTo( document.body );
+               tooltip.appendTo( this.document[0].body );
                if ( $.fn.bgiframe ) {
                        tooltip.bgiframe();
                }
index b78530dca1780a8827830c37112b7bc3a760adb0..4b4d41fb1068a61d23d1116f06c9c5c541810268 100644 (file)
@@ -195,6 +195,8 @@ $.Widget.prototype = {
                if ( element !== this ) {
                        $.data( element, this.widgetName, this );
                        this._bind({ remove: "destroy" });
+                       this.document = $( element.ownerDocument );
+                       this.window = $( this.document[0].defaultView );
                }
 
                this._create();