Skip to content

Instantly share code, notes, and snippets.

@menslow
Created February 17, 2012 20:55
Show Gist options
  • Save menslow/1855391 to your computer and use it in GitHub Desktop.
Save menslow/1855391 to your computer and use it in GitHub Desktop.
JavaScript: Boilerplate JavaScript App
App = function(){
/* private */
var default_topic = 'Placeholder Text';
/* HTML5 elememt support tester */
var element_supports_attribute = function(element,attribute){
var test = document.createElement(element);
if (attribute in test) {
return true;
} else {
return false;
}
};
/* end private */
return {
init: function() {
if (!element_supports_attribute('input','placeholder')) {
App.add_focus_events();
}
},
add_focus_events: function(){
$('#foo').val(default_topic);
$('#foo').focus(function(){
if($(this).val()===default_topic){
$(this).val('');
}
});
$('#foo').blur(function(){
if($(this).val()===''){
$(this).val(default_topic);
}
});
}
};
}();
$(document).ready(function($){
App.init();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment