Permalink
Browse files

extract method

remove conditional
  • Loading branch information...
1 parent 6783d8f commit 2d915cb38e257a6212770ae9affe69dfb25afd5b @stuarthalloway committed May 22, 2009
Showing with 7 additions and 9 deletions.
  1. +7 −9 public/javascripts/jquery.numberformatter-1.1.2.js
@@ -205,7 +205,11 @@
return array;
};
-
+
+ jQuery.fn.valOrText = function() {
+ return (jQuery(this).is(":input") ? jQuery.fn.val : jQuery.fn.text).apply(this,arguments);
+ };
+
jQuery.fn.format = function(options) {
var options = jQuery.extend({},jQuery.fn.format.defaults, options);
@@ -219,9 +223,7 @@
return this.each(function(){
- var text = new String(jQuery(this).text());
- if (jQuery(this).is(":input"))
- text = new String(jQuery(this).val());
+ var text = new String(jQuery(this).valOrText());
// now we need to convert it into a number
while (text.indexOf(group)>-1)
@@ -327,11 +329,7 @@
}
returnString = options.prefix + returnString + options.suffix;
- if (jQuery(this).is(":input"))
- jQuery(this).val(returnString);
- else
- jQuery(this).text(returnString);
-
+ jQuery(this).valOrText(returnString);
});
};

0 comments on commit 2d915cb

Please sign in to comment.