mirror of
https://github.com/wezm/wezm.net.git
synced 2024-12-22 12:19:52 +00:00
7 lines
2.1 KiB
HTML
7 lines
2.1 KiB
HTML
I've make a bookmarklet out of <a href="http://individed.com/code/to-title-case/">David Gouch's Javascript implementation</a> of <a href="http://daringfireball.net/2008/05/title_case">John Gruber's Title Case</a> Perl script.
|
||
|
||
Drag this link to your bookmarks bar: <a href="javascript:function%20toTitleCase%28t%29%7B%20return%20t.replace%28%2F%28%5B%5Cw%26%60%27%E2%80%98%E2%80%99%22%E2%80%9C.%40%3A%5C%2F%5C%7B%5C%28%5C%5B%3C%3E_%5D%2B-%3F%20%2A%29%2Fg%2C%20function%28match%2C%20p1%2C%20index%2C%20title%29%7B%20if%20%28index%20%3E%200%20%26%26%20title.charAt%28index%20-%202%29%20%21%3D%20%22%3A%22%20%26%26%20match.search%28%2F%5E%28a%28nd%3F%7Cs%7Ct%29%3F%7Cb%28ut%7Cy%29%7Cen%7Cfor%7Ci%5Bfn%5D%7Co%5Bfnr%5D%7Ct%28he%7Co%29%7Cvs%3F%5C.%3F%7Cvia%29%5B%20-%5D%2Fi%29%20%3E%20-1%29%20return%20match.toLowerCase%28%29%3B%20if%20%28title.substring%28index%20-%201%2C%20index%20%2B%201%29.search%28%2F%5B%27%22_%7B%28%5B%5D%2F%29%20%3E%20-1%29%20return%20match.charAt%280%29%20%2B%20match.charAt%281%29.toUpperCase%28%29%20%2B%20match.substr%282%29%3B%20if%20%28match.substr%281%29.search%28%2F%5BA-Z%5D%2B%7C%26%7C%5B%5Cw%5D%2B%5B._%5D%5B%5Cw%5D%2B%2F%29%20%3E%20-1%20%7C%7C%20title.substring%28index%20-%201%2C%20index%20%2B%201%29.search%28%2F%5B%5C%5D%29%7D%5D%2F%29%20%3E%20-1%29%20return%20match%3B%20return%20match.charAt%280%29.toUpperCase%28%29%20%2B%20match.substr%281%29%3B%20%7D%29%3B%20%7D%3Bvar%20S%20%3D%20%22%22%20%2B%20%28window.getSelection%20%3F%20window.getSelection%28%29%20%3A%20document.getSelection%20%3F%20document.getSelection%28%29%20%3A%20document.selection.createRange%28%29.text%29%3Bif%28%21S%29%20S%3Dprompt%28%22You%20didn%27t%20select%20any%20text.%20%20Enter%20text%20now%3A%22%2C%20%22%22%29%3Bif%20%28S%21%3Dnull%29%7Balert%28toTitleCase%28S%29%29%7D%3B%20void%200">Title Case</a>
|
||
|
||
Seems to work ok in Firefox, IE 6 has issues.
|
||
|
||
**Update 15 Mar 2010:** In Mac OS X 10.6 a better way to do this is via a service that calls Gruber's Perl script. See [Creating a ‘Make Title Case’ Service in Snow Leopard](http://web.archive.org/web/20090913073618/http://seansperte.com/entry/creating_a_make_title_case_service_in_snow_leopard/) for instructions.
|