1/** 2 * Example: inputPlaceholder( document.getElementById('my_input_element') ) 3 * @param {Element} input 4 * @param {String} [color='#AAA'] 5 * @return {Element} input 6 */ 7function inputPlaceholder (input, color) { 8 9 if (!input) return null; 10 11 // Do nothing if placeholder supported by the browser (Webkit, Firefox 3.7) 12 if (input.placeholder && 'placeholder' in document.createElement(input.tagName)) return input; 13 14 color = '#AAA'; 15 var default_color = input.style.color; 16 var placeholder = input.getAttribute('placeholder'); 17 18 if (input.value === '' || input.value == placeholder) { 19 input.value = placeholder; 20 input.style.color = color; 21 input.setAttribute('data-placeholder-visible', 'true'); 22 } 23 24 var add_event = /*@cc_on'attachEvent'||@*/'addEventListener'; 25 26 input[add_event](/*@cc_on'on'+@*/'focus', function(){ 27 input.style.color = default_color; 28 if (input.getAttribute('data-placeholder-visible')) { 29 input.setAttribute('data-placeholder-visible', ''); 30 input.value = ''; 31 } 32 }, false); 33 34 input[add_event](/*@cc_on'on'+@*/'blur', function(){ 35 if (input.value === '') { 36 input.setAttribute('data-placeholder-visible', 'true'); 37 input.value = placeholder; 38 input.style.color = color; 39 } else { 40 input.style.color = default_color; 41 input.setAttribute('data-placeholder-visible', ''); 42 } 43 }, false); 44 45 input.form && input.form[add_event](/*@cc_on'on'+@*/'submit', function(){ 46 if (input.getAttribute('data-placeholder-visible')) { 47 input.value = ''; 48 } 49 }, false); 50 51 return input; 52} 53 54dojo.ready(function() { 55 dojo.query('[placeholder]').forEach(inputPlaceholder); 56});
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.