/* Copyright (c) 2010, Yahoo! Inc. All rights reserved. Code licensed under the BSD License: http://developer.yahoo.com/yui/license.html version: 3.3.0 build: 3167 */ YUI.add('datatype-number-parse', function(Y) { /** * Parse number submodule. * * @module datatype * @submodule datatype-number-parse * @for DataType.Number */ var LANG = Y.Lang; Y.mix(Y.namespace("DataType.Number"), { /** * Converts data to type Number. * * @method parse * @param data {String | Number | Boolean} Data to convert. The following * values return as null: null, undefined, NaN, "". * @return {Number} A number, or null. */ parse: function(data) { var number = (data === null) ? data : +data; if(LANG.isNumber(number)) { return number; } else { return null; } } }); // Add Parsers shortcut Y.namespace("Parsers").number = Y.DataType.Number.parse; }, '3.3.0' ,{requires:['yui-base']}); YUI.add('datatype-number-format', function(Y) { /** * Number submodule. * * @module datatype * @submodule datatype-number */ /** * Format number submodule. * * @module datatype * @submodule datatype-number-format */ /** * DataType.Number provides a set of utility functions to operate against Number objects. * * @class DataType.Number * @static */ var LANG = Y.Lang; Y.mix(Y.namespace("DataType.Number"), { /** * Takes a Number and formats to string for display to user. * * @method format * @param data {Number} Number. * @param config {Object} (Optional) Optional configuration values: *
*
prefix {String} *
String prepended before each number, like a currency designator "$"
*
decimalPlaces {Number} *
Number of decimal places to round. Must be a number 0 to 20.
*
decimalSeparator {String} *
Decimal separator
*
thousandsSeparator {String} *
Thousands separator
*
suffix {String} *
String appended after each number, like " items" (note the space)
*
* @return {String} Formatted number for display. Note, the following values * return as "": null, undefined, NaN, "". */ format: function(data, config) { if(LANG.isNumber(data)) { config = config || {}; var isNeg = (data < 0), output = data + "", decPlaces = config.decimalPlaces, decSep = config.decimalSeparator || ".", thouSep = config.thousandsSeparator, decIndex, newOutput, count, i; // Decimal precision if(LANG.isNumber(decPlaces) && (decPlaces >= 0) && (decPlaces <= 20)) { // Round to the correct decimal place output = data.toFixed(decPlaces); } // Decimal separator if(decSep !== "."){ output = output.replace(".", decSep); } // Add the thousands separator if(thouSep) { // Find the dot or where it would be decIndex = output.lastIndexOf(decSep); decIndex = (decIndex > -1) ? decIndex : output.length; // Start with the dot and everything to the right newOutput = output.substring(decIndex); // Working left, every third time add a separator, every time add a digit for (count = 0, i=decIndex; i>0; i--) { if ((count%3 === 0) && (i !== decIndex) && (!isNeg || (i > 1))) { newOutput = thouSep + newOutput; } newOutput = output.charAt(i-1) + newOutput; count++; } output = newOutput; } // Prepend prefix output = (config.prefix) ? config.prefix + output : output; // Append suffix output = (config.suffix) ? output + config.suffix : output; return output; } // Not a Number, just return as string else { return (LANG.isValue(data) && data.toString) ? data.toString() : ""; } } }); }, '3.3.0' ,{requires:['yui-base']}); YUI.add('datatype-number', function(Y){}, '3.3.0' ,{use:['datatype-number-parse', 'datatype-number-format']}); YUI.add('datatype-date-parse', function(Y) { /** * Parse number submodule. * * @module datatype * @submodule datatype-date-parse * @for DataType.Date */ var LANG = Y.Lang; Y.mix(Y.namespace("DataType.Date"), { /** * Converts data to type Date. * * @method parse * @param data {String | Number} Data to convert. Values supported by the Date constructor are supported. * @return {Date} A Date, or null. */ parse: function(data) { var date = null; //Convert to date if(!(LANG.isDate(data))) { date = new Date(data); } else { return date; } // Validate if(LANG.isDate(date) && (date != "Invalid Date") && !isNaN(date)) { // Workaround for bug 2527965 return date; } else { return null; } } }); // Add Parsers shortcut Y.namespace("Parsers").date = Y.DataType.Date.parse; }, '3.3.0' ,{requires:['yui-base']}); YUI.add('datatype-date-format', function(Y) { /** * The DataType Utility provides type-conversion and string-formatting * convenience methods for various JavaScript object types. * * @module datatype */ /** * Date submodule. * * @module datatype * @submodule datatype-date */ /** * Format date submodule implements strftime formatters for javascript based on the * Open Group specification defined at * http://www.opengroup.org/onlinepubs/007908799/xsh/strftime.html * This implementation does not include modified conversion specifiers (i.e., Ex and Ox) * * @module datatype * @submodule datatype-date-format */ /** * DataType.Date provides a set of utility functions to operate against Date objects. * * @class DataType.Date * @static */ /** * Pad a number with leading spaces, zeroes or something else * @method xPad * @param x {Number} The number to be padded * @param pad {String} The character to pad the number with * @param r {Number} (optional) The base of the pad, eg, 10 implies to two digits, 100 implies to 3 digits. * @private */ var xPad=function (x, pad, r) { if(typeof r === "undefined") { r=10; } pad = pad.toString(); for( ; parseInt(x, 10)1; r/=10) { x = pad + x; } return x.toString(); }; var Dt = { formats: { a: function (d, l) { return l.a[d.getDay()]; }, A: function (d, l) { return l.A[d.getDay()]; }, b: function (d, l) { return l.b[d.getMonth()]; }, B: function (d, l) { return l.B[d.getMonth()]; }, C: function (d) { return xPad(parseInt(d.getFullYear()/100, 10), 0); }, d: ["getDate", "0"], e: ["getDate", " "], g: function (d) { return xPad(parseInt(Dt.formats.G(d)%100, 10), 0); }, G: function (d) { var y = d.getFullYear(); var V = parseInt(Dt.formats.V(d), 10); var W = parseInt(Dt.formats.W(d), 10); if(W > V) { y++; } else if(W===0 && V>=52) { y--; } return y; }, H: ["getHours", "0"], I: function (d) { var I=d.getHours()%12; return xPad(I===0?12:I, 0); }, j: function (d) { var gmd_1 = new Date("" + d.getFullYear() + "/1/1 GMT"); var gmdate = new Date("" + d.getFullYear() + "/" + (d.getMonth()+1) + "/" + d.getDate() + " GMT"); var ms = gmdate - gmd_1; var doy = parseInt(ms/60000/60/24, 10)+1; return xPad(doy, 0, 100); }, k: ["getHours", " "], l: function (d) { var I=d.getHours()%12; return xPad(I===0?12:I, " "); }, m: function (d) { return xPad(d.getMonth()+1, 0); }, M: ["getMinutes", "0"], p: function (d, l) { return l.p[d.getHours() >= 12 ? 1 : 0 ]; }, P: function (d, l) { return l.P[d.getHours() >= 12 ? 1 : 0 ]; }, s: function (d, l) { return parseInt(d.getTime()/1000, 10); }, S: ["getSeconds", "0"], u: function (d) { var dow = d.getDay(); return dow===0?7:dow; }, U: function (d) { var doy = parseInt(Dt.formats.j(d), 10); var rdow = 6-d.getDay(); var woy = parseInt((doy+rdow)/7, 10); return xPad(woy, 0); }, V: function (d) { var woy = parseInt(Dt.formats.W(d), 10); var dow1_1 = (new Date("" + d.getFullYear() + "/1/1")).getDay(); // First week is 01 and not 00 as in the case of %U and %W, // so we add 1 to the final result except if day 1 of the year // is a Monday (then %W returns 01). // We also need to subtract 1 if the day 1 of the year is // Friday-Sunday, so the resulting equation becomes: var idow = woy + (dow1_1 > 4 || dow1_1 <= 1 ? 0 : 1); if(idow === 53 && (new Date("" + d.getFullYear() + "/12/31")).getDay() < 4) { idow = 1; } else if(idow === 0) { idow = Dt.formats.V(new Date("" + (d.getFullYear()-1) + "/12/31")); } return xPad(idow, 0); }, w: "getDay", W: function (d) { var doy = parseInt(Dt.formats.j(d), 10); var rdow = 7-Dt.formats.u(d); var woy = parseInt((doy+rdow)/7, 10); return xPad(woy, 0, 10); }, y: function (d) { return xPad(d.getFullYear()%100, 0); }, Y: "getFullYear", z: function (d) { var o = d.getTimezoneOffset(); var H = xPad(parseInt(Math.abs(o/60), 10), 0); var M = xPad(Math.abs(o%60), 0); return (o>0?"-":"+") + H + M; }, Z: function (d) { var tz = d.toString().replace(/^.*:\d\d( GMT[+-]\d+)? \(?([A-Za-z ]+)\)?\d*$/, "$2").replace(/[a-z ]/g, ""); if(tz.length > 4) { tz = Dt.formats.z(d); } return tz; }, "%": function (d) { return "%"; } }, aggregates: { c: "locale", D: "%m/%d/%y", F: "%Y-%m-%d", h: "%b", n: "\n", r: "%I:%M:%S %p", R: "%H:%M", t: "\t", T: "%H:%M:%S", x: "locale", X: "locale" //"+": "%a %b %e %T %Z %Y" }, /** * Takes a native JavaScript Date and formats it as a string for display to user. * * @for DataType.Date * @method format * @param oDate {Date} Date. * @param oConfig {Object} (Optional) Object literal of configuration values: *
*
format {String} (Optional)
*
*

* Any strftime string is supported, such as "%I:%M:%S %p". strftime has several format specifiers defined by the Open group at * http://www.opengroup.org/onlinepubs/007908799/xsh/strftime.html * PHP added a few of its own, defined at http://www.php.net/strftime *

*

* This javascript implementation supports all the PHP specifiers and a few more. The full list is below. *

*

* If not specified, it defaults to the ISO 8601 standard date format: %Y-%m-%d. * This may be overridden by the deprecated Y.config.dateFormat property. *

*
*
%a
abbreviated weekday name according to the current locale
*
%A
full weekday name according to the current locale
*
%b
abbreviated month name according to the current locale
*
%B
full month name according to the current locale
*
%c
preferred date and time representation for the current locale
*
%C
century number (the year divided by 100 and truncated to an integer, range 00 to 99)
*
%d
day of the month as a decimal number (range 01 to 31)
*
%D
same as %m/%d/%y
*
%e
day of the month as a decimal number, a single digit is preceded by a space (range " 1" to "31")
*
%F
same as %Y-%m-%d (ISO 8601 date format)
*
%g
like %G, but without the century
*
%G
The 4-digit year corresponding to the ISO week number
*
%h
same as %b
*
%H
hour as a decimal number using a 24-hour clock (range 00 to 23)
*
%I
hour as a decimal number using a 12-hour clock (range 01 to 12)
*
%j
day of the year as a decimal number (range 001 to 366)
*
%k
hour as a decimal number using a 24-hour clock (range 0 to 23); single digits are preceded by a blank. (See also %H.)
*
%l
hour as a decimal number using a 12-hour clock (range 1 to 12); single digits are preceded by a blank. (See also %I.)
*
%m
month as a decimal number (range 01 to 12)
*
%M
minute as a decimal number
*
%n
newline character
*
%p
either "AM" or "PM" according to the given time value, or the corresponding strings for the current locale
*
%P
like %p, but lower case
*
%r
time in a.m. and p.m. notation equal to %I:%M:%S %p
*
%R
time in 24 hour notation equal to %H:%M
*
%s
number of seconds since the Epoch, ie, since 1970-01-01 00:00:00 UTC
*
%S
second as a decimal number
*
%t
tab character
*
%T
current time, equal to %H:%M:%S
*
%u
weekday as a decimal number [1,7], with 1 representing Monday
*
%U
week number of the current year as a decimal number, starting with the * first Sunday as the first day of the first week
*
%V
The ISO 8601:1988 week number of the current year as a decimal number, * range 01 to 53, where week 1 is the first week that has at least 4 days * in the current year, and with Monday as the first day of the week.
*
%w
day of the week as a decimal, Sunday being 0
*
%W
week number of the current year as a decimal number, starting with the * first Monday as the first day of the first week
*
%x
preferred date representation for the current locale without the time
*
%X
preferred time representation for the current locale without the date
*
%y
year as a decimal number without a century (range 00 to 99)
*
%Y
year as a decimal number including the century
*
%z
numerical time zone representation
*
%Z
time zone name or abbreviation
*
%%
a literal "%" character
*
*
*
locale {String} (Deprecated, optional)
*
* Deprecated - use Y.config.lang instead, which provides access to a much larger set of built-in languages. * The locale to use when displaying days of week, months of the year, and other locale specific * strings. If not specified, this defaults to "en" (though this may be overridden by the deprecated Y.config.locale). * The following locales are built in: *
*
en
*
English
*
en-US
*
US English
*
en-GB
*
British English
*
en-AU
*
Australian English (identical to British English)
*
* More locales may be added by subclassing of the deprecated Y.DataType.Date.Locale["en"]. * See Y.DataType.Date.Locale for more information. *
*
* @return {String} Formatted date for display. */ format : function (oDate, oConfig) { oConfig = oConfig || {}; if(!Y.Lang.isDate(oDate)) { return Y.Lang.isValue(oDate) ? oDate : ""; } var format, resources, compatMode, sLocale, LOCALE; // Y.config.dateFormat is deprecated - remove from YUI 3.2 format = oConfig.format || Y.config.dateFormat || "%Y-%m-%d"; // compatMode supports deprecated features - remove from YUI 3.2 compatMode = Y.Lang.isUndefined(Y.config.lang) && (Y.Lang.isValue(oConfig.locale) || Y.Lang.isValue(Y.config.locale)); if (compatMode) { sLocale = oConfig.locale || Y.config.locale; LOCALE = Y.DataType.Date.Locale; sLocale = sLocale.replace(/_/g, "-"); // Make sure we have a definition for the requested locale, or default to en. if(!LOCALE[sLocale]) { var tmpLocale = sLocale.replace(/-[a-zA-Z]+$/, ""); if(tmpLocale in LOCALE) { sLocale = tmpLocale; } else if(Y.config.locale in LOCALE) { sLocale = Y.config.locale; } else { sLocale = "en"; } } resources = LOCALE[sLocale]; } else { resources = Y.Intl.get('datatype-date-format'); } var replace_aggs = function (m0, m1) { if (compatMode && m1 === "r") { return resources[m1]; } var f = Dt.aggregates[m1]; return (f === "locale" ? resources[m1] : f); }; var replace_formats = function (m0, m1) { var f = Dt.formats[m1]; switch(Y.Lang.type(f)) { case "string": // string => built in date function return oDate[f](); case "function": // function => our own function return f.call(oDate, oDate, resources); case "array": // built in function with padding if(Y.Lang.type(f[0]) === "string") { return xPad(oDate[f[0]](), f[1]); } // no break; (fall through to default:) default: // Y.config.dateFormat is deprecated - remove from YUI 3.2 return m1; } }; // First replace aggregates (run in a loop because an agg may be made up of other aggs) while(format.match(/%[cDFhnrRtTxX]/)) { format = format.replace(/%([cDFhnrRtTxX])/g, replace_aggs); } // Now replace formats (do not run in a loop otherwise %%a will be replace with the value of %a) var str = format.replace(/%([aAbBCdegGHIjklmMpPsSuUVwWyYzZ%])/g, replace_formats); replace_aggs = replace_formats = undefined; return str; } }; Y.mix(Y.namespace("DataType.Date"), Dt); /** * @module datatype */ /** * The Date.Locale class is a container for all localised date strings * used by Y.DataType.Date. It is used internally, but may be extended * to provide new date localisations. * * To create your own Locale, follow these steps: *
    *
  1. Find an existing locale that matches closely with your needs
  2. *
  3. Use this as your base class. Use Y.DataType.Date.Locale["en"] if nothing * matches.
  4. *
  5. Create your own class as an extension of the base class using * Y.merge, and add your own localisations where needed.
  6. *
* See the Y.DataType.Date.Locale["en-US"] and Y.DataType.Date.Locale["en-GB"] * classes which extend Y.DataType.Date.Locale["en"]. * * For example, to implement locales for French french and Canadian french, * we would do the following: *
    *
  1. For French french, we have no existing similar locale, so use * Y.DataType.Date.Locale["en"] as the base, and extend it: *
     *      Y.DataType.Date.Locale["fr"] = Y.merge(Y.DataType.Date.Locale, {
     *          a: ["dim", "lun", "mar", "mer", "jeu", "ven", "sam"],
     *          A: ["dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi"],
     *          b: ["jan", "fév", "mar", "avr", "mai", "jun", "jui", "aoû", "sep", "oct", "nov", "déc"],
     *          B: ["janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre"],
     *          c: "%a %d %b %Y %T %Z",
     *          p: ["", ""],
     *          P: ["", ""],
     *          x: "%d.%m.%Y",
     *          X: "%T"
     *      });
     *   
    *
  2. *
  3. For Canadian french, we start with French french and change the meaning of \%x: *
     *      Y.DataType.Date.Locale["fr-CA"] = Y.merge(Y.DataType.Date.Locale["fr"], {
     *          x: "%Y-%m-%d"
     *      });
     *   
    *
  4. *
* * With that, you can use your new locales: *
 *    var d = new Date("2008/04/22");
 *    Y.DataType.Date.format(d, { format: "%A, %d %B == %x", locale: "fr" });
 * 
* will return: *
 *    mardi, 22 avril == 22.04.2008
 * 
* And *
 *    Y.DataType.Date.format(d, {format: "%A, %d %B == %x", locale: "fr-CA" });
 * 
* Will return: *
 *   mardi, 22 avril == 2008-04-22
 * 
* @requires oop * @class DataType.Date.Locale * @static * @deprecated - use Y.config.lang to request one of many built-in languages instead. */ var YDateEn = { a: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], A: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"], b: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"], B: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"], c: "%a %d %b %Y %T %Z", p: ["AM", "PM"], P: ["am", "pm"], r: "%I:%M:%S %p", x: "%d/%m/%y", X: "%T" }; Y.namespace("DataType.Date.Locale"); Y.DataType.Date.Locale["en"] = YDateEn; Y.DataType.Date.Locale["en-US"] = Y.merge(YDateEn, { c: "%a %d %b %Y %I:%M:%S %p %Z", x: "%m/%d/%Y", X: "%I:%M:%S %p" }); Y.DataType.Date.Locale["en-GB"] = Y.merge(YDateEn, { r: "%l:%M:%S %P %Z" }); Y.DataType.Date.Locale["en-AU"] = Y.merge(YDateEn); }, '3.3.0' ,{requires:['yui-base'], lang:['ar','ar-JO','ca','ca-ES','da','da-DK','de','de-AT','de-DE','el','el-GR','en','en-AU','en-CA','en-GB','en-IE','en-IN','en-JO','en-MY','en-NZ','en-PH','en-SG','en-US','es','es-AR','es-BO','es-CL','es-CO','es-EC','es-ES','es-MX','es-PE','es-PY','es-US','es-UY','es-VE','fi','fi-FI','fr','fr-BE','fr-CA','fr-FR','hi','hi-IN','id','id-ID','it','it-IT','ja','ja-JP','ko','ko-KR','ms','ms-MY','nb','nb-NO','nl','nl-BE','nl-NL','pl','pl-PL','pt','pt-BR','ro','ro-RO','ru','ru-RU','sv','sv-SE','th','th-TH','tr','tr-TR','vi','vi-VN','zh-Hans','zh-Hans-CN','zh-Hant','zh-Hant-HK','zh-Hant-TW']}); YUI.add('datatype-date', function(Y){}, '3.3.0' ,{use:['datatype-date-parse', 'datatype-date-format']}); YUI.add('datatype-xml-parse', function(Y) { /** * Parse XML submodule. * * @module datatype * @submodule datatype-xml-parse * @for DataType.XML */ var LANG = Y.Lang; Y.mix(Y.namespace("DataType.XML"), { /** * Converts data to type XMLDocument. * * @method parse * @param data {String} Data to convert. * @return {XMLDoc} XML Document. */ parse: function(data) { var xmlDoc = null; if(LANG.isString(data)) { try { if(!LANG.isUndefined(ActiveXObject)) { xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async = false; xmlDoc.loadXML(data); } } catch(ee) { try { if(!LANG.isUndefined(DOMParser)) { xmlDoc = new DOMParser().parseFromString(data, "text/xml"); } } catch(e) { } } } if( (LANG.isNull(xmlDoc)) || (LANG.isNull(xmlDoc.documentElement)) || (xmlDoc.documentElement.nodeName === "parsererror") ) { } return xmlDoc; } }); // Add Parsers shortcut Y.namespace("Parsers").xml = Y.DataType.XML.parse; }, '3.3.0' ,{requires:['yui-base']}); YUI.add('datatype-xml-format', function(Y) { /** * Format XML submodule. * * @module datatype * @submodule datatype-xml-format */ /** * XML submodule. * * @module datatype * @submodule datatype-xml */ /** * DataType.XML provides a set of utility functions to operate against XML documents. * * @class DataType.XML * @static */ var LANG = Y.Lang; Y.mix(Y.namespace("DataType.XML"), { /** * Converts data to type XMLDocument. * * @method format * @param data {XMLDoc} Data to convert. * @return {String} String. */ format: function(data) { try { if(!LANG.isUndefined(XMLSerializer)) { return (new XMLSerializer()).serializeToString(data); } } catch(e) { if(data && data.xml) { return data.xml; } else { return (LANG.isValue(data) && data.toString) ? data.toString() : ""; } } } }); }, '3.3.0' ,{requires:['yui-base']}); YUI.add('datatype-xml', function(Y){}, '3.3.0' ,{use:['datatype-xml-parse', 'datatype-xml-format']}); YUI.add('datatype', function(Y){}, '3.3.0' ,{use:['datatype-number', 'datatype-date', 'datatype-xml']});