[extensions-web] switch: added disabled state
- From: Yuri Konotopov <ykonotopov src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [extensions-web] switch: added disabled state
- Date: Mon, 7 Jan 2019 18:29:55 +0000 (UTC)
commit 33c51233364f66d5f04b510f5abcb0a3d3077fc4
Author: Yuri Konotopov <ykonotopov gnome org>
Date: Mon Jan 7 21:37:42 2019 +0400
switch: added disabled state
sweettooth/static/css/switch.css | 4 ++++
sweettooth/static/js/switch.js | 44 +++++++++++++++++++++++++++++++++++-----
2 files changed, 43 insertions(+), 5 deletions(-)
---
diff --git a/sweettooth/static/css/switch.css b/sweettooth/static/css/switch.css
index 8eb3fd3..e4e0125 100644
--- a/sweettooth/static/css/switch.css
+++ b/sweettooth/static/css/switch.css
@@ -12,6 +12,10 @@
cursor: pointer;
}
+._gnome-switch.disabled {
+ opacity: 0.3;
+}
+
._gnome-switch.outdated,
._gnome-switch.incompatible {
width: auto;
diff --git a/sweettooth/static/js/switch.js b/sweettooth/static/js/switch.js
index efcc171..cd2c5c8 100644
--- a/sweettooth/static/js/switch.js
+++ b/sweettooth/static/js/switch.js
@@ -35,6 +35,11 @@ define(['jquery'], function ($) {
}
function mouseup(e) {
+ if($(this).hasClass('disabled'))
+ {
+ return false;
+ }
+
$slider.addClass('not-dragging');
$(document).off('mousemove.slider').off('mouseup.slider');
var s = getSides($elem, $slider);
@@ -47,6 +52,11 @@ define(['jquery'], function ($) {
}
function mousemove(e) {
+ if($(this).hasClass('disabled'))
+ {
+ return false;
+ }
+
var s = getSides($elem, $slider);
var x = e.pageX - data.initialPageX + data.initialLeft;
if (x < s.left)
@@ -95,7 +105,12 @@ define(['jquery'], function ($) {
}
methods.activate.call($elem, activated);
- $slider.on('mousedown', function (e) {
+ $slider.on('mousedown', (e) => {
+ if($elem.hasClass('disabled'))
+ {
+ return false;
+ }
+
data.initialActivated = data.activated;
data.initialPageX = e.pageX;
var left = $slider.position().left;
@@ -110,6 +125,11 @@ define(['jquery'], function ($) {
});
$elem.on('click', function (e) {
+ if($(this).hasClass('disabled'))
+ {
+ return false;
+ }
+
var doToggle;
var isActivated = !!data.activated;
@@ -193,17 +213,31 @@ define(['jquery'], function ($) {
$elem.prop('title', title);
}
});
+ },
+
+ disable: function() {
+ return this.addClass('disabled');
+ },
+
+ enable: function() {
+ return this.removeClass('disabled');
}
};
$.fn.switchify = function (method) {
- if (methods[method])
+ if(!method || typeof method === 'object')
{
- return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
+ return methods.init.apply(this, arguments);
}
- else if (typeof method === 'object' || !method)
+
+ if(!$(this).data('switch'))
{
- return methods.init.apply(this, arguments);
+ methods.init.apply(this);
+ }
+
+ if (methods[method])
+ {
+ return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
}
else
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]