euscanwww: Upgrading Bootstrap toogle buttons

Signed-off-by: volpino <fox91@anche.no>
This commit is contained in:
volpino 2012-09-24 15:36:11 +02:00 committed by Corentin Chary
parent c519f6b28a
commit 4b3e0bd525
2 changed files with 282 additions and 147 deletions

View File

@ -1,25 +1,17 @@
/* line 7, ../sass/screen.scss */ /* line 11, ../sass/bootstrap-toggle-buttons.scss */
.toggle-button { .toggle-button {
display: inline-block; display: inline-block;
cursor: pointer; cursor: pointer;
background: #0088CC; -webkit-border-radius: 5px;
background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #0088cc), color-stop(100%, #0055cc)); -moz-border-radius: 5px;
background-image: -webkit-linear-gradient(top, #0088cc, #0055cc); -ms-border-radius: 5px;
background-image: -moz-linear-gradient(top, #0088cc, #0055cc); -o-border-radius: 5px;
background-image: -o-linear-gradient(top, #0088cc, #0055cc); border-radius: 5px;
background-image: linear-gradient(top, #0088cc, #0055cc);
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
-ms-border-radius: 4px;
-o-border-radius: 4px;
border-radius: 4px;
border: 1px solid; border: 1px solid;
border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25); border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
position: relative; position: relative;
bottom: -2px;
text-align: left; text-align: left;
min-height: 25px; overflow: hidden;
max-height: 25px;
-webkit-touch-callout: none; -webkit-touch-callout: none;
-webkit-user-select: none; -webkit-user-select: none;
-khtml-user-select: none; -khtml-user-select: none;
@ -27,50 +19,46 @@
-ms-user-select: none; -ms-user-select: none;
user-select: none; user-select: none;
} }
/* line 29, ../sass/screen.scss */ /* line 29, ../sass/bootstrap-toggle-buttons.scss */
.toggle-button:before, .toggle-button:after { .toggle-button.deactivate {
line-height: 25px; filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=50);
font-weight: bold; opacity: 0.5;
letter-spacing: .4px; cursor: default !important;
} }
/* line 35, ../sass/screen.scss */ /* line 32, ../sass/bootstrap-toggle-buttons.scss */
.toggle-button:before { .toggle-button.deactivate label, .toggle-button.deactivate span {
color: #fefefe; cursor: default !important;
padding-left: 0%;
margin-left: 10px;
text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.3);
content: attr(data-enabled);
} }
/* line 43, ../sass/screen.scss */ /* line 36, ../sass/bootstrap-toggle-buttons.scss */
.toggle-button.disabled { .toggle-button > div {
background: #fefefe; display: inline-block;
background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #fefefe), color-stop(100%, #e6e6e6)); width: 150px;
background-image: -webkit-linear-gradient(top, #fefefe, #e6e6e6);
background-image: -moz-linear-gradient(top, #fefefe, #e6e6e6);
background-image: -o-linear-gradient(top, #fefefe, #e6e6e6);
background-image: linear-gradient(top, #fefefe, #e6e6e6);
border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
}
/* line 47, ../sass/screen.scss */
.toggle-button.disabled:before {
color: #555555;
padding-left: 50%;
margin-left: 10px;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.3);
content: attr(data-disabled);
}
/* line 54, ../sass/screen.scss */
.toggle-button.disabled label {
margin-left: -1px;
left: 0%;
}
/* line 60, ../sass/screen.scss */
.toggle-button label {
cursor: pointer;
position: absolute; position: absolute;
width: 50%; top: 0;
height: 25px; }
/* line 41, ../sass/bootstrap-toggle-buttons.scss */
.toggle-button > div.disabled {
left: -50%;
}
/* line 45, ../sass/bootstrap-toggle-buttons.scss */
.toggle-button input[type=checkbox] {
display: none;
}
/* line 53, ../sass/bootstrap-toggle-buttons.scss */
.toggle-button span, .toggle-button label {
cursor: pointer;
position: relative;
float: left;
display: inline-block;
}
/* line 60, ../sass/bootstrap-toggle-buttons.scss */
.toggle-button label {
background: #fefefe; background: #fefefe;
margin-left: -4px;
margin-right: -4px;
border: 1px solid #E6E6E6;
margin-top: -1px;
z-index: 100;
background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #fefefe), color-stop(100%, #e6e6e6)); background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #fefefe), color-stop(100%, #e6e6e6));
background-image: -webkit-linear-gradient(top, #fefefe, #e6e6e6); background-image: -webkit-linear-gradient(top, #fefefe, #e6e6e6);
background-image: -moz-linear-gradient(top, #fefefe, #e6e6e6); background-image: -moz-linear-gradient(top, #fefefe, #e6e6e6);
@ -81,23 +69,43 @@
-ms-border-radius: 4px; -ms-border-radius: 4px;
-o-border-radius: 4px; -o-border-radius: 4px;
border-radius: 4px; border-radius: 4px;
border: 1px solid;
border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
top: -1px;
margin-left: 0;
left: 50%;
} }
/* line 75, ../sass/screen.scss */ /* line 72, ../sass/bootstrap-toggle-buttons.scss */
.toggle-button input[type=checkbox] { .toggle-button span {
display: none; color: #fefefe;
text-align: center;
font-weight: bold;
z-index: 1;
} }
/* line 84, ../sass/screen.scss */ /* line 78, ../sass/bootstrap-toggle-buttons.scss */
.toggle-button.primary:before, .toggle-button.info:before, .toggle-button.success:before, .toggle-button.warning:before, .toggle-button.danger:before { .toggle-button span.labelLeft {
color: white; -moz-border-radius-topleft: 4px;
text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.3); -webkit-border-top-left-radius: 4px;
border-top-left-radius: 4px;
-moz-border-radius-bottomleft: 4px;
-webkit-border-bottom-left-radius: 4px;
border-bottom-left-radius: 4px;
padding-left: 3px;
} }
/* line 90, ../sass/screen.scss */ /* line 83, ../sass/bootstrap-toggle-buttons.scss */
.toggle-button.primary { .toggle-button span.labelRight {
-moz-border-radius-topright: 4px;
-webkit-border-top-right-radius: 4px;
border-top-right-radius: 4px;
-moz-border-radius-bottomright: 4px;
-webkit-border-bottom-right-radius: 4px;
border-bottom-right-radius: 4px;
color: black;
background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #fefefe), color-stop(100%, #e6e6e6));
background-image: -webkit-linear-gradient(top, #fefefe, #e6e6e6);
background-image: -moz-linear-gradient(top, #fefefe, #e6e6e6);
background-image: -o-linear-gradient(top, #fefefe, #e6e6e6);
background-image: linear-gradient(top, #fefefe, #e6e6e6);
padding-right: 3px;
}
/* line 91, ../sass/bootstrap-toggle-buttons.scss */
.toggle-button span.primary, .toggle-button span.labelLeft {
color: #fefefe;
background: #0088cc; background: #0088cc;
background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #0088cc), color-stop(100%, #0055cc)); background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #0088cc), color-stop(100%, #0055cc));
background-image: -webkit-linear-gradient(top, #0088cc, #0055cc); background-image: -webkit-linear-gradient(top, #0088cc, #0055cc);
@ -105,8 +113,9 @@
background-image: -o-linear-gradient(top, #0088cc, #0055cc); background-image: -o-linear-gradient(top, #0088cc, #0055cc);
background-image: linear-gradient(top, #0088cc, #0055cc); background-image: linear-gradient(top, #0088cc, #0055cc);
} }
/* line 94, ../sass/screen.scss */ /* line 96, ../sass/bootstrap-toggle-buttons.scss */
.toggle-button.info { .toggle-button span.info {
color: #fefefe;
background: #5bc0de; background: #5bc0de;
background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #5bc0de), color-stop(100%, #2f96b4)); background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #5bc0de), color-stop(100%, #2f96b4));
background-image: -webkit-linear-gradient(top, #5bc0de, #2f96b4); background-image: -webkit-linear-gradient(top, #5bc0de, #2f96b4);
@ -114,8 +123,9 @@
background-image: -o-linear-gradient(top, #5bc0de, #2f96b4); background-image: -o-linear-gradient(top, #5bc0de, #2f96b4);
background-image: linear-gradient(top, #5bc0de, #2f96b4); background-image: linear-gradient(top, #5bc0de, #2f96b4);
} }
/* line 99, ../sass/screen.scss */ /* line 102, ../sass/bootstrap-toggle-buttons.scss */
.toggle-button.success { .toggle-button span.success {
color: #fefefe;
background: #62c462; background: #62c462;
background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #62c462), color-stop(100%, #51a351)); background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #62c462), color-stop(100%, #51a351));
background-image: -webkit-linear-gradient(top, #62c462, #51a351); background-image: -webkit-linear-gradient(top, #62c462, #51a351);
@ -123,8 +133,9 @@
background-image: -o-linear-gradient(top, #62c462, #51a351); background-image: -o-linear-gradient(top, #62c462, #51a351);
background-image: linear-gradient(top, #62c462, #51a351); background-image: linear-gradient(top, #62c462, #51a351);
} }
/* line 104, ../sass/screen.scss */ /* line 108, ../sass/bootstrap-toggle-buttons.scss */
.toggle-button.warning { .toggle-button span.warning {
color: #fefefe;
background: #dbb450; background: #dbb450;
background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #dbb450), color-stop(100%, #f89406)); background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #dbb450), color-stop(100%, #f89406));
background-image: -webkit-linear-gradient(top, #dbb450, #f89406); background-image: -webkit-linear-gradient(top, #dbb450, #f89406);
@ -132,8 +143,9 @@
background-image: -o-linear-gradient(top, #dbb450, #f89406); background-image: -o-linear-gradient(top, #dbb450, #f89406);
background-image: linear-gradient(top, #dbb450, #f89406); background-image: linear-gradient(top, #dbb450, #f89406);
} }
/* line 109, ../sass/screen.scss */ /* line 114, ../sass/bootstrap-toggle-buttons.scss */
.toggle-button.danger { .toggle-button span.danger {
color: #fefefe;
background: #ee5f5b; background: #ee5f5b;
background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #ee5f5b), color-stop(100%, #bd362f)); background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #ee5f5b), color-stop(100%, #bd362f));
background-image: -webkit-linear-gradient(top, #ee5f5b, #bd362f); background-image: -webkit-linear-gradient(top, #ee5f5b, #bd362f);

View File

@ -1,96 +1,211 @@
!function ($) { !function ($) {
"use strict"; "use strict";
// version: 1.3 // version: 2.2
// by Mattia Larentis - follow me on twitter! @SpiritualGuru
$.fn.toggleButtons = function (opt) { $.fn.toggleButtons = function (method) {
var $element var $element
, $labelEnabled , $div
, options
, active
, styleActive
, styleDisabled
, animationCss
, transitionSpeed = 0.05 , transitionSpeed = 0.05
, defaultSpeed = 0.05; , methods = {
init: function (opt) {
this.each(function () {
var $spanLeft
, $spanRight
, options
, moving;
this.each(function () { $element = $(this);
$element = $(this); $element.addClass('toggle-button');
options = $.extend({}, $.fn.toggleButtons.defaults, opt); options = $.extend({}, $.fn.toggleButtons.defaults, opt);
$(this).data('options', options);
$element.addClass('toggle-button'); $spanLeft = $('<span></span>').addClass("labelLeft").text(options.label.enabled === undefined ? "ON" : options.label.enabled);
$spanRight = $('<span></span>').addClass("labelRight").text(options.label.disabled === undefined ? "OFF " : options.label.disabled);
$labelEnabled = $('<label></label>').attr('for', $element.find('input').attr('id')); // html layout
$element.append($labelEnabled); $div = $element.find('input').wrap($('<div></div>')).parent();
$div.append($spanLeft);
$div.append($('<label></label>').attr('for', $element.find('input').attr('id')));
$div.append($spanRight);
if (options.animated) { if ($element.find('input').is(':checked'))
$element.addClass('toggle-button-animated'); $element.find('>div').css('left', "0");
else $element.find('>div').css('left', "-50%");
if (options.transitionSpeed !== undefined) if (options.animated) {
if (/^(\d*%$)/.test(options.transitionSpeed)) // is a percent value? if (options.transitionSpeed !== undefined)
transitionSpeed = defaultSpeed * parseInt(options.transitionSpeed) / 100; if (/^(\d*%$)/.test(options.transitionSpeed)) // is a percent value?
else transitionSpeed = 0.05 * parseInt(options.transitionSpeed) / 100;
transitionSpeed = options.transitionSpeed; else
transitionSpeed = options.transitionSpeed;
}
else transitionSpeed = 0;
animationCss = ["-webkit-", "-moz-", "-o-", ""]; $(this).data('transitionSpeed', transitionSpeed * 1000);
$(animationCss).each(function () {
$element.find('label').css(this + 'transition', 'all ' + transitionSpeed + 's');
});
}
$element.css('width', options.width);
$element.attr("data-enabled", options.label.enabled === undefined ? "ON" : options.label.enabled);
$element.attr("data-disabled", options.label.disabled === undefined ? "OFF " : options.label.disabled);
active = $element.find('input').is(':checked');
if (!active)
$element.addClass('disabled');
styleActive = options.style.enabled === undefined ? "" : options.style.enabled;
styleDisabled = options.style.disabled === undefined ? "" : options.style.disabled;
if (active && styleActive !== undefined)
$element.addClass(styleActive);
if (!active && styleDisabled !== undefined)
$element.addClass(styleDisabled);
$element.on('click', function (e) {
if ($(e.target).is('input'))
return true;
e.stopPropagation();
$(this).find('label').click();
});
$element.find('label').on('click', function (e) { options["width"] /= 2;
e.stopPropagation();
e.preventDefault();
$element = $(this).parent(); // width of the bootstrap-toggle-button
$element
.css('width', options.width * 2)
.find('>div').css('width', options.width * 3)
.find('>span, >label').css('width', options.width);
$element // height of the bootstrap-toggle-button
.delay(transitionSpeed * 500).queue(function () { $element
$(this).toggleClass('disabled') .css('height', options.height)
.toggleClass(styleActive) .find('span, label')
.toggleClass(styleDisabled) .css('height', options.height)
.dequeue(); .filter('span')
}); .css('line-height', options.height + "px");
active = !($element.find('input').is(':checked')); if ($element.find('input').is(':disabled'))
$(this).addClass('deactivate');
$element.find('input').attr('checked', active); $element.find('span').css(options.font);
options.onChange($element, active, e);
});
}); // enabled custom color
if (options.style.enabled === undefined) {
if (options.style.custom !== undefined && options.style.custom.enabled !== undefined) {
$spanLeft.css('color', options.style.custom.enabledColor);
if (options.style.custom.enabledGradient === undefined)
$spanLeft.css('background', options.style.custom.enabled);
else $.each(["-webkit-", "-moz-", "-o-", ""], function (i, el) {
$spanLeft.css('background-image', el + 'linear-gradient(top, ' + options.style.custom.enabled + ',' + options.style.custom.enabledGradient + ')');
});
}
}
else $spanLeft.addClass(options.style.enabled);
// disabled custom color
if (options.style.disabled === undefined) {
if (options.style.custom !== undefined && options.style.custom.disabled !== undefined) {
$spanRight.css('color', options.style.custom.disabledColor);
if (options.style.custom.disabledGradient === undefined)
$spanRight.css('background', options.style.custom.disabled);
else $.each(["-webkit-", "-moz-", "-o-", ""], function (i, el) {
$spanRight.css('background-image', el + 'linear-gradient(top, ' + options.style.custom.disabled + ',' + options.style.custom.disabledGradient + ')');
});
}
}
else $spanRight.addClass(options.style.disabled);
var changeStatus = function ($this) {
$this.siblings('label').trigger('mousedown').trigger('mouseup').trigger('click');
};
$spanLeft.on('click', function (e) {
changeStatus($(this));
});
$spanRight.on('click', function (e) {
changeStatus($(this));
});
$('.toggle-button').find('input').on('change', function (e) {
var $element = $(this).parent()
, active = $(this).is(':checked')
, $toggleButton = $(this).closest('.toggle-button');
e.preventDefault();
e.stopImmediatePropagation();
$element.animate({'left': active ? '0' : '-50%'}, $toggleButton.data('transitionSpeed'));
options = $toggleButton.data('options');
options.onChange($element, active, e);
});
$('.toggle-button').find('label').on('mousedown', function (e) {
moving = false;
e.preventDefault();
e.stopImmediatePropagation();
if ($(this).closest('.toggle-button').is('.deactivate'))
$(this).unbind('click');
else {
$(this).on('mousemove', function (e) {
var $element = $(this).closest('.toggle-button')
, relativeX = e.pageX - $element.offset().left
, percent = ((relativeX / (options.width * 2)) * 100);
moving = true;
if (percent < 25)
percent = 25;
else if (percent > 75)
percent = 75;
$element.find('>div').css('left', (percent - 75) + "%")
});
$(this).on('click', function (e) {
var $target = $(e.target)
, $myCheckBox = $target.siblings('input');
e.stopImmediatePropagation();
e.preventDefault();
$(this).unbind('mouseleave');
if (moving)
if (parseInt($(this).parent().css('left')) < -25)
$myCheckBox.attr('checked', false);
else $myCheckBox.attr('checked', true);
else $myCheckBox.attr("checked", !$myCheckBox.is(":checked"));
$myCheckBox.trigger('change');
});
$(this).on('mouseleave', function (e) {
var $myCheckBox = $(this).siblings('input');
e.preventDefault();
e.stopImmediatePropagation();
$(this).unbind('mouseleave');
$(this).trigger('mouseup');
if (parseInt($(this).parent().css('left')) < -25)
$myCheckBox.attr('checked', false);
else $myCheckBox.attr('checked', true);
$myCheckBox.trigger('change');
});
$(this).on('mouseup', function (e) {
e.stopImmediatePropagation();
e.preventDefault();
$(this).unbind('mousemove');
});
}
});
}
)
;
},
toggleActivation: function () {
$(this).toggleClass('deactivate');
}
};
if (methods[method])
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
else if (typeof method === 'object' || !method)
return methods.init.apply(this, arguments);
else
$.error('Method ' + method + ' does not exist on jQuery.tooltip');
}; };
$.fn.toggleButtons.defaults = { $.fn.toggleButtons.defaults = {
onChange: function () { onChange: function () {
}, },
width: 100, width: 100,
height: 25,
font: {},
animated: true, animated: true,
transitionSpeed: undefined, transitionSpeed: undefined,
label: { label: {
@ -99,7 +214,15 @@
}, },
style: { style: {
enabled: undefined, enabled: undefined,
disabled: undefined disabled: undefined,
custom: {
enabled: undefined,
enabledGradient: undefined,
enabledColor: "#FFFFFF",
disabled: undefined,
disabledGradient: undefined,
disabledColor: "#FFFFFF"
}
} }
}; };
}($); }($);