Add some jQuery magic

Open layout.jade and add in the foot of the doc:

  1. script(src='//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js')
  2. script(src="/javascripts/app.js")

Create the following file:

  1. $ touch public/javascripts/app.js

Open app.js and add the following:

  1. // Test for placeholder support
  2. $.support.placeholder = (function(){
  3. var i = document.createElement('input');
  4. return 'placeholder' in i;
  5. })();
  6. // Hide labels by default if placeholders are supported
  7. if($.support.placeholder) {
  8. $('.form li').each(function(){
  9. $(this).addClass('js-hide-label');
  10. });
  11. }
  12. $('.form li').find('input, textarea').on('keyup blur focus', function(){
  13. // Cache our selectors
  14. var el = $(this),
  15. parent = el.parent();
  16. // Add or remove classes
  17. if( el.val() === '' ) {
  18. parent.addClass('js-hide-label');
  19. } else {
  20. parent.removeClass('js-hide-label');
  21. }
  22. });