]> git.pond.sub.org Git - eow/blob - static/dojo-release-1.1.1/dojox/dtl/filter/misc.js
add Dojo 1.1.1
[eow] / static / dojo-release-1.1.1 / dojox / dtl / filter / misc.js
1 if(!dojo._hasResource["dojox.dtl.filter.misc"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojox.dtl.filter.misc"] = true;
3 dojo.provide("dojox.dtl.filter.misc");
4
5 dojo.mixin(dojox.dtl.filter.misc, {
6         filesizeformat: function(value){
7                 // summary: Format the value like a 'human-readable' file size (i.e. 13 KB, 4.1 MB, 102bytes, etc).
8                 value = parseFloat(value);
9                 if(value < 1024){
10                         return (value == 1) ? value + " byte" : value + " bytes";
11                 }else if(value < 1024 * 1024){
12                         return (value / 1024).toFixed(1) + " KB";
13                 }else if(value < 1024 * 1024 * 1024){
14                         return (value / 1024 / 1024).toFixed(1) + " MB";
15                 }
16                 return (value / 1024 / 1024 / 1024).toFixed(1) + " GB";
17         },
18         pluralize: function(value, arg){
19                 // summary:
20                 //              Returns a plural suffix if the value is not 1, for '1 vote' vs. '2 votes'
21                 //      description:
22                 //              By default, 's' is used as a suffix; if an argument is provided, that string
23                 //              is used instead. If the provided argument contains a comma, the text before
24                 //              the comma is used for the singular case.
25                 arg = arg || 's';
26                 if(arg.indexOf(",") == -1){
27                         arg = "," + arg;
28                 }
29                 var parts = arg.split(",");
30                 if(parts.length > 2){
31                         return "";
32                 }
33                 var singular = parts[0];
34                 var plural = parts[1];
35
36                 if(parseInt(value) != 1){
37                         return plural;
38                 }
39                 return singular;
40         },
41         _phone2numeric: { a: 2, b: 2, c: 2, d: 3, e: 3, f: 3, g: 4, h: 4, i: 4, j: 5, k: 5, l: 5, m: 6, n: 6, o: 6, p: 7, r: 7, s: 7, t: 8, u: 8, v: 8, w: 9, x: 9, y: 9 },
42         phone2numeric: function(value){
43                 // summary: Takes a phone number and converts it in to its numerical equivalent
44                 var dm = dojox.dtl.filter.misc;
45                 value = value + "";
46                 var output = "";
47                 for(var i = 0; i < value.length; i++){
48                         var chr = value.charAt(i).toLowerCase();
49                         (dm._phone2numeric[chr]) ? output += dm._phone2numeric[chr] : output += value.charAt(i);
50                 }
51                 return output;
52         },
53         pprint: function(value){
54                 // summary: A wrapper around toJson unless something better comes along
55                 return dojo.toJson(value);
56         }
57 });
58
59 }