PageSourceSearch

https://servicios.cac.es/comunicacion/assets/js/bootstrap-checkbox-radio-switch.js

js cac.es collected 2026-10-01 10:39:22 UTC 15,407 bytes, 502 lines download raw bytes

1!function ($) {
2
3 /* CHECKBOX PUBLIC CLASS DEFINITION
4  * ============================== */
5
6  var Checkbox = function (element, options) {
7    this.init(element, options);
8  }
9
10  Checkbox.prototype = {
11    
12    constructor: Checkbox
13    
14  , init: function (element, options) {      
15    var $el = this.$element = $(element)
16    
17    this.options = $.extend({}, $.fn.checkbox.defaults, options);      
18    $el.before(this.options.template);    
19    this.setState(); 
20  }  
21   
22  , setState: function () {    
23      var $el = this.$element
24        , $parent = $el.closest('.checkbox');
25        
26        $el.prop('disabled') && $parent.addClass('disabled');   
27        $el.prop('checked') && $parent.addClass('checked');
28    }  
29    
30  , toggle: function () {    
31      var ch = 'checked'
32        , $el = this.$element
33        , $parent = $el.closest('.checkbox')
34        , checked = $el.prop(ch)
35        , e = $.Event('toggle')
36      
37      if ($el.prop('disabled') == false) {
38        $parent.toggleClass(ch) && checked ? $el.removeAttr(ch) : $el.prop(ch, ch);
39        $el.trigger(e).trigger('change'); 
40      }
41    }  
42    
43  , setCheck: function (option) {    
44      var d = 'disabled'
45        , ch = 'checked'
46        , $el = this.$element
47        , $parent = $el.closest('.checkbox')
48        , checkAction = option == 'check' ? true : false
49        , e = $.Event(option)
50      
51      $parent[checkAction ? 'addClass' : 'removeClass' ](ch) && checkAction ? $el.prop(ch, ch) : $el.removeAttr(ch);
52      $el.trigger(e).trigger('change');       
53    }  
54      
55  }
56
57
58 /* CHECKBOX PLUGIN DEFINITION
59  * ======================== */
60
61  var old = $.fn.checkbox
62
63  $.fn.checkbox = function (option) {
64    return this.each(function () {
65      var $this = $(this)
66        , data = $this.data('checkbox')
67        , options = $.extend({}, $.fn.checkbox.defaults, $this.data(), typeof option == 'object' && option);
68      if (!data) $this.data('checkbox', (data = new Checkbox(this, options)));
69      if (option == 'toggle') data.toggle()
70      if (option == 'check' || option == 'uncheck') data.setCheck(option)
71      else if (option) data.setState(); 
72    });
73  }
74  
75  $.fn.checkbox.defaults = {
76    template: '<span class="icons"><span class="first-icon fa fa-square-o"></span><span class="second-icon fa fa-check-square-o"></span></span>'
77  }
78
79
80 /* CHECKBOX NO CONFLICT
81  * ================== */
82
83  $.fn.checkbox.noConflict = function () {
84    $.fn.checkbox = old;
85    return this;
86  }
87
88
89 /* CHECKBOX DATA-API
90  * =============== */
91
92  $(document).on('click.checkbox.data-api', '[data-toggle^=checkbox], .checkbox', function (e) {
93    var $checkbox = $(e.target);
94    if (e.target.tagName != "A") {      
95      e && e.preventDefault() && e.stopPropagation();
96      if (!$checkbox.hasClass('checkbox')) $checkbox = $checkbox.closest('.checkbox');
97      $checkbox.find(':checkbox').checkbox('toggle');
98    }
99  });
100  
101  $(function () {
102    $('[data-toggle="checkbox"]').each(function () {
103      var $checkbox = $(this);
104      $checkbox.checkbox();
105    });
106  });
107
108}(window.jQuery);
109
110
111
112/* =============================================================
113 * flatui-radio v0.0.3
114 * ============================================================ */
115
116!function ($) {
117
118 /* RADIO PUBLIC CLASS DEFINITION
119  * ============================== */
120
121  var Radio = function (element, options) {
122    this.init(element, options);
123  }
124
125  Radio.prototype = {
126  
127    constructor: Radio
128    
129  , init: function (element, options) {      
130      var $el = this.$element = $(element)
131      
132      this.options = $.extend({}, $.fn.radio.defaults, options);      
133      $el.before(this.options.template);    
134      this.setState();
135    }   
136    
137  , setState: function () {    
138      var $el = this.$element
139        , $parent = $el.closest('.radio');
140        
141        $el.prop('disabled') && $parent.addClass('disabled');   
142        $el.prop('checked') && $parent.addClass('checked');
143    } 
144    
145  , toggle: function () {    
146      var d = 'disabled'
147        , ch = 'checked'
148        , $el = this.$element
149        , checked = $el.prop(ch)
150        , $parent = $el.closest('.radio')      
151        , $parentWrap = $el.closest('form').length ? $el.closest('form') : $el.closest('body')
152        , $elemGroup = $parentWrap.find(':radio[name="' + $el.attr('name') + '"]')
153        , e = $.Event('toggle')
154      
155        if ($el.prop(d) == false) {
156            $elemGroup.not($el).each(function () {
157              var $el = $(this)
158                , $parent = $(this).closest('.radio');
159                
160                if ($el.prop(d) == false) {
161                  $parent.removeClass(ch) && $el.removeAttr(ch).trigger('change');
162                } 
163            });
164            
165            if (checked == false) $parent.addClass(ch) && $el.prop(ch, true);
166            $el.trigger(e);
167          
168            if (checked !== $el.prop(ch)) {
169                $el.trigger('change'); 
170            }
171        }               
172    } 
173     
174  , setCheck: function (option) {    
175      var ch = 'checked'
176        , $el = this.$element
177        , $parent = $el.closest('.radio')
178        , checkAction = option == 'check' ? true : false
179        , checked = $el.prop(ch)
180        , $parentWrap = $el.closest('form').length ? $el.closest('form') : $el.closest('body')
181        , $elemGroup = $parentWrap.find(':radio[name="' + $el['attr']('name') + '"]')
182        , e = $.Event(option)
183        
184      $elemGroup.not($el).each(function () {
185        var $el = $(this)
186          , $parent = $(this).closest('.radio');
187          
188          $parent.removeClass(ch) && $el.removeAttr(ch);
189      });
190            
191      $parent[checkAction ? 'addClass' : 'removeClass'](ch) && checkAction ? $el.prop(ch, ch) : $el.removeAttr(ch);
192      $el.trigger(e);  
193          
194      if (checked !== $el.prop(ch)) {
195        $el.trigger('change'); 
196      }
197    }  
198     
199  }
200
201
202 /* RADIO PLUGIN DEFINITION
203  * ======================== */
204
205  var old = $.fn.radio
206
207  $.fn.radio = function (option) {
208    return this.each(function () {
209      var $this = $(this)
210        , data = $this.data('radio')
211        , options = $.extend({}, $.fn.radio.defaults, $this.data(), typeof option == 'object' && option);
212      if (!data) $this.data('radio', (data = new Radio(this, options)));
213      if (option == 'toggle') data.toggle()
214      if (option == 'check' || option == 'uncheck') data.setCheck(option)
215      else if (option) data.setState(); 
216    });
217  }
218  
219  $.fn.radio.defaults = {
220    template: '<span class="icons"><span class="first-icon fa fa-circle-o"></span><span class="second-icon fa fa-dot-circle-o"></span></span>'
221  }
222
223
224 /* RADIO NO CONFLICT
225  * ================== */
226
227  $.fn.radio.noConflict = function () {
228    $.fn.radio = old;
229    return this;
230  }
231
232
233 /* RADIO DATA-API
234  * =============== */
235
236  $(document).on('click.radio.data-api', '[data-toggle^=radio], .radio', function (e) {
237    var $radio = $(e.target);
238    e && e.preventDefault() && e.stopPropagation();
239    if (!$radio.hasClass('radio')) $radio = $radio.closest('.radio');
240    $radio.find(':radio').radio('toggle');
241  });
242  
243  $(function () {
244    $('[data-toggle="radio"]').each(function () {
245      var $radio = $(this);
246      $radio.radio();
247    });
248  });
249
250}(window.jQuery);
251
252
253
254/* ============================================================
255 * bootstrapSwitch v1.3 by Larentis Mattia @spiritualGuru
256 * http://www.larentis.eu/switch/
257 * ============================================================
258 * Licensed under the Apache License, Version 2.0
259 * http://www.apache.org/licenses/LICENSE-2.0
260 * ============================================================ */
261
262!function ($) {
263  "use strict";
264
265  $.fn['bootstrapSwitch'] = function (method) {
266    var methods = {
267      init: function () {
268        return this.each(function () {
269            var $element = $(this)
270              , $div
271              , $switchLeft
272              , $switchRight
273              , $label
274              , myClasses = ""
275              , classes = $element.attr('class')
276              , color
277              , moving
278              , onLabel = "ON"
279              , offLabel = "OFF"
280              , icon = false;
281
282            $.each(['switch-mini', 'switch-small', 'switch-large'], function (i, el) {
283              if (classes.indexOf(el) >= 0)
284                myClasses = el;
285            });
286
287            $element.addClass('has-switch');
288
289            if ($element.data('on') !== undefined)
290              color = "switch-" + $element.data('on');
291
292            if ($element.data('on-label') !== undefined)
293              onLabel = $element.data('on-label');
294
295            if ($element.data('off-label') !== undefined)
296              offLabel = $element.data('off-label');
297
298            if ($element.data('icon') !== undefined)
299              icon = $element.data('icon');
300
301            $switchLeft = $('<span>')
302              .addClass("switch-left")
303              .addClass(myClasses)
304              .addClass(color)
305              .html(onLabel);
306
307            color = '';
308            if ($element.data('off') !== undefined)
309              color = "switch-" + $element.data('off');
310
311            $switchRight = $('<span>')
312              .addClass("switch-right")
313              .addClass(myClasses)
314              .addClass(color)
315              .html(offLabel);
316
317            $label = $('<label>')
318              .html("&nbsp;")
319              .addClass(myClasses)
320              .attr('for', $element.find('input').attr('id'));
321
322            if (icon) {
323              $label.html('<i class="' + icon + '"></i>');
324            }
325
326            $div = $element.find(':checkbox').wrap($('<div>')).parent().data('animated', false);
327
328            if ($element.data('animated') !== false)
329              $div.addClass('switch-animate').data('animated', true);
330
331            $div
332              .append($switchLeft)
333              .append($label)
334              .append($switchRight);
335
336            $element.find('>div').addClass(
337              $element.find('input').is(':checked') ? 'switch-on' : 'switch-off'
338            );
339
340            if ($element.find('input').is(':disabled'))
341              $(this).addClass('deactivate');
342
343            var changeStatus = function ($this) {
344              $this.siblings('label').trigger('mousedown').trigger('mouseup').trigger('click');
345            };
346
347            $element.on('keydown', function (e) {
348              if (e.keyCode === 32) {
349                e.stopImmediatePropagation();
350                e.preventDefault();
351                changeStatus($(e.target).find('span:first'));
352              }
353            });
354
355            $switchLeft.on('click', function (e) {
356              changeStatus($(this));
357            });
358
359            $switchRight.on('click', function (e) {
360              changeStatus($(this));
361            });
362
363            $element.find('input').on('change', function (e) {
364              var $this = $(this)
365                , $element = $this.parent()
366                , thisState = $this.is(':checked')
367                , state = $element.is('.switch-off');
368
369              e.preventDefault();
370
371              $element.css('left', '');
372
373              if (state === thisState) {
374
375                if (thisState)
376                  $element.removeClass('switch-off').addClass('switch-on');
377                else $element.removeClass('switch-on').addClass('switch-off');
378
379                if ($element.data('animated') !== false)
380                  $element.addClass("switch-animate");
381
382                $element.parent().trigger('switch-change', {'el': $this, 'value': thisState})
383              }
384            });
385
386            $element.find('label').on('mousedown touchstart', function (e) {
387              var $this = $(this);
388              moving = false;
389
390              e.preventDefault();
391              e.stopImmediatePropagation();
392
393              $this.closest('div').removeClass('switch-animate');
394
395              if ($this.closest('.has-switch').is('.deactivate'))
396                $this.unbind('click');
397              else {
398                $this.on('mousemove touchmove', function (e) {
399                  var $element = $(this).closest('.switch')
400                    , relativeX = (e.pageX || e.originalEvent.targetTouches[0].pageX) - $element.offset().left
401                    , percent = (relativeX / $element.width()) * 100
402                    , left = 25
403                    , right = 75;
404
405                  moving = true;
406
407                  if (percent < left)
408                    percent = left;
409                  else if (percent > right)
410                    percent = right;
411
412                  $element.find('>div').css('left', (percent - right) + "%")
413                });
414
415                $this.on('click touchend', function (e) {
416                  var $this = $(this)
417                    , $target = $(e.target)
418                    , $myCheckBox = $target.siblings('input');
419
420                  e.stopImmediatePropagation();
421                  e.preventDefault();
422
423                  $this.unbind('mouseleave');
424
425                  if (moving)
426                    $myCheckBox.prop('checked', !(parseInt($this.parent().css('left')) < -25));
427                  else $myCheckBox.prop("checked", !$myCheckBox.is(":checked"));
428
429                  moving = false;
430                  $myCheckBox.trigger('change');
431                });
432
433                $this.on('mouseleave', function (e) {
434                  var $this = $(this)
435                    , $myCheckBox = $this.siblings('input');
436
437                  e.preventDefault();
438                  e.stopImmediatePropagation();
439
440                  $this.unbind('mouseleave');
441                  $this.trigger('mouseup');
442
443                  $myCheckBox.prop('checked', !(parseInt($this.parent().css('left')) < -25)).trigger('change');
444                });
445
446                $this.on('mouseup', function (e) {
447                  e.stopImmediatePropagation();
448                  e.preventDefault();
449
450                  $(this).unbind('mousemove');
451                });
452              }
453            });
454          }
455        );
456      },
457      toggleActivation: function () {
458        $(this).toggleClass('deactivate');
459      },
460      isActive: function () {
461        return !$(this).hasClass('deactivate');
462      },
463      setActive: function (active) {
464        if (active)
465          $(this).removeClass('deactivate');
466        else $(this).addClass('deactivate');
467      },
468      toggleState: function (skipOnChange) {
469        var $input = $(this).find('input:checkbox');
470        $input.prop('checked', !$input.is(':checked')).trigger('change', skipOnChange);
471      },
472      setState: function (value, skipOnChange) {
473        $(this).find('input:checkbox').prop('checked', value).trigger('change', skipOnChange);
474      },
475      status: function () {
476        return $(this).find('input:checkbox').is(':checked');
477      },
478      destroy: function () {
479        var $div = $(this).find('div')
480          , $checkbox;
481
482        $div.find(':not(input:checkbox)').remove();
483
484        $checkbox = $div.children();
485        $checkbox.unwrap().unwrap();
486
487        $checkbox.unbind('change');
488
489        return $checkbox;
490      }
491    };
492
493    if (methods[method])
494      return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
495    else if (typeof method === 'object' || !method)
496      return methods.init.apply(this, arguments);
497    else
498      $.error('Method ' + method + ' does not exist!');
499  };
500}(jQuery);
501
502

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.