if (window.$) { $.fn.int = function() { return parseInt($(this).val(),10) } $.fn.float = function() { return parseFloat($(this).val()) } $.fn.string = function() { return trim($(this).val()) } $.fn.enable = function() { return $(this).attr("disabled",null) } $.fn.disable = function() { return $(this).attr("disabled","disabled") } $.fn.sanitize = function(s) { return trim(sanitize($(this).val())) } $.fn.stripHTML = function(s) { return trim(stripHTML($(this).val())) } $.fn.sanitizeName = function(s) { return trim(sanitizeName($(this).val())) } $.fn.htmlSafe = function(s) { return $(this).html(sanitize(s)) } $.fn.toDollars = function(i) { return $(this).html((i/100).toFixed(2)) } } function trim (s){ return s.replace(/^\s+/,"").replace(/\s+$/,"") } function sanitize (s){ return (s || "").replace(new RegExp("[<>&]", 'g'), "") } function sanitizeName (s){ return (s || "").replace(new RegExp("[^-_a-zA-Z0-9]", 'g'), "") } function stripHTML (s){ return (s || "").replace(/<[^>]+>/g, "") } function sanitizeHTML (s){ return (s || "").replace(/&/g, "&").replace(//g, ">") } function capitalize (s){ return s.split(" ").map(capitalizeWord).join(" ") } function capitalizeWord (s){ return s.charAt(0).toUpperCase() + s.slice(1) } function slugify (s){ return (s || "").toLowerCase().replace(/\s/g,"-").replace(/[^-_a-zA-Z0-9]/g, '-').replace(/-+/g,"-") } function rgb_string (rgb) { return "rgb(" + rgb.map(Math.round).join(",") + ")" } function rgba_string (rgb,a) { return "rgba(" + rgb.map(Math.round).join(",") + "," + a + ")" } function hex_string (rgb) { return "#" + rgb.map(Math.round).map(function(n){ var s = n.toString(16); return s.length == 1 ? "0"+s : s }).join("") } function parse_rgba_string (s) { return s.match(/(\d+)/g).slice(0,3) } function title_case (str) { return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();}); } function pluralize (n,s,ss) { return n + " " + s + ( n == 1 ? "" : (ss || "s") ) } function as_cash(n){ var cents = ((n*100) % 100); if (cents < 10) { cents = "0" + (cents|0) } else { cents = cents|0 } return "$" + (n|0) + "." + cents } var E = Math.E var PI = Math.PI var PHI = (1+Math.sqrt(5))/2 var TWO_PI = PI*2 var HALF_PI = PI/2 var LN10 = Math.LN10 function clamp(n,a,b){ return n