]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/include/javascript/yui3/build/datatype/datatype.js
Release 6.5.0
[Github/sugarcrm.git] / jssource / src_files / include / javascript / yui3 / build / datatype / datatype.js
1 /*
2 Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.com/yui/license.html
5 version: 3.3.0
6 build: 3167
7 */
8 YUI.add('datatype-number-parse', function(Y) {
9
10 /**
11  * Parse number submodule.
12  *
13  * @module datatype
14  * @submodule datatype-number-parse
15  * @for DataType.Number
16  */
17
18 var LANG = Y.Lang;
19
20 Y.mix(Y.namespace("DataType.Number"), {
21     /**
22      * Converts data to type Number.
23      *
24      * @method parse
25      * @param data {String | Number | Boolean} Data to convert. The following
26      * values return as null: null, undefined, NaN, "".
27      * @return {Number} A number, or null.
28      */
29     parse: function(data) {
30         var number = (data === null) ? data : +data;
31         if(LANG.isNumber(number)) {
32             return number;
33         }
34         else {
35             return null;
36         }
37     }
38 });
39
40 // Add Parsers shortcut
41 Y.namespace("Parsers").number = Y.DataType.Number.parse;
42
43
44 }, '3.3.0' ,{requires:['yui-base']});
45 YUI.add('datatype-number-format', function(Y) {
46
47 /**
48  * Number submodule.
49  *
50  * @module datatype
51  * @submodule datatype-number
52  */
53
54 /**
55  * Format number submodule.
56  *
57  * @module datatype
58  * @submodule datatype-number-format
59  */
60  
61 /**
62  * DataType.Number provides a set of utility functions to operate against Number objects.
63  *
64  * @class DataType.Number
65  * @static
66  */
67 var LANG = Y.Lang;
68
69 Y.mix(Y.namespace("DataType.Number"), {
70      /**
71      * Takes a Number and formats to string for display to user.
72      *
73      * @method format
74      * @param data {Number} Number.
75      * @param config {Object} (Optional) Optional configuration values:
76      *  <dl>
77      *   <dt>prefix {String}</dd>
78      *   <dd>String prepended before each number, like a currency designator "$"</dd>
79      *   <dt>decimalPlaces {Number}</dd>
80      *   <dd>Number of decimal places to round. Must be a number 0 to 20.</dd>
81      *   <dt>decimalSeparator {String}</dd>
82      *   <dd>Decimal separator</dd>
83      *   <dt>thousandsSeparator {String}</dd>
84      *   <dd>Thousands separator</dd>
85      *   <dt>suffix {String}</dd>
86      *   <dd>String appended after each number, like " items" (note the space)</dd>
87      *  </dl>
88      * @return {String} Formatted number for display. Note, the following values
89      * return as "": null, undefined, NaN, "".
90      */
91     format: function(data, config) {
92         if(LANG.isNumber(data)) {
93             config = config || {};
94
95             var isNeg = (data < 0),
96                 output = data + "",
97                 decPlaces = config.decimalPlaces,
98                 decSep = config.decimalSeparator || ".",
99                 thouSep = config.thousandsSeparator,
100                 decIndex,
101                 newOutput, count, i;
102
103             // Decimal precision
104             if(LANG.isNumber(decPlaces) && (decPlaces >= 0) && (decPlaces <= 20)) {
105                 // Round to the correct decimal place
106                 output = data.toFixed(decPlaces);
107             }
108
109             // Decimal separator
110             if(decSep !== "."){
111                 output = output.replace(".", decSep);
112             }
113
114             // Add the thousands separator
115             if(thouSep) {
116                 // Find the dot or where it would be
117                 decIndex = output.lastIndexOf(decSep);
118                 decIndex = (decIndex > -1) ? decIndex : output.length;
119                 // Start with the dot and everything to the right
120                 newOutput = output.substring(decIndex);
121                 // Working left, every third time add a separator, every time add a digit
122                 for (count = 0, i=decIndex; i>0; i--) {
123                     if ((count%3 === 0) && (i !== decIndex) && (!isNeg || (i > 1))) {
124                         newOutput = thouSep + newOutput;
125                     }
126                     newOutput = output.charAt(i-1) + newOutput;
127                     count++;
128                 }
129                 output = newOutput;
130             }
131
132             // Prepend prefix
133             output = (config.prefix) ? config.prefix + output : output;
134
135             // Append suffix
136             output = (config.suffix) ? output + config.suffix : output;
137
138             return output;
139         }
140         // Not a Number, just return as string
141         else {
142             return (LANG.isValue(data) && data.toString) ? data.toString() : "";
143         }
144     }
145 });
146
147
148 }, '3.3.0' ,{requires:['yui-base']});
149
150
151 YUI.add('datatype-number', function(Y){}, '3.3.0' ,{use:['datatype-number-parse', 'datatype-number-format']});
152
153 YUI.add('datatype-date-parse', function(Y) {
154
155 /**
156  * Parse number submodule.
157  *
158  * @module datatype
159  * @submodule datatype-date-parse
160  * @for DataType.Date
161  */
162 var LANG = Y.Lang;
163
164 Y.mix(Y.namespace("DataType.Date"), {
165     /**
166      * Converts data to type Date.
167      *
168      * @method parse
169      * @param data {String | Number} Data to convert. Values supported by the Date constructor are supported.
170      * @return {Date} A Date, or null.
171      */
172     parse: function(data) {
173         var date = null;
174
175         //Convert to date
176         if(!(LANG.isDate(data))) {
177             date = new Date(data);
178         }
179         else {
180             return date;
181         }
182
183         // Validate
184         if(LANG.isDate(date) && (date != "Invalid Date") && !isNaN(date)) { // Workaround for bug 2527965
185             return date;
186         }
187         else {
188             return null;
189         }
190     }
191 });
192
193 // Add Parsers shortcut
194 Y.namespace("Parsers").date = Y.DataType.Date.parse;
195
196
197 }, '3.3.0' ,{requires:['yui-base']});
198 YUI.add('datatype-date-format', function(Y) {
199
200 /**
201  * The DataType Utility provides type-conversion and string-formatting
202  * convenience methods for various JavaScript object types.
203  *
204  * @module datatype
205  */
206
207 /**
208  * Date submodule.
209  *
210  * @module datatype
211  * @submodule datatype-date
212  */
213
214 /**
215  * Format date submodule implements strftime formatters for javascript based on the
216  * Open Group specification defined at
217  * http://www.opengroup.org/onlinepubs/007908799/xsh/strftime.html
218  * This implementation does not include modified conversion specifiers (i.e., Ex and Ox)
219  *
220  * @module datatype
221  * @submodule datatype-date-format
222  */
223
224 /**
225  * DataType.Date provides a set of utility functions to operate against Date objects.
226  *
227  * @class DataType.Date
228  * @static
229  */
230
231 /**
232  * Pad a number with leading spaces, zeroes or something else
233  * @method xPad
234  * @param x {Number}    The number to be padded
235  * @param pad {String}  The character to pad the number with
236  * @param r {Number}    (optional) The base of the pad, eg, 10 implies to two digits, 100 implies to 3 digits.
237  * @private
238  */
239 var xPad=function (x, pad, r)
240 {
241         if(typeof r === "undefined")
242         {
243                 r=10;
244         }
245         pad = pad.toString();
246         for( ; parseInt(x, 10)<r && r>1; r/=10) {
247                 x = pad + x;
248         }
249         return x.toString();
250 };
251
252 var Dt = {
253         formats: {
254                 a: function (d, l) { return l.a[d.getDay()]; },
255                 A: function (d, l) { return l.A[d.getDay()]; },
256                 b: function (d, l) { return l.b[d.getMonth()]; },
257                 B: function (d, l) { return l.B[d.getMonth()]; },
258                 C: function (d) { return xPad(parseInt(d.getFullYear()/100, 10), 0); },
259                 d: ["getDate", "0"],
260                 e: ["getDate", " "],
261                 g: function (d) { return xPad(parseInt(Dt.formats.G(d)%100, 10), 0); },
262                 G: function (d) {
263                                 var y = d.getFullYear();
264                                 var V = parseInt(Dt.formats.V(d), 10);
265                                 var W = parseInt(Dt.formats.W(d), 10);
266         
267                                 if(W > V) {
268                                         y++;
269                                 } else if(W===0 && V>=52) {
270                                         y--;
271                                 }
272         
273                                 return y;
274                         },
275                 H: ["getHours", "0"],
276                 I: function (d) { var I=d.getHours()%12; return xPad(I===0?12:I, 0); },
277                 j: function (d) {
278                                 var gmd_1 = new Date("" + d.getFullYear() + "/1/1 GMT");
279                                 var gmdate = new Date("" + d.getFullYear() + "/" + (d.getMonth()+1) + "/" + d.getDate() + " GMT");
280                                 var ms = gmdate - gmd_1;
281                                 var doy = parseInt(ms/60000/60/24, 10)+1;
282                                 return xPad(doy, 0, 100);
283                         },
284                 k: ["getHours", " "],
285                 l: function (d) { var I=d.getHours()%12; return xPad(I===0?12:I, " "); },
286                 m: function (d) { return xPad(d.getMonth()+1, 0); },
287                 M: ["getMinutes", "0"],
288                 p: function (d, l) { return l.p[d.getHours() >= 12 ? 1 : 0 ]; },
289                 P: function (d, l) { return l.P[d.getHours() >= 12 ? 1 : 0 ]; },
290                 s: function (d, l) { return parseInt(d.getTime()/1000, 10); },
291                 S: ["getSeconds", "0"],
292                 u: function (d) { var dow = d.getDay(); return dow===0?7:dow; },
293                 U: function (d) {
294                                 var doy = parseInt(Dt.formats.j(d), 10);
295                                 var rdow = 6-d.getDay();
296                                 var woy = parseInt((doy+rdow)/7, 10);
297                                 return xPad(woy, 0);
298                         },
299                 V: function (d) {
300                                 var woy = parseInt(Dt.formats.W(d), 10);
301                                 var dow1_1 = (new Date("" + d.getFullYear() + "/1/1")).getDay();
302                                 // First week is 01 and not 00 as in the case of %U and %W,
303                                 // so we add 1 to the final result except if day 1 of the year
304                                 // is a Monday (then %W returns 01).
305                                 // We also need to subtract 1 if the day 1 of the year is 
306                                 // Friday-Sunday, so the resulting equation becomes:
307                                 var idow = woy + (dow1_1 > 4 || dow1_1 <= 1 ? 0 : 1);
308                                 if(idow === 53 && (new Date("" + d.getFullYear() + "/12/31")).getDay() < 4)
309                                 {
310                                         idow = 1;
311                                 }
312                                 else if(idow === 0)
313                                 {
314                                         idow = Dt.formats.V(new Date("" + (d.getFullYear()-1) + "/12/31"));
315                                 }
316         
317                                 return xPad(idow, 0);
318                         },
319                 w: "getDay",
320                 W: function (d) {
321                                 var doy = parseInt(Dt.formats.j(d), 10);
322                                 var rdow = 7-Dt.formats.u(d);
323                                 var woy = parseInt((doy+rdow)/7, 10);
324                                 return xPad(woy, 0, 10);
325                         },
326                 y: function (d) { return xPad(d.getFullYear()%100, 0); },
327                 Y: "getFullYear",
328                 z: function (d) {
329                                 var o = d.getTimezoneOffset();
330                                 var H = xPad(parseInt(Math.abs(o/60), 10), 0);
331                                 var M = xPad(Math.abs(o%60), 0);
332                                 return (o>0?"-":"+") + H + M;
333                         },
334                 Z: function (d) {
335                         var tz = d.toString().replace(/^.*:\d\d( GMT[+-]\d+)? \(?([A-Za-z ]+)\)?\d*$/, "$2").replace(/[a-z ]/g, "");
336                         if(tz.length > 4) {
337                                 tz = Dt.formats.z(d);
338                         }
339                         return tz;
340                 },
341                 "%": function (d) { return "%"; }
342         },
343
344         aggregates: {
345                 c: "locale",
346                 D: "%m/%d/%y",
347                 F: "%Y-%m-%d",
348                 h: "%b",
349                 n: "\n",
350                 r: "%I:%M:%S %p",
351                 R: "%H:%M",
352                 t: "\t",
353                 T: "%H:%M:%S",
354                 x: "locale",
355                 X: "locale"
356                 //"+": "%a %b %e %T %Z %Y"
357         },
358
359          /**
360          * Takes a native JavaScript Date and formats it as a string for display to user.
361          *
362          * @for DataType.Date
363          * @method format
364          * @param oDate {Date} Date.
365          * @param oConfig {Object} (Optional) Object literal of configuration values:
366          *  <dl>
367          *   <dt>format {String} (Optional)</dt>
368          *   <dd>
369          *   <p>
370          *   Any strftime string is supported, such as "%I:%M:%S %p". strftime has several format specifiers defined by the Open group at 
371          *   <a href="http://www.opengroup.org/onlinepubs/007908799/xsh/strftime.html">http://www.opengroup.org/onlinepubs/007908799/xsh/strftime.html</a>
372          *   PHP added a few of its own, defined at <a href="http://www.php.net/strftime">http://www.php.net/strftime</a>
373          *   </p>
374          *   <p>
375          *   This javascript implementation supports all the PHP specifiers and a few more.  The full list is below.
376          *   </p>
377          *   <p>
378          *   If not specified, it defaults to the ISO 8601 standard date format: %Y-%m-%d.
379      *   This may be overridden by the deprecated Y.config.dateFormat property.
380          *   </p>
381          *   <dl>
382          *      <dt>%a</dt> <dd>abbreviated weekday name according to the current locale</dd>
383          *      <dt>%A</dt> <dd>full weekday name according to the current locale</dd>
384          *      <dt>%b</dt> <dd>abbreviated month name according to the current locale</dd>
385          *      <dt>%B</dt> <dd>full month name according to the current locale</dd>
386          *      <dt>%c</dt> <dd>preferred date and time representation for the current locale</dd>
387          *      <dt>%C</dt> <dd>century number (the year divided by 100 and truncated to an integer, range 00 to 99)</dd>
388          *      <dt>%d</dt> <dd>day of the month as a decimal number (range 01 to 31)</dd>
389          *      <dt>%D</dt> <dd>same as %m/%d/%y</dd>
390          *      <dt>%e</dt> <dd>day of the month as a decimal number, a single digit is preceded by a space (range " 1" to "31")</dd>
391          *      <dt>%F</dt> <dd>same as %Y-%m-%d (ISO 8601 date format)</dd>
392          *      <dt>%g</dt> <dd>like %G, but without the century</dd>
393          *      <dt>%G</dt> <dd>The 4-digit year corresponding to the ISO week number</dd>
394          *      <dt>%h</dt> <dd>same as %b</dd>
395          *      <dt>%H</dt> <dd>hour as a decimal number using a 24-hour clock (range 00 to 23)</dd>
396          *      <dt>%I</dt> <dd>hour as a decimal number using a 12-hour clock (range 01 to 12)</dd>
397          *      <dt>%j</dt> <dd>day of the year as a decimal number (range 001 to 366)</dd>
398          *      <dt>%k</dt> <dd>hour as a decimal number using a 24-hour clock (range 0 to 23); single digits are preceded by a blank. (See also %H.)</dd>
399          *      <dt>%l</dt> <dd>hour as a decimal number using a 12-hour clock (range 1 to 12); single digits are preceded by a blank. (See also %I.) </dd>
400          *      <dt>%m</dt> <dd>month as a decimal number (range 01 to 12)</dd>
401          *      <dt>%M</dt> <dd>minute as a decimal number</dd>
402          *      <dt>%n</dt> <dd>newline character</dd>
403          *      <dt>%p</dt> <dd>either "AM" or "PM" according to the given time value, or the corresponding strings for the current locale</dd>
404          *      <dt>%P</dt> <dd>like %p, but lower case</dd>
405          *      <dt>%r</dt> <dd>time in a.m. and p.m. notation equal to %I:%M:%S %p</dd>
406          *      <dt>%R</dt> <dd>time in 24 hour notation equal to %H:%M</dd>
407          *      <dt>%s</dt> <dd>number of seconds since the Epoch, ie, since 1970-01-01 00:00:00 UTC</dd>
408          *      <dt>%S</dt> <dd>second as a decimal number</dd>
409          *      <dt>%t</dt> <dd>tab character</dd>
410          *      <dt>%T</dt> <dd>current time, equal to %H:%M:%S</dd>
411          *      <dt>%u</dt> <dd>weekday as a decimal number [1,7], with 1 representing Monday</dd>
412          *      <dt>%U</dt> <dd>week number of the current year as a decimal number, starting with the
413          *                      first Sunday as the first day of the first week</dd>
414          *      <dt>%V</dt> <dd>The ISO 8601:1988 week number of the current year as a decimal number,
415          *                      range 01 to 53, where week 1 is the first week that has at least 4 days
416          *                      in the current year, and with Monday as the first day of the week.</dd>
417          *      <dt>%w</dt> <dd>day of the week as a decimal, Sunday being 0</dd>
418          *      <dt>%W</dt> <dd>week number of the current year as a decimal number, starting with the
419          *                      first Monday as the first day of the first week</dd>
420          *      <dt>%x</dt> <dd>preferred date representation for the current locale without the time</dd>
421          *      <dt>%X</dt> <dd>preferred time representation for the current locale without the date</dd>
422          *      <dt>%y</dt> <dd>year as a decimal number without a century (range 00 to 99)</dd>
423          *      <dt>%Y</dt> <dd>year as a decimal number including the century</dd>
424          *      <dt>%z</dt> <dd>numerical time zone representation</dd>
425          *      <dt>%Z</dt> <dd>time zone name or abbreviation</dd>
426          *      <dt>%%</dt> <dd>a literal "%" character</dd>
427          *   </dl>
428          *  </dd>
429          *  <dt>locale {String} (Deprecated, optional)</dt>
430          *  <dd>
431      *   <b>Deprecated - use Y.config.lang instead, which provides access to a much larger set of built-in languages.</b>
432          *   The locale to use when displaying days of week, months of the year, and other locale specific
433          *   strings. If not specified, this defaults to "en" (though this may be overridden by the deprecated Y.config.locale).
434          *   The following locales are built in:
435          *   <dl>
436          *    <dt>en</dt>
437          *    <dd>English</dd>
438          *    <dt>en-US</dt>
439          *    <dd>US English</dd>
440          *    <dt>en-GB</dt>
441          *    <dd>British English</dd>
442          *    <dt>en-AU</dt>
443          *    <dd>Australian English (identical to British English)</dd>
444          *   </dl>
445          *   More locales may be added by subclassing of the deprecated Y.DataType.Date.Locale["en"].
446          *   See Y.DataType.Date.Locale for more information.
447          *  </dd>
448          * </dl>
449          * @return {String} Formatted date for display.
450          */
451         format : function (oDate, oConfig) {
452                 oConfig = oConfig || {};
453                 
454                 if(!Y.Lang.isDate(oDate)) {
455                         return Y.Lang.isValue(oDate) ? oDate : "";
456                 }
457
458                 var format, resources, compatMode, sLocale, LOCALE;
459
460         // Y.config.dateFormat is deprecated - remove from YUI 3.2
461         format = oConfig.format || Y.config.dateFormat  || "%Y-%m-%d";
462         // compatMode supports deprecated features - remove from YUI 3.2
463         compatMode = Y.Lang.isUndefined(Y.config.lang) && (Y.Lang.isValue(oConfig.locale) || Y.Lang.isValue(Y.config.locale));
464         if (compatMode) {
465                         sLocale = oConfig.locale || Y.config.locale;
466                         LOCALE = Y.DataType.Date.Locale;
467             sLocale = sLocale.replace(/_/g, "-");
468             
469             // Make sure we have a definition for the requested locale, or default to en.
470             if(!LOCALE[sLocale]) {
471                 var tmpLocale = sLocale.replace(/-[a-zA-Z]+$/, "");
472                 if(tmpLocale in LOCALE) {
473                     sLocale = tmpLocale;
474                 } else if(Y.config.locale in LOCALE) {
475                     sLocale = Y.config.locale;
476                 } else {
477                     sLocale = "en";
478                 }
479             }
480     
481             resources = LOCALE[sLocale];
482         } else {
483             resources = Y.Intl.get('datatype-date-format');
484         }
485
486                 var replace_aggs = function (m0, m1) {
487                         if (compatMode && m1 === "r") {
488                             return resources[m1];
489                         }
490                         var f = Dt.aggregates[m1];
491                         return (f === "locale" ? resources[m1] : f);
492                 };
493
494                 var replace_formats = function (m0, m1) {
495                         var f = Dt.formats[m1];
496                         switch(Y.Lang.type(f)) {
497                                 case "string":                                  // string => built in date function
498                                         return oDate[f]();
499                                 case "function":                                // function => our own function
500                                         return f.call(oDate, oDate, resources);
501                                 case "array":                                   // built in function with padding
502                                         if(Y.Lang.type(f[0]) === "string") {
503                                                 return xPad(oDate[f[0]](), f[1]);
504                                         } // no break; (fall through to default:)
505                                 default:
506                     // Y.config.dateFormat is deprecated - remove from YUI 3.2
507                                         return m1;
508                         }
509                 };
510
511                 // First replace aggregates (run in a loop because an agg may be made up of other aggs)
512                 while(format.match(/%[cDFhnrRtTxX]/)) {
513                         format = format.replace(/%([cDFhnrRtTxX])/g, replace_aggs);
514                 }
515
516                 // Now replace formats (do not run in a loop otherwise %%a will be replace with the value of %a)
517                 var str = format.replace(/%([aAbBCdegGHIjklmMpPsSuUVwWyYzZ%])/g, replace_formats);
518
519                 replace_aggs = replace_formats = undefined;
520
521                 return str;
522         }
523 };
524
525 Y.mix(Y.namespace("DataType.Date"), Dt);
526 /**
527  * @module datatype
528 */
529
530 /**
531  * The Date.Locale class is a container for all localised date strings
532  * used by Y.DataType.Date. It is used internally, but may be extended
533  * to provide new date localisations.
534  *
535  * To create your own Locale, follow these steps:
536  * <ol>
537  *  <li>Find an existing locale that matches closely with your needs</li>
538  *  <li>Use this as your base class.  Use Y.DataType.Date.Locale["en"] if nothing
539  *   matches.</li>
540  *  <li>Create your own class as an extension of the base class using
541  *   Y.merge, and add your own localisations where needed.</li>
542  * </ol>
543  * See the Y.DataType.Date.Locale["en-US"] and Y.DataType.Date.Locale["en-GB"]
544  * classes which extend Y.DataType.Date.Locale["en"].
545  *
546  * For example, to implement locales for French french and Canadian french,
547  * we would do the following:
548  * <ol>
549  *  <li>For French french, we have no existing similar locale, so use
550  *   Y.DataType.Date.Locale["en"] as the base, and extend it:
551  *   <pre>
552  *      Y.DataType.Date.Locale["fr"] = Y.merge(Y.DataType.Date.Locale, {
553  *          a: ["dim", "lun", "mar", "mer", "jeu", "ven", "sam"],
554  *          A: ["dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi"],
555  *          b: ["jan", "f&eacute;v", "mar", "avr", "mai", "jun", "jui", "ao&ucirc;", "sep", "oct", "nov", "d&eacute;c"],
556  *          B: ["janvier", "f&eacute;vrier", "mars", "avril", "mai", "juin", "juillet", "ao&ucirc;t", "septembre", "octobre", "novembre", "d&eacute;cembre"],
557  *          c: "%a %d %b %Y %T %Z",
558  *          p: ["", ""],
559  *          P: ["", ""],
560  *          x: "%d.%m.%Y",
561  *          X: "%T"
562  *      });
563  *   </pre>
564  *  </li>
565  *  <li>For Canadian french, we start with French french and change the meaning of \%x:
566  *   <pre>
567  *      Y.DataType.Date.Locale["fr-CA"] = Y.merge(Y.DataType.Date.Locale["fr"], {
568  *          x: "%Y-%m-%d"
569  *      });
570  *   </pre>
571  *  </li>
572  * </ol>
573  *
574  * With that, you can use your new locales:
575  * <pre>
576  *    var d = new Date("2008/04/22");
577  *    Y.DataType.Date.format(d, { format: "%A, %d %B == %x", locale: "fr" });
578  * </pre>
579  * will return:
580  * <pre>
581  *    mardi, 22 avril == 22.04.2008
582  * </pre>
583  * And
584  * <pre>
585  *    Y.DataType.Date.format(d, {format: "%A, %d %B == %x", locale: "fr-CA" });
586  * </pre>
587  * Will return:
588  * <pre>
589  *   mardi, 22 avril == 2008-04-22
590  * </pre>
591  * @requires oop
592  * @class DataType.Date.Locale
593  * @static
594  * @deprecated - use Y.config.lang to request one of many built-in languages instead.
595  */
596 var YDateEn = {
597         a: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
598         A: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
599         b: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
600         B: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
601         c: "%a %d %b %Y %T %Z",
602         p: ["AM", "PM"],
603         P: ["am", "pm"],
604         r: "%I:%M:%S %p",
605         x: "%d/%m/%y",
606         X: "%T"
607 };
608
609 Y.namespace("DataType.Date.Locale");
610
611 Y.DataType.Date.Locale["en"] = YDateEn;
612
613 Y.DataType.Date.Locale["en-US"] = Y.merge(YDateEn, {
614         c: "%a %d %b %Y %I:%M:%S %p %Z",
615         x: "%m/%d/%Y",
616         X: "%I:%M:%S %p"
617 });
618
619 Y.DataType.Date.Locale["en-GB"] = Y.merge(YDateEn, {
620         r: "%l:%M:%S %P %Z"
621 });
622 Y.DataType.Date.Locale["en-AU"] = Y.merge(YDateEn);
623
624
625
626
627 }, '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']});
628
629
630 YUI.add('datatype-date', function(Y){}, '3.3.0' ,{use:['datatype-date-parse', 'datatype-date-format']});
631
632 YUI.add('datatype-xml-parse', function(Y) {
633
634 /**
635  * Parse XML submodule.
636  *
637  * @module datatype
638  * @submodule datatype-xml-parse
639  * @for DataType.XML
640  */
641
642 var LANG = Y.Lang;
643
644 Y.mix(Y.namespace("DataType.XML"), {
645     /**
646      * Converts data to type XMLDocument.
647      *
648      * @method parse
649      * @param data {String} Data to convert.
650      * @return {XMLDoc} XML Document.
651      */
652     parse: function(data) {
653         var xmlDoc = null;
654         if(LANG.isString(data)) {
655             try {
656                 if(!LANG.isUndefined(ActiveXObject)) {
657                         xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
658                         xmlDoc.async = false;
659                         xmlDoc.loadXML(data);
660                 }
661             }
662             catch(ee) {
663                 try {
664                     if(!LANG.isUndefined(DOMParser)) {
665                         xmlDoc = new DOMParser().parseFromString(data, "text/xml");
666                     }
667                 }
668                 catch(e) {
669                 }
670             }
671         }
672         
673         if( (LANG.isNull(xmlDoc)) || (LANG.isNull(xmlDoc.documentElement)) || (xmlDoc.documentElement.nodeName === "parsererror") ) {
674         }
675         
676         return xmlDoc;
677     }
678 });
679
680 // Add Parsers shortcut
681 Y.namespace("Parsers").xml = Y.DataType.XML.parse;
682
683
684
685 }, '3.3.0' ,{requires:['yui-base']});
686 YUI.add('datatype-xml-format', function(Y) {
687
688 /**
689  * Format XML submodule.
690  *
691  * @module datatype
692  * @submodule datatype-xml-format
693  */
694
695 /**
696  * XML submodule.
697  *
698  * @module datatype
699  * @submodule datatype-xml
700  */
701
702 /**
703  * DataType.XML provides a set of utility functions to operate against XML documents.
704  *
705  * @class DataType.XML
706  * @static
707  */
708 var LANG = Y.Lang;
709
710 Y.mix(Y.namespace("DataType.XML"), {
711     /**
712      * Converts data to type XMLDocument.
713      *
714      * @method format
715      * @param data {XMLDoc} Data to convert.
716      * @return {String} String.
717      */
718     format: function(data) {
719         try {
720             if(!LANG.isUndefined(XMLSerializer)) {
721                 return (new XMLSerializer()).serializeToString(data);
722             }
723         }
724         catch(e) {
725             if(data && data.xml) {
726                 return data.xml;
727             }
728             else {
729                 return (LANG.isValue(data) && data.toString) ? data.toString() : "";
730             }
731         }
732     }
733 });
734
735
736
737 }, '3.3.0' ,{requires:['yui-base']});
738
739
740 YUI.add('datatype-xml', function(Y){}, '3.3.0' ,{use:['datatype-xml-parse', 'datatype-xml-format']});
741
742
743
744 YUI.add('datatype', function(Y){}, '3.3.0' ,{use:['datatype-number', 'datatype-date', 'datatype-xml']});
745