Skip to content

Instantly share code, notes, and snippets.

@stnvh
Last active April 22, 2016 13:26
Show Gist options
  • Save stnvh/261a91d321842d34a85f to your computer and use it in GitHub Desktop.
Save stnvh/261a91d321842d34a85f to your computer and use it in GitHub Desktop.
left hand assignment ftw
/* ie placeholders */
$('[placeholder]').on('focus blur', function() {
var h = this.getAttribute('placeholder'), v = this.value;
this.value = !v && h || ((v != h) && v || '');
}).trigger('blur');
(function(d) {
for(var p = d.querySelectorAll('[placeholder]'), l = 0; l < p.length; l++) {
for(var a = (d.attachEvent ? 'attachEvent' : 'addEventListener'), c = ['focusin', 'focusout'], e = 0; e < c.length; e++) {
if(a.match(/t$/)) c[e] = 'on' + c[e];
p[l][a](c[e], (function(f) {f = function(o) {
var s = (o == this ? o : window.event.srcElement);
h = s.getAttribute('placeholder'), v = s.value;
s.value = !v && h || ((v != h) && v || '');
}
return (e < 1 && f.apply(p[l],[p[l]])) || f;
})(), false)
}
}
}(document))()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment