Skip to content

Added your licence to the CSS file if you don't mind :) + added support for different scaling sizes #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
29 changes: 29 additions & 0 deletions jquery.switchButton.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
/**
* jquery.switchButton.js v1.0
* jQuery iPhone-like switch button
* @author Olivier Lance <[email protected]>
*
* Copyright (c) Olivier Lance - released under MIT License {{{
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
* }}}
*/


.switch-button-label {
float: left;

Expand Down
15 changes: 8 additions & 7 deletions jquery.switchButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
on_label: "ON", // Text to be displayed when checked
off_label: "OFF", // Text to be displayed when unchecked

width: 25, // Width of the button in pixels
size_unit: "px", // Size Unit for the Switch
width: 25, // Width of the button in pixels
height: 11, // Height of the button in pixels
button_width: 12, // Width of the sliding part in pixels

Expand Down Expand Up @@ -183,10 +184,10 @@
this.off_label.html(this.options.off_label);

// Refresh button's dimensions
this.button_bg.width(this.options.width);
this.button_bg.height(this.options.height);
this.button.width(this.options.button_width);
this.button.height(this.options.height);
this.button_bg.width(this.options.width.concat(this.options.size_unit));
this.button_bg.height(this.options.height.concat(this.options.size_unit));
this.button.width(this.options.button_width.concat(this.options.size_unit));
this.button.height(this.options.height.concat(this.options.size_unit));
},

_initEvents: function() {
Expand Down Expand Up @@ -258,8 +259,8 @@
this.element.prop("checked", true);
this.element.change();

var dLeft = this.options.width - this.options.button_width;
newLeft = "+=" + dLeft;
var dLeft = this.options.width - this.options.button_width;
newLeft = dLeft + this.options.size_unit;

// Update labels states
if(this.options.labels_placement == "both")
Expand Down