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