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

The extension-based approach #5216

Merged
merged 4 commits into from
Oct 25, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion js/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
'jquery.hashchange.js',
'widgets/page.js',
'jquery.mobile.core.js',
'widgets/loader.js',
'widgets/loader.js',
'jquery.mobile.navigation.js',
'jquery.mobile.navigation.pushstate.js',
'jquery.mobile.transition.js',
Expand All @@ -42,6 +42,7 @@
'widgets/listview.filter.js',
'widgets/listview.autodividers.js',
'jquery.mobile.nojs.js',
'widgets/forms/reset.js',
'widgets/forms/checkboxradio.js',
'widgets/forms/button.js',
'widgets/forms/slider.js',
Expand Down
3 changes: 3 additions & 0 deletions js/jquery.mobile.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ define( [ "jquery", "text!../version.txt" ], function( $, __version__ ) {
WINDOWS: 91 // COMMAND
},

// Place to store various widget extensions
behaviors: {},

// Scroll page vertically: scroll to 0 to hide iOS address bar, or pass a Y value
silentScroll: function( ypos ) {
if ( $.type( ypos ) !== "number" ) {
Expand Down
11 changes: 10 additions & 1 deletion js/widgets/forms/checkboxradio.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//>>css.structure: ../css/structure/jquery.mobile.forms.checkboxradio.css
//>>css.theme: ../css/themes/default/jquery.mobile.theme.css

define( [ "jquery", "../../jquery.mobile.core", "../../jquery.mobile.widget", "../../jquery.mobile.buttonMarkup" ], function( $ ) {
define( [ "jquery", "../../jquery.mobile.core", "../../jquery.mobile.widget", "../../jquery.mobile.buttonMarkup", "./reset" ], function( $ ) {
//>>excludeEnd("jqmBuildExclude");
(function( $, undefined ) {

Expand Down Expand Up @@ -138,6 +138,9 @@ $.widget( "mobile.checkboxradio", $.mobile.widget, {
}
});

if ( this._handleFormReset ) {
this._handleFormReset();
}
this.refresh();
},

Expand Down Expand Up @@ -170,6 +173,10 @@ $.widget( "mobile.checkboxradio", $.mobile.widget, {
.checkboxradio( "refresh" );
},

_reset: function() {
this.refresh();
},

refresh: function() {
var input = this.element[0],
label = this.label,
Expand Down Expand Up @@ -199,6 +206,8 @@ $.widget( "mobile.checkboxradio", $.mobile.widget, {
}
});

$.widget( "mobile.checkboxradio", $.mobile.checkboxradio, $.mobile.behaviors.formReset );

//auto self-init widgets
$( document ).bind( "pagecreate create", function( e ) {
$.mobile.checkboxradio.prototype.enhanceWithin( e.target, true );
Expand Down
23 changes: 23 additions & 0 deletions js/widgets/forms/reset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
//>>description: Make a widget react to a form's reset.
//>>label: formReset
//>>group: Forms

define( [ "jquery", "../../jquery.mobile.core" ], function( $ ) {
//>>excludeEnd("jqmBuildExclude");
(function( $, undefined ) {

$.mobile.behaviors.formReset = {
_handleFormReset: function() {
this._on( this.element.closest( "form" ), {
reset: function() {
this._delay( "_reset" );
}
});
}
};

})( jQuery );
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
});
//>>excludeEnd("jqmBuildExclude");
11 changes: 10 additions & 1 deletion js/widgets/forms/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//>>css.structure: ../css/structure/jquery.mobile.forms.select.css
//>>css.theme: ../css/themes/default/jquery.mobile.theme.css

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

Expand Down Expand Up @@ -141,6 +141,9 @@ $.widget( "mobile.selectmenu", $.mobile.widget, {
self.refresh();
});

if ( this._handleFormReset ) {
this._handleFormReset();
}
this.build();
},

Expand Down Expand Up @@ -231,6 +234,10 @@ $.widget( "mobile.selectmenu", $.mobile.widget, {
}
},

_reset: function() {
this.refresh();
},

refresh: function() {
this.setButtonText();
this.setButtonCount();
Expand All @@ -252,6 +259,8 @@ $.widget( "mobile.selectmenu", $.mobile.widget, {
}
});

$.widget( "mobile.selectmenu", $.mobile.selectmenu, $.mobile.behaviors.formReset );

//auto self-init widgets
$( document ).bind( "pagecreate create", function( e ) {
$.mobile.selectmenu.prototype.enhanceWithin( e.target, true );
Expand Down
20 changes: 17 additions & 3 deletions js/widgets/forms/slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
//>>css.structure: ../css/structure/jquery.mobile.forms.slider.css
//>>css.theme: ../css/themes/default/jquery.mobile.theme.css

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

$.widget( "mobile.slider", $.mobile.widget, {
widgetEventPrefix: "slide",

options: {
theme: null,
trackTheme: null,
Expand Down Expand Up @@ -178,6 +176,10 @@ $.widget( "mobile.slider", $.mobile.widget, {

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

if ( this._handleFormReset ) {
this._handleFormReset();
}

this.refresh( undefined, undefined, true );
},

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


_reset: function() {
this.refresh( undefined, false, true );
},

refresh: function( val, isfromControl, preventInputUpdate ) {

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

});

$.widget( "mobile.slider", $.mobile.slider, $.mobile.behaviors.formReset );

// FIXME: Move the declaration of widgetEventPrefix back to the top of the
// initial declaration of the slider widget once we start using a version of
// the widget factory that includes a fix for http://bugs.jqueryui.com/ticket/8724
$.widget( "mobile.slider", $.mobile.slider, { widgetEventPrefix: "slide" } );

//auto self-init widgets
$( document ).bind( "pagecreate create", function( e ) {
$.mobile.slider.prototype.enhanceWithin( e.target, true );
Expand Down