Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Title fields (for articles and projects) now have a helpful 'titlecas…
…e it' button next to them to run John Resig's titlecasing script on their contents.
- Loading branch information
Showing
5 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Title Caps | ||
* | ||
* Ported to JavaScript By John Resig - http://ejohn.org/ - 21 May 2008 | ||
* Original by John Gruber - http://daringfireball.net/ - 10 May 2008 | ||
* License: http://www.opensource.org/licenses/mit-license.php | ||
*/ | ||
|
||
(function(){ | ||
var small = "(a|an|and|as|at|but|by|en|for|if|in|of|on|or|the|to|v[.]?|via|vs[.]?)"; | ||
var punct = "([!\"#$%&'()*+,./:;<=>?@[\\\\\\]^_`{|}~-]*)"; | ||
|
||
this.titleCaps = function(title){ | ||
var parts = [], split = /[:.;?!] |(?: |^)["Ò]/g, index = 0; | ||
|
||
while (true) { | ||
var m = split.exec(title); | ||
|
||
parts.push( title.substring(index, m ? m.index : title.length) | ||
.replace(/\b([A-Za-z][a-z.'Õ]*)\b/g, function(all){ | ||
return /[A-Za-z]\.[A-Za-z]/.test(all) ? all : upper(all); | ||
}) | ||
.replace(RegExp("\\b" + small + "\\b", "ig"), lower) | ||
.replace(RegExp("^" + punct + small + "\\b", "ig"), function(all, punct, word){ | ||
return punct + upper(word); | ||
}) | ||
.replace(RegExp("\\b" + small + punct + "$", "ig"), upper)); | ||
|
||
index = split.lastIndex; | ||
|
||
if ( m ) parts.push( m[0] ); | ||
else break; | ||
} | ||
|
||
return parts.join("").replace(/ V(s?)\. /ig, " v$1. ") | ||
.replace(/(['Õ])S\b/ig, "$1s") | ||
.replace(/\b(AT&T|Q&A)\b/ig, function(all){ | ||
return all.toUpperCase(); | ||
}); | ||
}; | ||
|
||
function lower(word){ | ||
return word.toLowerCase(); | ||
} | ||
|
||
function upper(word){ | ||
return word.substr(0,1).toUpperCase() + word.substr(1); | ||
} | ||
})(); |
This file contains 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
This file contains 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
This file contains 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