Added wrt files, prior to converting into Qt/C++.
[ptas] / wrt / misc / rss / preview / script / lib / console.js
1 //      for console support\r
2 if (typeof window.parent.console == 'undefined') {\r
3         window.console = {\r
4         \r
5                         sprintf: function(args){\r
6                                 if (typeof args == 'undefined') {\r
7                                         return null;\r
8                                 }\r
9                                 \r
10                                 if (args.length < 1) {\r
11                                         return null;\r
12                                 };\r
13                                 \r
14                                 if (typeof args[0] != 'string') {\r
15                                         return null;\r
16                                 }\r
17                                 \r
18                                 if (typeof RegExp == 'undefined') {\r
19                                         return null;\r
20                                 }\r
21                                 \r
22                                 if (args.length == 1) {\r
23                                         return args[0];\r
24                                 }\r
25                                 \r
26                                 \r
27                                 var str = args[0];\r
28                                 var newString = args[0];\r
29                                 var arr = new Array();\r
30                                 var exp = new RegExp(/[^%](%)([a-zA-Z])/g);\r
31                                 var match = null;\r
32                                 var lastMatch = 0;\r
33                                 var argPos = 1;\r
34                                 while (match = exp.exec(str) && argPos < args.length) {\r
35                                         if (str[exp.lastIndex - 1] == "%") {\r
36                                                 \r
37                                         }\r
38                                         else \r
39                                                 if (str[exp.lastIndex - 1] == "d") {\r
40                                                         arr.push(str.substring(lastMatch, exp.lastIndex - 2));\r
41                                                         arr.push(args[argPos++]);\r
42                                                 }\r
43                                                 else \r
44                                                         if (str[exp.lastIndex - 1] == "i") {\r
45                                                                 arr.push(str.substring(lastMatch, exp.lastIndex - 2));\r
46                                                                 arr.push(args[argPos++]);\r
47                                                         }\r
48                                                         else \r
49                                                                 if (str[exp.lastIndex - 1] == "f") {\r
50                                                                         arr.push(str.substring(lastMatch, exp.lastIndex - 2));\r
51                                                                         arr.push(args[argPos++]);\r
52                                                                 }\r
53                                                                 else \r
54                                                                         if (str[exp.lastIndex - 1] == "s") {\r
55                                                                                 arr.push(str.substring(lastMatch, exp.lastIndex - 2));\r
56                                                                                 arr.push(args[argPos++]);\r
57                                                                         }\r
58                                                                         else \r
59                                                                                 if (str[exp.lastIndex - 1] != "%") {\r
60                                                                                         arr.push(str.substring(lastMatch, exp.lastIndex - 2));\r
61                                                                                         arr.push("\"");\r
62                                                                                         arr.push(args[argPos++]);\r
63                                                                                         arr.push("\"");\r
64                                                                                 }\r
65                                         lastMatch = exp.lastIndex;\r
66                                 }\r
67                                 if (lastMatch < str.length) {\r
68                                         arr.push(str.substring(lastMatch, str.length));\r
69                                 }\r
70                                 while (argPos < args.length) {\r
71                                         arr.push(" ");\r
72                                         arr.push(args[argPos++]);\r
73                                 }\r
74                                 return arr.join("").replace(/\%\%/g,"%");\r
75                         },\r
76                 error: function(){\r
77                         var errorStr = console.sprintf(arguments);\r
78                         if (errorStr) {\r
79                                 _BRIDGE_REF.nokia.layout.log('error', errorStr);\r
80                         }\r
81                 },\r
82                 info: function(){\r
83                         var errorStr = console.sprintf(arguments);\r
84                         if (errorStr) {\r
85                                 _BRIDGE_REF.nokia.layout.log('info', errorStr);\r
86                         }\r
87                 },\r
88                 warn: function(){\r
89                         var errorStr = console.sprintf(arguments);\r
90                         if (errorStr) {\r
91                                 _BRIDGE_REF.nokia.layout.log('warn', errorStr);\r
92                         }\r
93                 },\r
94                 log: function(){\r
95                         var errorStr = console.sprintf(arguments);\r
96                         if (errorStr) {\r
97                                 _BRIDGE_REF.nokia.layout.log('log', errorStr);\r
98                         }\r
99                 },\r
100                 debug: function(){\r
101                         var errorStr = console.sprintf(arguments);\r
102                         if (errorStr) {\r
103                                 _BRIDGE_REF.nokia.layout.log('debug', errorStr);\r
104                         }\r
105                 },\r
106                 assert: function(){\r
107                         var errorStr = console.sprintf(arguments);\r
108                         if (errorStr) {\r
109                                 //      @todo\r
110                         }\r
111                 }\r
112         }\r
113         \r
114         //      enable the Console.\r
115         _BRIDGE_REF.nokia.layout._console_enabled = true;\r
116         _BRIDGE_REF.nokia.layout.render();\r
117 \r
118 }\r
119 \r
120 //      make TRUE console.js script loaded\r
121 window.parent.NOKIA.scriptsLoaded.console = true;\r