From f6299be67bcbe24e0d7a7a5d3fd4ba9b5777c547 Mon Sep 17 00:00:00 2001 From: Will Larson Date: Sun, 1 Jun 2008 21:20:36 +0900 Subject: [PATCH] Title fields (for articles and projects) now have a helpful 'titlecase it' button next to them to run John Resig's titlecasing script on their contents. --- media/lifeflow/editor/editor.css | 5 ++ media/lifeflow/editor/titleCaps.js | 49 +++++++++++++++++++ templates/lifeflow/editor/base.html | 1 + templates/lifeflow/editor/edit_one.html | 7 ++- .../lifeflow/editor/project_details.html | 7 +++ 5 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 media/lifeflow/editor/titleCaps.js diff --git a/media/lifeflow/editor/editor.css b/media/lifeflow/editor/editor.css index e70c754..c536a0a 100644 --- a/media/lifeflow/editor/editor.css +++ b/media/lifeflow/editor/editor.css @@ -316,6 +316,11 @@ a.button { margin: 0px; } +a.titlecase { + text-decoration: none; + +} + a.positive:hover { background-color: blue; } diff --git a/media/lifeflow/editor/titleCaps.js b/media/lifeflow/editor/titleCaps.js new file mode 100644 index 0000000..d33d950 --- /dev/null +++ b/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); + } +})(); \ No newline at end of file diff --git a/templates/lifeflow/editor/base.html b/templates/lifeflow/editor/base.html index 41a0f0d..a0be9aa 100644 --- a/templates/lifeflow/editor/base.html +++ b/templates/lifeflow/editor/base.html @@ -10,6 +10,7 @@ + LifeFlow Editor: {{ lifeflow_blog_name }} diff --git a/templates/lifeflow/editor/edit_one.html b/templates/lifeflow/editor/edit_one.html index 3f07468..9777124 100644 --- a/templates/lifeflow/editor/edit_one.html +++ b/templates/lifeflow/editor/edit_one.html @@ -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())); +}