Skip to content

Commit f6d4e37

Browse files
author
Gabriel Schulhof
committed
Flipswitch: Use .nodeName and .toLowerCase()
Fixes jquery-archivegh-7959 Closes jquery-archivegh-7965
1 parent ab24dd4 commit f6d4e37

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

js/widgets/forms/flipswitch.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@ $.widget( "mobile.flipswitch", $.extend({
2727
},
2828

2929
_create: function() {
30+
this.type = this.element[ 0 ].nodeName.toLowerCase();
31+
3032
if ( !this.options.enhanced ) {
3133
this._enhance();
3234
} else {
3335
$.extend( this, {
3436
flipswitch: this.element.parent(),
3537
on: this.element.find( ".ui-flipswitch-on" ).eq( 0 ),
36-
off: this.element.find( ".ui-flipswitch-off" ).eq(0),
37-
type: this.element.get( 0 ).tagName
38+
off: this.element.find( ".ui-flipswitch-off" ).eq( 0 )
3839
});
3940
}
4041

@@ -81,7 +82,7 @@ $.widget( "mobile.flipswitch", $.extend({
8182

8283
_left: function() {
8384
this.flipswitch.removeClass( "ui-flipswitch-active" );
84-
if ( this.type === "SELECT" ) {
85+
if ( this.type === "select" ) {
8586
this.element.get( 0 ).selectedIndex = 0;
8687
} else {
8788
this.element.prop( "checked", false );
@@ -91,7 +92,7 @@ $.widget( "mobile.flipswitch", $.extend({
9192

9293
_right: function() {
9394
this.flipswitch.addClass( "ui-flipswitch-active" );
94-
if ( this.type === "SELECT" ) {
95+
if ( this.type === "select" ) {
9596
this.element.get( 0 ).selectedIndex = 1;
9697
} else {
9798
this.element.prop( "checked", true );
@@ -110,10 +111,9 @@ $.widget( "mobile.flipswitch", $.extend({
110111
"href": "#"
111112
}),
112113
off = $( "<span></span>" ),
113-
type = element.get( 0 ).tagName,
114-
onText = ( type === "INPUT" ) ?
114+
onText = ( this.type === "input" ) ?
115115
options.onText : element.find( "option" ).eq( 1 ).text(),
116-
offText = ( type === "INPUT" ) ?
116+
offText = ( this.type === "input" ) ?
117117
options.offText : element.find( "option" ).eq( 0 ).text();
118118

119119
on
@@ -145,8 +145,7 @@ $.widget( "mobile.flipswitch", $.extend({
145145
$.extend( this, {
146146
flipswitch: flipswitch,
147147
on: on,
148-
off: off,
149-
type: type
148+
off: off
150149
});
151150
},
152151

@@ -158,7 +157,7 @@ $.widget( "mobile.flipswitch", $.extend({
158157
var direction,
159158
existingDirection = this.flipswitch.hasClass( "ui-flipswitch-active" ) ? "_right" : "_left";
160159

161-
if ( this.type === "SELECT" ) {
160+
if ( this.type === "select" ) {
162161
direction = ( this.element.get( 0 ).selectedIndex > 0 ) ? "_right": "_left";
163162
} else {
164163
direction = this.element.prop( "checked" ) ? "_right": "_left";

0 commit comments

Comments
 (0)