<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Word Count</title><link>http://www.virtuosimedia.com/dev/javascript/mootools-plugins/word-count//feed/rss</link><description>Word Count is a JavaScript word and character counter based on MooTools 1.3. It can count static text or text being entered into a form element, as it's being typed. It's simple to use and has been tested in IE6+, Firefox, Chrome, Opera, and Safari.</description><pubDate>Thu, 17 May 2012 00:53:12 +0000</pubDate><lastBuildDate>Thu, 17 May 2012 00:53:12 +0000</lastBuildDate><copyright>asf</copyright><image><url>http://www.virtuosimedia.com/includes/Files/Uploaded/Images/Feeds/avatar80.png</url><title>Word Count</title><link /><width>144</width><height>100</height></image><item><title>Word Count Tutorial</title><description><![CDATA[<p>Word Count is a JavaScript word and character counter based on MooTools 1.3. It can count static text or text being entered into a form element, as it&#39;s being typed. It&#39;s simple to use and has been tested in IE6+, Firefox, Chrome, Opera, and Safari.</p>

<ul class="actionCall">
	<li><a class="secondary" href="http://www.virtuosimedia.com/dev/javascript/mootools-plugins/word-count/">About</a></li>
	<li><a class="secondary" href="http://www.virtuosimedia.com/dev/javascript/mootools-plugins/word-count/api-documentation">Docs</a></li>
	<li><a class="secondary" href="http://www.virtuosimedia.com/dev/javascript/mootools-plugins/word-count/demos">Demos</a></li>
	<li><a class="primary" href="https://github.com/VirtuosiMedia/Word-Count/zipball/master" rel="nofollow">Download</a></li>
</ul>
<p>Let&#39;s build a small form and count the text as it is being typed. Word Count requires the MooTools library, so we&#39;ll need to download the entire <a href="http://mootools.net/core" rel="nofollow">MooTools 1.2 Core file</a>. Go download it quickly if you don&#39;t already have it. Don&#39;t forget to download a copy of Word Count as well.</p>
<p>If you&#39;re new to JavaScript (or MooTools), you&#39;ll find the implementation of Word Count fairly easy. Word Count requires no changes to your form whatsoever; it works with what you already have. We&#39;ll start with constructing our HTML form. Since we don&#39;t need a complicated form for this tutorial, we&#39;re just going to include a textarea and a target for the word count to be displayed.</p>
<pre class="html">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot; /&gt;
&lt;title&gt;Word Count Tutorial&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
	&lt;form id=&quot;wordCount&quot; method=&quot;post&quot; action=&quot;&quot;&gt;
		&lt;textarea name=&quot;countMe&quot; type=&quot;text&quot; /&gt;
		&lt;div id=&quot;target&quot;&gt;Tell me more about yourself...&lt;/div&gt;
	&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>That was pretty easy, right? Let&#39;s go ahead and add just a little CSS styling to make our form look a little more appetizing. Just for fun, let&#39;s use a little CSS3 styling. For this tutorial, we&#39;re just going to put it in the head of our XHTML document, but in practice we recommend putting in your stylesheet in a separate file.</p>
