summaryrefslogtreecommitdiff
path: root/framework/Web/Javascripts/extended
diff options
context:
space:
mode:
authorxue <>2007-03-27 00:47:38 +0000
committerxue <>2007-03-27 00:47:38 +0000
commitc5d0cd2824e3c3bb2f6f3834177a71c1d7b78519 (patch)
tree3f8b2ced94b30277c62b4d8d31f09e7eda09f1ea /framework/Web/Javascripts/extended
parentfb29e39241b47fee99a17fab73447b9e23eabd83 (diff)
merge from 3.0 branch till 1779.
Diffstat (limited to 'framework/Web/Javascripts/extended')
-rw-r--r--framework/Web/Javascripts/extended/base.js332
-rw-r--r--framework/Web/Javascripts/extended/builder.js24
-rw-r--r--framework/Web/Javascripts/extended/date.js151
-rw-r--r--framework/Web/Javascripts/extended/effects.js7
-rw-r--r--framework/Web/Javascripts/extended/event.js110
-rw-r--r--framework/Web/Javascripts/extended/string.js172
6 files changed, 0 insertions, 796 deletions
diff --git a/framework/Web/Javascripts/extended/base.js b/framework/Web/Javascripts/extended/base.js
deleted file mode 100644
index e76a46c0..00000000
--- a/framework/Web/Javascripts/extended/base.js
+++ /dev/null
@@ -1,332 +0,0 @@
-
-/**
- * Similar to bindAsEventLister, but takes additional arguments.
- */
-Function.prototype.bindEvent = function()
-{
- var __method = this, args = $A(arguments), object = args.shift();
- return function(event)
- {
- return __method.apply(object, [event || window.event].concat(args));
- }
-}
-
-/**
- * Creates a new function by copying function definition from
- * the <tt>base</tt> and optional <tt>definition</tt>.
- * @param function a base function to copy from.
- * @param array additional definition
- * @param function return a new function with definition from both
- * <tt>base</tt> and <tt>definition</tt>.
- */
-Class.extend = function(base, definition)
-{
- var component = Class.create();
- Object.extend(component.prototype, base.prototype);
- if(definition)
- Object.extend(component.prototype, definition);
- return component;
-}
-
-/*
- Base, version 1.0.2
- Copyright 2006, Dean Edwards
- License: http://creativecommons.org/licenses/LGPL/2.1/
-*/
-
-var Base = function() {
- if (arguments.length) {
- if (this == window) { // cast an object to this class
- Base.prototype.extend.call(arguments[0], arguments.callee.prototype);
- } else {
- this.extend(arguments[0]);
- }
- }
-};
-
-Base.version = "1.0.2";
-
-Base.prototype = {
- extend: function(source, value) {
- var extend = Base.prototype.extend;
- if (arguments.length == 2) {
- var ancestor = this[source];
- // overriding?
- if ((ancestor instanceof Function) && (value instanceof Function) &&
- ancestor.valueOf() != value.valueOf() && /\bbase\b/.test(value)) {
- var method = value;
- // var _prototype = this.constructor.prototype;
- // var fromPrototype = !Base._prototyping && _prototype[source] == ancestor;
- value = function() {
- var previous = this.base;
- // this.base = fromPrototype ? _prototype[source] : ancestor;
- this.base = ancestor;
- var returnValue = method.apply(this, arguments);
- this.base = previous;
- return returnValue;
- };
- // point to the underlying method
- value.valueOf = function() {
- return method;
- };
- value.toString = function() {
- return String(method);
- };
- }
- return this[source] = value;
- } else if (source) {
- var _prototype = {toSource: null};
- // do the "toString" and other methods manually
- var _protected = ["toString", "valueOf"];
- // if we are prototyping then include the constructor
- if (Base._prototyping) _protected[2] = "constructor";
- for (var i = 0; (name = _protected[i]); i++) {
- if (source[name] != _prototype[name]) {
- extend.call(this, name, source[name]);
- }
- }
- // copy each of the source object's properties to this object
- for (var name in source) {
- if (!_prototype[name]) {
- extend.call(this, name, source[name]);
- }
- }
- }
- return this;
- },
-
- base: function() {
- // call this method from any other method to invoke that method's ancestor
- }
-};
-
-Base.extend = function(_instance, _static) {
- var extend = Base.prototype.extend;
- if (!_instance) _instance = {};
- // build the prototype
- Base._prototyping = true;
- var _prototype = new this;
- extend.call(_prototype, _instance);
- var constructor = _prototype.constructor;
- _prototype.constructor = this;
- delete Base._prototyping;
- // create the wrapper for the constructor function
- var klass = function() {
- if (!Base._prototyping) constructor.apply(this, arguments);
- this.constructor = klass;
- };
- klass.prototype = _prototype;
- // build the class interface
- klass.extend = this.extend;
- klass.implement = this.implement;
- klass.toString = function() {
- return String(constructor);
- };
- extend.call(klass, _static);
- // single instance
- var object = constructor ? klass : _prototype;
- // class initialisation
- if (object.init instanceof Function) object.init();
- return object;
-};
-
-Base.implement = function(_interface) {
- if (_interface instanceof Function) _interface = _interface.prototype;
- this.prototype.extend(_interface);
-};
-
-/*
- * Signals and Slots for Prototype: Easy custom javascript events
- * http://tetlaw.id.au/view/blog/signals-and-slots-for-prototype-easy-custom-javascript-events
- * Andrew Tetlaw
- * Version 1.2 (2006-06-19)
- *
- * http://creativecommons.org/licenses/by-sa/2.5/
- *
-Signal = {
- throwErrors : true,
- MT : function(){ return true },
- connect : function(obj1, func1, obj2, func2, options) {
- var options = Object.extend({
- connectOnce : false,
- before : false,
- mutate : function() {return arguments;}
- }, options || {});
- if(typeof func1 != 'string' || typeof func2 != 'string') return;
-
- var sigObj = obj1 || window;
- var slotObj = obj2 || window;
- var signame = func1+'__signal_';
- var slotsname = func1+'__slots_';
- if(!sigObj[signame]) {
- // having the slotFunc in a var and setting it by using an anonymous function in this way
- // is apparently a good way to prevent memory leaks in IE if the objects are DOM nodes.
- var slotFunc = function() {
- var args = [];
- for(var x = 0; x < arguments.length; x++){
- args.push(arguments[x]);
- }
- args = options.mutate.apply(null,args)
- var result;
- if(!options.before) result = sigObj[signame].apply(sigObj,arguments); //default: call sign before slot
- sigObj[slotsname].each(function(slot){
- try {
- if(slot && slot[0]) { // testing for null, a disconnect may have nulled this slot
- slot[0][slot[1]].apply(slot[0],args); //[0] = obj, [1] = func name
- }
- } catch(e) {
- if(Signal.throwErrors) throw e;
- }
- });
- if(options.before) result = sigObj[signame].apply(sigObj,arguments); //call slot before sig
- return result; //return sig result
- };
- (function() {
- sigObj[slotsname] = $A([]);
- sigObj[signame] = sigObj[func1] || Signal.MT;
- sigObj[func1] = slotFunc;
- })();
- }
- var con = (sigObj[slotsname].length > 0) ?
- (options.connectOnce ? !sigObj[slotsname].any(function(slot) { return (slot[0] == slotObj && slot[1] == func2) }) : true) :
- true;
- if(con) {
- sigObj[slotsname].push([slotObj,func2]);
- }
- },
- connectOnce : function(obj1, func1, obj2, func2, options) {
- Signal.connect(obj1, func1, obj2, func2, Object.extend(options || {}, {connectOnce : true}))
- },
- disconnect : function(obj1, func1, obj2, func2, options) {
- var options = Object.extend({
- disconnectAll : false
- }, options || {});
- if(typeof func1 != 'string' || typeof func2 != 'string') return;
-
- var sigObj = obj1 || window;
- var slotObj = obj2 || window;
- var signame = func1+'__signal_';
- var slotsname = func1+'__slots_';
-
- // I null them in this way so that any currectly active signal will read a null slot,
- // otherwise the slot will be applied even though it's been disconnected
- if(sigObj[slotsname]) {
- if(options.disconnectAll) {
- sigObj[slotsname] = sigObj[slotsname].collect(function(slot) {
- if(slot[0] == slotObj && slot[1] == func2) {
- slot[0] = null;
- return null;
- } else {
- return slot;
- }
- }).compact();
- } else {
- var idx = -1;
- sigObj[slotsname] = sigObj[slotsname].collect(function(slot, index) {
- if(slot[0] == slotObj && slot[1] == func2 && idx < 0) { //disconnect first match
- idx = index;
- slot[0] = null;
- return null;
- } else {
- return slot;
- }
- }).compact();
- }
- }
- },
- disconnectAll : function(obj1, func1, obj2, func2, options) {
- Signal.disconnect(obj1, func1, obj2, func2, Object.extend(options || {}, {disconnectAll : true}))
- }
-}
-*/
-
-/*
- Tests
-
-// 1. Simple Test 1 "hello Fred" should trigger "Fred is a stupid head"
-
-
- sayHello = function(n) {
- alert("Hello! " + n);
- }
- moron = function(n) {
- alert(n + " is a stupid head");
- }
- Signal.connect(null,'sayHello',null,'moron');
-
- onclick="sayHello('Fred')"
-
-
-// 2. Simple Test 2 repeated insults about Fred
-
-
- Signal.connect(null,'sayHello2',null,'moron2');
- Signal.connect(null,'sayHello2',null,'moron2');
- Signal.connect(null,'sayHello2',null,'moron2');
-
-
-// 3. Simple Test 3 multiple insults about Fred
-
-
- Signal.connect(null,'sayHello3',null,'moron3');
- Signal.connect(null,'sayHello3',null,'bonehead3');
- Signal.connect(null,'sayHello3',null,'idiot3');
-
-
-// 4. Simple Test 4 3 insults about Fred first - 3 then none
-
-
- Signal.connect(null,'sayHello4',null,'moron4');
- Signal.connect(null,'sayHello4',null,'moron4');
- Signal.connect(null,'sayHello4',null,'moron4');
- Signal.disconnect(null,'sayHello4',null,'moron4');
- Signal.disconnect(null,'sayHello4',null,'moron4');
- Signal.disconnect(null,'sayHello4',null,'moron4');
-
-
-// 5. Simple Test 5 connect 3 insults about Fred first - only one, then none
-
-
- Signal.connect(null,'sayHello5',null,'moron5');
- Signal.connect(null,'sayHello5',null,'moron5');
- Signal.connect(null,'sayHello5',null,'moron5');
- Signal.disconnectAll(null,'sayHello5',null,'moron5');
-
-
-// 6. Simple Test 6 connect 3 insults but only one comes out
-
-
- Signal.connectOnce(null,'sayHello6',null,'moron6');
- Signal.connectOnce(null,'sayHello6',null,'moron6');
- Signal.connectOnce(null,'sayHello6',null,'moron6');
-
-
-// 7. Simple Test 7 connect via objects
-
-
- var o = {};
- o.sayHello = function(n) {
- alert("Hello! " + n + " (from object o)");
- }
- var m = {};
- m.moron = function(n) {
- alert(n + " is a stupid head (from object m)");
- }
-
- Signal.connect(o,'sayHello',m,'moron');
-
- onclick="o.sayHello('Fred')"
-
-
-// 8. Simple Test 8 connect but the insult comes first using {before:true}
-
-
- Signal.connect(null,'sayHello8',null,'moron8', {before:true});
-
-
-// 9. Simple Test 9 connect but the insult is mutated
-
-
- Signal.connect(null,'sayHello9',null,'moron9', {mutate:function() { return ['smelly ' + arguments[0]] }});
-
- */
diff --git a/framework/Web/Javascripts/extended/builder.js b/framework/Web/Javascripts/extended/builder.js
deleted file mode 100644
index c50fc6c6..00000000
--- a/framework/Web/Javascripts/extended/builder.js
+++ /dev/null
@@ -1,24 +0,0 @@
-
-Object.extend(Builder,
-{
- exportTags:function()
- {
- var tags=["BUTTON","TT","PRE","H1","H2","H3","BR","CANVAS","HR","LABEL","TEXTAREA","FORM","STRONG","SELECT","OPTION","OPTGROUP","LEGEND","FIELDSET","P","UL","OL","LI","TD","TR","THEAD","TBODY","TFOOT","TABLE","TH","INPUT","SPAN","A","DIV","IMG", "CAPTION"];
- tags.each(function(tag)
- {
- window[tag]=function()
- {
- var args=$A(arguments);
- if(args.length==0)
- return Builder.node(tag,null);
- if(args.length==1)
- return Builder.node(tag,args[0]);
- if(args.length>1)
- return Builder.node(tag,args.shift(),args);
-
- };
- });
- }
-});
-
-Builder.exportTags();
diff --git a/framework/Web/Javascripts/extended/date.js b/framework/Web/Javascripts/extended/date.js
deleted file mode 100644
index b27f9da2..00000000
--- a/framework/Web/Javascripts/extended/date.js
+++ /dev/null
@@ -1,151 +0,0 @@
-
-Object.extend(Date.prototype,
-{
- SimpleFormat: function(format, data)
- {
- data = data || {};
- var bits = new Array();
- bits['d'] = this.getDate();
- bits['dd'] = String(this.getDate()).zerofill(2);
-
- bits['M'] = this.getMonth()+1;
- bits['MM'] = String(this.getMonth()+1).zerofill(2);
- if(data.AbbreviatedMonthNames)
- bits['MMM'] = data.AbbreviatedMonthNames[this.getMonth()];
- if(data.MonthNames)
- bits['MMMM'] = data.MonthNames[this.getMonth()];
- var yearStr = "" + this.getFullYear();
- yearStr = (yearStr.length == 2) ? '19' + yearStr: yearStr;
- bits['yyyy'] = yearStr;
- bits['yy'] = bits['yyyy'].toString().substr(2,2);
-
- // do some funky regexs to replace the format string
- // with the real values
- var frm = new String(format);
- for (var sect in bits)
- {
- var reg = new RegExp("\\b"+sect+"\\b" ,"g");
- frm = frm.replace(reg, bits[sect]);
- }
- return frm;
- },
-
- toISODate : function()
- {
- var y = this.getFullYear();
- var m = String(this.getMonth() + 1).zerofill(2);
- var d = String(this.getDate()).zerofill(2);
- return String(y) + String(m) + String(d);
- }
-});
-
-Object.extend(Date,
-{
- SimpleParse: function(value, format)
- {
- val=String(value);
- format=String(format);
-
- if(val.length <= 0) return null;
-
- if(format.length <= 0) return new Date(value);
-
- var isInteger = function (val)
- {
- var digits="1234567890";
- for (var i=0; i < val.length; i++)
- {
- if (digits.indexOf(val.charAt(i))==-1) { return false; }
- }
- return true;
- };
-
- var getInt = function(str,i,minlength,maxlength)
- {
- for (var x=maxlength; x>=minlength; x--)
- {
- var token=str.substring(i,i+x);
- if (token.length < minlength) { return null; }
- if (isInteger(token)) { return token; }
- }
- return null;
- };
-
- var i_val=0;
- var i_format=0;
- var c="";
- var token="";
- var token2="";
- var x,y;
- var now=new Date();
- var year=now.getFullYear();
- var month=now.getMonth()+1;
- var date=1;
-
- while (i_format < format.length)
- {
- // Get next token from format string
- c=format.charAt(i_format);
- token="";
- while ((format.charAt(i_format)==c) && (i_format < format.length))
- {
- token += format.charAt(i_format++);
- }
-
- // Extract contents of value based on format token
- if (token=="yyyy" || token=="yy" || token=="y")
- {
- if (token=="yyyy") { x=4;y=4; }
- if (token=="yy") { x=2;y=2; }
- if (token=="y") { x=2;y=4; }
- year=getInt(val,i_val,x,y);
- if (year==null) { return null; }
- i_val += year.length;
- if (year.length==2)
- {
- if (year > 70) { year=1900+(year-0); }
- else { year=2000+(year-0); }
- }
- }
-
- else if (token=="MM"||token=="M")
- {
- month=getInt(val,i_val,token.length,2);
- if(month==null||(month<1)||(month>12)){return null;}
- i_val+=month.length;
- }
- else if (token=="dd"||token=="d")
- {
- date=getInt(val,i_val,token.length,2);
- if(date==null||(date<1)||(date>31)){return null;}
- i_val+=date.length;
- }
- else
- {
- if (val.substring(i_val,i_val+token.length)!=token) {return null;}
- else {i_val+=token.length;}
- }
- }
-
- // If there are any trailing characters left in the value, it doesn't match
- if (i_val != val.length) { return null; }
-
- // Is date valid for month?
- if (month==2)
- {
- // Check for leap year
- if ( ( (year%4==0)&&(year%100 != 0) ) || (year%400==0) ) { // leap year
- if (date > 29){ return null; }
- }
- else { if (date > 28) { return null; } }
- }
-
- if ((month==4)||(month==6)||(month==9)||(month==11))
- {
- if (date > 30) { return null; }
- }
-
- var newdate=new Date(year,month-1,date, 0, 0, 0);
- return newdate;
- }
-}); \ No newline at end of file
diff --git a/framework/Web/Javascripts/extended/effects.js b/framework/Web/Javascripts/extended/effects.js
deleted file mode 100644
index 236686df..00000000
--- a/framework/Web/Javascripts/extended/effects.js
+++ /dev/null
@@ -1,7 +0,0 @@
-Prado.Effect =
-{
- Highlight : function(element, options)
- {
- new Effect.Highlight(element,options||{});
- }
-} \ No newline at end of file
diff --git a/framework/Web/Javascripts/extended/event.js b/framework/Web/Javascripts/extended/event.js
deleted file mode 100644
index e257931a..00000000
--- a/framework/Web/Javascripts/extended/event.js
+++ /dev/null
@@ -1,110 +0,0 @@
-/**
- * @class Event extensions.
- */
-Object.extend(Event,
-{
- /**
- * Register a function to be executed when the page is loaded.
- * Note that the page is only loaded if all resources (e.g. images)
- * are loaded.
- *
- * Example: Show an alert box with message "Page Loaded!" when the
- * page finished loading.
- * <code>
- * Event.OnLoad(function(){ alert("Page Loaded!"); });
- * </code>
- *
- * @param {Function} function to execute when page is loaded.
- */
- OnLoad : function (fn)
- {
- // opera onload is in document, not window
- var w = document.addEventListener &&
- !window.addEventListener ? document : window;
- Event.observe(w,'load',fn);
- },
-
- /**
- * @param {Event} a keyboard event
- * @return {Number} the Unicode character code generated by the key
- * that was struck.
- */
- keyCode : function(e)
- {
- return e.keyCode != null ? e.keyCode : e.charCode
- },
-
- /**
- * @param {String} event type or event name.
- * @return {Boolean} true if event type is of HTMLEvent, false
- * otherwise
- */
- isHTMLEvent : function(type)
- {
- var events = ['abort', 'blur', 'change', 'error', 'focus',
- 'load', 'reset', 'resize', 'scroll', 'select',
- 'submit', 'unload'];
- return events.include(type);
- },
-
- /**
- * @param {String} event type or event name
- * @return {Boolean} true if event type is of MouseEvent,
- * false otherwise
- */
- isMouseEvent : function(type)
- {
- var events = ['click', 'mousedown', 'mousemove', 'mouseout',
- 'mouseover', 'mouseup'];
- return events.include(type);
- },
-
- /**
- * Dispatch the DOM event of a given <tt>type</tt> on a DOM
- * <tt>element</tt>. Only HTMLEvent and MouseEvent can be
- * dispatched, keyboard events or UIEvent can not be dispatch
- * via javascript consistently.
- * For the "submit" event the submit() method is called.
- * @param {Object} element id string or a DOM element.
- * @param {String} event type to dispatch.
- */
- fireEvent : function(element,type,canBubble)
- {
- canBubble = (typeof(canBubble) == undefined) ? true : canBubble;
- element = $(element);
- if(type == "submit")
- return element.submit();
- if(document.createEvent)
- {
- if(Event.isHTMLEvent(type))
- {
- var event = document.createEvent('HTMLEvents');
- event.initEvent(type, canBubble, true);
- }
- else if(Event.isMouseEvent(type))
- {
- var event = document.createEvent('MouseEvents');
- if (event.initMouseEvent)
- {
- event.initMouseEvent(type,canBubble,true,
- document.defaultView, 1, 0, 0, 0, 0, false,
- false, false, false, 0, null);
- }
- else
- {
- // Safari
- // TODO we should be initialising other mouse-event related attributes here
- event.initEvent(type, canBubble, true);
- }
- }
- element.dispatchEvent(event);
- }
- else if(document.createEventObject)
- {
- var evObj = document.createEventObject();
- element.fireEvent('on'+type, evObj);
- }
- else if(typeof(element['on'+type]) == "function")
- element['on'+type]();
- }
-}); \ No newline at end of file
diff --git a/framework/Web/Javascripts/extended/string.js b/framework/Web/Javascripts/extended/string.js
deleted file mode 100644
index 2bb40759..00000000
--- a/framework/Web/Javascripts/extended/string.js
+++ /dev/null
@@ -1,172 +0,0 @@
-/**
- * @class String extensions
- */
-Object.extend(String.prototype,
-{
- /**
- * @param {String} "left" to pad the string on the left, "right" to pad right.
- * @param {Number} minimum string length.
- * @param {String} character(s) to pad
- * @return {String} padded character(s) on the left or right to satisfy minimum string length
- */
-
- pad : function(side, len, chr) {
- if (!chr) chr = ' ';
- var s = this;
- var left = side.toLowerCase()=='left';
- while (s.length<len) s = left? chr + s : s + chr;
- return s;
- },
-
- /**
- * @param {Number} minimum string length.
- * @param {String} character(s) to pad
- * @return {String} padded character(s) on the left to satisfy minimum string length
- */
- padLeft : function(len, chr) {
- return this.pad('left',len,chr);
- },
-
- /**
- * @param {Number} minimum string length.
- * @param {String} character(s) to pad
- * @return {String} padded character(s) on the right to satisfy minimum string length
- */
- padRight : function(len, chr) {
- return this.pad('right',len,chr);
- },
-
- /**
- * @param {Number} minimum string length.
- * @return {String} append zeros to the left to satisfy minimum string length.
- */
- zerofill : function(len) {
- return this.padLeft(len,'0');
- },
-
- /**
- * @return {String} removed white spaces from both ends.
- */
- trim : function() {
- return this.replace(/^\s+|\s+$/g,'');
- },
-
- /**
- * @return {String} removed white spaces from the left end.
- */
- trimLeft : function() {
- return this.replace(/^\s+/,'');
- },
-
- /**
- * @return {String} removed white spaces from the right end.
- */
- trimRight : function() {
- return this.replace(/\s+$/,'');
- },
-
- /**
- * Convert period separated function names into a function reference.
- * e.g. "Prado.AJAX.Callback.Action.setValue".toFunction() will return
- * the actual function Prado.AJAX.Callback.Action.setValue()
- * @return {Function} the corresponding function represented by the string.
- */
- toFunction : function()
- {
- var commands = this.split(/\./);
- var command = window;
- commands.each(function(action)
- {
- if(command[new String(action)])
- command=command[new String(action)];
- });
- if(typeof(command) == "function")
- return command;
- else
- {
- if(typeof Logger != "undefined")
- Logger.error("Missing function", this);
-
- throw new Error ("Missing function '"+this+"'");
- }
- },
-
- /**
- * Convert a string into integer, returns null if not integer.
- * @return {Number} null if string does not represent an integer.
- */
- toInteger : function()
- {
- var exp = /^\s*[-\+]?\d+\s*$/;
- if (this.match(exp) == null)
- return null;
- var num = parseInt(this, 10);
- return (isNaN(num) ? null : num);
- },
-
- /**
- * Convert a string into a double/float value. <b>Internationalization
- * is not supported</b>
- * @param {String} the decimal character
- * @return {Double} null if string does not represent a float value
- */
- toDouble : function(decimalchar)
- {
- if(this.length <= 0) return null;
- decimalchar = decimalchar || ".";
- var exp = new RegExp("^\\s*([-\\+])?(\\d+)?(\\" + decimalchar + "(\\d+))?\\s*$");
- var m = this.match(exp);
-
- if (m == null)
- return null;
- m[1] = m[1] || "";
- m[2] = m[2] || "0";
- m[4] = m[4] || "0";
-
- var cleanInput = m[1] + (m[2].length>0 ? m[2] : "0") + "." + m[4];
- var num = parseFloat(cleanInput);
- return (isNaN(num) ? null : num);
- },
-
- /**
- * Convert strings that represent a currency value (e.g. a float with grouping
- * characters) to float. E.g. "10,000.50" will become "10000.50". The number
- * of dicimal digits, grouping and decimal characters can be specified.
- * <i>The currency input format is <b>very</b> strict, null will be returned if
- * the pattern does not match</i>.
- * @param {String} the grouping character, default is ","
- * @param {Number} number of decimal digits
- * @param {String} the decimal character, default is "."
- * @type {Double} the currency value as float.
- */
- toCurrency : function(groupchar, digits, decimalchar)
- {
- groupchar = groupchar || ",";
- decimalchar = decimalchar || ".";
- digits = typeof(digits) == "undefined" ? 2 : digits;
-
- var exp = new RegExp("^\\s*([-\\+])?(((\\d+)\\" + groupchar + ")*)(\\d+)"
- + ((digits > 0) ? "(\\" + decimalchar + "(\\d{1," + digits + "}))?" : "")
- + "\\s*$");
- var m = this.match(exp);
- if (m == null)
- return null;
- var intermed = m[2] + m[5] ;
- var cleanInput = m[1] + intermed.replace(
- new RegExp("(\\" + groupchar + ")", "g"), "")
- + ((digits > 0) ? "." + m[7] : "");
- var num = parseFloat(cleanInput);
- return (isNaN(num) ? null : num);
- },
-
- /**
- * Converts the string to a date by finding values that matches the
- * date format pattern.
- * @param string date format pattern, e.g. MM-dd-yyyy
- * @return {Date} the date extracted from the string
- */
- toDate : function(format)
- {
- return Date.SimpleParse(this, format);
- }
-}); \ No newline at end of file