Trying a different toggle button

This commit is contained in:
Falkvinge
2016-11-13 14:17:37 +01:00
parent 91385596c3
commit 01a50e371a
5 changed files with 368 additions and 3 deletions
+7 -3
View File
@@ -10,6 +10,7 @@
<script language="javascript" type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js" ></script>
<script language="javascript" type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/jquery-ui.min.js" ></script>
<script language="javascript" type="text/javascript" src="/Scripts/jquery.tmpl.js" ></script>
<script language="javascript" type="text/javascript" src="/Scripts/jquery.toggles.min.js" ></script>
<script language="javascript" type="text/javascript" src="/Scripts/jquery.leanModal.min.js" ></script>
<script language="javascript" type="text/javascript" src="/Scripts/jquery.color.js" ></script>
<script language="javascript" type="text/javascript" src="/Scripts/jquery.animate-shadow.js" ></script>
@@ -31,6 +32,7 @@
<link href="/Style/style-v5.css?CacheId=<%= _cacheVersionMark %>" rel="stylesheet" type="text/css" />
</asp:PlaceHolder>
<link href="/Style/jquery.qtip.css" rel="stylesheet" type="text/css" />
<link href="/Style/jquery.toggles.css" rel="stylesheet" type="text/css" />
<link href="/Style/alertify.core.css" rel="stylesheet" type="text/css" />
<link href="/Style/alertify.default.css" rel="stylesheet" type="text/css" />
<link href="/Style/superfish.css" rel="stylesheet" type="text/css" />
@@ -354,9 +356,11 @@
// This JavaScript block is for the Master Modal Person Editor.
$(document).ready(function() {
$('.EditCheck').switchbutton({
checkedLabel: SwarmopsJS.unescape('<%= this.Localized_SwitchLabelOn_Upper %>'),
uncheckedLabel: SwarmopsJS.unescape('<%= this.Localized_SwitchLabelOff_Upper %>')
$('.MasterToggles').toggles(
{ text: {
on: SwarmopsJS.unescape('<%= this.Localized_SwitchLabelOn_Upper %>'),
off: SwarmopsJS.unescape('<%= this.Localized_SwitchLabelOff_Upper %>')
}
}).change(function() {});
});
+272
View File
@@ -0,0 +1,272 @@
/**
@license jQuery Toggles v4.0.0
Copyright 2012 - 2015 Simon Tabor - MIT License
https://github.com/simontabor/jquery-toggles / http://simontabor.com/labs/toggles
*/
(function (root) {
var factory = function ($) {
var Toggles = root['Toggles'] = function (el, opts) {
var self = this;
if (typeof opts === 'boolean' && el.data('toggles')) {
el.data('toggles').toggle(opts);
return;
}
var dataAttr = [
'on',
'drag',
'click',
'width',
'height',
'animate',
'easing',
'type',
'checkbox'
];
var dataOpts = {};
for (var i = 0; i < dataAttr.length; i++) {
var opt = el.data('toggle-' + dataAttr[i]);
if (typeof opt !== 'undefined') dataOpts[dataAttr[i]] = opt;
}
// extend default opts with the users options
opts = $.extend({
// can the toggle be dragged
'drag': true,
// can it be clicked to toggle
'click': true,
'text': {
// text for the ON/OFF position
'on': 'ON',
'off': 'OFF'
},
// is the toggle ON on init
'on': false,
// animation time (ms)
'animate': 250,
// animation transition easing function,
'easing': 'swing',
// the checkbox to toggle (for use in forms)
'checkbox': null,
// element that can be clicked on to toggle. removes binding from the toggle itself (use nesting)
'clicker': null,
// width (falls back to 50px)
'width': 0,
// height (falls back to 20px)
'height': 0,
// defaults to a compact toggle, other option is 'select' where both options are shown at once
'type': 'compact',
// the event name to fire when we toggle
'event': 'toggle'
}, opts || {}, dataOpts);
el.data('toggles', self);
// set active to the opposite of what we want, so toggle will run properly
var active = !opts['on'];
var selectType = opts['type'] === 'select';
// make checkbox a jquery element
var checkbox = $(opts['checkbox']);
var clicker = opts['clicker'] && $(opts['clicker']);
var height = opts['height'] || el.height() || 20;
var width = opts['width'] || el.width() || 50;
el.height(height);
el.width(width);
var div = function (name) {
return $('<div class="toggle-' + name + '">');
};
// wrapper inside toggle
var elSlide = div('slide');
// inside slide, this bit moves
var elInner = div('inner');
// the on/off divs
var elOn = div('on');
var elOff = div('off');
// the grip to drag the toggle
var elBlob = div('blob');
var halfHeight = height / 2;
var onOffWidth = width - halfHeight;
var text = opts['text'];
// set up the CSS for the individual elements
elOn
.css({
height: height,
width: onOffWidth,
textIndent: selectType ? '' : -height / 3,
lineHeight: height + 'px'
})
.html(text['on']);
elOff
.css({
height: height,
width: onOffWidth,
marginLeft: selectType ? '' : -halfHeight,
textIndent: selectType ? '' : height / 3,
lineHeight: height + 'px'
})
.html(text['off']);
elBlob.css({
height: height,
width: height,
marginLeft: -halfHeight
});
elInner.css({
width: width * 2 - height,
marginLeft: selectType ? 0 : -width + height
});
if (selectType) {
elSlide.addClass('toggle-select');
el.css('width', onOffWidth * 2);
elBlob.hide();
}
// construct the toggle
elInner.append(elOn, elBlob, elOff);
elSlide.html(elInner);
el.html(elSlide);
var doToggle = self.toggle = function (state, noAnimate, noEvent) {
// check we arent already in the desired state
if (active === state) return;
active = self['active'] = !active;
el.data('toggle-active', active);
elOff.toggleClass('active', !active);
elOn.toggleClass('active', active);
checkbox.prop('checked', active);
if (!noEvent) el.trigger(opts['event'], active);
if (selectType) return;
var margin = active ? 0 : -width + height;
// move the toggle!
elInner.stop().animate({
'marginLeft': margin
}, noAnimate ? 0 : opts['animate'], opts['easing']);
};
// evt handler for click events
var clickHandler = function (e) {
// if the target isn't the blob or dragging is disabled, toggle!
if (!el.hasClass('disabled') && (e['target'] !== elBlob[0] || !opts['drag'])) {
doToggle();
}
};
// if click is enabled and toggle isn't within the clicker element (stops double binding)
if (opts['click'] && (!clicker || !clicker.has(el).length)) {
el.on('click', clickHandler);
}
// setup the clicker element
if (clicker) {
clicker.on('click', clickHandler);
}
// bind up dragging stuff
if (opts['drag'] && !selectType) {
// time to begin the dragging parts/blob clicks
var diff;
var slideLimit = (width - height) / 4;
// fired on mouseup and mouseleave events
var upLeave = function (e) {
el.off('mousemove');
elSlide.off('mouseleave');
elBlob.off('mouseup');
if (!diff && opts['click'] && e.type !== 'mouseleave') {
doToggle();
return;
}
var overBound = active ? diff < -slideLimit : diff > slideLimit;
if (overBound) {
// dragged far enough, toggle
doToggle();
} else {
// reset to previous state
elInner.stop().animate({
marginLeft: active ? 0 : -width + height
}, opts['animate'] / 2, opts['easing']);
}
};
var wh = -width + height;
elBlob.on('mousedown', function (e) {
if (el.hasClass('disabled')) return;
// reset diff
diff = 0;
elBlob.off('mouseup');
elSlide.off('mouseleave');
var cursor = e.pageX;
el.on('mousemove', elBlob, function (e) {
diff = e.pageX - cursor;
var marginLeft;
if (active) {
marginLeft = diff;
// keep it within the limits
if (diff > 0) marginLeft = 0;
if (diff < wh) marginLeft = wh;
} else {
marginLeft = diff + wh;
if (diff < 0) marginLeft = wh;
if (diff > -wh) marginLeft = 0;
}
elInner.css('margin-left', marginLeft);
});
elBlob.on('mouseup', upLeave);
elSlide.on('mouseleave', upLeave);
});
}
// toggle the toggle to the correct state with no animation and no event
doToggle(opts['on'], true, true);
};
$.fn['toggles'] = function (opts) {
return this.each(function () {
new Toggles($(this), opts);
});
};
};
if (typeof define === 'function' && define['amd']) {
define(['jquery'], factory);
} else {
factory(root['jQuery'] || root['Zepto'] || root['ender'] || root['$'] || $);
}
})(this);
+11
View File
@@ -0,0 +1,11 @@
/*
jQuery Toggles v4.0.0
Copyright 2012 - 2015 Simon Tabor - MIT License
https://github.com/simontabor/jquery-toggles / http://simontabor.com/labs/toggles
*/
(function(g){function p(q){var p=g.Toggles=function(c,a){var g=this;if("boolean"===typeof a&&c.data("toggles"))c.data("toggles").toggle(a);else{for(var k="on drag click width height animate easing type checkbox".split(" "),b={},l=0;l<k.length;l++){var t=c.data("toggle-"+k[l]);"undefined"!==typeof t&&(b[k[l]]=t)}a=q.extend({drag:!0,click:!0,text:{on:"ON",off:"OFF"},on:!1,animate:250,easing:"swing",checkbox:null,clicker:null,width:0,height:0,type:"compact",event:"toggle"},a||{},b);c.data("toggles",
g);var f=!a.on,n="select"===a.type,p=q(a.checkbox),k=a.clicker&&q(a.clicker),d=a.height||c.height()||20,m=a.width||c.width()||50;c.height(d);c.width(m);var b=function(a){return q('<div class="toggle-'+a+'">')},r=b("slide"),s=b("inner"),w=b("on"),x=b("off"),h=b("blob"),b=d/2,l=m-b,t=a.text;w.css({height:d,width:l,textIndent:n?"":-d/3,lineHeight:d+"px"}).html(t.on);x.css({height:d,width:l,marginLeft:n?"":-b,textIndent:n?"":d/3,lineHeight:d+"px"}).html(t.off);h.css({height:d,width:d,marginLeft:-b});
s.css({width:2*m-d,marginLeft:n?0:-m+d});n&&(r.addClass("toggle-select"),c.css("width",2*l),h.hide());s.append(w,h,x);r.html(s);c.html(r);var v=g.toggle=function(b,e,A){f!==b&&(f=g.active=!f,c.data("toggle-active",f),x.toggleClass("active",!f),w.toggleClass("active",f),p.prop("checked",f),A||c.trigger(a.event,f),n||(b=f?0:-m+d,s.stop().animate({marginLeft:b},e?0:a.animate,a.easing)))},b=function(b){c.hasClass("disabled")||b.target===h[0]&&a.drag||v()};if(a.click&&(!k||!k.has(c).length))c.on("click",
b);if(k)k.on("click",b);if(a.drag&&!n){var e,y=(m-d)/4,z=function(b){c.off("mousemove");r.off("mouseleave");h.off("mouseup");!e&&a.click&&"mouseleave"!==b.type?v():(f?e<-y:e>y)?v():s.stop().animate({marginLeft:f?0:-m+d},a.animate/2,a.easing)},u=-m+d;h.on("mousedown",function(a){if(!c.hasClass("disabled")){e=0;h.off("mouseup");r.off("mouseleave");var b=a.pageX;c.on("mousemove",h,function(a){e=a.pageX-b;f?(a=e,0<e&&(a=0),e<u&&(a=u)):(a=e+u,0>e&&(a=u),e>-u&&(a=0));s.css("margin-left",a)});h.on("mouseup",
z);r.on("mouseleave",z)}})}v(a.on,!0,!0)}};q.fn.toggles=function(c){return this.each(function(){new p(q(this),c)})}}"function"===typeof define&&define.amd?define(["jquery"],p):p(g.jQuery||g.Zepto||g.ender||g.$||$)})(this);
+3
View File
@@ -1725,6 +1725,8 @@
<Content Include="Scripts\jquery.snipe.js" />
<Content Include="Scripts\jquery.switchButton.js" />
<Content Include="Scripts\jquery.tmpl.js" />
<Content Include="Scripts\jquery.toggles.js" />
<Content Include="Scripts\jquery.toggles.min.js" />
<Content Include="Scripts\jquery.ui.widget.min.js" />
<Content Include="Scripts\qrcode.js" />
<Content Include="Scripts\qrcode.min.js" />
@@ -1765,6 +1767,7 @@
<Content Include="Style\jquery.qtip.css" />
<Content Include="Style\jquery.qtip.min.css" />
<Content Include="Style\jquery.switchButton.css" />
<Content Include="Style\jquery.toggles.css" />
<Content Include="Style\style-v5.css" />
<Content Include="Style\superfish.css" />
<Content Include="Style\v5-easyui-elements.css" />
+75
View File
@@ -0,0 +1,75 @@
.toggle-slide {
overflow: hidden;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
direction: ltr;
text-align: center;
}
div.disabled > .toggle-slide {
opacity: 0.7;
pointer-events: none;
}
.toggle-slide .toggle-on,
.toggle-slide .toggle-off,
.toggle-slide .toggle-blob {
float: left;
}
.toggle-slide .toggle-blob {
position: relative;
z-index: 99;
cursor: hand;
cursor: grab;
}
.toggle-iphone .toggle-slide {
border-radius: 9999px;
box-shadow: 0 0 0 1px #999;
}
.toggle-iphone .toggle-on,
.toggle-iphone .toggle-off {
color: white;
font-size: 18px;
font-weight: bold;
text-shadow: 0 0 8px rgba(0, 0, 0, 0.5);
}
.toggle-iphone .toggle-on {
border-radius: 9999px 0 0 9999px;
background: #037bda;
box-shadow: inset 2px 2px 5px rgba(0, 0, 0, 0.4);
}
.toggle-iphone .toggle-on:after {
background: -webkit-linear-gradient(#1189f1, #3797ef);
background: linear-gradient(#1189f1, #3797ef);
height: 50%;
content: '';
margin-top: -19%;
display: block;
border-radius: 9999px;
margin-left: 10%;
}
.toggle-iphone .toggle-off {
box-shadow: inset -2px 2px 5px rgba(0, 0, 0, 0.4);
border-radius: 0 9999px 9999px 0;
color: #828282;
background: #ECECEC;
text-shadow: 0 0 1px white;
}
.toggle-iphone .toggle-off:after {
background: -webkit-linear-gradient(#fafafa, #fdfdfd);
background: linear-gradient(#fafafa, #fdfdfd);
height: 50%;
content: '';
margin-top: -19%;
display: block;
margin-right: 10%;
border-radius: 9999px;
}
.toggle-iphone .toggle-blob {
border-radius: 50px;
background: -webkit-linear-gradient(#d1d1d1, #fafafa);
background: linear-gradient(#d1d1d1, #fafafa);
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.6), inset 0 0 0 2px white, 0 0 3px rgba(0, 0, 0, 0.6);
}