<pre class="css">&lt;style type=&quot;text/css&quot;&gt;
	body {margin:0px; padding:0px; background:#333;}
	textarea {width:300px; height:60px; outline:none; margin-left:10px; border:1px solid; border-color:#000 #999 #999 #000; border-radius:10px; -moz-border-radius:10px; -webkit-border-radius:10px; padding:5px;}
	#target {width:300px; height:30px; display:block; border:1px solid; border-color:#FFF #000 #000 #FFF; line-height:30px; margin:10px 10px; border-radius:10px; -moz-border-radius:10px; -webkit-border-radius:10px; padding:5px; color:#555; text-shadow:#FFF 1px 1px 1px; text-indent:5px; background: #e2e2e2; background: -moz-linear-gradient(top, #e2e2e2 0%, #dbdbdb 50%, #d1d1d1 51%, #fefefe 100%); background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#e2e2e2), color-stop(50%,#dbdbdb), color-stop(51%,#d1d1d1), color-stop(100%,#fefefe));}
&lt;/style&gt;
</pre>
<p>Next we need to add our JavaScript files, MooTools1.3-core.js and word-count.js. We&#39;ll put those in the document head as well.</p>
<pre class="html">&lt;script type=&quot;text/javascript&quot; src=&quot;mootools-1.3-core.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;word-count.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
</pre>
<p>Now we need to add a little bit of MooTools specific JavaScript. MooTools has a special event called &#39;domready&#39; that executes whenever the HTML has finished loading. Most MooTools scripts are at least partially executed from within the &#39;domready&#39; event. Again, we&#39;re just going to put this code in the document head, but it could also be in its own file.</p>
<pre>
&lt;script type=&quot;text/javascript&quot;&gt;
	window.addEvent('domready', function(){
		//Our Word Count code will go here
	});
&lt;/script&gt;
</pre><p>All of our code is going to be inserted into the &#39;domready&#39; event, right where the comment currently is. The first thing we&#39;ll need to do is initialize the Word Count class. In this case, we&#39;ll use the variable <em>password</em>, but you can use <em>pass</em>, or <em>bob</em>, or whatever you like. We&#39;ll set<em>password</em>equal to a new instance of PassMeter. Because the constructor for the PassMeter class has one required argument, the name of the password form element, we&#39;re going to enter in the name &#39;password&#39;, surrounded in quotes to make it a string.</p>
<pre>
&lt;script type=&quot;text/javascript&quot;&gt;
	window.addEvent('domready', function(){
		var counter = new WordCount('target', {inputName:'countMe'});
	});
&lt;/script&gt;
</pre><p>The constructor for Word Count also has an optional argument for options. Beyond what you can do with CSS, Word Count has 8 different configurable options, but don&#39;t let that intimidate you. It&#39;s designed to work well out of the box, so that you just have to provide the CSS styling for it. If you want to change an option, you only have to change that option and you can leave the rest of them alone. Let&#39;s pretend we need to change our text count to Spanish and that we only want to get a word count. To do that, we&#39;ll have to use the option variables of <em>wordText</em> and <em>countChars</em> and assign our new values to them. The options are inserted after the target id argument. Because the options accept more than one option, we need to enclose it in an object. That simply means we&#39;ll put curly braces {} around our entire set of options. Each option has two parts: the option name and its value, which are separated by a colon. If you have more than one option, each option should be separated by a comma, except the last one. Sound complicated? It&#39;s actually easier than it sounds.</p>
<pre>
&lt;script type=&quot;text/javascript&quot;&gt;
	window.addEvent('domready', function(){
		var counter = new WordCount('target', {
			inputName:'countMe',
			wordText: 'palabras',
			countChars: false
		});
	});
&lt;/script&gt;</pre><p>That&#39;s all there is to it! Reload your page and you&#39;ll see that you&#39;ll only get a word count and it will be in Spanish.</p>
<p>This concludes our quick tutorial. If you encounter a bug, have a question or comment, feel free to contact us. We&#39;d also love to know if you&#39;re using it on your site. If you liked Word Count, tell someone else about it. Thanks, and enjoy!</p>
]]></description><link>http://www.virtuosimedia.com/dev/javascript/mootools-plugins/word-count/tutorial</link><category>Word Count</category><pubDate>Wed, 23 Mar 2011 21:24:00 +0000</pubDate></item><item><title>Word Count API Documentation</title><description><![CDATA[<p>Word Count is a JavaScript word and character counter based on MooTools 1.3. It can count static text or text being entered into a form element, as it&#39;s being typed. It&#39;s simple to use and has been tested in IE6+, Firefox, Chrome, Opera, and Safari.</p>

<ul class="actionCall">
	<li><a class="secondary" href="http://www.virtuosimedia.com/dev/javascript/mootools-plugins/word-count/">About</a></li>
	<li><a class="secondary" href="http://www.virtuosimedia.com/dev/javascript/mootools-plugins/word-count/tutorial">Tutorial</a></li>
	<li><a class="secondary" href="http://www.virtuosimedia.com/dev/javascript/mootools-plugins/word-count/demos">Demos</a></li>
	<li><a class="primary" href="https://github.com/VirtuosiMedia/Word-Count/zipball/master" rel="nofollow">Download</a></li>
</ul>
<h2>Documentation</h2>
<h2>Class: WordCount</h2>
<p>This class is for getting word and character counts from text or form inputs.</p>
<h3>Implements:</h3>
<ul>
	<li><a href="http://docs.mootools.net/Class/Class.Extras#Events" rel="nofollow">Events</a>, <a href="http://docs.mootools.net/Class/Class.Extras#Options" rel="nofollow">Options</a></li>
</ul>
<h2>WordCount Method: constructor</h2>
<p>Word Count is completely unobtrusive and requires no changes to existing markup.</p>
<h3>Syntax:</h3>
<pre class="js">var counter = new WordCount(target[, options]);
</pre>
<h3>Arguments:</h3>
<ol>
	<li>target - (<em>string</em>) The id of the element to contain the word and character count. Any text in the target element will be replaced.</li>
	<li>options - (<em>object</em>, optional) Any of the options below.</li>
