github.com/aleksi/gonuts.io@v0.0.0-20130622121132-3b0f2d1999fb/app/public/search.js (about) 1 function bindEvent(el, e, fn) { 2 if (el.addEventListener){ 3 el.addEventListener(e, fn, false); 4 } else if (el.attachEvent){ 5 el.attachEvent('on'+e, fn); 6 } 7 } 8 9 function bindSearchEvents() { 10 var search = document.getElementById('search'); 11 function clearInactive() { 12 if (search.className == "inactive") { 13 search.value = ""; 14 search.className = ""; 15 } 16 } 17 function restoreInactive() { 18 if (search.value !== "") { 19 return; 20 } 21 if (search.type != "search") { 22 search.value = search.getAttribute("placeholder"); 23 } 24 search.className = "inactive"; 25 } 26 restoreInactive(); 27 bindEvent(search, 'focus', clearInactive); 28 bindEvent(search, 'blur', restoreInactive); 29 } 30 31 bindEvent(window, 'load', bindSearchEvents);