From c241313f1d31b18751a81c1321662512d8086cbc Mon Sep 17 00:00:00 2001 From: =?utf8?q?Scott=20Gonz=C3=A1lez?= Date: Mon, 20 May 2013 11:30:49 -0400 Subject: [PATCH] Widget: Properly set widgetEventPrefix when redefining a widget. Fixes #9316 - Widget: widgetEventPrefix is empty when widget is (occasionally) loaded twice. (cherry picked from commit 2eb89f07341a557084fa3363fe22afe62530654d) --- tests/unit/widget/widget_core.js | 10 ++++++++++ ui/jquery.ui.widget.js | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/unit/widget/widget_core.js b/tests/unit/widget/widget_core.js index 8102b1f4f..86b6ca5f9 100644 --- a/tests/unit/widget/widget_core.js +++ b/tests/unit/widget/widget_core.js @@ -331,6 +331,16 @@ test( "re-init", function() { deepEqual( actions, [ "optionfoo", "init" ], "correct methods called on re-init with options" ); }); +test( "redeclare", function() { + expect( 2 ); + + $.widget( "ui.testWidget", {} ); + equal( $.ui.testWidget.prototype.widgetEventPrefix, "testWidget" ); + + $.widget( "ui.testWidget", {} ); + equal( $.ui.testWidget.prototype.widgetEventPrefix, "testWidget" ); +}); + test( "inheritance", function() { expect( 6 ); // #5830 - Widget: Using inheritance overwrites the base classes options diff --git a/ui/jquery.ui.widget.js b/ui/jquery.ui.widget.js index c581e4b81..050125fa9 100644 --- a/ui/jquery.ui.widget.js +++ b/ui/jquery.ui.widget.js @@ -106,7 +106,7 @@ $.widget = function( name, base, prototype ) { // TODO: remove support for widgetEventPrefix // always use the name + a colon as the prefix, e.g., draggable:start // don't prefix for widgets that aren't DOM-based - widgetEventPrefix: existingConstructor ? basePrototype.widgetEventPrefix : name + widgetEventPrefix: existingConstructor ? (basePrototype.widgetEventPrefix || name) : name }, proxiedPrototype, { constructor: constructor, namespace: namespace, -- 2.39.5