</ol>
<h4>Options:</h4>
<ul>
	<li>inputName - (<em>string</em>, defaults to null) The name of the form element from which text should be retrieved.</li>
	<li>countWords - (<em>boolean</em>, defaults to true) Whether or not to count words.</li>
	<li>countChars - (<em>boolean</em>, defaults to true) Whether or not to count characters.</li>
	<li>charText - (<em>string</em>, defaults to &#39;characters&#39;) The text that follows the number of characters.</li>
	<li>wordText - (<em>string</em>, defaults to &#39;words&#39;) The text that follows the number of words.</li>
	<li>separator - (<em>string</em>, defaults to &#39;, &#39;) Whether or not to use the event trigger, set false if you&#39;d like to call the getCount function separately.</li>
	<li>liveCount - (<em>boolean</em>, defaults to true) Whether or not to count characters.</li>
	<li>eventTrigger - (<em>string</em>, defaults to &#39;keyup&#39;) The event that triggers the count update.</li>
</ul>
<h3>Example:</h3>
<pre class="js">window.addEvent(&#39;domready&#39;, function(){
	var counter = new WordCount(&#39;target&#39;, {
		inputName:&#39;countMe&#39;,
		wordText: &#39;palabras&#39;,
		countChars: false
	});
});
</pre>
<h2>WordCount Method: getCount</h2>
<p>Gets text count and updates the target element.</p>
<h3>Syntax:</h3>
<pre class="js">counter.getCount(text);
</pre>
<h3>Arguments:</h3>
<ol>
	<li>text - (<em>string</em>) The text from which a count should be retrieved.</li>
</ol>
<h3>Example:</h3>
<pre class="js">window.addEvent(&#39;domready&#39;, function(){
	var counter = new WordCount(&#39;target&#39;);
	$(&#39;target&#39;).addEvent(&#39;click&#39;, function(){
		counter.getCount($(&#39;text&#39;).get(&#39;text&#39;)); //Assumes an element with the id of &#39;text&#39; that contains the countable text
	});
});
</pre>]]></description><link>http://www.virtuosimedia.com/dev/javascript/mootools-plugins/word-count/api-documentation</link><category>Word Count</category><pubDate>Wed, 23 Mar 2011 21:29:00 +0000</pubDate></item><item><title>Word Count Demos</title><description><![CDATA[<p>Word Count is a JavaScript word and character counter based on MooTools 1.3. It can count static text or text being entered into a form element, as it&#39;s being typed. It&#39;s simple to use and has been tested in IE6+, Firefox, Chrome, Opera, and Safari.</p>

<ul class="actionCall">
	<li><a class="secondary" href="http://www.virtuosimedia.com/dev/javascript/mootools-plugins/word-count/">About</a></li>
	<li><a class="secondary" href="http://www.virtuosimedia.com/dev/javascript/mootools-plugins/word-count/tutorial">Tutorial</a></li>
	<li><a class="secondary" href="http://www.virtuosimedia.com/dev/javascript/mootools-plugins/word-count/demos">Demos</a></li>
	<li><a class="primary" href="https://github.com/VirtuosiMedia/Word-Count/zipball/master" rel="nofollow">Download</a></li>
</ul>
<h2>Demos</h2>
<h3>Static Text Demo</h3>
<p>This demo shows how Word Count can be used to count static text on a click event. <b>Note: You must press the &#39;Run&#39; button to start the demo.</b></p>
<p><iframe src="http://jsfiddle.net/gh/get/mootools/1.3/VirtuosiMedia/Word-Count/tree/master/Demos/Static/" style="width:954px; height:600px"></iframe></p>
<h3>Text Input Demo</h3>
<p>This demo shows how Word Count can be used with a text input to count live typing. <b>Note: You must press the &#39;Run&#39; button to start the demo.</b></p>
<p><iframe src="http://jsfiddle.net/gh/get/mootools/1.3/VirtuosiMedia/Word-Count/tree/master/Demos/Text/" style="width:954px; height:600px"></iframe></p>
<h3>Textarea Demo</h3>
<p>This demo shows how Word Count can be used with a textarea to count live typing. <b>Note: You must press the &#39;Run&#39; button to start the demo.</b></p>
<p><iframe src="http://jsfiddle.net/gh/get/mootools/1.3/VirtuosiMedia/Word-Count/tree/master/Demos/Textarea/" style="width:954px; height:600px"></iframe></p>
Hi Mom!]]></description><link>http://www.virtuosimedia.com/dev/javascript/mootools-plugins/word-count/demos</link><category>Word Count</category><pubDate>Wed, 23 Mar 2011 21:36:00 +0000</pubDate></item></channel></rss>
