<?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>The True Tribe &#187; Prototype</title>
	<atom:link href="http://www.thetruetribe.com/category/prototype-javascript-framework/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.thetruetribe.com</link>
	<description>Vroom! That&#039;s us leaving IE in the dust.</description>
	<lastBuildDate>Fri, 22 Jan 2010 23:34:03 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Scrolling to an element when outside of the viewport with prototypejs</title>
		<link>http://www.thetruetribe.com/2009/08/scrolling-to-an-element-when-outside-of-the-viewport-with-prototypejs/</link>
		<comments>http://www.thetruetribe.com/2009/08/scrolling-to-an-element-when-outside-of-the-viewport-with-prototypejs/#comments</comments>
		<pubDate>Fri, 28 Aug 2009 23:17:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Prototype]]></category>

		<guid isPermaLink="false">http://www.thetruetribe.com/?p=234</guid>
		<description><![CDATA[Often times you&#8217;ll have be playing, say, videos with a list of videos down the page. If the list gets too long the video player becomes out of sight as the user scrolls down. This can be a big confuser to users: they click on a link to see a video and they don&#8217;t see [...]]]></description>
			<content:encoded><![CDATA[<p>Often times you&#8217;ll have be playing, say, videos with a list of videos down the page. If the list gets too long the video player becomes out of sight as the user scrolls down. This can be a big confuser to users: they click on a link to see a video and they don&#8217;t see anything happen because the video player is out of sight. Here&#8217;s what you can do: scroll to the video player if it is out of sight like so:</p>
<pre class="js" name="code">
if ($("videoplayer").viewportOffset()[1] < 0) {
 Effect.ScrollTo('videoplayer', {duration: 0.2});
}
</pre>
<p>Requires both prototype and effects.js in scriptaculous.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.thetruetribe.com%2F2009%2F08%2Fscrolling-to-an-element-when-outside-of-the-viewport-with-prototypejs%2F&amp;linkname=Scrolling%20to%20an%20element%20when%20outside%20of%20the%20viewport%20with%20prototypejs"><img src="http://www.thetruetribe.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.thetruetribe.com/2009/08/scrolling-to-an-element-when-outside-of-the-viewport-with-prototypejs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Stylize the last element in prototype</title>
		<link>http://www.thetruetribe.com/2008/06/stylize-the-last-element-in-prototype/</link>
		<comments>http://www.thetruetribe.com/2008/06/stylize-the-last-element-in-prototype/#comments</comments>
		<pubDate>Thu, 12 Jun 2008 15:47:00 +0000</pubDate>
		<dc:creator>grandecomplex</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Prototype]]></category>

		<guid isPermaLink="false">http://wordpress.thetruetribe.com/?p=39</guid>
		<description><![CDATA[Here is an example of removing the last border in a list of elements.
Event.observe(window, "load", function() {
    $$(".homepageContainer .upcomingEvents").last().setStyle({
        border: 0
    });
});
You can compare to jQuery by going here
]]></description>
			<content:encoded><![CDATA[<p>Here is an example of removing the last border in a list of elements.</p>
<pre class="code">Event.observe(window, "load", function() {
    $$(".homepageContainer .upcomingEvents").last().setStyle({
        border: 0
    });
});<span id="more-39"></span></pre>
<p>You can compare to jQuery by going <a href="http://www.thetruetribe.com/2008/06/stylize-last-element-in-jquery.php">here</a></p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.thetruetribe.com%2F2008%2F06%2Fstylize-the-last-element-in-prototype%2F&amp;linkname=Stylize%20the%20last%20element%20in%20prototype"><img src="http://www.thetruetribe.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.thetruetribe.com/2008/06/stylize-the-last-element-in-prototype/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Truncating Text with JavaScript</title>
		<link>http://www.thetruetribe.com/2008/05/truncating-text-with-javascript/</link>
		<comments>http://www.thetruetribe.com/2008/05/truncating-text-with-javascript/#comments</comments>
		<pubDate>Tue, 06 May 2008 02:03:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Prototype]]></category>

		<guid isPermaLink="false">http://wordpress.thetruetribe.com/?p=20</guid>
		<description><![CDATA[Since Alex posted an article on truncating text with Prototype, I thought I would write an article on truncating text without the help of a JavaScript framework.
I won&#8217;t define a class like in his example, but I will try to provide the same functionality, and perhaps add some functionality as well. This code will search [...]]]></description>
			<content:encoded><![CDATA[<p>Since Alex posted an article on <a href="http://www.thetruetribe.com/2008/05/how-to-truncate-in-prototype.html">truncating text with Prototype</a>, I thought I would write an article on truncating text without the help of a JavaScript framework.<span id="more-20"></span></p>
<p>I won&#8217;t define a class like in his example, but I will try to provide the same functionality, and perhaps add some functionality as well. This code will search for all HTML elements with the class &#8216;truncate&#8217;, or with another className if one is specified, and will truncate to the nearest word less than the character-count you specify. It also defaults to appending &#8216;&#8230;&#8217; (the ellipsis) but you can override this with an empty string as the third optional parameter, if you prefer not to have anything appended.</p>
<p>Note: I wrote in the comments on Alex&#8217;s article that you may want to add ellipsis to his code. I realized after reading the <a href="http://www.prototypejs.org/api/string/truncate">Prototype API docs</a> that in fact, this is exactly what it does by default. Unless you specify an override with an optional parameter, the Prototype truncate() method will automatically add an ellipsis at the end of the string it returns.</p>
<p>Here is my implementation of the truncate() function, without the use of JavaScript libraries:</p>
<pre class="js:nocontrols">// Input parameters:
// String text, [Number length, String ellipsis]
//
// Returns:
// String text

function truncate(text, length, ellipsis) {    

    // Set length and ellipsis to defaults if not defined
    if (typeof length == 'undefined') var length = 100;
    if (typeof ellipsis == 'undefined') var ellipsis = '...';

    // Return if the text is already lower than the cutoff
    if (text.length &lt; length) return text;

    // Otherwise, check if the last character is a space.
    // If not, keep counting down from the last character
    // until we find a character that is a space
    for (var i = length-1; text.charAt(i) != ' '; i--) {
        length--;
    }

    // The for() loop ends when it finds a space, and the length var
    // has been updated so it doesn't cut in the middle of a word.
    return text.substr(0, length) + ellipsis;
}</pre>
<h3>Truncating Text by Class Name</h3>
<p>In Alex&#8217;s example, he wrote a class in Prototype that you initialize with an array of HTML elements. For this example, we&#8217;ll register an event handler to the window onload that will look for <span style="font-weight:bold;">all elements with the class &#8216;truncate&#8217;</span> and truncate them to our specifications.</p>
<pre class="js:nocontrols">window.onload = function() {
    var elements = document.getElementsByClassName('truncate');
    for (var i = 0; i &lt; elements.length; i++) {
        elements[i].innerHTML = truncate(elements[i].innerHTML, 100);
    }
}</pre>
<p>It&#8217;s basically doing the same thing as in Alex&#8217;s example, except that I&#8217;m using the window.onload event instead of the custom &#8216;domready&#8217; event (called <a href="http://www.prototypejs.org/api/document/observe">dom:loaded in Prototype</a>) which triggers much quicker. If you are using a framework, then use one of the custom &#8216;domready&#8217; events because they trigger as soon as the DOM is accessible for manipulation, whereas the traditional window.onload event waits to fire until each and every image is finished downloading. Good grief!</p>
<p>Note that this example will only work in Firefox 3 or Safari 3, as other browsers do not natively support document.getElementsByClassName. You could just implement your own getElementsByClassName function like so:</p>
<pre class="js">function getElementsByClassName(className) {
    // RegExp from http://www.robertnyman.com
    //             /2005/11/07/the-ultimate-getelementsbyclassname/

    var match = new RegExp('(^|\\\\s)' + className + '(\\\\s|$)');

    // All elements which match are added to the array
    var matchingTags = new Array();

    var allTags = document.getElementsByTagName('*');
    for (var i = 0; i &lt; allTags.length; i++) {
        if (match.test(allTags[i].className)) {
            matchingTags.push(allTags[i]);
        }
    }
    return matchingTags;
}

window.onload = function() {
    var elements = getElementsByClassName('truncate');
    for (var i = 0; i &lt; elements.length; i++) {
        elements[i].innerHTML = truncate(elements[i].innerHTML, 100);
    }
}</pre>
<p>Make sure that you only give the &#8216;truncate&#8217; class to elements whose <span style="font-weight:bold;">only child is a text node</span>. If the element has other HTML children then this won&#8217;t work correctly. It&#8217;s possible to code around this but for the sake of this example, let&#8217;s just keep it simple. Here are two examples that show proper and improper use:</p>
<p><span style="font-weight:bold;">This is OK:</span></p>
<pre class="html:nocontrols">&lt;span class="truncate"&gt;some text &lt;/span&gt;</pre>
<p><span style="font-weight:bold;">This is not OK</span>:</p>
<pre class="html:nocontrols">&lt;span class="truncate"&gt;&lt;span&gt;some text &lt;/span&gt;&lt;/span&gt;</pre>
<p>As always, feel free to post in the comments with any questions or alternative suggestions for the code. This is a fairly simplistic implementation and truth be told, if you&#8217;re using a JavaScript library (which it seems most people are these days) then this may not be too relevant for you. But, hopefully it has been informative to explore this library-free, albeit simple, implementation.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.thetruetribe.com%2F2008%2F05%2Ftruncating-text-with-javascript%2F&amp;linkname=Truncating%20Text%20with%20JavaScript"><img src="http://www.thetruetribe.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.thetruetribe.com/2008/05/truncating-text-with-javascript/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to Truncate in Prototype</title>
		<link>http://www.thetruetribe.com/2008/05/how-to-truncate-in-prototype/</link>
		<comments>http://www.thetruetribe.com/2008/05/how-to-truncate-in-prototype/#comments</comments>
		<pubDate>Mon, 05 May 2008 16:16:00 +0000</pubDate>
		<dc:creator>grandecomplex</dc:creator>
				<category><![CDATA[Prototype]]></category>

		<guid isPermaLink="false">http://wordpress.thetruetribe.com/?p=19</guid>
		<description><![CDATA[This is to truncate multiple items in the javascript library Prototype. If it has the class=&#8221;truncate&#8221; it will be truncated!
Simple way:
var toTruncate = $$(".truncate");
var len = 190;
for(i=0;i
Class Based:
var TruncateIt = Class.create({

      initialize: function(sTruncate) {

            var toTruncate = (typeof sTruncate [...]]]></description>
			<content:encoded><![CDATA[<p>This is to truncate multiple items in the javascript library Prototype. If it has the class=&#8221;truncate&#8221; it will be truncated!<span id="more-19"></span></p>
<p>Simple way:</p>
<pre class="js">var toTruncate = $$(".truncate");
var len = 190;
for(i=0;i</pre>
<p>Class Based:</p>
<pre class="js">var TruncateIt = Class.create({

      initialize: function(sTruncate) {

            var toTruncate = (typeof sTruncate != 'undefined') ? $$(sTruncate) : $$('.truncate');

            var len = 100;

            for (var i = 0; i &lt; toTruncate.length; i++) {

                 toTruncate[i].innerHTML=toTruncate[i].innerHTML.truncate(len);

            }

      }

});

document.observe('dom:loaded', function(){ 

  var truncate = new TruncateIt('.truncate');

});</pre>
<p>Thanks to Kris for helping me write this in a class as I&#8217;m totally new to prototype. See his hip new site at <a href="http://komputerart.com/">komputerart.com</a>.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.thetruetribe.com%2F2008%2F05%2Fhow-to-truncate-in-prototype%2F&amp;linkname=How%20to%20Truncate%20in%20Prototype"><img src="http://www.thetruetribe.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.thetruetribe.com/2008/05/how-to-truncate-in-prototype/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
