PageSourceSearch

https://edjoin.org/Scripts/plugins/prettyCheckable/prettyCheckable_old.js

js edjoin.org collected 2026-09-25 09:43:15 UTC 4,572 bytes, 161 lines download raw bytes

1/*
2 *  Project: prettyCheckable
3 *  Description: jQuery plugin to replace checkboxes and radios for custom images
4 *  Author: Arthur Gouveia
5 *  License: Licensed under the MIT License
6 */
7
8;(function ( $, window, undefined ) {
9
10    var pluginName = 'prettyCheckable',
11      document = window.document,
12      defaults = {
13        labelPosition: 'right',
14        customClass: '',
15        color: 'blue'
16      };
17
18    function Plugin( element, options ) {
19      this.element = element;
20      this.options = $.extend( {}, defaults, options) ;
21
22      this._defaults = defaults;
23      this._name = pluginName;
24
25      this.init();
26    }
27
28    function addCheckableEvents(element) {
29
30      element.find('a, label').on('touchstart click', function(e){
31
32        e.preventDefault();
33
34        var clickedParent = $(this).closest('.clearfix');
35        var input = clickedParent.find('input');
36        var fakeCheckable = clickedParent.find('a');
37
38        if (input.prop('disabled') === true) {
39          console.log('sdf');
40          return;
41
42        }
43
44        //if (input.prop('type') === 'radio') {
45
46        //  $('input[name="' + input.attr('name') + '"]').each(function(index, el){
47
48        //    $(el).prop('checked', false).parent().find('a').removeClass('checked');
49
50        //  });
51
52          //}
53
54        if (input.prop('type') === 'radio') {
55            if (input.prop('checked')) {
56                input.prop('checked', false).change();
57            } else {
58                $('input[name="' + input.attr('name') + '"]').each(function (index, el) {
59                    $(el).prop('checked', false).parent().find('a').removeClass('checked');
60                });
61            }
62        }
63
64        if (input.prop('checked')) {
65
66            input.prop('checked', false).change();
67            //input.click();
68        } else {
69
70            input.prop('checked', true).change();
71            //input.click();
72        }
73
74        fakeCheckable.toggleClass('checked');
75
76      });
77
78      element.find('a').on('keyup', function(e){
79
80        if (e.keyCode === 32) {
81
82          $(this).click();
83
84        }
85
86      });
87
88    }
89
90    Plugin.prototype.init = function () {
91
92      var el = $(this.element);
93
94      el.css('display', 'none');
95
96      var classType = el.data('type') !== undefined ? el.data('type') : el.attr('type');
97
98      var label = el.data('label') !== undefined ? el.data('label') : '';
99
100      var labelPosition = el.data('labelposition') !== undefined ? 'label' + el.data('labelposition') : 'label' + this.options.labelPosition;
101
102      var customClass = el.data('customclass') !== undefined ? el.data('customclass') : this.options.customClass;
103
104      var color =  el.data('color') !== undefined ? el.data('color') : this.options.color;
105
106      var disabled = el.prop('disabled') === true ? 'disabled' : '';
107
108      var containerClasses = ['pretty' + classType, labelPosition, customClass, color, disabled].join(' ');
109
110      el.wrap('<div class="clearfix ' + containerClasses + '"></div>').parent().html();
111
112      var dom = [];
113      var isChecked = el.prop('checked') ? 'checked' : '';
114      var isDisabled = el.prop('disabled') ? true : false;
115
116      if (labelPosition === 'labelright') {
117
118          dom.push('<a href="#" aria-label="Link used to control the look of a checkbox" class="checkHook ' + isChecked + '"></a>');
119          dom.push('<label class="removeLabel" for="' + el.attr('id') + '">' + label + '</label>');
120
121      } else {
122
123          dom.push('<label class="removeLabel" for="' + el.attr('id') + '">' + label + '</label>');
124          dom.push('<a href="#" aria-label="Link used to control the look of a checkbox" class="checkHook ' + isChecked + '"></a>');
125
126      }
127
128      el.parent().append(dom.join('\n'));
129      addCheckableEvents(el.parent());
130
131    };
132
133    Plugin.prototype.disableInput = function () {
134
135      var el = $(this.element);
136
137      el.parent().addClass('disabled');
138      el.prop('disabled', true);
139
140    };
141
142    Plugin.prototype.enableInput = function () {
143
144      var el = $(this.element);
145
146      el.parent().removeClass('disabled');
147      el.prop('disabled', false);
148
149    };
150
151    $.fn[pluginName] = function ( options ) {
152      var inputs = [];
153      this.each(function () {
154        if (!$.data(this, 'plugin_' + pluginName)) {
155          inputs.push($.data(this, 'plugin_' + pluginName, new Plugin( this, options )));
156        }
157      });
158      return inputs;
159    };
160
161}(jQuery, window));

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.