1(function($) { 2 3 /** 4 * Spoofs placeholders in browsers that don't support them (eg Firefox 3) 5 * 6 * Copyright 2011 Dan Bentley 7 * Licensed under the Apache License 2.0 8 * 9 * Author: Dan Bentley [github.com/danbentley] 10 */ 11 12 // Return if native support is available. 13 if ("placeholder" in document.createElement("input")) return; 14 15 $(document).ready(function(){ 16 $(':input[placeholder]').not(':password').each(function() { 17 setupPlaceholder($(this)); 18 }); 19 20 $(':password[placeholder]').each(function() { 21 setupPasswords($(this)); 22 }); 23 24 $('form').submit(function(e) { 25 clearPlaceholdersBeforeSubmit($(this)); 26 }); 27 }); 28 29 function setupPlaceholder(input) { 30 31 var placeholderText = input.attr('placeholder'); 32 33 setPlaceholderOrFlagChanged(input, placeholderText); 34 input.focus(function(e) { 35 if (input.data('changed') === true) return; 36 if (input.val() === placeholderText) input.val(''); 37 }).blur(function(e) { 38 if (input.val() === '') input.val(placeholderText); 39 }).change(function(e) { 40 input.data('changed', input.val() !== ''); 41 }); 42 } 43 44 function setPlaceholderOrFlagChanged(input, text) { 45 (input.val() === '') ? input.val(text) : input.data('changed', true); 46 } 47 48 function setupPasswords(input) { 49 var passwordPlaceholder = createPasswordPlaceholder(input); 50 input.after(passwordPlaceholder); 51 52 (input.val() === '') ? input.hide() : passwordPlaceholder.hide(); 53 54 $(input).blur(function(e) { 55 if (input.val() !== '') return; 56 input.hide(); 57 passwordPlaceholder.show(); 58 }); 59 60 $(passwordPlaceholder).focus(function(e) { 61 input.show().focus(); 62 passwordPlaceholder.hide(); 63 }); 64 } 65 66 function createPasswordPlaceholder(input) { 67 return $('<input>').attr({ 68 placeholder: input.attr('placeholder'), 69 value: input.attr('placeholder'), 70 id: input.attr('id'), 71 readonly: true 72 }).addClass(input.attr('class')); 73 } 74 75 function clearPlaceholdersBeforeSubmit(form) { 76 form.find(':input[placeholder]').each(function() { 77 if ($(this).data('changed') === true) return; 78 if ($(this).val() === $(this).attr('placeholder')) $(this).val(''); 79 }); 80 } 81})(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.