Skip to content

Commit 61b3885

Browse files
author
Thomas Grainger
committed
manually fix airbnb violations
1 parent 38813b7 commit 61b3885

File tree

2 files changed

+34
-32
lines changed

2 files changed

+34
-32
lines changed

src/js/bootstrap-switch.js

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -264,18 +264,16 @@ class BootstrapSwitch {
264264
return this.$element;
265265
}
266266

267-
baseClass(value) {
267+
baseClass() {
268268
return this.options.baseClass;
269269
}
270270

271271
wrapperClass(value) {
272272
if (typeof value === 'undefined') { return this.options.wrapperClass; }
273-
if (!value) {
274-
value = $.fn.bootstrapSwitch.defaults.wrapperClass;
275-
}
273+
const wrapperClass = value || $.fn.bootstrapSwitch.defaults.wrapperClass;
276274
this.$wrapper.removeClass(this._getClasses(this.options.wrapperClass).join(' '));
277-
this.$wrapper.addClass(this._getClasses(value).join(' '));
278-
this.options.wrapperClass = value;
275+
this.$wrapper.addClass(this._getClasses(wrapperClass).join(' '));
276+
this.options.wrapperClass = wrapperClass;
279277
return this.$element;
280278
}
281279

@@ -289,21 +287,16 @@ class BootstrapSwitch {
289287

290288
onInit(value) {
291289
if (typeof value === 'undefined') { return this.options.onInit; }
292-
if (!value) {
293-
value = $.fn.bootstrapSwitch.defaults.onInit;
294-
}
295-
this.options.onInit = value;
290+
this.options.onInit = value || $.fn.bootstrapSwitch.defaults.onInit;
296291
return this.$element;
297292
}
298293

299294
onSwitchChange(value) {
300295
if (typeof value === 'undefined') {
301296
return this.options.onSwitchChange;
302297
}
303-
if (!value) {
304-
value = $.fn.bootstrapSwitch.defaults.onSwitchChange;
305-
}
306-
this.options.onSwitchChange = value;
298+
this.options.onSwitchChange =
299+
value || $.fn.bootstrapSwitch.defaults.onSwitchChange;
307300
return this.$element;
308301
}
309302

@@ -366,7 +359,7 @@ class BootstrapSwitch {
366359
return this.$wrapper.width(this._handleWidth + this._labelWidth);
367360
}
368361

369-
_containerPosition(state = this.options.state, callback) {
362+
_containerPosition(state = this.ope) {
370363
this.$container.css('margin-left', () => {
371364
const values = [0, `-${this._handleWidth}px`];
372365
if (this.options.indeterminate) {
@@ -390,22 +383,21 @@ class BootstrapSwitch {
390383
this.setPrevOptions();
391384
this._width();
392385
this._containerPosition();
393-
setTimeout(() => {
394-
if (this.options.animate) {
395-
return this.$wrapper.addClass(this._getClass('animate'));
396-
}
397-
}, 50);
386+
setTimeout(() => (
387+
this.options.animate &&
388+
this.$wrapper.addClass(this._getClass('animate'),
389+
)), 50);
398390
};
399391
if (this.$wrapper.is(':visible')) {
400392
init();
401393
return;
402394
}
403-
const initInterval = window.setInterval(() => {
404-
if (this.$wrapper.is(':visible')) {
405-
init();
406-
return window.clearInterval(initInterval);
407-
}
408-
}, 50);
395+
const initInterval = window.setInterval(
396+
() => (
397+
this.$wrapper.is(':visible') &&
398+
(init() || true) &&
399+
window.clearInterval(initInterval)
400+
), 50);
409401
}
410402

411403
_elementHandlers() {
@@ -544,6 +536,14 @@ class BootstrapSwitch {
544536
}
545537

546538
_formHandler() {
539+
function isBootstrapSwitch() {
540+
return $(this).data('bootstrap-switch');
541+
}
542+
543+
function performReset() {
544+
return $(this).bootstrapSwitch('state', this.checked);
545+
}
546+
547547
const $form = this.$element.closest('form');
548548
if ($form.data('bootstrap-switch')) {
549549
return;
@@ -552,8 +552,8 @@ class BootstrapSwitch {
552552
.on('reset.bootstrapSwitch', () => {
553553
window.setTimeout(() => {
554554
$form.find('input')
555-
.filter(function () { return $(this).data('bootstrap-switch'); })
556-
.each(function () { return $(this).bootstrapSwitch('state', this.checked); });
555+
.filter(isBootstrapSwitch)
556+
.each(performReset);
557557
}, 1);
558558
})
559559
.data('bootstrap-switch', true);
@@ -571,7 +571,7 @@ class BootstrapSwitch {
571571
}
572572
}
573573

574-
$.fn.bootstrapSwitch = function (option, ...args) {
574+
function bootstrapSwitch(option, ...args) {
575575
function reducer(ret, next) {
576576
const $this = $(next);
577577
const existingData = $this.data('bootstrap-switch');
@@ -585,7 +585,9 @@ $.fn.bootstrapSwitch = function (option, ...args) {
585585
return ret;
586586
}
587587
return Array.prototype.reduce.call(this, reducer, this);
588-
};
588+
}
589+
590+
$.fn.bootstrapSwitch = bootstrapSwitch;
589591
$.fn.bootstrapSwitch.Constructor = BootstrapSwitch;
590592
$.fn.bootstrapSwitch.defaults = {
591593
state: true,

src/js/bootstrap-switch.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ describe('Bootstrap Switch:', () => {
4444
const $switch = createCheckbox().bootstrapSwitch();
4545
let eventDoc = 0;
4646
let eventElement = 0;
47-
$(document).on('switchChange.bootstrapSwitch', ':checkbox', (event, state) => { eventDoc++; });
48-
$(':checkbox').on('switchChange.bootstrapSwitch', (event, state) => { eventElement++; });
47+
$(document).on('switchChange.bootstrapSwitch', ':checkbox', () => { eventDoc += 1; });
48+
$(':checkbox').on('switchChange.bootstrapSwitch', () => { eventElement += 1; });
4949
$switch.click();
5050
expect(eventElement).toEqual(eventDoc);
5151
expect(eventElement).toEqual(1);

0 commit comments

Comments
 (0)