Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.

Commit 010ec24

Browse files
author
Gabriel "_|Nix|_" Schulhof
committed
Merge pull request #5216 from jquery/fix-5137-3
The extension-based approach -- Fixes #5137
2 parents 4527be3 + 2778325 commit 010ec24

File tree

6 files changed

+65
-6
lines changed

6 files changed

+65
-6
lines changed

js/index.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
'jquery.hashchange.js',
2020
'widgets/page.js',
2121
'jquery.mobile.core.js',
22-
'widgets/loader.js',
22+
'widgets/loader.js',
2323
'jquery.mobile.navigation.js',
2424
'jquery.mobile.navigation.pushstate.js',
2525
'jquery.mobile.transition.js',
@@ -42,6 +42,7 @@
4242
'widgets/listview.filter.js',
4343
'widgets/listview.autodividers.js',
4444
'jquery.mobile.nojs.js',
45+
'widgets/forms/reset.js',
4546
'widgets/forms/checkboxradio.js',
4647
'widgets/forms/button.js',
4748
'widgets/forms/slider.js',

js/jquery.mobile.core.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ define( [ "jquery", "text!../version.txt" ], function( $, __version__ ) {
120120
WINDOWS: 91 // COMMAND
121121
},
122122

123+
// Place to store various widget extensions
124+
behaviors: {},
125+
123126
// Scroll page vertically: scroll to 0 to hide iOS address bar, or pass a Y value
124127
silentScroll: function( ypos ) {
125128
if ( $.type( ypos ) !== "number" ) {

js/widgets/forms/checkboxradio.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//>>css.structure: ../css/structure/jquery.mobile.forms.checkboxradio.css
1010
//>>css.theme: ../css/themes/default/jquery.mobile.theme.css
1111

12-
define( [ "jquery", "../../jquery.mobile.core", "../../jquery.mobile.widget", "../../jquery.mobile.buttonMarkup" ], function( $ ) {
12+
define( [ "jquery", "../../jquery.mobile.core", "../../jquery.mobile.widget", "../../jquery.mobile.buttonMarkup", "./reset" ], function( $ ) {
1313
//>>excludeEnd("jqmBuildExclude");
1414
(function( $, undefined ) {
1515

@@ -138,6 +138,9 @@ $.widget( "mobile.checkboxradio", $.mobile.widget, {
138138
}
139139
});
140140

141+
if ( this._handleFormReset ) {
142+
this._handleFormReset();
143+
}
141144
this.refresh();
142145
},
143146

@@ -170,6 +173,10 @@ $.widget( "mobile.checkboxradio", $.mobile.widget, {
170173
.checkboxradio( "refresh" );
171174
},
172175

176+
_reset: function() {
177+
this.refresh();
178+
},
179+
173180
refresh: function() {
174181
var input = this.element[0],
175182
label = this.label,
@@ -199,6 +206,8 @@ $.widget( "mobile.checkboxradio", $.mobile.widget, {
199206
}
200207
});
201208

209+
$.widget( "mobile.checkboxradio", $.mobile.checkboxradio, $.mobile.behaviors.formReset );
210+
202211
//auto self-init widgets
203212
$( document ).bind( "pagecreate create", function( e ) {
204213
$.mobile.checkboxradio.prototype.enhanceWithin( e.target, true );

js/widgets/forms/reset.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
2+
//>>description: Make a widget react to a form's reset.
3+
//>>label: formReset
4+
//>>group: Forms
5+
6+
define( [ "jquery", "../../jquery.mobile.core" ], function( $ ) {
7+
//>>excludeEnd("jqmBuildExclude");
8+
(function( $, undefined ) {
9+
10+
$.mobile.behaviors.formReset = {
11+
_handleFormReset: function() {
12+
this._on( this.element.closest( "form" ), {
13+
reset: function() {
14+
this._delay( "_reset" );
15+
}
16+
});
17+
}
18+
};
19+
20+
})( jQuery );
21+
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
22+
});
23+
//>>excludeEnd("jqmBuildExclude");

js/widgets/forms/select.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//>>css.structure: ../css/structure/jquery.mobile.forms.select.css
66
//>>css.theme: ../css/themes/default/jquery.mobile.theme.css
77

8-
define( [ "jquery", "../../jquery.mobile.core", "../../jquery.mobile.widget", "../../jquery.mobile.buttonMarkup", "../../jquery.mobile.zoom" ], function( $ ) {
8+
define( [ "jquery", "../../jquery.mobile.core", "../../jquery.mobile.widget", "../../jquery.mobile.buttonMarkup", "../../jquery.mobile.zoom", "./reset" ], function( $ ) {
99
//>>excludeEnd("jqmBuildExclude");
1010
(function( $, undefined ) {
1111

@@ -141,6 +141,9 @@ $.widget( "mobile.selectmenu", $.mobile.widget, {
141141
self.refresh();
142142
});
143143

144+
if ( this._handleFormReset ) {
145+
this._handleFormReset();
146+
}
144147
this.build();
145148
},
146149

@@ -231,6 +234,10 @@ $.widget( "mobile.selectmenu", $.mobile.widget, {
231234
}
232235
},
233236

237+
_reset: function() {
238+
this.refresh();
239+
},
240+
234241
refresh: function() {
235242
this.setButtonText();
236243
this.setButtonCount();
@@ -252,6 +259,8 @@ $.widget( "mobile.selectmenu", $.mobile.widget, {
252259
}
253260
});
254261

262+
$.widget( "mobile.selectmenu", $.mobile.selectmenu, $.mobile.behaviors.formReset );
263+
255264
//auto self-init widgets
256265
$( document ).bind( "pagecreate create", function( e ) {
257266
$.mobile.selectmenu.prototype.enhanceWithin( e.target, true );

js/widgets/forms/slider.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@
55
//>>css.structure: ../css/structure/jquery.mobile.forms.slider.css
66
//>>css.theme: ../css/themes/default/jquery.mobile.theme.css
77

8-
define( [ "jquery", "../../jquery.mobile.core", "../../jquery.mobile.widget", "./textinput", "../../jquery.mobile.buttonMarkup" ], function( $ ) {
8+
define( [ "jquery", "../../jquery.mobile.core", "../../jquery.mobile.widget", "./textinput", "../../jquery.mobile.buttonMarkup", "./reset" ], function( $ ) {
99
//>>excludeEnd("jqmBuildExclude");
1010
(function( $, undefined ) {
1111

1212
$.widget( "mobile.slider", $.mobile.widget, {
13-
widgetEventPrefix: "slide",
14-
1513
options: {
1614
theme: null,
1715
trackTheme: null,
@@ -178,6 +176,10 @@ $.widget( "mobile.slider", $.mobile.widget, {
178176

179177
this.handle.bind( "vclick", false );
180178

179+
if ( this._handleFormReset ) {
180+
this._handleFormReset();
181+
}
182+
181183
this.refresh( undefined, undefined, true );
182184
},
183185

@@ -341,6 +343,11 @@ $.widget( "mobile.slider", $.mobile.widget, {
341343
return this.isToggleSwitch ? this.element[0].selectedIndex : parseFloat( this.element.val() ) ;
342344
},
343345

346+
347+
_reset: function() {
348+
this.refresh( undefined, false, true );
349+
},
350+
344351
refresh: function( val, isfromControl, preventInputUpdate ) {
345352

346353
// NOTE: we don't return here because we want to support programmatic
@@ -468,6 +475,13 @@ $.widget( "mobile.slider", $.mobile.widget, {
468475

469476
});
470477

478+
$.widget( "mobile.slider", $.mobile.slider, $.mobile.behaviors.formReset );
479+
480+
// FIXME: Move the declaration of widgetEventPrefix back to the top of the
481+
// initial declaration of the slider widget once we start using a version of
482+
// the widget factory that includes a fix for http://bugs.jqueryui.com/ticket/8724
483+
$.widget( "mobile.slider", $.mobile.slider, { widgetEventPrefix: "slide" } );
484+
471485
//auto self-init widgets
472486
$( document ).bind( "pagecreate create", function( e ) {
473487
$.mobile.slider.prototype.enhanceWithin( e.target, true );

0 commit comments

Comments
 (0)