1/* 2 3Uniform v2.1.2 4Copyright © 2009 Josh Pyles / Pixelmatrix Design LLC 5http://pixelmatrixdesign.com 6 7Requires jQuery 1.3 or newer 8 9Much thanks to Thomas Reynolds and Buck Wilson for their help and advice on 10this. 11 12Disabling text selection is made possible by Mathias Bynens 13<http://mathiasbynens.be/> and his noSelect plugin. 14<https://github.com/mathiasbynens/jquery-noselect>, which is embedded. 15 16Also, thanks to David Kaneda and Eugene Bond for their contributions to the 17plugin. 18 19Tyler Akins has also rewritten chunks of the plugin, helped close many issues, 20and ensured version 2 got out the door. 21 22License: 23MIT License - http://www.opensource.org/licenses/mit-license.php 24 25Enjoy! 26 27*/ 28/*global jQuery, document, navigator*/ 29 30(function (wind, $, undef) { 31 "use strict"; 32 33 /** 34 * Use .prop() if jQuery supports it, otherwise fall back to .attr() 35 * 36 * @param jQuery $el jQuery'd element on which we're calling attr/prop 37 * @param ... All other parameters are passed to jQuery's function 38 * @return The result from jQuery 39 */ 40 function attrOrProp($el) { 41 var args = Array.prototype.slice.call(arguments, 1); 42 43 if ($el.prop) { 44 // jQuery 1.6+ 45 return $el.prop.apply($el, args); 46 } 47 48 // jQuery 1.5 and below 49 return $el.attr.apply($el, args); 50 } 51 52 /** 53 * For backwards compatibility with older jQuery libraries, only bind 54 * one thing at a time. Also, this function adds our namespace to 55 * events in one consistent location, shrinking the minified code. 56 * 57 * The properties on the events object are the names of the events 58 * that we are supposed to add to. It can be a space separated list. 59 * The namespace will be added automatically. 60 * 61 * @param jQuery $el 62 * @param Object options Uniform options for this element 63 * @param Object events Events to bind, properties are event names 64 */ 65 function bindMany($el, options, events) { 66 var name, namespaced; 67 68 for (name in events) { 69 if (events.hasOwnProperty(name)) { 70 namespaced = name.replace(/ |$/g, options.eventNamespace); 71 $el.bind(namespaced, events[name]); 72 } 73 } 74 } 75 76 /** 77 * Bind the hover, active, focus, and blur UI updates 78 * 79 * @param jQuery $el Original element 80 * @param jQuery $target Target for the events (our div/span) 81 * @param Object options Uniform options for the element $target 82 */ 83 function bindUi($el, $target, options) { 84 bindMany($el, options, { 85 focus: function () { 86 $target.addClass(options.focusClass); 87 }, 88 blur: function () { 89 $target.removeClass(options.focusClass); 90 $target.removeClass(options.activeClass); 91 }, 92 mouseenter: function () { 93 $target.addClass(options.hoverClass); 94 }, 95 mouseleave: function () { 96 $target.removeClass(options.hoverClass); 97 $target.removeClass(options.activeClass); 98 }, 99 "mousedown touchbegin": function () { 100 if (!$el.is(":disabled")) { 101 $target.addClass(options.activeClass); 102 } 103 }, 104 "mouseup touchend": function () { 105 $target.removeClass(options.activeClass); 106 } 107 }); 108 } 109 110 /** 111 * Remove the hover, focus, active classes. 112 * 113 * @param jQuery $el Element with classes 114 * @param Object options Uniform options for the element 115 */ 116 function classClearStandard($el, options) { 117 $el.removeClass(options.hoverClass + " " + options.focusClass + " " + options.activeClass); 118 } 119 120 /** 121 * Add or remove a class, depending on if it's "enabled" 122 * 123 * @param jQuery $el Element that has the class added/removed 124 * @param String className Class or classes to add/remove 125 * @param Boolean enabled True to add the class, false to remove 126 */ 127 function classUpdate($el, className, enabled) { 128 if (enabled) { 129 $el.addClass(className); 130 } else { 131 $el.removeClass(className); 132 } 133 } 134 135 /** 136 * Updating the "checked" property can be a little tricky. This 137 * changed in jQuery 1.6 and now we can pass booleans to .prop(). 138 * Prior to that, one either adds an attribute ("checked=checked") or 139 * removes the attribute. 140 * 141 * @param jQuery $tag Our Uniform span/div 142 * @param jQuery $el Original form element 143 * @param Object options Uniform options for this element 144 */ 145 function classUpdateChecked($tag, $el, options) { 146 var c = "checked", 147 isChecked = $el.is(":" + c); 148 149 if ($el.prop) { 150 // jQuery 1.6+ 151 $el.prop(c, isChecked); 152 } else { 153 // jQuery 1.5 and below 154 if (isChecked) { 155 $el.attr(c, c); 156 } else { 157 $el.removeAttr(c); 158 } 159 } 160 161 classUpdate($tag, options.checkedClass, isChecked); 162 } 163 164 /** 165 * Set or remove the "disabled" class for disabled elements, based on 166 * if the element is detected to be disabled. 167 * 168 * @param jQuery $tag Our Uniform span/div 169 * @param jQuery $el Original form element 170 * @param Object options Uniform options for this element 171 */ 172 function classUpdateDisabled($tag, $el, options) { 173 classUpdate($tag, options.disabledClass, $el.is(":disabled")); 174 } 175 176 /** 177 * Wrap an element inside of a container or put the container next 178 * to the element. See the code for examples of the different methods. 179 * 180 * Returns the container that was added to the HTML. 181 * 182 * @param jQuery $el Element to wrap 183 * @param jQuery $container Add this new container around/near $el 184 * @param String method One of "after", "before" or "wrap" 185 * @return $container after it has been cloned for adding to $el 186 */ 187 function divSpanWrap($el, $container, method) { 188 switch (method) { 189 case "after": 190 // Result: <element /> <container /> 191 $el.after($container); 192 return $el.next(); 193 case "before": 194 // Result: <container /> <element /> 195 $el.before($container); 196 return $el.prev(); 197 case "wrap": 198 // Result: <container> <element /> </container> 199 $el.wrap($container); 200 return $el.parent(); 201 } 202 203 return null; 204 } 205 206 207 /** 208 * Create a div/span combo for uniforming an element 209 * 210 * @param jQuery $el Element to wrap 211 * @param Object options Options for the element, set by the user 212 * @param Object divSpanConfig Options for how we wrap the div/span 213 * @return Object Contains the div and span as properties 214 */ 215 function divSpan($el, options, divSpanConfig) { 216 var $div, $span, id; 217 218 if (!divSpanConfig) { 219 divSpanConfig = {}; 220 } 221 222 divSpanConfig = $.extend({ 223 bind: {}, 224 divClass: null, 225 divWrap: "wrap", 226 spanClass: null, 227 spanHtml: null, 228 spanWrap: "wrap" 229 }, divSpanConfig); 230
231 $div = $('<div />'); 232 $span = $('<span />'); 233 234 // Automatically hide this div/span if the element is hidden. 235 // Do not hide if the element is hidden because a parent is hidden. 236 if (options.autoHide && $el.is(':hidden') && $el.css('display') === 'none') { 237 $div.hide(); 238 } 239 240 if (divSpanConfig.divClass) { 241 $div.addClass(divSpanConfig.divClass); 242 } 243 244 if (options.wrapperClass) { 245 $div.addClass(options.wrapperClass); 246 } 247 248 if (divSpanConfig.spanClass) { 249 $span.addClass(divSpanConfig.spanClass); 250 } 251 252 id = attrOrProp($el, 'id'); 253 254 if (options.useID && id) { 255 attrOrProp($div, 'id', options.idPrefix + '-' + id); 256 } 257 258 if (divSpanConfig.spanHtml) { 259 $span.html(divSpanConfig.spanHtml); 260 } 261 262 $div = divSpanWrap($el, $div, divSpanConfig.divWrap); 263 $span = divSpanWrap($el, $span, divSpanConfig.spanWrap); 264 classUpdateDisabled($div, $el, options); 265 return { 266 div: $div, 267 span: $span 268 }; 269 } 270 271 272 /** 273 * Wrap an element with a span to apply a global wrapper class 274 * 275 * @param jQuery $el Element to wrap 276 * @param object options 277 * @return jQuery Wrapper element 278 */ 279 function wrapWithWrapperClass($el, options) { 280 var $span; 281 282 if (!options.wrapperClass) { 283 return null; 284 } 285 286 $span = $('<span />').addClass(options.wrapperClass); 287 $span = divSpanWrap($el, $span, "wrap"); 288 return $span; 289 } 290 291 292 /** 293 * Test if high contrast mode is enabled. 294 * 295 * In high contrast mode, background images can not be set and 296 * they are always returned as 'none'. 297 * 298 * @return boolean True if in high contrast mode 299 */ 300 function highContrast() { 301 var c, $div, el, rgb; 302 303 // High contrast mode deals with white and black 304 rgb = 'rgb(120,2,153)'; 305 $div = $('<div style="width:0;height:0;color:' + rgb + '">'); 306 $('body').append($div); 307 el = $div.get(0); 308 309 // $div.css() will get the style definition, not 310 // the actually displaying style 311 if (wind.getComputedStyle) { 312 c = wind.getComputedStyle(el, '').color; 313 } else { 314 c = (el.currentStyle || el.style || {}).color; 315 } 316 317 $div.remove(); 318 return c.replace(/ /g, '') !== rgb; 319 } 320 321 322 /** 323 * Change text into safe HTML 324 * 325 * @param String text 326 * @return String HTML version 327 */ 328 function htmlify(text) { 329 if (!text) { 330 return ""; 331 } 332 333 return $('<span />').text(text).html(); 334 } 335 336 /** 337 * If not MSIE, return false. 338 * If it is, return the version number. 339 * 340 * @return false|number 341 */ 342 function isMsie() { 343 return navigator.cpuClass && !navigator.product; 344 } 345 346 /** 347 * Return true if this version of IE allows styling 348 * 349 * @return boolean 350 */ 351 function isMsieSevenOrNewer() { 352 if (wind.XMLHttpRequest !== undefined) { 353 return true; 354 } 355 356 return false; 357 } 358 359 /** 360 * Test if the element is a multiselect 361 * 362 * @param jQuery $el Element 363 * @return boolean true/false 364 */ 365 function isMultiselect($el) { 366 var elSize; 367 368 if ($el[0].multiple) { 369 return true; 370 } 371 372 elSize = attrOrProp($el, "size"); 373 374 if (!elSize || elSize <= 1) { 375 return false; 376 } 377 378 return true; 379 } 380 381 /** 382 * Meaningless utility function. Used mostly for improving minification. 383 * 384 * @return false 385 */ 386 function returnFalse() { 387 return false; 388 } 389 390 /** 391 * noSelect plugin, very slightly modified 392 * http://mths.be/noselect v1.0.3 393 * 394 * @param jQuery $elem Element that we don't want to select 395 * @param Object options Uniform options for the element 396 */ 397 function noSelect($elem, options) { 398 var none = 'none'; 399 bindMany($elem, options, { 400 'selectstart dragstart mousedown': returnFalse 401 }); 402 403 $elem.css({ 404 MozUserSelect: none, 405 msUserSelect: none, 406 webkitUserSelect: none, 407 userSelect: none 408 }); 409 } 410 411 /** 412 * Updates the filename tag based on the value of the real input 413 * element. 414 * 415 * @param jQuery $el Actual form element 416 * @param jQuery $filenameTag Span/div to update 417 * @param Object options Uniform options for this element 418 */ 419 function setFilename($el, $filenameTag, options) { 420 var filename = $el.val(); 421 422 if (filename === "") { 423 filename = options.fileDefaultHtml; 424 } else { 425 filename = filename.split(/[\/\\]+/); 426 filename = filename[(filename.length - 1)]; 427 } 428 429 $filenameTag.text(filename); 430 } 431 432 433 /** 434 * Function from jQuery to swap some CSS values, run a callback, 435 * then restore the CSS. Modified to pass JSLint and handle undefined 436 * values with 'use strict'. 437 * 438 * @param jQuery $el Element 439 * @param object newCss CSS values to swap out 440 * @param Function callback Function to run 441 */ 442 function swap($elements, newCss, callback) { 443 var restore, item; 444 445 restore = []; 446 447 $elements.each(function () { 448 var name; 449 450 for (name in newCss) { 451 if (Object.prototype.hasOwnProperty.call(newCss, name)) { 452 restore.push({ 453 el: this, 454 name: name, 455 old: this.style[name] 456 }); 457 458 this.style[name] = newCss[name]; 459 } 460 } 461 }); 462 463 callback(); 464 465 while (restore.length) { 466 item = restore.pop(); 467 item.el.style[item.name] = item.old; 468 } 469 } 470 471 472 /** 473 * The browser doesn't provide sizes of elements that are not visible. 474 * This will clone an element and add it to the DOM for calculations. 475 * 476 * @param jQuery $el 477 * @param String method 478 */ 479 function sizingInvisible($el, callback) { 480 var targets; 481 482 // We wish to target ourselves and any parents as long as 483 // they are not visible 484 targets = $el.parents(); 485 targets.push($el[0]); 486 targets = targets.not(':visible'); 487 swap(targets, { 488 visibility: "hidden", 489 display: "block", 490 position: "absolute" 491 }, callback); 492 } 493 494 495 /** 496 * Standard way to unwrap the div/span combination from an element 497 * 498 * @param jQuery $el Element that we wish to preserve 499 * @param Object options Uniform options for the element 500 * @return Function This generated function will perform the given work 501 */ 502 function unwrapUnwrapUnbindFunction($el, options) { 503 return function () { 504 $el.unwrap().unwrap().unbind(options.eventNamespace); 505 }; 506 } 507 508 var allowStyling = true, // False if IE6 or other unsupported browsers 509 highContrastTest = false, // Was the high contrast test ran? 510 uniformHandlers = [ // Objects that take care of "unification" 511 { 512 // Buttons 513 match: function ($el) { 514 return $el.is("a, button, :submit, :reset, input[type='button']"); 515 }, 516 apply: function ($el, options) { 517 var $div, defaultSpanHtml, ds, getHtml, doingClickEvent; 518 defaultSpanHtml = options.submitDefaultHtml; 519
520 if ($el.is(":reset")) { 521 defaultSpanHtml = options.resetDefaultHtml; 522 } 523 524 if ($el.is("a, button")) { 525 // Use the HTML inside the tag 526 getHtml = function () { 527 return $el.html() || defaultSpanHtml; 528 }; 529 } else { 530 // Use the value property of the element 531 getHtml = function () { 532 return htmlify(attrOrProp($el, "value")) || defaultSpanHtml; 533 }; 534 } 535 536 ds = divSpan($el, options, { 537 divClass: options.buttonClass, 538 spanHtml: getHtml() 539 }); 540 $div = ds.div; 541 bindUi($el, $div, options); 542 doingClickEvent = false; 543 bindMany($div, options, { 544 "click touchend": function () { 545 var ev, res, target, href; 546 547 if (doingClickEvent) { 548 return; 549 } 550 551 if ($el.is(':disabled')) { 552 return; 553 } 554 555 doingClickEvent = true; 556 557 if ($el[0].dispatchEvent) { 558 ev = document.createEvent("MouseEvents"); 559 ev.initEvent("click", true, true); 560 res = $el[0].dispatchEvent(ev); 561 562 if ($el.is('a') && res) { 563 target = attrOrProp($el, 'target'); 564 href = attrOrProp($el, 'href'); 565 566 if (!target || target === '_self') { 567 document.location.href = href; 568 } else { 569 wind.open(href, target); 570 } 571 } 572 } else { 573 $el.click(); 574 } 575 576 doingClickEvent = false; 577 } 578 }); 579 noSelect($div, options); 580 return { 581 remove: function () { 582 // Move $el out 583 $div.after($el); 584 585 // Remove div and span 586 $div.remove(); 587 588 // Unbind events 589 $el.unbind(options.eventNamespace); 590 return $el; 591 }, 592 update: function () { 593 classClearStandard($div, options); 594 classUpdateDisabled($div, $el, options); 595 $el.detach(); 596 ds.span.html(getHtml()).append($el); 597 } 598 }; 599 } 600 }, 601 { 602 // Checkboxes 603 match: function ($el) { 604 return $el.is(":checkbox"); 605 }, 606 apply: function ($el, options) { 607 var ds, $div, $span; 608 ds = divSpan($el, options, { 609 divClass: options.checkboxClass 610 }); 611 $div = ds.div; 612 $span = ds.span; 613 614 // Add focus classes, toggling, active, etc. 615 bindUi($el, $div, options); 616 bindMany($el, options, { 617 "click touchend": function () { 618 classUpdateChecked($span, $el, options); 619 } 620 }); 621 classUpdateChecked($span, $el, options); 622 return { 623 remove: unwrapUnwrapUnbindFunction($el, options), 624 update: function () { 625 classClearStandard($div, options); 626 $span.removeClass(options.checkedClass); 627 classUpdateChecked($span, $el, options); 628 classUpdateDisabled($div, $el, options); 629 } 630 }; 631 } 632 }, 633 { 634 // File selection / uploads 635 match: function ($el) { 636 return $el.is(":file"); 637 }, 638 apply: function ($el, options) { 639 640 var ds, $div, $filename, $button; 641 642 // The "span" is the button 643 ds = divSpan($el, options, { 644 divClass: options.fileClass, 645 spanClass: options.fileButtonClass, 646 spanHtml: options.fileButtonHtml, 647 spanWrap: "after" 648 }); 649 $div = ds.div; 650 $button = ds.span; 651 $filename = $("<span />").html(options.fileDefaultHtml); 652 $filename.addClass(options.filenameClass); 653 $filename = divSpanWrap($el, $filename, "after"); 654 655 // Set the size 656 if (!attrOrProp($el, "size")) { 657 attrOrProp($el, "size", $div.width() / 10); 658 } 659 660 // Actions 661 function filenameUpdate() { 662 setFilename($el, $filename, options); 663 } 664 665 bindUi($el, $div, options); 666 667 // Account for input saved across refreshes 668 filenameUpdate(); 669 670 // IE7 doesn't fire onChange until blur or second fire. 671 if (isMsie()) { 672 // IE considers browser chrome blocking I/O, so it 673 // suspends tiemouts until after the file has 674 // been selected. 675 bindMany($el, options, { 676 click: function () { 677 $el.trigger("change"); 678 setTimeout(filenameUpdate, 0); 679 } 680 }); 681 } else { 682 // All other browsers behave properly 683 bindMany($el, options, { 684 change: filenameUpdate 685 }); 686 } 687 688 noSelect($filename, options); 689 noSelect($button, options); 690 return { 691 remove: function () { 692 // Remove filename and button 693 $filename.remove(); 694 $button.remove(); 695 696 // Unwrap parent div, remove events 697 return $el.unwrap().unbind(options.eventNamespace); 698 }, 699 update: function () { 700 classClearStandard($div, options); 701 setFilename($el, $filename, options); 702 classUpdateDisabled($div, $el, options); 703 } 704 }; 705 } 706 }, 707 {
708 // Input fields (text) 709 match: function ($el) { 710 if ($el.is("input")) { 711 var t = (" " + attrOrProp($el, "type") + " ").toLowerCase(), 712 allowed = " color date datetime datetime-local email month number password search tel text time url week "; 713 return allowed.indexOf(t) >= 0; 714 } 715 716 return false; 717 }, 718 apply: function ($el, options) { 719 var elType, $wrapper; 720 721 elType = attrOrProp($el, "type"); 722 $el.addClass(options.inputClass); 723 $wrapper = wrapWithWrapperClass($el, options); 724 bindUi($el, $el, options); 725 726 if (options.inputAddTypeAsClass) { 727 $el.addClass(elType); 728 } 729 730 return { 731 remove: function () { 732 $el.removeClass(options.inputClass); 733 734 if (options.inputAddTypeAsClass) { 735 $el.removeClass(elType); 736 } 737 738 if ($wrapper) { 739 $el.unwrap(); 740 } 741 }, 742 update: returnFalse 743 }; 744 } 745 }, 746 { 747 // Radio buttons 748 match: function ($el) { 749 return $el.is(":radio"); 750 }, 751 apply: function ($el, options) { 752 var ds, $div, $span; 753 ds = divSpan($el, options, { 754 divClass: options.radioClass 755 }); 756 $div = ds.div; 757 $span = ds.span; 758 759 // Add classes for focus, handle active, checked 760 bindUi($el, $div, options); 761 bindMany($el, options, { 762 "click touchend": function () { 763 // Find all radios with the same name, then update 764 // them with $.uniform.update() so the right 765 // per-element options are used 766 $.uniform.update($(':radio[name="' + attrOrProp($el, "name") + '"]')); 767 } 768 }); 769 classUpdateChecked($span, $el, options); 770 return { 771 remove: unwrapUnwrapUnbindFunction($el, options), 772 update: function () { 773 classClearStandard($div, options); 774 classUpdateChecked($span, $el, options); 775 classUpdateDisabled($div, $el, options); 776 } 777 }; 778 } 779 }, 780 { 781 // Select lists, but do not style multiselects here 782 match: function ($el) { 783 if ($el.is("select") && !isMultiselect($el)) { 784 return true; 785 } 786 787 return false; 788 }, 789 apply: function ($el, options) { 790 var ds, $div, $span, origElemWidth; 791 792 if (options.selectAutoWidth) { 793 sizingInvisible($el, function () { 794 origElemWidth = $el.width(); 795 }); 796 } 797 798 ds = divSpan($el, options, { 799 divClass: options.selectClass, 800 spanHtml: ($el.find(":selected:first") || $el.find("option:first")).html(), 801 spanWrap: "before" 802 }); 803 $div = ds.div; 804 $span = ds.span; 805 806 if (options.selectAutoWidth) { 807 // Use the width of the select and adjust the 808 // span and div accordingly 809 sizingInvisible($el, function () { 810 // Force "display: block" - related to bug #287 811 swap($([ $span[0], $div[0] ]), { 812 display: "block" 813 }, function () { 814 var spanPad; 815 spanPad = $span.outerWidth() - $span.width(); 816 $div.width(origElemWidth); 817 $span.width(origElemWidth -spanPad); 818 }); 819 }); 820 821 } else { 822 // Force the select to fill the size of the div 823 $div.addClass('fixedWidth'); 824 } 825 826 // Take care of events 827 bindUi($el, $div, options); 828 bindMany($el, options, { 829 change: function () { 830 $span.html($el.find(":selected").html()); 831 $div.removeClass(options.activeClass); 832 }, 833 "click touchend": function () { 834 // IE7 and IE8 may not update the value right 835 // until after click event - issue #238 836 var selHtml = $el.find(":selected").html(); 837 838 if ($span.html() !== selHtml) { 839 // Change was detected 840 // Fire the change event on the select tag 841 $el.trigger('change'); 842 } 843 }, 844 keyup: function () { 845 $span.html($el.find(":selected").html()); 846 } 847 }); 848 noSelect($span, options); 849 return { 850 remove: function () { 851 // Remove sibling span 852 $span.remove(); 853 854 // Unwrap parent div 855 $el.unwrap().unbind(options.eventNamespace); 856 return $el; 857 }, 858 update: function () { 859 if (options.selectAutoWidth) { 860 // Easier to remove and reapply formatting 861 $.uniform.restore($el); 862 $el.uniform(options); 863 } else { 864 classClearStandard($div, options); 865 866 // Reset current selected text 867 $span.html($el.find(":selected").html()); 868 classUpdateDisabled($div, $el, options); 869 } 870 } 871 }; 872 } 873 }, 874 { 875 // Select lists - multiselect lists only 876 match: function ($el) {
877 if ($el.is("select") && isMultiselect($el)) { 878 return true; 879 } 880 881 return false; 882 }, 883 apply: function ($el, options) { 884 var $wrapper; 885 886 $el.addClass(options.selectMultiClass); 887 $wrapper = wrapWithWrapperClass($el, options); 888 bindUi($el, $el, options); 889 890 return { 891 remove: function () { 892 $el.removeClass(options.selectMultiClass); 893 894 if ($wrapper) { 895 $el.unwrap(); 896 } 897 }, 898 update: returnFalse 899 }; 900 } 901 }, 902 { 903 // Textareas 904 match: function ($el) { 905 return $el.is("textarea"); 906 }, 907 apply: function ($el, options) { 908 var $wrapper; 909 910 $el.addClass(options.textareaClass); 911 $wrapper = wrapWithWrapperClass($el, options); 912 bindUi($el, $el, options); 913 914 return { 915 remove: function () { 916 $el.removeClass(options.textareaClass); 917 918 if ($wrapper) { 919 $el.unwrap(); 920 } 921 }, 922 update: returnFalse 923 }; 924 } 925 } 926 ]; 927 928 // IE6 can't be styled - can't set opacity on select 929 if (isMsie() && !isMsieSevenOrNewer()) { 930 allowStyling = false; 931 } 932 933 $.uniform = { 934 // Default options that can be overridden globally or when uniformed 935 // globally: $.uniform.defaults.fileButtonHtml = "Pick A File"; 936 // on uniform: $('input').uniform({fileButtonHtml: "Pick a File"}); 937 defaults: { 938 activeClass: "active", 939 autoHide: true, 940 buttonClass: "button", 941 checkboxClass: "checker", 942 checkedClass: "checked", 943 disabledClass: "disabled", 944 eventNamespace: ".uniform", 945 fileButtonClass: "action", 946 fileButtonHtml: "Choose File", 947 fileClass: "uploader", 948 fileDefaultHtml: "No file selected", 949 filenameClass: "filename", 950 focusClass: "focus", 951 hoverClass: "hover", 952 idPrefix: "uniform", 953 inputAddTypeAsClass: true, 954 inputClass: "uniform-input", 955 radioClass: "radio", 956 resetDefaultHtml: "Reset", 957 resetSelector: false, // We'll use our own function when you don't specify one 958 selectAutoWidth: true, 959 selectClass: "selector", 960 selectMultiClass: "uniform-multiselect", 961 submitDefaultHtml: "Submit", // Only text allowed 962 textareaClass: "uniform", 963 useID: true, 964 wrapperClass: null 965 }, 966 967 // All uniformed elements - DOM objects 968 elements: [] 969 }; 970 971 $.fn.uniform = function (options) { 972 console.log(options); 973 console.log(this); 974 var el = this; 975 options = $.extend({}, $.uniform.defaults, options); 976 977 // If we are in high contrast mode, do not allow styling 978 if (!highContrastTest) { 979 highContrastTest = true; 980 981 if (highContrast()) { 982 allowStyling = false; 983 } 984 } 985 986 // Only uniform on browsers that work 987 if (!allowStyling) { 988 return this; 989 } 990 991 // Code for specifying a reset button 992 if (options.resetSelector) { 993 $(options.resetSelector).mouseup(function () { 994 wind.setTimeout(function () { 995 $.uniform.update(el); 996 }, 10); 997 }); 998 } 999 1000 return this.each(function () { 1001 var $el = $(this), i, handler, callbacks; 1002 1003 // Avoid uniforming elements already uniformed - just update 1004 if ($el.data("uniformed")) { 1005 $.uniform.update($el); 1006 return; 1007 } 1008 1009 // See if we have any handler for this type of element 1010 for (i = 0; i < uniformHandlers.length; i = i + 1) { 1011 handler = uniformHandlers[i]; 1012 1013 if (handler.match($el, options)) { 1014 callbacks = handler.apply($el, options); 1015 $el.data("uniformed", callbacks); 1016 1017 // Store element in our global array 1018 $.uniform.elements.push($el.get(0)); 1019 return; 1020 } 1021 } 1022 1023 // Could not style this element 1024 }); 1025 }; 1026 1027 $.uniform.restore = $.fn.uniform.restore = function (elem) { 1028 console.log('restore'); 1029 if (elem === undef) { 1030 elem = $.uniform.elements; 1031 } 1032 1033 $(elem).each(function () { 1034 var $el = $(this), index, elementData; 1035 elementData = $el.data("uniformed"); 1036 1037 // Skip elements that are not uniformed 1038 if (!elementData) { 1039 return; 1040 } 1041 1042 // Unbind events, remove additional markup that was added 1043 elementData.remove(); 1044 1045 // Remove item from list of uniformed elements 1046 index = $.inArray(this, $.uniform.elements); 1047 1048 if (index >= 0) { 1049 $.uniform.elements.splice(index, 1); 1050 } 1051 1052 $el.removeData("uniformed"); 1053 }); 1054 }; 1055 1056 $.uniform.update = $.fn.uniform.update = function (elem) { 1057 console.log('update'); 1058 if (elem === undef) { 1059 elem = $.uniform.elements; 1060 } 1061 1062 $(elem).each(function () { 1063 var $el = $(this), elementData; 1064 elementData = $el.data("uniformed"); 1065 1066 // Skip elements that are not uniformed 1067 if (!elementData) { 1068 return; 1069 } 1070 1071 elementData.update($el, elementData.options); 1072 }); 1073 }; 1074}(this, jQuery)); 1075 1076 1077if (typeof isMobile != 'undefined' && !isMobile){ 1078 1079 $(window).load(function () { 1080 console.log('test'); 1081 $("select.form-control,input[type='checkbox']:not(.comparator), input[type='radio'],input#id_carrier2, input[type='file']").not(".not_uniform").not(".CybotCookiebotDialogBodyLevelButton").uniform(); 1082 }); 1083 1084 // refresh uniform selects on document width change 1085 $(window).resize( 1086 function () { 1087 $.uniform.update("select.form-control, input[type='file']"); 1088 } 1089 ); 1090}
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.