YUI().use('node', function(Y) { var app = { MAX_MESSAGE_LENGTH: 180, formli: Y.get('li#postMessageForm'), linkli: Y.get('li#postMessageLink'), wordcount: Y.get('#postMessageRemainingCount'), textarea: Y.get('#postMessageTextArea'), submitlink: Y.get('#postMessageSubmit'), content: '', setRemainingCharactersCount: function(content) { if (content.length > this.MAX_MESSAGE_LENGTH) { content = content.substring(0, this.MAX_MESSAGE_LENGTH); this.textarea.set('value', content); } var count = this.MAX_MESSAGE_LENGTH - content.length; this.wordcount.set('text', count); }, setupListeners: function() { this.formli.addClass('hidden'); this.setRemainingCharactersCount(this.content); this.linkli.on('click', function(e) { e.preventDefault(); this.formli.removeClass('hidden'); this.linkli.addClass('hidden'); }, this); this.textarea.on('blur', function() { this.content = this.textarea.get('value'); if (this.content == '') { this.textarea.set('value', 'Type your message here...'); this.textarea.addClass('ghosting'); } }, this); this.textarea.on('focus', function() { if (this.content == '') { this.textarea.set('value', this.content); this.textarea.removeClass('ghosting'); } }, this); this.textarea.on('keyup', function() { this.setRemainingCharactersCount(this.textarea.get('value')); }, this); this.submitlink.on('click', function(e) { e.preventDefault(); if (this.content == '') { alert('Please type your message in the box provided.'); } else { this.formli.one('form').submit(); } }, this); } }; app.setupListeners(); });