Permalink
Browse files

now counting correctly, will factor out selector next

  • Loading branch information...
1 parent 2fb7d99 commit 58c4d17b119df46ac470adddb6678e9115610161 Patrick Hall committed Jul 26, 2010
Showing with 13 additions and 21 deletions.
  1. +10 −20 js/jquery.numwords.js
  2. +3 −1 livecount.html
View
@@ -4,34 +4,24 @@
$.fn.numwords = function(){
-/*
- var defaults = {
- //target: $(this).before($('<span id="numwords"/>'))
- target: $('h1')
- };
-
- var options = $.extend(defaults, options);
-
-*/
-
return this.each(function(){
- $this = $(this);
- var count = $.fn.numwords.tokenize($this.val());
- $this.bind('keyup, change', function(){
+ var count = $.fn.numwords.countwords($(this).val())
+
+ $(this).bind('keyup change', function(){
$('h1').html(count);
- })
- })
+ });
+ });
};
$.fn.numwords.tokenize = function(text){
var text = $.trim(text);
- return text.split(/\s+/)
- }
+ return text.split(/\s+/);
+ };
- $.fn.numwords = function countWords(text) {
- return $.fn.numwords.tokenize(text).length
- }
+ $.fn.numwords.countwords = function(text) {
+ return $.fn.numwords.tokenize(text).length ;
+ };
})(jQuery)
View
@@ -28,8 +28,10 @@
<script text="text/javascript">
$(function(){
+
$('textarea').numwords();
-}})
+
+})
/*
function tokenize(text) { return text.split(/\s+/) }

0 comments on commit 58c4d17

Please sign in to comment.