1/*! 2 * jQuery Placeholder Plugin v2.3.1 3 * https://github.com/mathiasbynens/jquery-placeholder 4 * 5 * Copyright 2011, 2015 Mathias Bynens 6 * Released under the MIT license 7 */ 8(function(factory) { 9 if (typeof define === 'function' && define.amd) { 10 // AMD 11 define(['jquery'], factory); 12 } else if (typeof module === 'object' && module.exports) { 13 factory(require('jquery')); 14 } else { 15 // Browser globals 16 factory(jQuery); 17 } 18}(function($) { 19 20 /**** 21 * Allows plugin behavior simulation in modern browsers for easier debugging. 22 * When setting to true, use attribute "placeholder-x" rather than the usual "placeholder" in your inputs/textareas 23 * i.e. <input type="text" placeholder-x="my placeholder text" /> 24 */ 25 var debugMode = false; 26 27 // Opera Mini v7 doesn't support placeholder although its DOM seems to indicate so 28 var isOperaMini = Object.prototype.toString.call(window.operamini) === '[object OperaMini]'; 29 var isInputSupported = 'placeholder' in document.createElement('input') && !isOperaMini && !debugMode; 30 var isTextareaSupported = 'placeholder' in document.createElement('textarea') && !isOperaMini && !debugMode; 31 var valHooks = $.valHooks; 32 var propHooks = $.propHooks; 33 var hooks; 34 var placeholder; 35 var settings = {}; 36 37 if (isInputSupported && isTextareaSupported) { 38 39 placeholder = $.fn.placeholder = function() { 40 return this; 41 }; 42 43 placeholder.input = true; 44 placeholder.textarea = true; 45 46 } else { 47 48 placeholder = $.fn.placeholder = function(options) { 49 50 var defaults = {customClass: 'placeholder'}; 51 settings = $.extend({}, defaults, options); 52 53 return this.filter((isInputSupported ? 'textarea' : ':input') + '[' + (debugMode ? 'placeholder-x' : 'placeholder') + ']') 54 .not('.'+settings.customClass) 55 .not(':radio, :checkbox, [type=hidden]') 56 .bind({ 57 'focus.placeholder': clearPlaceholder, 58 'blur.placeholder': setPlaceholder 59 }) 60 .data('placeholder-enabled', true) 61 .trigger('blur.placeholder'); 62 }; 63 64 placeholder.input = isInputSupported; 65 placeholder.textarea = isTextareaSupported; 66 67 hooks = { 68 'get': function(element) { 69 70 var $element = $(element); 71 var $passwordInput = $element.data('placeholder-password'); 72 73 if ($passwordInput) { 74 return $passwordInput[0].value; 75 } 76 77 return $element.data('placeholder-enabled') && $element.hasClass(settings.customClass) ? '' : element.value; 78 }, 79 'set': function(element, value) { 80 81 var $element = $(element); 82 var $replacement; 83 var $passwordInput; 84 85 if (value !== '') { 86 87 $replacement = $element.data('placeholder-textinput'); 88 $passwordInput = $element.data('placeholder-password'); 89 90 if ($replacement) { 91 clearPlaceholder.call($replacement[0], true, value) || (element.value = value); 92 $replacement[0].value = value; 93 94 } else if ($passwordInput) { 95 clearPlaceholder.call(element, true, value) || ($passwordInput[0].value = value); 96 element.value = value; 97 } 98 } 99 100 if (!$element.data('placeholder-enabled')) { 101 element.value = value; 102 return $element; 103 } 104 105 if (value === '') { 106 107 element.value = value; 108 109 // Setting the placeholder causes problems if the element continues to have focus. 110 if (element != safeActiveElement()) { 111 // We can't use `triggerHandler` here because of dummy text/password inputs :( 112 setPlaceholder.call(element); 113 } 114 115 } else { 116 117 if ($element.hasClass(settings.customClass)) { 118 clearPlaceholder.call(element); 119 } 120 121 element.value = value; 122 } 123 // `set` can not return `undefined`; see http://jsapi.info/jquery/1.7.1/val#L2363 124 return $element; 125 } 126 }; 127 128 if (!isInputSupported) { 129 valHooks.input = hooks; 130 propHooks.value = hooks; 131 } 132 133 if (!isTextareaSupported) { 134 valHooks.textarea = hooks; 135 propHooks.value = hooks; 136 } 137 138 $(function() { 139 // Look for forms 140 $(document).delegate('form', 'submit.placeholder', function() { 141 142 // Clear the placeholder values so they don't get submitted
143 var $inputs = $('.'+settings.customClass, this).each(function() { 144 clearPlaceholder.call(this, true, ''); 145 }); 146 147 setTimeout(function() { 148 $inputs.each(setPlaceholder); 149 }, 10); 150 }); 151 }); 152 153 // Clear placeholder values upon page reload 154 $(window).bind('beforeunload.placeholder', function() { 155 156 var clearPlaceholders = true; 157 158 try { 159 // Prevent IE javascript:void(0) anchors from causing cleared values 160 if (document.activeElement.toString() === 'javascript:void(0)') { 161 clearPlaceholders = false; 162 } 163 } catch (exception) { } 164 165 if (clearPlaceholders) { 166 $('.'+settings.customClass).each(function() { 167 this.value = ''; 168 }); 169 } 170 }); 171 } 172 173 function args(elem) { 174 // Return an object of element attributes 175 var newAttrs = {}; 176 var rinlinejQuery = /^jQuery\d+$/; 177 178 $.each(elem.attributes, function(i, attr) { 179 if (attr.specified && !rinlinejQuery.test(attr.name)) { 180 newAttrs[attr.name] = attr.value; 181 } 182 }); 183 184 return newAttrs; 185 } 186 187 function clearPlaceholder(event, value) { 188 189 var input = this; 190 var $input = $(this); 191 192 if (input.value === $input.attr((debugMode ? 'placeholder-x' : 'placeholder')) && $input.hasClass(settings.customClass)) { 193 194 input.value = ''; 195 $input.removeClass(settings.customClass); 196 197 if ($input.data('placeholder-password')) { 198 199 $input = $input.hide().nextAll('input[type="password"]:first').show().attr('id', $input.removeAttr('id').data('placeholder-id')); 200 201 // If `clearPlaceholder` was called from `$.valHooks.input.set` 202 if (event === true) { 203 $input[0].value = value; 204 205 return value; 206 } 207 208 $input.focus(); 209 210 } else { 211 input == safeActiveElement() && input.select(); 212 } 213 } 214 } 215 216 function setPlaceholder(event) { 217 var $replacement; 218 var input = this; 219 var $input = $(this); 220 var id = input.id; 221 222 // If the placeholder is activated, triggering blur event (`$input.trigger('blur')`) should do nothing. 223 if (event && event.type === 'blur' && $input.hasClass(settings.customClass)) { 224 return; 225 } 226 227 if (input.value === '') { 228 if (input.type === 'password') { 229 if (!$input.data('placeholder-textinput')) { 230 231 try { 232 $replacement = $input.clone().prop({ 'type': 'text' }); 233 } catch(e) { 234 $replacement = $('<input>').attr($.extend(args(this), { 'type': 'text' })); 235 } 236 237 $replacement 238 .removeAttr('name') 239 .data({ 240 'placeholder-enabled': true, 241 'placeholder-password': $input, 242 'placeholder-id': id 243 }) 244 .bind('focus.placeholder', clearPlaceholder); 245 246 $input 247 .data({ 248 'placeholder-textinput': $replacement, 249 'placeholder-id': id 250 }) 251 .before($replacement); 252 } 253 254 input.value = ''; 255 $input = $input.removeAttr('id').hide().prevAll('input[type="text"]:first').attr('id', $input.data('placeholder-id')).show(); 256 257 } else { 258 259 var $passwordInput = $input.data('placeholder-password'); 260 261 if ($passwordInput) { 262 $passwordInput[0].value = ''; 263 $input.attr('id', $input.data('placeholder-id')).show().nextAll('input[type="password"]:last').hide().removeAttr('id'); 264 } 265 } 266 267 $input.addClass(settings.customClass); 268 $input[0].value = $input.attr((debugMode ? 'placeholder-x' : 'placeholder')); 269 270 } else { 271 $input.removeClass(settings.customClass); 272 } 273 } 274 275 function safeActiveElement() { 276 // Avoid IE9 `document.activeElement` of death 277 try { 278 return document.activeElement; 279 } catch (exception) {} 280 } 281}));
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.