Skip to content

Instantly share code, notes, and snippets.

@VirtuosiMedia
Created May 16, 2012 19:57
Show Gist options
  • Select an option

  • Save VirtuosiMedia/2713464 to your computer and use it in GitHub Desktop.

Select an option

Save VirtuosiMedia/2713464 to your computer and use it in GitHub Desktop.
Hyphenator
var Hyphenator = new Class ({
Implements: [Events, Options],
options: {
separator: '-',
trigger: 'keyup',
prepend: '',
allowed: /[^\w\d\s-]/g
},
initialize: function(input, target, options){
this.setOptions(options);
var separator = this.options.separator;
var prepend = this.options.prepend;
var options = this.options;
input.addEvent(this.options.trigger, function(){
this.text = this.get('value').clean().replace(options.allowed, '').replace(/[\s]/g, separator).toLowerCase();
(target.get('tag') == 'input') ? target.set('value', prepend+this.text) : target.set('text', prepend+this.text);
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment