PageSourceSearch

https://www.ast-lab.jp/js/iCheck/jquery.icheck.js

js ast-lab.jp collected 2026-10-06 13:10:56 UTC 12,901 bytes, 462 lines download raw bytes

vendor: 4,818 bytes, lines 1-166
1/*!
2 * iCheck v0.9.1, http://git.io/uhUPMA
3 * =================================
4 * Powerful jQuery plugin for checkboxes and radio buttons customization
5 *
6 * (c) 2013 Damir Foy, http://damirfoy.com
7 * MIT Licensed
8 */
9
10(function($) {
11
12  // Cached vars
13  var _iCheck = 'iCheck',
14    _iCheckHelper = _iCheck + '-helper',
15    _checkbox = 'checkbox',
16    _radio = 'radio',
17    _checked = 'checked',
18    _unchecked = 'un' + _checked,
19    _disabled = 'disabled',
20    _determinate = 'determinate',
21    _indeterminate = 'in' + _determinate,
22    _update = 'update',
23    _type = 'type',
24    _click = 'click',
25    _touch = 'touchbegin.i touchend.i',
26    _add = 'addClass',
27    _remove = 'removeClass',
28    _callback = 'trigger',
29    _label = 'label',
30    _cursor = 'cursor',
31    _mobile = /ipad|iphone|ipod|android|blackberry|windows phone|opera mini|silk/i.test(navigator.userAgent);
32
33  // Plugin init
34  $.fn[_iCheck] = function(options, fire) {
35
36    // Walker
37    var handle = ':' + _checkbox + ', :' + _radio,
38      stack = $(),
39      walker = function(object) {
40        object.each(function() {
41          var self = $(this);
42
43          if (self.is(handle)) {
44            stack = stack.add(self);
45          } else {
46            stack = stack.add(self.find(handle));
47          };
48        });
49      };
50
51    // Check if we should operate with some method
52    if (/^(check|uncheck|toggle|indeterminate|determinate|disable|enable|update|destroy)$/i.test(options)) {
53
54      // Normalize method's name
55      options = options.toLowerCase();
56
57      // Find checkboxes and radio buttons
58      walker(this);
59
60      return stack.each(function() {
61        if (options == 'destroy') {
62          tidy(this, 'ifDestroyed');
63        } else {
64          operate($(this), true, options);
65        };
66
67        // Fire method's callback
68        if ($.isFunction(fire)) {
69          fire();
70        };
71      });
72
73    // Customization
74    } else if (typeof options == 'object' || !options) {
75
76      // Check if any options were passed
77      var settings = $.extend({
78          checkedClass: _checked,
79          disabledClass: _disabled,
80          indeterminateClass: _indeterminate,
81          labelHover: true
82        }, options),
83
84        selector = settings.handle,
85        hoverClass = settings.hoverClass || 'hover',
86        focusClass = settings.focusClass || 'focus',
87        activeClass = settings.activeClass || 'active',
88        labelHover = !!settings.labelHover,
89        labelHoverClass = settings.labelHoverClass || 'hover',
90
91        // Setup clickable area
92        area = ('' + settings.increaseArea).replace('%', '') | 0;
93
94      // Selector limit
95      if (selector == _checkbox || selector == _radio) {
96        handle = ':' + selector;
97      };
98
99      // Clickable area limit
100      if (area < -50) {
101        area = -50;
102      };
103
104      // Walk around the selector
105      walker(this);
106
107      return stack.each(function() {
108
109        // If already customized
110        tidy(this);
111
112        var self = $(this),
113          node = this,
114          id = node.id,
115
116          // Layer styles
117          offset = -area + '%',
118          size = 100 + (area * 2) + '%',
119          layer = {
120            position: 'absolute',
121            top: offset,
122            left: offset,
123            display: 'block',
124            width: size,
125            height: size,
126            margin: 0,
127            padding: 0,
128            background: '#fff',
129            border: 0,
130            opacity: 0
131          },
132
133          // Choose how to hide input
134          hide = _mobile ? {
135            position: 'absolute',
136            visibility: 'hidden'
137          } : area ? layer : {
138            position: 'absolute',
139            opacity: 0
140          },
141
142          // Get proper class
143          className = node[_type] == _checkbox ? settings.checkboxClass || 'i' + _checkbox : settings.radioClass || 'i' + _radio,
144
145          // Find assigned labels
146          label = $(_label + '[for="' + id + '"]').add(self.closest(_label)),
147
148          // Wrap input
149          parent = self.wrap('<div class="' + className + '"/>')[_callback]('ifCreated').parent().append(settings.insert),
150
151          // Layer addition
152          helper = $('<ins class="' + _iCheckHelper + '"/>').css(layer).appendTo(parent);
153
154        // Finalize customization
155        self.data(_iCheck, {o: settings, s: self.attr('style')}).css(hide);
156        !!settings.inheritClass && parent[_add](node.className);
157        !!settings.inheritID && id && parent.attr('id', _iCheck + '-' + id);
158        parent.css('position') == 'static' && parent.css('position', 'relative');
159        operate(self, true, _update);
160
161        // Label events
162        if (label.length) {
163          label.on(_click + '.i mouseenter.i mouseleave.i ' + _touch, function(event) {
164            var type = event[_type],
165              item = $(this);
166
167            // Do nothing if input is disabled
168            if (!node[_disabled]) {
169
170              // Click
171              if (type == _click) {
172                operate(self, false, true);
173
174              // Hover state
175              } else if (labelHover) {
176
177                // mouseleave|touchend
178                if (/ve|nd/.test(type)) {
179                  parent[_remove](hoverClass);
180                  item[_remove](labelHoverClass);
181                } else {
182                  parent[_add](hoverClass);
183                  item[_add](labelHoverClass);
184                };
185              };
186
187              if (_mobile) {
188                event.stopPropagation();
189              } else {
190                return false;
191              };
192            };
193          });
194        };
195
196        // Input events
197        self.on(_click + '.i focus.i blur.i keyup.i keydown.i keypress.i', function(event) {
198          var type = event[_type],
199            key = event.keyCode;
200
201          // Click
202          if (type == _click) {
203            return false;
204
205          // Keydown
206          } else if (type == 'keydown' && key == 32) {
207            if (!(node[_type] == _radio && node[_checked])) {
208              if (node[_checked]) {
209                off(self, _checked);
210              } else {
211                on(self, _checked);
212              };
213            };
214
215            return false;
216
217          // Keyup
218          } else if (type == 'keyup' && node[_type] == _radio) {
219            !node[_checked] && on(self, _checked);
220
221          // Focus/blur
222          } else if (/us|ur/.test(type)) {
223            parent[type == 'blur' ? _remove : _add](focusClass);
224          };
225        });
226
227        // Helper events
228        helper.on(_click + ' mousedown mouseup mouseover mouseout ' + _touch, function(event) {
229          var type = event[_type],
230
231            // mousedown|mouseup
232            toggle = /wn|up/.test(type) ? activeClass : hoverClass;
233
234          // Do nothing if input is disabled
235          if (!node[_disabled]) {
236
237            // Click
238            if (type == _click) {
239              operate(self, false, true);
240
241            // Active and hover states
242            } else {
243
244              // State is on
245              if (/wn|er|in/.test(type)) {
246
247                // mousedown|mouseover|touchbegin
248                parent[_add](toggle);
249
250              // State is off
251              } else {
252                parent[_remove](toggle + ' ' + activeClass);
253              };
254
255              // Label hover
256              if (label.length && labelHover && toggle == hoverClass) {
257
258                // mouseout|touchend
259                label[/ut|nd/.test(type) ? _remove : _add](labelHoverClass);
260              };
261            };
262
263            if (_mobile) {
264              event.stopPropagation();
265            } else {
266              return false;
267            };
268          };
269        });
270      });
271    } else {
272      return this;
273    };
274  };
275
276  // Do something with inputs
277  function operate(input, direct, method) {
278    var node = input[0];
279      state = /er/.test(method) ? _indeterminate : /bl/.test(method) ? _disabled : _checked,
280      active = method == _update ? {
281        checked: node[_checked],
282        disabled: node[_disabled],
283        indeterminate: input.attr(_indeterminate) == 'true' || input.attr(_determinate) == 'false'
284      } : node[state];
285
286    // Check, disable or indeterminate
287    if (/^(ch|di|in)/.test(method) && !active) {
288      on(input, state);
289
290    // Uncheck, enable or determinate
291    } else if (/^(un|en|de)/.test(method) && active) {
292      off(input, state);
293
294    // Update
295    } else if (method == _update) {
296
297      // Handle states
298      for (var state in active) {
299        if (active[state]) {
300          on(input, state, true);
301        } else {
302          off(input, state, true);
303        };
304      };
305
306    } else if (!direct || method == 'toggle') {
307
308      // Helper or label was clicked
309      if (!direct) {
310        input[_callback]('ifClicked');
311      };
312
313      // Toggle checked state
314      if (active) {
315        if (node[_type] !== _radio) {
316          off(input, state);
317        };
318      } else {
319        on(input, state);
320      };
321    };
322  };
323
324  // Add checked, disabled or indeterminate state
325  function on(input, state, keep) {
326    var node = input[0],
327      parent = input.parent(),
328      checked = state == _checked,
329      indeterminate = state == _indeterminate,
330      callback = indeterminate ? _determinate : checked ? _unchecked : 'enabled',
331      regular = option(node, callback + capitalize(node[_type])),
332      specific = option(node, state + capitalize(node[_type]));
333
334    // Prevent unnecessary actions
335    if (node[state] !== true) {
336
337      // Toggle assigned radio buttons
338      if (!keep && state == _checked && node[_type] == _radio && node.name) {
339        var form = input.closest('form'),
340          inputs = 'input[name="' + node.name + '"]';
341
342        inputs = form.length ? form.find(inputs) : $(inputs);
343
344        inputs.each(function() {
345          if (this !== node && $.data(this, _iCheck)) {
346            off($(this), state);
347          };
348        });
349      };
350
351      // Indeterminate state
352      if (indeterminate) {
353
354        // Add indeterminate state
355        node[state] = true;
356
357        // Remove checked state
358        if (node[_checked]) {
359          off(input, _checked, 'force');
360        };
361
362      // Checked or disabled state
363      } else {
364
365        // Add checked or disabled state
366        if (!keep) {
367          node[state] = true;
368        };
369
370        // Remove indeterminate state
371        if (checked && node[_indeterminate]) {
372          off(input, _indeterminate, false);
373        };
374      };
375
376      // Trigger callbacks
377      callbacks(input, checked, state, keep);
378    };
379
380    // Add proper cursor
381    if (node[_disabled] && !!option(node, _cursor, true)) {
382      parent.find('.' + _iCheckHelper).css(_cursor, 'default');
383    };
384
385    // Add state class
386    parent[_add](specific || option(node, state));
387
388    // Remove regular state class
389    parent[_remove](regular || option(node, callback) || '');
390  };
391
392  // Remove checked, disabled or indeterminate state
393  function off(input, state, keep) {
394    var node = input[0],
395      parent = input.parent(),
396      checked = state == _checked,
397      indeterminate = state == _indeterminate,
398      callback = indeterminate ? _determinate : checked ? _unchecked : 'enabled',
399      regular = option(node, callback + capitalize(node[_type])),
400      specific = option(node, state + capitalize(node[_type]));
401
402    // Prevent unnecessary actions
403    if (node[state] !== false) {
404
405      // Toggle state
406      if (indeterminate || !keep || keep == 'force') {
407        node[state] = false;
408      };
409
410      // Trigger callbacks
411      callbacks(input, checked, callback, keep);
412    };
413
414    // Add proper cursor
415    if (!node[_disabled] && !!option(node, _cursor, true)) {
416      parent.find('.' + _iCheckHelper).css(_cursor, 'pointer');
417    };
418
419    // Remove state class
420    parent[_remove](specific || option(node, state) || '');
421
422    // Add regular state class
423    parent[_add](regular || option(node, callback));
424  };
425
426  // Remove all traces
427  function tidy(node, callback) {
428    if ($.data(node, _iCheck)) {
429      var input = $(node);
430
431      // Remove everything except input
432      input.parent().html(input.attr('style', $.data(node, _iCheck).s || '')[_callback](callback || ''));
433
434      // Unbind events
435      input.off('.i').unwrap();
436      $(_label + '[for="' + node.id + '"]').add(input.closest(_label)).off('.i');
437    };
438  };
439
440  // Get some option
441  function option(node, state, regular) {
442    if ($.data(node, _iCheck)) {
443      return $.data(node, _iCheck).o[state + (regular ? '' : 'Class')];
444    };
445  };
446
447  // Capitalize some string
448  function capitalize(string) {
449    return string.charAt(0).toUpperCase() + string.slice(1);
450  };
451
452  // Executable handlers
453  function callbacks(input, checked, callback, keep) {
454    if (!keep) {
455      if (checked) {
456        input[_callback]('ifToggled');
457      };
458
459      input[_callback]('ifChanged')[_callback]('if' + capitalize(callback));
460    };
461  };
462})(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.