aboutsummaryrefslogtreecommitdiff
path: root/includes/js/dojo/currency.js
diff options
context:
space:
mode:
authormensonge <mensonge@b3834d28-1941-0410-a4f8-b48e95affb8f>2008-11-13 09:49:11 +0000
committermensonge <mensonge@b3834d28-1941-0410-a4f8-b48e95affb8f>2008-11-13 09:49:11 +0000
commite44a7e37b6c7b5961adaffc62b9042b8d442938e (patch)
tree95b67c356e93163467db2451f2b8cce84ed5d582 /includes/js/dojo/currency.js
parenta62b9742ee5e28bcec6872d88f50f25b820914f6 (diff)
downloadsemanticscuttle-e44a7e37b6c7b5961adaffc62b9042b8d442938e.tar.gz
semanticscuttle-e44a7e37b6c7b5961adaffc62b9042b8d442938e.tar.bz2
New feature: basic Ajax suggestion for tags and implementation of Dojo toolkit
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@151 b3834d28-1941-0410-a4f8-b48e95affb8f
Diffstat (limited to 'includes/js/dojo/currency.js')
-rw-r--r--includes/js/dojo/currency.js97
1 files changed, 97 insertions, 0 deletions
diff --git a/includes/js/dojo/currency.js b/includes/js/dojo/currency.js
new file mode 100644
index 0000000..6e0eb31
--- /dev/null
+++ b/includes/js/dojo/currency.js
@@ -0,0 +1,97 @@
+if(!dojo._hasResource["dojo.currency"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
+dojo._hasResource["dojo.currency"] = true;
+dojo.provide("dojo.currency");
+
+dojo.require("dojo.number");
+dojo.require("dojo.i18n");
+dojo.requireLocalization("dojo.cldr", "currency", null, "zh,en-ca,pt,en-us,de,ja,en,en-au,ROOT,fr,es,ko,zh-tw,it");
+dojo.require("dojo.cldr.monetary");
+
+/*=====
+dojo.currency = {
+ // summary: localized formatting and parsing routines for currencies
+}
+=====*/
+
+dojo.currency._mixInDefaults = function(options){
+ options = options || {};
+ options.type = "currency";
+
+ // Get locale-depenent currency data, like the symbol
+ var bundle = dojo.i18n.getLocalization("dojo.cldr", "currency", options.locale) || {};
+
+ // Mixin locale-independent currency data, like # of places
+ var iso = options.currency;
+ var data = dojo.cldr.monetary.getData(iso);
+
+ dojo.forEach(["displayName","symbol","group","decimal"], function(prop){
+ data[prop] = bundle[iso+"_"+prop];
+ });
+
+ data.fractional = [true, false];
+
+ // Mixin with provided options
+ return dojo.mixin(data, options);
+}
+
+dojo.currency.format = function(/*Number*/value, /*dojo.number.__FormatOptions?*/options){
+// summary:
+// Format a Number as a currency, using locale-specific settings
+//
+// description:
+// Create a string from a Number using a known, localized pattern.
+// [Formatting patterns](http://www.unicode.org/reports/tr35/#Number_Elements) appropriate to the locale are chosen from the [CLDR](http://unicode.org/cldr)
+// as well as the appropriate symbols and delimiters.
+//
+// value:
+// the number to be formatted.
+
+ return dojo.number.format(value, dojo.currency._mixInDefaults(options));
+}
+
+dojo.currency.regexp = function(/*dojo.number.__RegexpOptions?*/options){
+//
+// summary:
+// Builds the regular needed to parse a currency value
+//
+// description:
+// Returns regular expression with positive and negative match, group and decimal separators
+// Note: the options.places default, the number of decimal places to accept, is defined by the currency type.
+ return dojo.number.regexp(dojo.currency._mixInDefaults(options)); // String
+}
+
+/*=====
+dojo.declare("dojo.currency.__ParseOptions", [dojo.number.__ParseOptions], {
+ // type: String?
+ // currency, set by default.
+ // symbol: String?
+ // override currency symbol. Normally, will be looked up in table of supported currencies,
+ // and ISO currency code will be used if not found. See dojo.i18n.cldr.nls->currency.js
+ // places: Number?
+ // number of decimal places to accept. Default is defined by currency.
+ // fractional: Boolean?|Array?
+ // where places are implied by pattern or explicit 'places' parameter, whether to include the fractional portion.
+ // By default for currencies, it the fractional portion is optional.
+ type: "",
+ symbol: "",
+ places: "",
+ fractional: ""
+});
+=====*/
+
+dojo.currency.parse = function(/*String*/expression, /*dojo.currency.__ParseOptions?*/options){
+ //
+ // summary:
+ // Convert a properly formatted currency string to a primitive Number,
+ // using locale-specific settings.
+ //
+ // description:
+ // Create a Number from a string using a known, localized pattern.
+ // [Formatting patterns](http://www.unicode.org/reports/tr35/#Number_Format_Patterns) are chosen appropriate to the locale.
+ //
+ // expression: A string representation of a Number
+
+ return dojo.number.parse(expression, dojo.currency._mixInDefaults(options));
+}
+
+}