I got a lot of help from this other question here: Transform ALL CAPS to Proper Case using CSS and jQuery
But I've been trying to modify the script so that if an mdash occurs in the title, the letter right after it will also be capitalized see http://jsfiddle.net/wm5kZ/5/. And here's the script:
$('ul.proper-case li a').each(function(){
var ele = $(this);
ele.text(toProperCase(ele.text()));
});
function toProperCase(str)
{
var noCaps = ['of','a','the','and','an','am','or','nor','but','is','if','then',
'else','when','at','from','by','on','off','for','in','out','to','into','with'];
return str.replace(/\w\S*/g, function(txt, offset){
if(offset != 0 && noCaps.indexOf(txt.toLowerCase()) != -1){
return txt.toLowerCase();
}
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
});
}
I've been trying to understand the regular expression and I tried putting in different things for the mdash but I'm not quite sure how to do it. Nothing I've tried so far works.
Can anyone help me to know where to modify the script to do this? Could you also just explain sort of what it's doing so I can try to understand it? Thanks so much.