fix firefox toggle, closes #69

requires another element :(
This commit is contained in:
Adam Bradley
2013-11-07 12:53:39 -06:00
parent afba3f1deb
commit 284b329555
6 changed files with 81 additions and 71 deletions

43
dist/css/ionic.css vendored
View File

@ -3911,20 +3911,16 @@ input[type="checkbox"][readonly] {
position: relative; position: relative;
display: inline-block; } display: inline-block; }
.toggle input[type="checkbox"] { /* hide the actual input checkbox */
/* set the actual checkbox input to have a width/height */ .toggle input {
/* but hide its appearance, then use :after to style it */ display: none; }
width: 54px;
height: 32px; /* the track appearance when the toggle is "off" */
border: 0; .toggle .track {
background: transparent;
-webkit-appearance: none;
/* the track appearance when the toggle is "off" */ }
.toggle input[type="checkbox"]:after {
display: inline-block; display: inline-block;
box-sizing: border-box; box-sizing: border-box;
width: 100%; width: 54px;
height: 100%; height: 32px;
border: solid 2px #e5e5e5; border: solid 2px #e5e5e5;
border-radius: 20px; border-radius: 20px;
background-color: #e5e5e5; background-color: #e5e5e5;
@ -3935,7 +3931,7 @@ input[type="checkbox"][readonly] {
transition-property: background-color, border; } transition-property: background-color, border; }
/* the handle (circle) thats inside the toggle's track area */ /* the handle (circle) thats inside the toggle's track area */
/* also the appearance when the handle is "off" */ /* also the handle's appearance when it is "off" */
.toggle .handle { .toggle .handle {
position: absolute; position: absolute;
top: 2px; top: 2px;
@ -3945,25 +3941,26 @@ input[type="checkbox"][readonly] {
height: 28px; height: 28px;
border-radius: 50%; border-radius: 50%;
background-color: white; background-color: white;
transition: -webkit-transform 0.1s ease-in-out; -webkit-transition: 0.1s ease-in-out;
transition: 0.1s ease-in-out;
/* used to create a larger (but hidden) hit area to slide the handle */ } /* used to create a larger (but hidden) hit area to slide the handle */ }
.toggle .handle:before { .toggle .handle:before {
position: absolute; position: absolute;
top: -2px; top: -4px;
left: -16px; left: -22px;
display: table; padding: 19px 35px;
padding: 17px 30px;
content: " "; } content: " "; }
/* The track when the toggle is "on" */ /* the track when the toggle is "on" */
.toggle input:checked:after { .toggle input:checked + .track {
border-color: #4a87ee; border-color: #4a87ee;
background-color: #4a87ee; } background-color: #4a87ee; }
/* the handle when the toggle is "on" */ /* the handle when the toggle is "on" */
.toggle input:checked + .handle { .toggle input:checked + .track .handle {
background-color: white; -webkit-transform: translate(22px, 0);
-webkit-transform: translate3d(22px, 0, 0); } transform: translate(22px, 0);
background-color: white; }
/* make sure list item content have enough padding on right to fit the toggle */ /* make sure list item content have enough padding on right to fit the toggle */
.item-toggle .item-content { .item-toggle .item-content {

View File

@ -1351,7 +1351,7 @@ angular.module('ionic.ui.toggle', [])
replace: true, replace: true,
require: '?ngModel', require: '?ngModel',
scope: true, scope: true,
template: '<div class="toggle"><input type="checkbox"><div class="handle"></div></div>', template: '<div class="toggle"><input type="checkbox"><div class="track"><div class="handle"></div></div></div>',
link: function($scope, $element, $attr, ngModel) { link: function($scope, $element, $attr, ngModel) {
var checkbox, handle; var checkbox, handle;

View File

@ -8,7 +8,7 @@ angular.module('ionic.ui.toggle', [])
replace: true, replace: true,
require: '?ngModel', require: '?ngModel',
scope: true, scope: true,
template: '<div class="toggle"><input type="checkbox"><div class="handle"></div></div>', template: '<div class="toggle"><input type="checkbox"><div class="track"><div class="handle"></div></div></div>',
link: function($scope, $element, $attr, ngModel) { link: function($scope, $element, $attr, ngModel) {
var checkbox, handle; var checkbox, handle;

View File

@ -197,6 +197,13 @@
// CSS3 PROPERTIES // CSS3 PROPERTIES
// -------------------------------------------------- // --------------------------------------------------
// Appearance
@mixin appearance($val) {
-webkit-appearance: $val;
-moz-appearance: $val;
appearance: $val;
}
// Border Radius // Border Radius
@mixin border-radius($radius) { @mixin border-radius($radius) {
-webkit-border-radius: $radius; -webkit-border-radius: $radius;

View File

@ -8,21 +8,17 @@
display: inline-block; display: inline-block;
} }
.toggle input[type="checkbox"] { /* hide the actual input checkbox */
/* set the actual checkbox input to have a width/height */ .toggle input {
/* but hide its appearance, then use :after to style it */ display: none;
width: $toggle-width; }
height: $toggle-height;
border: 0;
background: transparent;
-webkit-appearance: none;
/* the track appearance when the toggle is "off" */ /* the track appearance when the toggle is "off" */
&:after { .toggle .track {
display: inline-block; display: inline-block;
box-sizing: border-box; box-sizing: border-box;
width: 100%; width: $toggle-width;
height: 100%; height: $toggle-height;
border: solid $toggle-border-width $toggle-off-border-color; border: solid $toggle-border-width $toggle-off-border-color;
border-radius: $toggle-border-radius; border-radius: $toggle-border-radius;
background-color: $toggle-off-bg-color; background-color: $toggle-off-bg-color;
@ -32,11 +28,10 @@
transition-timing-function: ease-in-out; transition-timing-function: ease-in-out;
transition-duration: $toggle-transition-duration; transition-duration: $toggle-transition-duration;
transition-property: background-color, border; transition-property: background-color, border;
}
} }
/* the handle (circle) thats inside the toggle's track area */ /* the handle (circle) thats inside the toggle's track area */
/* also the appearance when the handle is "off" */ /* also the handle's appearance when it is "off" */
.toggle .handle { .toggle .handle {
position: absolute; position: absolute;
top: $toggle-border-width; top: $toggle-border-width;
@ -46,29 +41,28 @@
height: $toggle-handle-height; height: $toggle-handle-height;
border-radius: $toggle-handle-radius; border-radius: $toggle-handle-radius;
background-color: $toggle-handle-off-bg-color; background-color: $toggle-handle-off-bg-color;
transition: -webkit-transform $toggle-transition-duration ease-in-out; @include transition($toggle-transition-duration ease-in-out);
/* used to create a larger (but hidden) hit area to slide the handle */ /* used to create a larger (but hidden) hit area to slide the handle */
&:before { &:before {
position: absolute; position: absolute;
top: -2px; top: -4px;
left: ( ($toggle-handle-width / 2) * -1) - 2; left: ( ($toggle-handle-width / 2) * -1) - 8;
display: table; padding: ($toggle-handle-height / 2) + 5 ($toggle-handle-width + 7);
padding: ($toggle-handle-height / 2) + 3 ($toggle-handle-width + 2);
content: " "; content: " ";
} }
} }
/* The track when the toggle is "on" */ /* the track when the toggle is "on" */
.toggle input:checked:after { .toggle input:checked + .track {
border-color: $toggle-on-border-color; border-color: $toggle-on-border-color;
background-color: $toggle-on-bg-color; background-color: $toggle-on-bg-color;
} }
/* the handle when the toggle is "on" */ /* the handle when the toggle is "on" */
.toggle input:checked + .handle { .toggle input:checked + .track .handle {
@include translate($toggle-width - $toggle-handle-width - ($toggle-border-width * 2), 0);
background-color: $toggle-handle-on-bg-color; background-color: $toggle-handle-on-bg-color;
-webkit-transform: translate3d( $toggle-width - $toggle-handle-width - ($toggle-border-width * 2) ,0,0);
} }
/* make sure list item content have enough padding on right to fit the toggle */ /* make sure list item content have enough padding on right to fit the toggle */

View File

@ -22,7 +22,9 @@
</div> </div>
<label class="toggle"> <label class="toggle">
<input type="checkbox" checked> <input type="checkbox" checked>
<div class="track">
<div class="handle"></div> <div class="handle"></div>
</track>
</label> </label>
</li> </li>
<li class="item item-toggle"> <li class="item item-toggle">
@ -31,7 +33,9 @@
</div> </div>
<label class="toggle"> <label class="toggle">
<input type="checkbox" checked> <input type="checkbox" checked>
<div class="track">
<div class="handle"></div> <div class="handle"></div>
</track>
</label> </label>
</li> </li>
<li class="item item-toggle"> <li class="item item-toggle">
@ -40,7 +44,9 @@
</div> </div>
<label class="toggle"> <label class="toggle">
<input type="checkbox"> <input type="checkbox">
<div class="track">
<div class="handle"></div> <div class="handle"></div>
</track>
</label> </label>
</li> </li>
<li class="item item-toggle"> <li class="item item-toggle">
@ -49,7 +55,9 @@
</div> </div>
<label class="toggle"> <label class="toggle">
<input type="checkbox"> <input type="checkbox">
<div class="track">
<div class="handle"></div> <div class="handle"></div>
</track>
</label> </label>
</li> </li>
<li class="item item-toggle"> <li class="item item-toggle">
@ -58,7 +66,9 @@
</div> </div>
<label class="toggle"> <label class="toggle">
<input type="checkbox" checked> <input type="checkbox" checked>
<div class="track">
<div class="handle"></div> <div class="handle"></div>
</track>
</label> </label>
</li> </li>
<li class="item item-toggle"> <li class="item item-toggle">
@ -67,7 +77,9 @@
</div> </div>
<label class="toggle"> <label class="toggle">
<input type="checkbox"> <input type="checkbox">
<div class="track">
<div class="handle"></div> <div class="handle"></div>
</track>
</label> </label>
</li> </li>
</ul> </ul>