Skip to content

Commit

Permalink
Title fields (for articles and projects) now have a helpful 'titlecas…
Browse files Browse the repository at this point in the history
…e it' button next to them to run John Resig's titlecasing script on their contents.
  • Loading branch information
lethain committed Jun 1, 2008
1 parent 2dd461b commit f6299be
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 1 deletion.
5 changes: 5 additions & 0 deletions media/lifeflow/editor/editor.css
Expand Up @@ -316,6 +316,11 @@ a.button {
margin: 0px;
}

a.titlecase {
text-decoration: none;

}

a.positive:hover {
background-color: blue;
}
Expand Down
49 changes: 49 additions & 0 deletions media/lifeflow/editor/titleCaps.js
@@ -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);
}
})();
1 change: 1 addition & 0 deletions templates/lifeflow/editor/base.html
Expand Up @@ -10,6 +10,7 @@
<link type="text/css" rel="stylesheet" href="/media/lifeflow/editor/editor.css">
<script type="text/javascript" src="/media/lifeflow/editor/jquery.js"></script>
<script type="text/javascript" src="/media/lifeflow/editor/lfe.js"></script>
<script type="text/javascript" src="/media/lifeflow/editor/titleCaps.js"></script>
<title>LifeFlow Editor: {{ lifeflow_blog_name }}</title>
</head>

Expand Down
7 changes: 6 additions & 1 deletion templates/lifeflow/editor/edit_one.html
Expand Up @@ -11,6 +11,11 @@
$("#title").hover(function(){},function(){ update(); });
$("#text").hover(function(){},function(){ update(); });
});

var capitalize_title = function () {
var txt = titleCaps($("#title").val());
$("#title").val(titleCaps($("#title").val()));
}
</script>

<div class="breadcrumbs">
Expand All @@ -27,7 +32,7 @@
<ul>
<li>
<p> Choose a title for your entry. </p>
<input id="title" value="{{ object.title }}">
<input id="title" value="{{ object.title }}"> <a class="titlecase" onclick="capitalize_title();">titlecase it</a>
</li>
<li>
<p> Write a brief summary of your entry (using html). </p>
Expand Down
7 changes: 7 additions & 0 deletions templates/lifeflow/editor/project_details.html
Expand Up @@ -13,6 +13,12 @@
$("#details").hover(function(){},function(){ update(); });
$("#summary").hover(function(){},function(){ update(); });
});


var capitalize_title = function () {
var txt = titleCaps($("#title").val());
$("#title").val(titleCaps($("#title").val()));
}
</script>

<div class="breadcrumbs">
Expand All @@ -28,6 +34,7 @@
<table>
<tr>
<td> Title </td> <td><input id="title" value="{{ object.title }}"> </td>
<td> <a class="titlecase" onclick="capitalize_title();">titlecase it</a></td>
</tr>
<tr>
<td> Slug </td> <td><input id="slug" value="{{ object.slug }}"></td>
Expand Down

0 comments on commit f6299be

Please sign in to comment.