PageSourceSearch

https://rewards.ayreshotels.com/assets/vendor/bootstrap/js/bootstrap-switch.js

js ayreshotels.com collected 2026-09-24 20:19:04 UTC 12,822 bytes, 383 lines download raw bytes

1
2/*! ============================================================
3 * bootstrapSwitch v1.8 by Larentis Mattia @SpiritualGuru
4 * http://www.larentis.eu/
5 *
6 * Enhanced for radiobuttons by Stein, Peter @BdMdesigN
7 * http://www.bdmdesign.org/
8 *
9 * Project site:
10 * http://www.larentis.eu/switch/
11 * ============================================================
12 * Licensed under the Apache License, Version 2.0
13 * http://www.apache.org/licenses/LICENSE-2.0
14 * ============================================================ */
15
16!function ($) {
17  "use strict";
18
19  $.fn['bootstrapSwitch'] = function (method) {
20    var inputSelector = 'input[type!="hidden"]';
21    var methods = {
22      init: function () {
23        return this.each(function () {
24            var $element = $(this)
25              , $div
26              , $switchLeft
27              , $switchRight
28              , $label
29              , $form = $element.closest('form')
30              , myClasses = ""
31              , classes = $element.attr('class')
32              , color
33              , moving
34              , onLabel = "ON"
35              , offLabel = "OFF"
36              , icon = false
37              , textLabel = false;
38
39            $.each(['switch-mini', 'switch-small', 'switch-large'], function (i, el) {
40              if (classes.indexOf(el) >= 0)
41                myClasses = el;
42            });
43
44            $element.addClass('has-switch');
45
46            if ($element.data('on') !== undefined)
47              color = "switch-" + $element.data('on');
48
49            if ($element.data('on-label') !== undefined)
50              onLabel = $element.data('on-label');
51
52            if ($element.data('off-label') !== undefined)
53              offLabel = $element.data('off-label');
54
55            if ($element.data('label-icon') !== undefined)
56              icon = $element.data('label-icon');
57
58            if ($element.data('text-label') !== undefined)
59              textLabel = $element.data('text-label');
60
61            $switchLeft = $('<span>')
62              .addClass("switch-left")
63              .addClass(myClasses)
64              .addClass(color)
65              .html(onLabel);
66
67            color = '';
68            if ($element.data('off') !== undefined)
69              color = "switch-" + $element.data('off');
70
71            $switchRight = $('<span>')
72              .addClass("switch-right")
73              .addClass(myClasses)
74              .addClass(color)
75              .html(offLabel);
76
77            $label = $('<label>')
78              .html("&nbsp;")
79              .addClass(myClasses)
80              .attr('for', $element.find(inputSelector).attr('id'));
81
82            if (icon) {
83              $label.html('<i class="icon ' + icon + '"></i>');
84            }
85
86            if (textLabel) {
87              $label.html('' + textLabel + '');
88            }
89
90            $div = $element.find(inputSelector).wrap($('<div>')).parent().data('animated', false);
91
92            if ($element.data('animated') !== false)
93              $div.addClass('switch-animate').data('animated', true);
94
95            $div
96              .append($switchLeft)
97              .append($label)
98              .append($switchRight);
99
100            $element.find('>div').addClass(
101              $element.find(inputSelector).is(':checked') ? 'switch-on' : 'switch-off'
102            );
103
104            if ($element.find(inputSelector).is(':disabled'))
105              $(this).addClass('deactivate');
106
107            var changeStatus = function ($this) {
108              if ($element.parent('label').is('.label-change-switch')) {
109
110              } else {
111                $this.siblings('label').trigger('mousedown').trigger('mouseup').trigger('click');
112              }
113            };
114
115            $element.on('keydown', function (e) {
116              if (e.keyCode === 32) {
117                e.stopImmediatePropagation();
118                e.preventDefault();
119                changeStatus($(e.target).find('span:first'));
120              }
121            });
122
123            $switchLeft.on('click', function (e) {
124              changeStatus($(this));
125            });
126
127            $switchRight.on('click', function (e) {
128              changeStatus($(this));
129            });
130
131            $element.find(inputSelector).on('change', function (e, skipOnChange) {
132              var $this = $(this)
133                , $element = $this.parent()
134                , thisState = $this.is(':checked')
135                , state = $element.is('.switch-off');
136
137              e.preventDefault();
138
139              $element.css('left', '');
140
141              if (state === thisState) {
142
143                if (thisState)
144                  $element.removeClass('switch-off').addClass('switch-on');
145                else $element.removeClass('switch-on').addClass('switch-off');
146
147                if ($element.data('animated') !== false)
148                  $element.addClass("switch-animate");
149
150                if (typeof skipOnChange === 'boolean' && skipOnChange)
151                  return;
152
153                $element.parent().trigger('switch-change', {'el': $this, 'value': thisState})
154              }
155            });
156
157            $element.find('label').on('mousedown touchstart', function (e) {
158              var $this = $(this);
159              moving = false;
160
161              e.preventDefault();
162              e.stopImmediatePropagation();
163
164              $this.closest('div').removeClass('switch-animate');
165
166              if ($this.closest('.has-switch').is('.deactivate')) {
167                $this.unbind('click');
168              } else if ($this.closest('.switch-on').parent().is('.radio-no-uncheck')) {
169                $this.unbind('click');
170              } else {
171                $this.on('mousemove touchmove', function (e) {
172                  var $element = $(this).closest('.make-switch')
173                    , relativeX = (e.pageX || e.originalEvent.targetTouches[0].pageX) - $element.offset().left
174                    , percent = (relativeX / $element.width()) * 100
175                    , left = 25
176                    , right = 75;
177
178                  moving = true;
179
180                  if (percent < left)
181                    percent = left;
182                  else if (percent > right)
183                    percent = right;
184
185                  $element.find('>div').css('left', (percent - right) + "%")
186                });
187
188                $this.on('click touchend', function (e) {
189                  var $this = $(this)
190                    , $myInputBox = $this.siblings('input');
191
192                  e.stopImmediatePropagation();
193                  e.preventDefault();
194
195                  $this.unbind('mouseleave');
196
197                  if (moving)
198                    $myInputBox.prop('checked', !(parseInt($this.parent().css('left')) < -25));
199                  else
200                    $myInputBox.prop("checked", !$myInputBox.is(":checked"));
201
202                  moving = false;
203                  $myInputBox.trigger('change');
204                });
205
206                $this.on('mouseleave', function (e) {
207                  var $this = $(this)
208                    , $myInputBox = $this.siblings('input');
209
210                  e.preventDefault();
211                  e.stopImmediatePropagation();
212
213                  $this.unbind('mouseleave mousemove');
214                  $this.trigger('mouseup');
215
216                  $myInputBox.prop('checked', !(parseInt($this.parent().css('left')) < -25)).trigger('change');
217                });
218
219                $this.on('mouseup', function (e) {
220                  e.stopImmediatePropagation();
221                  e.preventDefault();
222
223                  $(this).trigger('mouseleave');
224                });
225              }
226            });
227
228            if ($form.data('bootstrapSwitch') !== 'injected') {
229              $form.bind('reset', function () {
230                setTimeout(function () {
231                  $form.find('.make-switch').each(function () {
232                    var $input = $(this).find(inputSelector);
233
234                    $input.prop('checked', $input.is(':checked')).trigger('change');
235                  });
236                }, 1);
237              });
238              $form.data('bootstrapSwitch', 'injected');
239            }
240          }
241        );
242      },
243      toggleActivation: function () {
244        var $this = $(this);
245
246        $this.toggleClass('deactivate');
247        $this.find(inputSelector).prop('disabled', $this.is('.deactivate'));
248      },
249      isActive: function () {
250        return !$(this).hasClass('deactivate');
251      },
252      setActive: function (active) {
253        var $this = $(this);
254
255        if (active) {
256          $this.removeClass('deactivate');
257          $this.find(inputSelector).removeAttr('disabled');
258        }
259        else {
260          $this.addClass('deactivate');
261          $this.find(inputSelector).attr('disabled', 'disabled');
262        }
263      },
264      toggleState: function (skipOnChange) {
265        var $input = $(this).find(':checkbox');
266        $input.prop('checked', !$input.is(':checked')).trigger('change', skipOnChange);
267      },
268      toggleRadioState: function (skipOnChange) {
269        var $radioinput = $(this).find(':radio');
270        $radioinput.not(':checked').prop('checked', !$radioinput.is(':checked')).trigger('change', skipOnChange);
271      },
272      toggleRadioStateAllowUncheck: function (uncheck, skipOnChange) {
273        var $radioinput = $(this).find(':radio');
274        if (uncheck) {
275          $radioinput.not(':checked').trigger('change', skipOnChange);
276        }
277        else {
278          $radioinput.not(':checked').prop('checked', !$radioinput.is(':checked')).trigger('change', skipOnChange);
279        }
280      },
281      setState: function (value, skipOnChange) {
282        $(this).find(inputSelector).prop('checked', value).trigger('change', skipOnChange);
283      },
284      setOnLabel: function (value) {
285        var $switchLeft = $(this).find(".switch-left");
286        $switchLeft.html(value);
287      },
288      setOffLabel: function (value) {
289        var $switchRight = $(this).find(".switch-right");
290        $switchRight.html(value);
291      },
292      setOnClass: function (value) {
293        var $switchLeft = $(this).find(".switch-left");
294        var color = '';
295        if (value !== undefined) {
296          if ($(this).attr('data-on') !== undefined) {
297            color = "switch-" + $(this).attr('data-on')
298          }
299          $switchLeft.removeClass(color);
300          color = "switch-" + value;
301          $switchLeft.addClass(color);
302        }
303      },
304      setOffClass: function (value) {
305        var $switchRight = $(this).find(".switch-right");
306        var color = '';
307        if (value !== undefined) {
308          if ($(this).attr('data-off') !== undefined) {
309            color = "switch-" + $(this).attr('data-off')
310          }
311          $switchRight.removeClass(color);
312          color = "switch-" + value;
313          $switchRight.addClass(color);
314        }
315      },
316      setAnimated: function (value) {
317        var $element = $(this).find(inputSelector).parent();
318        if (value === undefined) value = false;
319        $element.data('animated', value);
320        $element.attr('data-animated', value);
321
322        if ($element.data('animated') !== false) {
323          $element.addClass("switch-animate");
324        } else {
325          $element.removeClass("switch-animate");
326        }
327      },
328      setSizeClass: function (value) {
329        var $element = $(this);
330        var $switchLeft = $element.find(".switch-left");
331        var $switchRight = $element.find(".switch-right");
332        var $label = $element.find("label");
333        $.each(['switch-mini', 'switch-small', 'switch-large'], function (i, el) {
334          if (el !== value) {
335            $switchLeft.removeClass(el);
336            $switchRight.removeClass(el);
337            $label.removeClass(el);
338          } else {
339            $switchLeft.addClass(el);
340            $switchRight.addClass(el);
341            $label.addClass(el);
342          }
343        });
344      },
345      status: function () {
346        return $(this).find(inputSelector).is(':checked');
347      },
348      destroy: function () {
349        var $element = $(this)
350          , $div = $element.find('div')
351          , $form = $element.closest('form')
352          , $inputbox;
353
354        $div.find(':not(input)').remove();
355
356        $inputbox = $div.children();
357        $inputbox.unwrap().unwrap();
358
359        $inputbox.unbind('change');
360
361        if ($form) {
362          $form.unbind('reset');
363          $form.removeData('bootstrapSwitch');
364        }
365
366        return $inputbox;
367      }
368    };
369
370    if (methods[method])
371      return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
372    else if (typeof method === 'object' || !method)
373      return methods.init.apply(this, arguments);
374    else
375      $.error('Method ' + method + ' does not exist!');
376  };
377}(jQuery);
378
379(function ($) {
380  $(function () {
381    $('.make-switch')['bootstrapSwitch']();
382  });
383})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.