Created
February 17, 2012 20:55
-
-
Save menslow/1855391 to your computer and use it in GitHub Desktop.
JavaScript: Boilerplate JavaScript App
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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