This might not be too helpful, but maybe you can extract a way of
using this... I found a few places online where they were discussing
the capitalization process, and one thing that was interesting is that
if the intent is to change the text to a proper "title" you should be
aware that titles don't often capitalize certain prepositions (a, and,
the...etc). Also another Gotcha is the case where the title contains
proper names such as MacDonald where it would not be correct to
transform the name to Macdonald. The rules for title capitalization
are quite complex and unfortunatley the human brain is the best
script. But if you don't care about the rules, then this script might
be helpful.
The script below attempts to capitalize the strings, with some of the
preposition words in lowercase(you should be able to add more).
However, it does not solve the "MacDonald" dilema.
<html>
<head>
<script language=javascript>
function titleCase (titleID) {
var myStr = document.getElementById(titleID).innerHTML;
var preparray = new Array(13);
preparray[0] = "and ";
preparray[1] = "the ";
preparray[2] = "for ";
preparray[3] = "to ";
preparray[4] = "in ";
preparray[5] = "a ";
preparray[6] = "at ";
preparray[7] = "from ";
preparray[8] = "by ";
preparray[9] = "an ";
preparray[10] = "or ";
preparray[11] = "if ";
preparray[12] = "of ";
preparray[13] = "up ";
String.prototype.toTitleCase = function()
{
var str = this.toLowerCase(),
newStr = '';
for ( var i = 0, l = str.length; i < l; i++ )
{
newStr += ( i == 0 || (str.charAt( i - 1 ) == ' ' && !
IsPrep(str.substring(i))))?
str.charAt( i ).toUpperCase():
str.charAt( i );
}
return newStr;
}
function IsPrep(strP)
{
for(i=0;i<preparray.length;i++){
if(strP.indexOf(preparray[i]) == 0){
return true;
break;
}
}
return false;
}
document.getElementById(titleID).innerHTML=myStr.toTitleCase();
}
</script>
</head>
<body>
<p id="p1">I. This is the first heading</p>
<p id="p2">A. THIS IS THE SUB-HEADING</p>
<p id="p3">B. THIS IS THE SECOND SUB-HEADING</p>
<p id="p4">II. This is the second heading</p>
<input type="button"
onclick="titleCase('p1');titleCase('p2');titleCase('p3');titleCase('p4');"
value="Convert text to title format" />
</body>
</html>
On Dec 8, 8:27 am, AwayBBL <[EMAIL PROTECTED]> wrote:
> AH nevermind, not a bug... it's doing capitalization on the first
> letter of the word, but not changing the other letters. Guess it could
> be scripted to first do a lowercase, then capitalize.
>
> On Dec 8, 8:18 am, AwayBBL <[EMAIL PROTECTED]> wrote:
>
>
>
> > hmmm... I don't have an iphone, so I can't try it... could be a bug?
>
> > On Dec 7, 11:32 pm, Jake Wolpert <[EMAIL PROTECTED]> wrote:
>
> > > <style type="text/css">
> > > p.cap { text-transform: capitalize }
> > > </style>
> > > <p class="cap">THIS IS THE SECOND SUB-HEADING</p>
>
> > > shows as
>
> > > THIS IS THE SECOND SUB-HEADING
>
> > > You would need to do some dom manipulation instead of using a plain
> > > old text transform.
>
> > > On Dec 7, 2007, at 6:59 PM, awaybbl wrote:
>
> > > > not sure if this will help you or not...
>
> > > > <html>
> > > > <head>
> > > > <style type="text/css">
> > > > p.uppercase {text-transform: uppercase}
> > > > p.lowercase {text-transform: lowercase}
> > > > p.capitalize {text-transform: capitalize}
> > > > </style>
> > > > </head>
>
> > > > <body>
> > > > <p class="uppercase">This is some text in a paragraph</p>
>
> > > > <p class="lowercase">This is some text in a paragraph</p>
>
> > > > <p class="capitalize">This is some text in a paragraph</p>
> > > > </body>
>
> > > > </html>
>
> > > > On Dec 6, 6:25 pm, anmldr <[EMAIL PROTECTED]> wrote:
> > > >> I apologize for the cross post but I did not receive an answer on
> > > >> another Google group for CSS.
>
> > > >> ======
>
> > > >> I have an outline that the topic headings are in sentence case. The
> > > >> sub-headings are all uppercase. There are a LOT of pages and I do
> > > >> not
> > > >> want to go through each of them to change the case manually.
>
> > > >> I want all of it to be in Title Case. I have tried text-transform:
> > > >> capitalize; which works on the topic headings but there is no change
> > > >> in the subheadings (that are in UPPER case).
>
> > > >> When I use text-transform: capitalize the text that was in sentence
> > > >> case is transformed. The text that was all upper case remains in
> > > >> upper case.
>
> > > >> Any suggestions for how to change all of the headings and subheadings
> > > >> into Title Case?
>
> > > >> For instance: I have this:
>
> > > >> I. This is the first heading
> > > >> A. THIS IS THE SUB-HEADING
> > > >> B. THIS IS THE SECOND SUB-HEADING
> > > >> II. This is the second heading
>
> > > >> I want it all in Title Case:
>
> > > >> I. This Is The First Heading
> > > >> A. This Is The Sub-Heading
> > > >> B. This Is The Second Sub-Heading
> > > >> II. This Is The Second Heading
>
> > > >> Thank you very much for your help.
> > > >> Linda- Hide quoted text -
>
> > > - Show quoted text -- Hide quoted text -
>
> > - Show quoted text -- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"iPhoneWebDev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/iphonewebdev?hl=en
-~----------~----~----~----~------~----~------~--~---