1/*! http://mths.be/placeholder v2.0.8 by @mathias */ 2;(function(window, document, $) { 3 4 // Opera Mini v7 doesnât support placeholder although its DOM seems to indicate so 5 var isOperaMini = Object.prototype.toString.call(window.operamini) == '[object OperaMini]'; 6 var isInputSupported = 'placeholder' in document.createElement('input') && !isOperaMini; 7 var isTextareaSupported = 'placeholder' in document.createElement('textarea') && !isOperaMini; 8 var prototype = $.fn; 9 var valHooks = $.valHooks; 10 var propHooks = $.propHooks; 11 var hooks; 12 var placeholder; 13 14 if (isInputSupported && isTextareaSupported) { 15 16 placeholder = prototype.placeholder = function() { 17 return this; 18 }; 19 20 placeholder.input = placeholder.textarea = true; 21 22 } else { 23 24 placeholder = prototype.placeholder = function() { 25 var $this = this; 26 $this 27 .filter((isInputSupported ? 'textarea' : ':input') + '[placeholder]') 28 .not('.placeholder') 29 .bind({ 30 'focus.placeholder': clearPlaceholder, 31 'blur.placeholder': setPlaceholder 32 }) 33 .data('placeholder-enabled', true) 34 .trigger('blur.placeholder'); 35 return $this; 36 }; 37 38 placeholder.input = isInputSupported; 39 placeholder.textarea = isTextareaSupported; 40 41 hooks = { 42 'get': function(element) { 43 var $element = $(element); 44 45 var $passwordInput = $element.data('placeholder-password'); 46 if ($passwordInput) { 47 return $passwordInput[0].value; 48 } 49 50 return $element.data('placeholder-enabled') && $element.hasClass('placeholder') ? '' : element.value; 51 }, 52 'set': function(element, value) { 53 var $element = $(element); 54 55 var $passwordInput = $element.data('placeholder-password'); 56 if ($passwordInput) { 57 return $passwordInput[0].value = value; 58 } 59 60 if (!$element.data('placeholder-enabled')) { 61 return element.value = value; 62 } 63 if (value == '') { 64 element.value = value; 65 // Issue #56: Setting the placeholder causes problems if the element continues to have focus. 66 if (element != safeActiveElement()) { 67 // We can't use `triggerHandler` here because of dummy text/password inputs :( 68 setPlaceholder.call(element); 69 } 70 } else if ($element.hasClass('placeholder')) { 71 clearPlaceholder.call(element, true, value) || (element.value = value); 72 } else { 73 element.value = value; 74 } 75 // `set` can not return `undefined`; see http://jsapi.info/jquery/1.7.1/val#L2363 76 return $element; 77 } 78 }; 79 80 if (!isInputSupported) { 81 valHooks.input = hooks; 82 propHooks.value = hooks; 83 } 84 if (!isTextareaSupported) { 85 valHooks.textarea = hooks; 86 propHooks.value = hooks; 87 } 88 89 $(function() { 90 // Look for forms 91 $(document).delegate('form', 'submit.placeholder', function() { 92 // Clear the placeholder values so they don't get submitted 93 var $inputs = $('.placeholder', this).each(clearPlaceholder); 94 setTimeout(function() { 95 $inputs.each(setPlaceholder); 96 }, 10); 97 }); 98 }); 99 100 // Clear placeholder values upon page reload 101 $(window).bind('beforeunload.placeholder', function() { 102 $('.placeholder').each(function() { 103 this.value = ''; 104 }); 105 }); 106 107 } 108 109 function args(elem) { 110 // Return an object of element attributes 111 var newAttrs = {}; 112 var rinlinejQuery = /^jQuery\d+$/; 113 $.each(elem.attributes, function(i, attr) { 114 if (attr.specified && !rinlinejQuery.test(attr.name)) { 115 newAttrs[attr.name] = attr.value; 116 } 117 }); 118 return newAttrs; 119 } 120 121 function clearPlaceholder(event, value) { 122 var input = this; 123 var $input = $(input); 124 if (input.value == $input.attr('placeholder') && $input.hasClass('placeholder')) { 125 if ($input.data('placeholder-password')) { 126 $input = $input.hide().next().show().attr('id', $input.removeAttr('id').data('placeholder-id')); 127 // If `clearPlaceholder` was called from `$.valHooks.input.set` 128 if (event === true) { 129 return $input[0].value = value; 130 } 131 $input.focus(); 132 } else { 133 input.value = ''; 134 $input.removeClass('placeholder'); 135 input == safeActiveElement() && input.select(); 136 } 137 } 138 } 139 140 function setPlaceholder() { 141 var $replacement; 142 var input = this; 143 var $input = $(input); 144 var id = this.id; 145 if (input.value == '') { 146 if (input.type == 'password') { 147 if (!$input.data('placeholder-textinput')) { 148 try { 149 $replacement = $input.clone().attr({ 'type': 'text' }); 150 } catch(e) { 151 $replacement = $('<input>').attr($.extend(args(this), { 'type': 'text' })); 152 } 153 $replacement 154 .removeAttr('name') 155 .data({ 156 'placeholder-password': $input, 157 'placeholder-id': id 158 }) 159 .bind('focus.placeholder', clearPlaceholder); 160 $input 161 .data({ 162 'placeholder-textinput': $replacement, 163 'placeholder-id': id 164 }) 165 .before($replacement); 166 } 167 $input = $input.removeAttr('id').hide().prev().attr('id', id).show(); 168 // Note: `$input[0] != input` now! 169 } 170 $input.addClass('placeholder'); 171 $input[0].value = $input.attr('placeholder'); 172 } else { 173 $input.removeClass('placeholder'); 174 } 175 } 176 177 function safeActiveElement() { 178 // Avoid IE9 `document.activeElement` of death 179 // https://github.com/mathiasbynens/jquery-placeholder/pull/99 180 try { 181 return document.activeElement; 182 } catch (exception) {} 183 } 184 185}(this, document, 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.