Created
May 16, 2012 19:57
-
-
Save VirtuosiMedia/2713464 to your computer and use it in GitHub Desktop.
Hyphenator
This file contains hidden or 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
| 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