Skip to content

Instantly share code, notes, and snippets.

@scottgonzalez
Created October 2, 2011 03:40
Show Gist options
  • Select an option

  • Save scottgonzalez/1257003 to your computer and use it in GitHub Desktop.

Select an option

Save scottgonzalez/1257003 to your computer and use it in GitHub Desktop.
diff --git a/ui/jquery.ui.autocomplete.js b/ui/jquery.ui.autocomplete.js
index 6b06cfe..3715fdd 100644
--- a/ui/jquery.ui.autocomplete.js
+++ b/ui/jquery.ui.autocomplete.js
@@ -43,6 +43,10 @@ $.widget( "ui.autocomplete", {
select: null
},
+ dependencies: {
+ menu: $.ui.menu
+ },
+
pending: 0,
_create: function() {
@@ -206,7 +210,7 @@ $.widget( "ui.autocomplete", {
clearTimeout( self.closing );
}, 13);
})
- .menu({
+ .widget( this.dependencies.menu, {
// custom key handling for now
input: $(),
focus: function( event, ui ) {
@@ -256,7 +260,7 @@ $.widget( "ui.autocomplete", {
})
.zIndex( this.element.zIndex() + 1 )
.hide()
- .data( "menu" );
+ .data( this.dependencies.menu.prototype.widgetName );
if ( $.fn.bgiframe ) {
this.menu.element.bgiframe();
}
diff --git a/ui/jquery.ui.core.js b/ui/jquery.ui.core.js
index 8bcc4c4..7263422 100644
--- a/ui/jquery.ui.core.js
+++ b/ui/jquery.ui.core.js
@@ -17,6 +17,21 @@ if ( $.ui.version ) {
return;
}
+$.fn.widget = function( widget, options ) {
+ var isMethodCall = typeof options === "string",
+ widgetName = widget.prototype.widgetName,
+ args = [].slice.call( arguments, 2 );
+
+ return this.each( isMethodCall ?
+ function() {
+ var instance = $( this ).data( widgetName );
+ instance[ options ].apply( instance, args );
+ } :
+ function() {
+ widget( options, this );
+ });
+};
+
$.extend( $.ui, {
version: "@VERSION",
diff --git a/ui/jquery.ui.dialog.js b/ui/jquery.ui.dialog.js
index 065d640..16a1634 100644
--- a/ui/jquery.ui.dialog.js
+++ b/ui/jquery.ui.dialog.js
@@ -72,6 +72,11 @@ $.widget("ui.dialog", {
zIndex: 1000
},
+ dependencies: {
+ draggable: $.ui.draggable,
+ resizable: $.ui.resizable
+ },
+
_create: function() {
this.originalTitle = this.element.attr( "title" );
// #5742 - .attr() might return a DOMElement
@@ -382,7 +387,7 @@ $.widget("ui.dialog", {
};
}
- self.uiDialog.draggable({
+ self.uiDialog.widget( this.dependencies.draggable, {
cancel: ".ui-dialog-content, .ui-dialog-titlebar-close",
handle: ".ui-dialog-titlebar",
containment: "document",
@@ -427,7 +432,7 @@ $.widget("ui.dialog", {
};
}
- self.uiDialog.resizable({
+ self.uiDialog.widget( this.dependencies.resizable, {
cancel: ".ui-dialog-content",
containment: "document",
alsoResize: self.element,
@@ -532,7 +537,7 @@ $.widget("ui.dialog", {
this._size();
}
if ( this.uiDialog.is( ":data(resizable)" ) ) {
- this.uiDialog.resizable( "option", resizableOptions );
+ this.uiDialog.widget( this.dependencies.resizable, "option", resizableOptions );
}
},
@@ -563,7 +568,7 @@ $.widget("ui.dialog", {
case "draggable":
var isDraggable = uiDialog.is( ":data(draggable)" );
if ( isDraggable && !value ) {
- uiDialog.draggable( "destroy" );
+ uiDialog.widget( this.dependencies.draggable, "destroy" );
}
if ( !isDraggable && value ) {
@@ -577,12 +582,12 @@ $.widget("ui.dialog", {
// currently resizable, becoming non-resizable
var isResizable = uiDialog.is( ":data(resizable)" );
if ( isResizable && !value ) {
- uiDialog.resizable( "destroy" );
+ uiDialog.widget( this.dependencies.resizable, "destroy" );
}
// currently resizable, changing handles
if ( isResizable && typeof value === "string" ) {
- uiDialog.resizable( "option", "handles", value );
+ uiDialog.widget( this.dependencies.resizable, "option", "handles", value );
}
// currently non-resizable, becoming resizable
@@ -649,7 +654,7 @@ $.widget("ui.dialog", {
}
if (this.uiDialog.is( ":data(resizable)" ) ) {
- this.uiDialog.resizable( "option", "minHeight", this._minHeight() );
+ this.uiDialog.widget( this.dependencies.resizable, "option", "minHeight", this._minHeight() );
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment