Develop and Download Open Source Software

Browse Subversion Repository

Contents of /whitespacejs/trunk/src/core.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (show annotations) (download) (as text)
Wed Dec 28 02:10:34 2011 UTC (12 years, 4 months ago) by thejs
File MIME type: application/x-javascript
File size: 2215 byte(s)


1 /**
2 * @package thejs.whitespace
3 * @class
4 * @name Whitespace
5 */
6 (function(G){
7
8 G["Whitespace"] = function()
9 {
10 return prot.parse.apply(prot, arguments);
11 };
12
13 var D = document;
14
15 var __TABLE__ = {
16 "/*{{[[EOL]]}}*/" : G["__EOL__"],
17 "/*{{[[TAB]]}}*/" : "\t"
18 };
19
20 /** @lends Whitespace */
21 var prot = {
22
23 /**
24 * ホワイトスペースノードを実体化したDOMツリーを返す.
25 *
26 * @constructs
27 * @param {String} text
28 * @param {Object} [table]
29 * @return DOM
30 */
31 parse : function(text, table)
32 {
33 if (typeof table == "object") {
34 for (var key in table) {
35 __TABLE__[key] = table[key];
36 }
37 }
38 return this.__parse(text);
39 },
40
41 /**
42 * テキストをデコードして返す.
43 *
44 * @param {String} text
45 * @return {String}
46 */
47 __decode : function(text)
48 {
49 var LIST = __TABLE__;
50 for (var k in LIST) {
51 var v = LIST[k];
52 text = text.
53 split(k).join(v);
54 }
55 return text;
56 },
57
58 /**
59 * テキストをエンコードして返す.
60 *
61 * @param {String} text
62 * @return {String}
63 */
64 __encode : function(text)
65 {
66 var LIST = __TABLE__;
67 for (var k in LIST) {
68 var v = LIST[k];
69 text = text.
70 split(v).join(k);
71 }
72 return text;
73 },
74
75 /**
76 * ホワイトスペースノードを実体化したDOMツリーを返す.
77 *
78 * @param {String} str
79 * @return DOM
80 */
81 __parse : function(str)
82 {
83 var node, list, w;
84 var self = this;
85 node = D.createElement("div");
86 node.innerHTML = " ";
87 str+=G["__EOL__"];
88 if (!(w = node.childNodes[0])) {
89 str = this.__encode(str);
90 }
91 node.innerHTML = str;
92 list = node.childNodes;
93 if (!w) (function(cs){
94 for(var i=0; i<cs.length; i++){
95 var v, c = cs[i];
96 switch(c.nodeType){
97 case 1 :
98 arguments.callee(c.attributes);
99 arguments.callee(c.childNodes);
100 break;
101 default :
102 try {
103 if ((v = self.__decode(c.nodeValue))
104 != c.nodeValue) {
105 c.nodeValue = v;
106 }
107 }catch(e){}
108 }
109 }
110 })(list);
111 return list;
112 }
113 };
114 })(window);

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26