<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Leancode &#187; javascript</title>
	<atom:link href="http://leancode.com/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://leancode.com</link>
	<description>bernie's small batches of software goodness</description>
	<lastBuildDate>Mon, 21 Apr 2008 05:14:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Breaking up long words in HTML with Javascript/CSS</title>
		<link>http://leancode.com/2007/07/19/breaking-up-long-words-in-html-with-javascriptcss/</link>
		<comments>http://leancode.com/2007/07/19/breaking-up-long-words-in-html-with-javascriptcss/#comments</comments>
		<pubDate>Fri, 20 Jul 2007 03:26:37 +0000</pubDate>
		<dc:creator>Bernie Thompson</dc:creator>
				<category><![CDATA[Days Since]]></category>
		<category><![CDATA[Days Until]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://leancode.com/2007/07/19/breaking-up-long-words-in-html-with-javascriptcss/</guid>
		<description><![CDATA[[update 10/17: The substitution has been updated to cover more browsers. This should work on every major modern browser, EXCEPT Safari -- I can find no solution for that browser. If you find a solution for Safari, or a browser this doesn't work on, please comment. Thanks!] Long words can create a significant layout problem, [...]]]></description>
			<content:encoded><![CDATA[<p>[update 10/17: The substitution has been updated to cover more browsers.  This should work on every major modern browser, EXCEPT Safari -- I can find no solution for that browser. If you find a solution for Safari, or a browser this doesn't work on, please comment. Thanks!]</p>
<p>Long words can create a significant layout problem, especially for widgets which have to live in a small amount of screen space.</p>
<p><a href="http://leancode.com/dayssince/">DaysSince</a> and <a href="http://leancode.com/daysuntil/">DaysUntil</a> were both having a problem where very long words in the reminder description could push the &#8220;delete item&#8221; icon and other content off the right of the widget, make the text unreadable &#8212; and unreachable, so you can no longer delete the offending item.</p>
<p>What would be nice is to break up long words, but what&#8217;s the easiest way to do that, given that you don&#8217;t have a knowable fixed width to display in?</p>
<p>For a Javascript widget, this combination of regular expression and CSS hacks might get you what you need.</p>
<p>First, break up your strings with non-breaking spaces (nbsp), wrapped in a span that lets us make them invisible. If x holds the string with potentially long words, this regex will return this result (splitting every 9 characters).</p>
<pre><code>x.replace(/(&amp;#92;S{8,}?)/g, "$1&amp;lt;wbr/&amp;gt;&amp;lt;span class='break'&amp;gt; &amp;lt;/span&amp;gt;")</code></pre>
<p>In the regex,</p>
<ul>
<li>? is to make the match not greedy &#8212; that is, it will stop after just 8+1 characters.</li>
<li>/g is to match all 8+1 character or longer sets of non-whitespace characters</li>
<li>$1 returns the matched characters, to which we add a non-breaking space within a span that we&#8217;ll format below</li>
</ul>
<p>Next, add a new selector to your CSS for the spans you just inserted, to make them invisible (credit to <a href="http://learningtheworld.eu/">Martin Kliehm</a> for this hack).</p>
<pre><code>.break {
font-size: 1px;
line-height: 1px;
float:right !important;
float: none;
}</code></pre>
<p>All the styles are essential &#8212; the two apparently conflicting float styles are to <a href="http://modxcms.com/css-hacking-important.html">set different values for IE6 vs. other browsers</a>. </p>
<p>Days Since and Days Until have been updated with this fix (it may take some time for Google&#8217;s caches to update &#8212; so use a new copy <a href="http://fusion.google.com/add?moduleurl=http%3A//dayssince.googlecode.com/svn/trunk/dayssince.xml"><img src="http://buttons.googlesyndication.com/fusion/add.gif" width="104" height="17" border="0" alt="Add to Google"></a> to test.  </p>
<p>Any refinements we can make to this solution?  Anyone see any problems with specific browser versions?</p>
]]></content:encoded>
			<wfw:commentRss>http://leancode.com/2007/07/19/breaking-up-long-words-in-html-with-javascriptcss/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.351 seconds -->
