bootstrap5-toggle 4.3.4 → 4.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /* Copyright Notice
2
- * bootstrap5-toggle v4.3.4
2
+ * bootstrap5-toggle v4.3.6
3
3
  * https://palcarazm.github.io/bootstrap5-toggle/
4
4
  * @author 2011-2014 Min Hur (https://github.com/minhur)
5
5
  * @author 2018-2019 Brent Ely (https://github.com/gitbrent)
@@ -11,317 +11,367 @@
11
11
  */
12
12
 
13
13
 
14
- +function ($) {
15
- 'use strict';
16
-
17
- // TOGGLE PUBLIC CLASS DEFINITION
18
- // ==============================
19
-
20
- let Toggle = function (element, options) {
21
- // A: Capture ref to HMTL element
22
- this.$element = $(element)
23
- // B: Set options
24
- this.options = $.extend({}, this.defaults(), options)
25
- // LAST: Render Toggle
26
- this.render()
27
- }
28
-
29
- Toggle.DEFAULTS = {
30
- on: 'On',
31
- off: 'Off',
32
- onstyle: 'primary',
33
- offstyle: 'secondary',
34
- onvalue: null,
35
- offvalue: null,
36
- size: 'normal',
37
- style: '',
38
- width: null,
39
- height: null,
40
- tabindex: 0,
41
- tristate: false,
42
- name: null,
43
- }
44
-
45
- Toggle.prototype.defaults = function() {
46
- return {
47
- on: this.$element.attr('data-on') || Toggle.DEFAULTS.on,
48
- off: this.$element.attr('data-off') || Toggle.DEFAULTS.off,
49
- onstyle: this.$element.attr('data-onstyle') || Toggle.DEFAULTS.onstyle,
50
- offstyle: this.$element.attr('data-offstyle') || Toggle.DEFAULTS.offstyle,
51
- onvalue: this.$element.attr('value') || this.$element.attr('data-onvalue') || Toggle.DEFAULTS.onvalue,
52
- offvalue: this.$element.attr('data-offvalue') || Toggle.DEFAULTS.offvalue,
53
- size: this.$element.attr('data-size') || Toggle.DEFAULTS.size,
54
- style: this.$element.attr('data-style') || Toggle.DEFAULTS.style,
55
- width: this.$element.attr('data-width') || Toggle.DEFAULTS.width,
56
- height: this.$element.attr('data-height') || Toggle.DEFAULTS.height,
57
- tabindex: this.$element.attr('tabindex') || Toggle.DEFAULTS.tabindex,
58
- tristate: this.$element.is('[tristate]') || Toggle.DEFAULTS.tristate,
59
- name: this.$element.attr('name') || Toggle.DEFAULTS.name,
60
- }
61
- }
62
-
63
- Toggle.prototype.render = function () {
64
- // 0: Parse size
65
- let size;
66
- switch (this.options.size ) {
67
- case 'large':
68
- case 'lg':
69
- size = 'btn-lg';
70
- break;
71
- case 'small':
72
- case 'sm':
73
- size = 'btn-sm';
74
- break;
75
- case 'mini':
76
- case 'xs':
77
- size = 'btn-xs';
78
- break;
79
- default:
80
- size = ''
81
- break;
82
- }
83
-
84
- // 1: On
85
- let $toggleOn = $('<label for="'+ this.$element.prop('id') +'" class="btn">').html(this.options.on)
86
- .addClass('btn-' +this.options.onstyle + ' ' + size)
87
-
88
- // 2: Off
89
- let $toggleOff = $('<label for="'+ this.$element.prop('id') +'" class="btn">').html(this.options.off)
90
- .addClass('btn-' +this.options.offstyle + ' ' + size)
91
-
92
- // 3: Handle
93
- let $toggleHandle = $('<span class="toggle-handle btn">')
94
- .addClass(size)
95
-
96
- // 4: Toggle Group
97
- let $toggleGroup = $('<div class="toggle-group">')
98
- .append($toggleOn, $toggleOff, $toggleHandle)
99
-
100
- // 5: Toggle
101
- let $toggle = $('<div class="toggle btn" data-toggle="toggle" role="button">')
102
- .addClass( this.$element.prop('checked') ? 'btn-' +this.options.onstyle : 'btn-' +this.options.offstyle+' off' )
103
- .addClass(size).addClass(this.options.style)
104
- .attr('tabindex', this.options.tabindex)
105
- if (this.$element.prop('disabled') || this.$element.prop('readonly')){
106
- $toggle.addClass('disabled')
107
- $toggle.attr('disabled', 'disabled')
108
- }
109
-
110
- // 6: Set form values
111
- if(this.options.onvalue) this.$element.val(this.options.onvalue)
112
- let $invElement = null;
113
- if(this.options.offvalue){
114
- $invElement = this.$element.clone();
115
- $invElement.val(this.options.offvalue);
116
- $invElement.attr('data-toggle', 'invert-toggle');
117
- $invElement.removeAttr('id');
118
- $invElement.prop('checked', !this.$element.prop('checked'));
119
- }
120
-
121
- // 7: Replace HTML checkbox with Toggle-Button
122
- this.$element.wrap($toggle)
123
- $.extend(this, {
124
- $toggle: this.$element.parent(),
125
- $toggleOn: $toggleOn,
126
- $toggleOff: $toggleOff,
127
- $toggleGroup: $toggleGroup,
128
- $invElement: $invElement
129
- })
130
- this.$toggle.append($invElement, $toggleGroup)
131
-
132
- // 8: Set button W/H, lineHeight
133
- {
134
- // A: Set style W/H
135
- let width = this.options.width || Math.max($toggleOn.outerWidth(), $toggleOff.outerWidth())+($toggleHandle.outerWidth()/2)
136
- let height = this.options.height || Math.max($toggleOn.outerHeight(), $toggleOff.outerHeight())
137
- this.$toggle.css({ width: width, height: height })
138
-
139
- // B: Apply on/off class
140
- $toggleOn.addClass('toggle-on')
141
- $toggleOff.addClass('toggle-off')
142
-
143
- // C: Finally, set lineHeight if needed
144
- if (this.options.height) {
145
- $toggleOn.css('line-height', $toggleOn.height() + 'px')
146
- $toggleOff.css('line-height', $toggleOff.height() + 'px')
147
- }
148
- }
149
-
150
- // 9: Add listeners
151
- this.$toggle.on('touchstart', (e)=>{
152
- toggleActionPerformed(e, this)
153
- });
154
- this.$toggle.on('click', (e)=>{
155
- toggleActionPerformed(e, this)
156
- });
157
- this.$toggle.on('keypress', (e)=>{
158
- if(e.key == " "){
159
- toggleActionPerformed(e, this)
160
- }
161
- });
162
- // 10: Set elements to bootstrap object (NOT NEEDED)
163
- // 11: Keep reference to this instance for subsequent calls via `getElementById().bootstrapToggle()` (NOT NEEDED)
164
- }
165
-
166
- /**
167
- * Trigger actions
168
- * @param {Event} e event
169
- * @param {Toggle} target Toggle
170
- */
171
- function toggleActionPerformed(e , target){
172
- if(target.options.tristate){
173
- if(target.$toggle.hasClass('indeterminate')){
174
- target.determinate(true);
175
- target.toggle();
176
- }else{
177
- target.indeterminate();
178
- }
179
- }else{
180
- target.toggle()
181
- }
182
- e.preventDefault()
183
- }
184
-
185
- Toggle.prototype.toggle = function (silent = false) {
186
- if (this.$element.prop('checked')) this.off(silent)
187
- else this.on(silent)
188
- }
189
-
190
- Toggle.prototype.on = function (silent = false) {
191
- if (this.$element.prop('disabled') || this.$element.prop('readonly')) return false
192
- this.$toggle.removeClass('btn-' +this.options.offstyle + ' off').addClass('btn-' +this.options.onstyle)
193
- this.$element.prop('checked', true)
194
- if(this.$invElement) this.$invElement.prop('checked', false);
195
- if (!silent) this.trigger()
196
- }
197
-
198
- Toggle.prototype.off = function (silent = false) {
199
- if (this.$element.prop('disabled') || this.$element.prop('readonly')) return false
200
- this.$toggle.removeClass('btn-' +this.options.onstyle).addClass('btn-' +this.options.offstyle + ' off')
201
- this.$element.prop('checked', false)
202
- if(this.$invElement) this.$invElement.prop('checked', true);
203
- if (!silent) this.trigger()
204
- }
205
-
206
- Toggle.prototype.indeterminate = function (silent = false) {
207
- if (!this.options.tristate || this.$element.prop('disabled') || this.$element.prop('readonly')) return false;
208
- this.$toggle.addClass('indeterminate');
209
- this.$element.prop('indeterminate', true);
210
- this.$element.removeAttr('name');
211
- if(this.$invElement) this.$invElement.prop('indeterminate', true);
212
- if(this.$invElement) this.$invElement.removeAttr('name');
213
- if (!silent) this.trigger()
214
- }
215
-
216
- Toggle.prototype.determinate = function (silent = false) {
217
- if (!this.options.tristate || this.$element.prop('disabled') || this.$element.prop('readonly')) return false;
218
- this.$toggle.removeClass('indeterminate');
219
- this.$element.prop('indeterminate', false);
220
- if(this.options.name) this.$element.attr('name', this.options.name);
221
- if(this.$invElement) this.$invElement.prop('indeterminate', false);
222
- if(this.$invElement && this.options.name) this.$invElement.attr('name', this.options.name);
223
- if (!silent) this.trigger()
224
- }
225
-
226
- Toggle.prototype.enable = function () {
227
- this.$toggle.removeClass('disabled')
228
- this.$toggle.removeAttr('disabled')
229
- this.$element.prop('disabled', false)
230
- this.$element.prop('readonly',false)
231
- if(this.$invElement){
232
- this.$invElement.prop('disabled', false)
233
- this.$invElement.prop('readonly',false)
234
- }
235
- }
236
-
237
- Toggle.prototype.disable = function () {
238
- this.$toggle.addClass('disabled')
239
- this.$toggle.attr('disabled', 'disabled')
240
- this.$element.prop('disabled', true)
241
- this.$element.prop('readonly', false)
242
- if(this.$invElement){
243
- this.$invElement.prop('disabled', true)
244
- this.$invElement.prop('readonly', false)
245
- }
246
- }
247
-
248
- Toggle.prototype.readonly = function () {
249
- this.$toggle.addClass('disabled')
250
- this.$toggle.attr('disabled', 'disabled')
251
- this.$element.prop('disabled', false)
252
- this.$element.prop('readonly', true)
253
- if(this.$invElement){
254
- this.$invElement.prop('disabled', false)
255
- this.$invElement.prop('readonly', true)
256
- }
257
- }
258
-
259
- Toggle.prototype.update = function (silent) {
260
- if (this.$element.prop('disabled')) this.disable()
261
- else if (this.$element.prop('readonly')) this.readonly()
262
- else this.enable()
263
- if (this.$element.prop('checked')) this.on(silent)
264
- else this.off(silent)
265
- }
266
-
267
- Toggle.prototype.trigger = function (silent) {
268
- this.$element.off('change.bs.toggle')
269
- if (!silent) this.$element.change()
270
- this.$element.on('change.bs.toggle', $.proxy(function() {
271
- this.update()
272
- }, this))
273
- }
274
-
275
- Toggle.prototype.destroy = function() {
276
- // A: Remove button-group from UI, replace checkbox element
277
- this.$element.off('change.bs.toggle')
278
- this.$toggleGroup.remove()
279
- if(this.$invElement) this.$invElement.remove()
280
-
281
- // B: Delete internal refs
282
- this.$element.removeData('bs.toggle')
283
- this.$element.unwrap()
284
- }
285
-
286
- // TOGGLE PLUGIN DEFINITION
287
- // ========================
288
-
289
- function Plugin(option) {
290
- let optArg = Array.prototype.slice.call( arguments, 1 )[0]
291
-
292
- return this.each(function () {
293
- let $this = $(this)
294
- let data = $this.data('bs.toggle')
295
- let options = typeof option == 'object' && option
296
-
297
- if (!data) {
298
- data = new Toggle(this, options)
299
- $this.data('bs.toggle', data)
300
- }
301
- if (typeof option === 'string' && data[option] && typeof optArg === 'boolean') data[option](optArg)
302
- else if (typeof option === 'string' && data[option]) data[option]()
303
- //else if (option && !data[option]) console.log('bootstrap-toggle: error: method `'+ option +'` does not exist!');
304
- })
305
- }
306
-
307
- let old = $.fn.bootstrapToggle
308
-
309
- $.fn.bootstrapToggle = Plugin
310
- $.fn.bootstrapToggle.Constructor = Toggle
311
-
312
- // TOGGLE NO CONFLICT
313
- // ==================
314
-
315
- $.fn.toggle.noConflict = function () {
316
- $.fn.bootstrapToggle = old
317
- return this
318
- }
319
-
320
- /**
321
- * Replace all `input[type=checkbox][data-toggle="toggle"]` inputs with "Bootstrap-Toggle"
322
- * Executes once page elements have rendered enabling script to be placed in `<head>`
323
- */
324
- $(function() {
325
- $('input[type=checkbox][data-toggle^=toggle]').bootstrapToggle()
326
- })
327
- }(jQuery);
14
+ +(function ($) {
15
+ "use strict";
16
+
17
+ // TOGGLE PUBLIC CLASS DEFINITION
18
+ // ==============================
19
+
20
+ let Toggle = function (element, options) {
21
+ // A: Capture ref to HMTL element
22
+ this.$element = $(element);
23
+ // B: Set options
24
+ this.options = $.extend({}, this.defaults(), options);
25
+ // LAST: Render Toggle
26
+ this.render();
27
+ };
28
+
29
+ Toggle.DEFAULTS = {
30
+ on: "On",
31
+ off: "Off",
32
+ onstyle: "primary",
33
+ offstyle: "secondary",
34
+ onvalue: null,
35
+ offvalue: null,
36
+ size: "normal",
37
+ style: "",
38
+ width: null,
39
+ height: null,
40
+ tabindex: 0,
41
+ tristate: false,
42
+ name: null,
43
+ };
44
+
45
+ Toggle.prototype.defaults = function () {
46
+ return {
47
+ on: this.$element.attr("data-on") || Toggle.DEFAULTS.on,
48
+ off: this.$element.attr("data-off") || Toggle.DEFAULTS.off,
49
+ onstyle: this.$element.attr("data-onstyle") || Toggle.DEFAULTS.onstyle,
50
+ offstyle: this.$element.attr("data-offstyle") || Toggle.DEFAULTS.offstyle,
51
+ onvalue:
52
+ this.$element.attr("value") ||
53
+ this.$element.attr("data-onvalue") ||
54
+ Toggle.DEFAULTS.onvalue,
55
+ offvalue: this.$element.attr("data-offvalue") || Toggle.DEFAULTS.offvalue,
56
+ size: this.$element.attr("data-size") || Toggle.DEFAULTS.size,
57
+ style: this.$element.attr("data-style") || Toggle.DEFAULTS.style,
58
+ width: this.$element.attr("data-width") || Toggle.DEFAULTS.width,
59
+ height: this.$element.attr("data-height") || Toggle.DEFAULTS.height,
60
+ tabindex: this.$element.attr("tabindex") || Toggle.DEFAULTS.tabindex,
61
+ tristate: this.$element.is("[tristate]") || Toggle.DEFAULTS.tristate,
62
+ name: this.$element.attr("name") || Toggle.DEFAULTS.name,
63
+ };
64
+ };
65
+
66
+ Toggle.prototype.render = function () {
67
+ // 0: Parse size
68
+ let size;
69
+ switch (this.options.size) {
70
+ case "large":
71
+ case "lg":
72
+ size = "btn-lg";
73
+ break;
74
+ case "small":
75
+ case "sm":
76
+ size = "btn-sm";
77
+ break;
78
+ case "mini":
79
+ case "xs":
80
+ size = "btn-xs";
81
+ break;
82
+ default:
83
+ size = "";
84
+ break;
85
+ }
86
+
87
+ // 1: On
88
+ let $toggleOn = $('<label class="btn">')
89
+ .html(this.options.on)
90
+ .addClass("btn-" + this.options.onstyle + " " + size);
91
+ if (this.$element.prop("id")) {
92
+ $toggleOn.prop("for", this.$element.prop("id"));
93
+ }
94
+
95
+ // 2: Off
96
+ let $toggleOff = $('<label class="btn">')
97
+ .html(this.options.off)
98
+ .addClass("btn-" + this.options.offstyle + " " + size);
99
+ if (this.$element.prop("id")) {
100
+ $toggleOff.prop("for", this.$element.prop("id"));
101
+ }
102
+
103
+ // 3: Handle
104
+ let $toggleHandle = $('<span class="toggle-handle btn">').addClass(size);
105
+
106
+ // 4: Toggle Group
107
+ let $toggleGroup = $('<div class="toggle-group">').append(
108
+ $toggleOn,
109
+ $toggleOff,
110
+ $toggleHandle
111
+ );
112
+
113
+ // 5: Toggle
114
+ let $toggle = $(
115
+ '<div class="toggle btn" data-toggle="toggle" role="button">'
116
+ )
117
+ .addClass(
118
+ this.$element.prop("checked")
119
+ ? "btn-" + this.options.onstyle
120
+ : "btn-" + this.options.offstyle + " off"
121
+ )
122
+ .addClass(size)
123
+ .addClass(this.options.style)
124
+ .attr("tabindex", this.options.tabindex);
125
+ if (this.$element.prop("disabled") || this.$element.prop("readonly")) {
126
+ $toggle.addClass("disabled");
127
+ $toggle.attr("disabled", "disabled");
128
+ }
129
+
130
+ // 6: Set form values
131
+ if (this.options.onvalue) this.$element.val(this.options.onvalue);
132
+ let $invElement = null;
133
+ if (this.options.offvalue) {
134
+ $invElement = this.$element.clone();
135
+ $invElement.val(this.options.offvalue);
136
+ $invElement.attr("data-toggle", "invert-toggle");
137
+ $invElement.removeAttr("id");
138
+ $invElement.prop("checked", !this.$element.prop("checked"));
139
+ }
140
+
141
+ // 7: Replace HTML checkbox with Toggle-Button
142
+ this.$element.wrap($toggle);
143
+ $.extend(this, {
144
+ $toggle: this.$element.parent(),
145
+ $toggleOn: $toggleOn,
146
+ $toggleOff: $toggleOff,
147
+ $toggleGroup: $toggleGroup,
148
+ $invElement: $invElement,
149
+ });
150
+ this.$toggle.append($invElement, $toggleGroup);
151
+
152
+ // 8: Set button W/H, lineHeight
153
+ {
154
+ // A: Set style W/H
155
+ let width =
156
+ this.options.width ||
157
+ Math.max($toggleOn.outerWidth(), $toggleOff.outerWidth()) +
158
+ $toggleHandle.outerWidth() / 2;
159
+ let height =
160
+ this.options.height ||
161
+ Math.max($toggleOn.outerHeight(), $toggleOff.outerHeight());
162
+ this.$toggle.css({ width: width, height: height });
163
+
164
+ // B: Apply on/off class
165
+ $toggleOn.addClass("toggle-on");
166
+ $toggleOff.addClass("toggle-off");
167
+
168
+ // C: Finally, set lineHeight if needed
169
+ if (this.options.height) {
170
+ $toggleOn.css("line-height", $toggleOn.height() + "px");
171
+ $toggleOff.css("line-height", $toggleOff.height() + "px");
172
+ }
173
+ }
174
+
175
+ // 9: Add listeners
176
+ this.$toggle.on("touchstart", (e) => {
177
+ toggleActionPerformed(e, this);
178
+ });
179
+ this.$toggle.on("click", (e) => {
180
+ toggleActionPerformed(e, this);
181
+ });
182
+ this.$toggle.on("keypress", (e) => {
183
+ if (e.key == " ") {
184
+ toggleActionPerformed(e, this);
185
+ }
186
+ });
187
+ // 10: Set elements to bootstrap object (NOT NEEDED)
188
+ // 11: Keep reference to this instance for subsequent calls via `getElementById().bootstrapToggle()` (NOT NEEDED)
189
+ };
190
+
191
+ /**
192
+ * Trigger actions
193
+ * @param {Event} e event
194
+ * @param {Toggle} target Toggle
195
+ */
196
+ function toggleActionPerformed(e, target) {
197
+ if (target.options.tristate) {
198
+ if (target.$toggle.hasClass("indeterminate")) {
199
+ target.determinate(true);
200
+ target.toggle();
201
+ } else {
202
+ target.indeterminate();
203
+ }
204
+ } else {
205
+ target.toggle();
206
+ }
207
+ e.preventDefault();
208
+ }
209
+
210
+ Toggle.prototype.toggle = function (silent = false) {
211
+ if (this.$element.prop("checked")) this.off(silent);
212
+ else this.on(silent);
213
+ };
214
+
215
+ Toggle.prototype.on = function (silent = false) {
216
+ if (this.$element.prop("disabled") || this.$element.prop("readonly"))
217
+ return false;
218
+ this.$toggle
219
+ .removeClass("btn-" + this.options.offstyle + " off")
220
+ .addClass("btn-" + this.options.onstyle);
221
+ this.$element.prop("checked", true);
222
+ if (this.$invElement) this.$invElement.prop("checked", false);
223
+ if (!silent) this.trigger();
224
+ };
225
+
226
+ Toggle.prototype.off = function (silent = false) {
227
+ if (this.$element.prop("disabled") || this.$element.prop("readonly"))
228
+ return false;
229
+ this.$toggle
230
+ .removeClass("btn-" + this.options.onstyle)
231
+ .addClass("btn-" + this.options.offstyle + " off");
232
+ this.$element.prop("checked", false);
233
+ if (this.$invElement) this.$invElement.prop("checked", true);
234
+ if (!silent) this.trigger();
235
+ };
236
+
237
+ Toggle.prototype.indeterminate = function (silent = false) {
238
+ if (
239
+ !this.options.tristate ||
240
+ this.$element.prop("disabled") ||
241
+ this.$element.prop("readonly")
242
+ )
243
+ return false;
244
+ this.$toggle.addClass("indeterminate");
245
+ this.$element.prop("indeterminate", true);
246
+ this.$element.removeAttr("name");
247
+ if (this.$invElement) this.$invElement.prop("indeterminate", true);
248
+ if (this.$invElement) this.$invElement.removeAttr("name");
249
+ if (!silent) this.trigger();
250
+ };
251
+
252
+ Toggle.prototype.determinate = function (silent = false) {
253
+ if (
254
+ !this.options.tristate ||
255
+ this.$element.prop("disabled") ||
256
+ this.$element.prop("readonly")
257
+ )
258
+ return false;
259
+ this.$toggle.removeClass("indeterminate");
260
+ this.$element.prop("indeterminate", false);
261
+ if (this.options.name) this.$element.attr("name", this.options.name);
262
+ if (this.$invElement) this.$invElement.prop("indeterminate", false);
263
+ if (this.$invElement && this.options.name)
264
+ this.$invElement.attr("name", this.options.name);
265
+ if (!silent) this.trigger();
266
+ };
267
+
268
+ Toggle.prototype.enable = function () {
269
+ this.$toggle.removeClass("disabled");
270
+ this.$toggle.removeAttr("disabled");
271
+ this.$element.prop("disabled", false);
272
+ this.$element.prop("readonly", false);
273
+ if (this.$invElement) {
274
+ this.$invElement.prop("disabled", false);
275
+ this.$invElement.prop("readonly", false);
276
+ }
277
+ };
278
+
279
+ Toggle.prototype.disable = function () {
280
+ this.$toggle.addClass("disabled");
281
+ this.$toggle.attr("disabled", "disabled");
282
+ this.$element.prop("disabled", true);
283
+ this.$element.prop("readonly", false);
284
+ if (this.$invElement) {
285
+ this.$invElement.prop("disabled", true);
286
+ this.$invElement.prop("readonly", false);
287
+ }
288
+ };
289
+
290
+ Toggle.prototype.readonly = function () {
291
+ this.$toggle.addClass("disabled");
292
+ this.$toggle.attr("disabled", "disabled");
293
+ this.$element.prop("disabled", false);
294
+ this.$element.prop("readonly", true);
295
+ if (this.$invElement) {
296
+ this.$invElement.prop("disabled", false);
297
+ this.$invElement.prop("readonly", true);
298
+ }
299
+ };
300
+
301
+ Toggle.prototype.update = function (silent) {
302
+ if (this.$element.prop("disabled")) this.disable();
303
+ else if (this.$element.prop("readonly")) this.readonly();
304
+ else this.enable();
305
+ if (this.$element.prop("checked")) this.on(silent);
306
+ else this.off(silent);
307
+ };
308
+
309
+ Toggle.prototype.trigger = function (silent) {
310
+ this.$element.off("change.bs.toggle");
311
+ if (!silent) this.$element.change();
312
+ this.$element.on(
313
+ "change.bs.toggle",
314
+ $.proxy(function () {
315
+ this.update();
316
+ }, this)
317
+ );
318
+ };
319
+
320
+ Toggle.prototype.destroy = function () {
321
+ // A: Remove button-group from UI, replace checkbox element
322
+ this.$element.off("change.bs.toggle");
323
+ this.$toggleGroup.remove();
324
+ if (this.$invElement) this.$invElement.remove();
325
+
326
+ // B: Delete internal refs
327
+ this.$element.removeData("bs.toggle");
328
+ this.$element.unwrap();
329
+ };
330
+
331
+ // TOGGLE PLUGIN DEFINITION
332
+ // ========================
333
+
334
+ function Plugin(option) {
335
+ let optArg = Array.prototype.slice.call(arguments, 1)[0];
336
+
337
+ return this.each(function () {
338
+ let $this = $(this);
339
+ let data = $this.data("bs.toggle");
340
+ let options = typeof option == "object" && option;
341
+
342
+ if (!data) {
343
+ data = new Toggle(this, options);
344
+ $this.data("bs.toggle", data);
345
+ }
346
+ if (
347
+ typeof option === "string" &&
348
+ data[option] &&
349
+ typeof optArg === "boolean"
350
+ )
351
+ data[option](optArg);
352
+ else if (typeof option === "string" && data[option]) data[option]();
353
+ //else if (option && !data[option]) console.log('bootstrap-toggle: error: method `'+ option +'` does not exist!');
354
+ });
355
+ }
356
+
357
+ let old = $.fn.bootstrapToggle;
358
+
359
+ $.fn.bootstrapToggle = Plugin;
360
+ $.fn.bootstrapToggle.Constructor = Toggle;
361
+
362
+ // TOGGLE NO CONFLICT
363
+ // ==================
364
+
365
+ $.fn.toggle.noConflict = function () {
366
+ $.fn.bootstrapToggle = old;
367
+ return this;
368
+ };
369
+
370
+ /**
371
+ * Replace all `input[type=checkbox][data-toggle="toggle"]` inputs with "Bootstrap-Toggle"
372
+ * Executes once page elements have rendered enabling script to be placed in `<head>`
373
+ */
374
+ $(function () {
375
+ $("input[type=checkbox][data-toggle^=toggle]").bootstrapToggle();
376
+ });
377
+ })(jQuery);