Skip to content
Open
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
12 changes: 10 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@

jQuery/Switch is an iOS-inspired slide/toggle widget. It began as an alternative switch for jQuery Mobile, but it also targets desktop browsers as well.

**Note:** jQuery/Switch is still in heavy development. Features may change without warning!
## Install

Using [Bower](http://bower.io) you can just run `bower install jquery-switch`

For [Compass](http://compass-style.org) projects add this line to `config.rb`

add_import_path "BOWER_PATH/jquery.switch"

Then add `@import "jquery.switch"; @include jqSwitch;` in your stylesheet.

## Usage

Expand All @@ -18,7 +26,7 @@ jQuery/Switch builds from `<select>` elements which contain two `<option>` eleme
Then, initialize the plugin:

```javascript
$(document).ready(function() {
$(function() {
$('select').switchify();

// optionally, override the defaults:
Expand Down
18 changes: 5 additions & 13 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

<!-- Le jquery switch-->
<link href="jquery.switch/jquery.switch.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="jquery.switch/jquery.switch.min.js"></script>
<script type="text/javascript" src="jquery.switch/jquery.switch.js"></script>

<script>
$(function() {
Expand Down Expand Up @@ -105,14 +105,6 @@ <h1>
</header>

<section>
<div class="row">
<div class="span16">
<iframe style="width: 100%; height: 600px; border: solid 1px black;" src="http://jsfiddle.net/6twenty/3Uw2s/" frameborder="0"></iframe>
</div>
<div class="span16">
<p><a href="http://jsfiddle.net/6twenty/3Uw2s/" target="_blank">Go to this fiddle</a></p>
</div>
</div><!-- /row -->

<div class="page-header" style="margin-top:50px;">
<h1>Demos <small>cut to the chase</small></h1>
Expand Down Expand Up @@ -141,16 +133,16 @@ <h3>The code <small>the defaults</small></h3>
<div class="span4">
<h3>Custom values/labels</h3>
<select class="example-2">
<option value="a">True</option>
<option value="b">False</option>
<option value="a">Option one</option>
<option value="b">Much longer than option one</option>
</select>
</div>

<div class="span12">
<h3>The code <small>custom values/labels</small></h3>
<pre class="prettyprint linenums">&lt;select&gt;
&lt;option value="a"&gt;True&lt;/option&gt;
&lt;option value="b"&gt;False&lt;/option&gt;
&lt;option value="a"&gt;Option one&lt;/option&gt;
&lt;option value="b"&gt;Much longer than option one&lt;/option&gt;
&lt;/select&gt;</pre>
<pre class="prettyprint linenums">$('select').switchify();</pre>
</div>
Expand Down
94 changes: 14 additions & 80 deletions jquery.switch/jquery.switch.css
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
.ui-switch {
display: inline-block;
border: solid 1px #777;
position: relative;
cursor: pointer;
font-family: Helvetica, Arial, sans-serif;

-moz-border-radius: 18px;
-webkit-border-radius: 18px;
border-radius: 18px;

}

.ui-switch:focus {
Expand All @@ -25,15 +21,11 @@
}

.ui-switch-middle {
height: 20px; width: 60px;
border: solid 7px white;
height: 34px;
width: 60px;
position: relative;
margin-top: -34px;
z-index: 100;

-moz-border-radius: 17px;
-webkit-border-radius: 17px;
border-radius: 17px;
}

.ui-switch-mask {
Expand All @@ -57,15 +49,13 @@

.ui-switch-handle {
display: block;
height: 30px; width: 30px;
height: 25px;
width: 25px;
position: absolute;
top: -4px; left: -15px;
background: url(jquery.switch.png);
background: #fff;
background-size: 30px 30px;

-moz-border-radius: 15px;
-webkit-border-radius: 15px;
border-radius: 15px;
border: 1px solid #000;
}

.ui-switch-.disabled .ui-switch-handle:after {
Expand All @@ -75,16 +65,6 @@
top: 0; left: 0;
height: 30px; width: 30px;
background: white;

-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)"; /* IE 8 */
filter: alpha(opacity=50); /* IE 5-7 */
-moz-opacity: 0.5; /* Mozilla */
-khtml-opacity: 0.5; /* Safari 1.x */
opacity: 0.5; /* Good browsers */

-moz-border-radius: 15px;
-webkit-border-radius: 15px;
border-radius: 15px;
}

.ui-switch-lower {
Expand All @@ -105,82 +85,32 @@
line-height: 18px;
font-size: 12px;
color: white;
background: green;
padding: 0 10px;
border: solid 1px black;
text-align: center;
font-weight: bold;
text-decoration: none;

text-shadow: 0 1px 1px rgba(0,0,0,0.5);

-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px;
white-space: nowrap;
}

.ui-switch-on {
border-right: none;
border-color: #006600;
padding-right: 20px;

-moz-border-radius-topright: 0;
-moz-border-radius-bottomright: 0;
-webkit-border-top-right-radius: 0;
-webkit-border-bottom-right-radius: 0;
border-top-right-radius: 0;
border-bottom-right-radius: 0;

background: #0b9a15; /* Old browsers */
background: -moz-linear-gradient(top, #0b9a15 0%, #167309 2%, #1e9a0e 10%, #20a20f 12%, #23aa11 17%, #3ec52c 93%, #3dbe2c 98%, #0b9a15 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#0b9a15), color-stop(2%,#167309), color-stop(10%,#1e9a0e), color-stop(12%,#20a20f), color-stop(17%,#23aa11), color-stop(93%,#3ec52c), color-stop(98%,#3dbe2c), color-stop(100%,#0b9a15)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #0b9a15 0%,#167309 2%,#1e9a0e 10%,#20a20f 12%,#23aa11 17%,#3ec52c 93%,#3dbe2c 98%,#0b9a15 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #0b9a15 0%,#167309 2%,#1e9a0e 10%,#20a20f 12%,#23aa11 17%,#3ec52c 93%,#3dbe2c 98%,#0b9a15 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #0b9a15 0%,#167309 2%,#1e9a0e 10%,#20a20f 12%,#23aa11 17%,#3ec52c 93%,#3dbe2c 98%,#0b9a15 100%); /* IE10+ */
background: linear-gradient(top, #0b9a15 0%,#167309 2%,#1e9a0e 10%,#20a20f 12%,#23aa11 17%,#3ec52c 93%,#3dbe2c 98%,#0b9a15 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#0b9a15', endColorstr='#0b9a15',GradientType=0 ); /* IE6-9 */
background: green;
}

.ui-switch-off {
border-left: none;
border-color: #660000;
padding-left: 20px;

-moz-border-radius-topleft: 0;
-moz-border-radius-bottomleft: 0;
-webkit-border-top-left-radius: 0;
-webkit-border-bottom-left-radius: 0;
border-top-left-radius: 0;
border-bottom-left-radius: 0;

background: #9c1010; /* Old browsers */
background: -moz-linear-gradient(top, #9c1010 0%, #750a0a 2%, #850d0d 5%, #9c1010 10%, #a51111 12%, #ae1313 17%, #c92f2f 93%, #c72e2e 98%, #9c1010 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#9c1010), color-stop(2%,#750a0a), color-stop(5%,#850d0d), color-stop(10%,#9c1010), color-stop(12%,#a51111), color-stop(17%,#ae1313), color-stop(93%,#c92f2f), color-stop(98%,#c72e2e), color-stop(100%,#9c1010)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #9c1010 0%,#750a0a 2%,#850d0d 5%,#9c1010 10%,#a51111 12%,#ae1313 17%,#c92f2f 93%,#c72e2e 98%,#9c1010 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #9c1010 0%,#750a0a 2%,#850d0d 5%,#9c1010 10%,#a51111 12%,#ae1313 17%,#c92f2f 93%,#c72e2e 98%,#9c1010 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #9c1010 0%,#750a0a 2%,#850d0d 5%,#9c1010 10%,#a51111 12%,#ae1313 17%,#c92f2f 93%,#c72e2e 98%,#9c1010 100%); /* IE10+ */
background: linear-gradient(top, #9c1010 0%,#750a0a 2%,#850d0d 5%,#9c1010 10%,#a51111 12%,#ae1313 17%,#c92f2f 93%,#c72e2e 98%,#9c1010 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#9c1010', endColorstr='#9c1010',GradientType=0 ); /* IE6-9 */
background: red;
}

.ui-switch.disabled .ui-switch-on,
.ui-switch.disabled .ui-switch-off {
border-color: #333;

-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)"; /* IE 8 */
filter: alpha(opacity=50); /* IE 5-7 */
-moz-opacity: 0.5; /* Mozilla */
-khtml-opacity: 0.5; /* Safari 1.x */
opacity: 0.5; /* Good browsers */

background: #525252; /* Old browsers */
background: -moz-linear-gradient(top, #525252 0%, #3e3e3e 2%, #545454 10%, #5d5d5d 17%, #787878 90%, #757575 98%, #525252 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#525252), color-stop(2%,#3e3e3e), color-stop(10%,#545454), color-stop(17%,#5d5d5d), color-stop(90%,#787878), color-stop(98%,#757575), color-stop(100%,#525252)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #525252 0%,#3e3e3e 2%,#545454 10%,#5d5d5d 17%,#787878 90%,#757575 98%,#525252 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #525252 0%,#3e3e3e 2%,#545454 10%,#5d5d5d 17%,#787878 90%,#757575 98%,#525252 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #525252 0%,#3e3e3e 2%,#545454 10%,#5d5d5d 17%,#787878 90%,#757575 98%,#525252 100%); /* IE10+ */
background: linear-gradient(top, #525252 0%,#3e3e3e 2%,#545454 10%,#5d5d5d 17%,#787878 90%,#757575 98%,#525252 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#525252', endColorstr='#525252',GradientType=0 ); /* IE6-9 */
}

.ui-switch-on:hover,
Expand All @@ -194,4 +124,8 @@
-khtml-user-select: none;
-webkit-user-select: none;
user-select: none;
}

.ui-switch-width {
width: 54px;
}
7 changes: 4 additions & 3 deletions jquery.switch/jquery.switch.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
</div> \n\
</div> \n\
<div class="ui-switch-middle"></div> \n\
<div class="ui-switch-width"></div> \n\
</div>';

// helpers to indicate when the mouse button
Expand Down Expand Up @@ -76,8 +77,8 @@
on: options.on || opts.first().val(),
off: options.off || opts.last().val()
}, text = {
on: opts.filter('[value=' + values.on + ']').text(),
off: opts.filter('[value=' + values.off + ']').text()
on: opts.filter('[value="' + values.on + '"]').text(),
off: opts.filter('[value="' + values.off + '"]').text()
};

// assign the <select>'s val as a class on the switch
Expand All @@ -99,7 +100,7 @@
labelMaxWidth = Math.max(linkWidths[0], linkWidths[1]);

// adjust the switch widths
$switch.find('.ui-switch-middle').width(labelMaxWidth + 43);
$switch.find('.ui-switch-middle').width(labelMaxWidth + $switch.find('.ui-switch-width').width());
$switch.find('a').width(labelMaxWidth);

// cache the "off" and "on" positions
Expand Down
101 changes: 101 additions & 0 deletions jquery.switch/jquery.switch.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
$jqSwitch-bg-on: green !default;
$jqSwitch-bg-off: red !default;
$jqSwitch-border-label: black !default;
$jqSwitch-border-handle: black !default;

@mixin jqSwitch(){
.ui-switch {
display: inline-block; position: relative;
cursor: pointer;
&:focus {
border-color: #8aade1;
-webkit-box-shadow: 0 0 5px #8aade1; /* Safari before v5 and Google Chrome */
-moz-box-shadow: 0 0 5px #8aade1; /* Firefox */
-o-box-shadow: 0 0 5px #8aade1; /* Opera */
box-shadow: 0 0 5px #8aade1; /* CSS3 browsers */
outline: none; /* disabling Safari's default behavior*/
}
}

.ui-switch.disabled {
border-color: #999;
cursor: default;
}

$handleSize: 25px;
.ui-switch-handle {
display: block; height: $handleSize; width: $handleSize; position: absolute; top: -4px; left: -15px;
background: #fff; border: 1px solid $jqSwitch-border-handle;
}

.ui-switch-mask {
height: $handleSize + 3; margin: 2px 4px; overflow: hidden;
}

$outerHeight: $handleSize + 5;
.ui-switch-middle {
height: $outerHeight; width: 60px; position: relative; margin-top: -1*$outerHeight; z-index: 100;
}

.ui-switch-master {
height: 24px; position: relative; left: 10px;
}

$edgeGap: 5px;
$labelheight: $handleSize - $edgeGap;
.ui-switch-upper {
height: $labelheight; width: auto; margin: $edgeGap; position: absolute; z-index: 101;
}

.ui-switch-lower {
height: $labelheight; width: 1000px; margin: $edgeGap; position: absolute; z-index: 99;
}

.ui-switch-.disabled .ui-switch-handle:after {
display: block; position: absolute; top: 0; left: 0; height: $handleSize; width: $handleSize;
content: ' ';
background: white;
}

.ui-switch-labels {
clear: both;
a {
display: block; float: left; padding: 0 10px;
border: solid 1px $jqSwitch-border-label;
line-height: 18px; font-size: 12px; color: white; text-align: center; font-weight: bold; text-decoration: none; white-space: nowrap;
}
}

.ui-switch-on {
border-right: none; border-color: #006600; background: $jqSwitch-bg-on;
padding-right: 20px;
}

.ui-switch-off {
border-left: none; border-color: #660000; background: $jqSwitch-bg-off;
padding-left: 20px;
}

.ui-switch.disabled {
.ui-switch-on, .ui-switch-off {
border-color: #333;
}
}

.ui-switch-on, .ui-switch-off {
&:hover {
color: white; text-decoration: none;
}
}

.ui-switch, .ui-switch * {
-moz-user-select: -moz-none;
-khtml-user-select: none;
-webkit-user-select: none;
user-select: none;
}

.ui-switch-width {
width: 54px;
}
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jquery/switch",
"version": "0.4.1",
"version": "0.5.1",
"title": "jQuery/Switch",
"author": {
"name": "Mike Fulcher",
Expand All @@ -22,11 +22,11 @@
"slide",
"mobile"
],
"homepage": "https://github.com/rawnet/jquery-switch",
"homepage": "https://github.com/m1ke/jquery-switch",
"files": [
"jquery.switch/jquery.switch.js",
"jquery.switch/jquery.switch.min.js",
"jquery.switch/jquery.switch.css",
"jquery.switch/jquery.switch.png"
"jquery.switch/jquery.switch.scss"
]
}