Skip to content

Instantly share code, notes, and snippets.

@divoxx
Created March 4, 2009 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save divoxx/73980 to your computer and use it in GitHub Desktop.
Save divoxx/73980 to your computer and use it in GitHub Desktop.
var InputTitleAsValue = new Attitude.Behavior({
initialize: function() {
if (this.element.get('value') == '') {
this.element.set('value', this.element.get('title'))
} else if (this.element.get('value') != this.element.get('title')) {
this.element.removeClass('title-as-value')
}
},
onFocus: function() {
if (this.element.get('value') == this.element.get('title')) {
this.element.set('value', '')
this.element.removeClass('title-as-value')
}
},
onBlur: function() {
if (this.element.get('value') == '') {
this.element.set('value', this.element.get('title'))
this.element.addClass('title-as-value')
}
}
})
/**
* Initialization and binding of unobtrusive behaviors to elements
*/
Attitude.define({
'.title-as-value': InputTitleAsValue
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment