1318 |
alexandre_ |
1 |
/*
|
|
|
2 |
Copyright (c) 2004-2006, The Dojo Foundation
|
|
|
3 |
All Rights Reserved.
|
|
|
4 |
|
|
|
5 |
Licensed under the Academic Free License version 2.1 or above OR the
|
|
|
6 |
modified BSD license. For more information on Dojo licensing, see:
|
|
|
7 |
|
|
|
8 |
http://dojotoolkit.org/community/licensing.shtml
|
|
|
9 |
*/
|
|
|
10 |
|
1422 |
alexandre_ |
11 |
|
|
|
12 |
|
1318 |
alexandre_ |
13 |
dojo.provide("dojo.widget.html.stabile");
|
|
|
14 |
dojo.widget.html.stabile = {_sqQuotables:new RegExp("([\\\\'])", "g"), _depth:0, _recur:false, depthLimit:2};
|
|
|
15 |
dojo.widget.html.stabile.getState = function (id) {
|
|
|
16 |
dojo.widget.html.stabile.setup();
|
|
|
17 |
return dojo.widget.html.stabile.widgetState[id];
|
|
|
18 |
};
|
|
|
19 |
dojo.widget.html.stabile.setState = function (id, state, isCommit) {
|
|
|
20 |
dojo.widget.html.stabile.setup();
|
|
|
21 |
dojo.widget.html.stabile.widgetState[id] = state;
|
|
|
22 |
if (isCommit) {
|
|
|
23 |
dojo.widget.html.stabile.commit(dojo.widget.html.stabile.widgetState);
|
|
|
24 |
}
|
|
|
25 |
};
|
|
|
26 |
dojo.widget.html.stabile.setup = function () {
|
|
|
27 |
if (!dojo.widget.html.stabile.widgetState) {
|
|
|
28 |
var text = dojo.widget.html.stabile._getStorage().value;
|
|
|
29 |
dojo.widget.html.stabile.widgetState = text ? dj_eval("(" + text + ")") : {};
|
|
|
30 |
}
|
|
|
31 |
};
|
|
|
32 |
dojo.widget.html.stabile.commit = function (state) {
|
|
|
33 |
dojo.widget.html.stabile._getStorage().value = dojo.widget.html.stabile.description(state);
|
|
|
34 |
};
|
|
|
35 |
dojo.widget.html.stabile.description = function (v, showAll) {
|
|
|
36 |
var depth = dojo.widget.html.stabile._depth;
|
|
|
37 |
var describeThis = function () {
|
|
|
38 |
return this.description(this, true);
|
|
|
39 |
};
|
|
|
40 |
try {
|
|
|
41 |
if (v === void (0)) {
|
|
|
42 |
return "undefined";
|
|
|
43 |
}
|
|
|
44 |
if (v === null) {
|
|
|
45 |
return "null";
|
|
|
46 |
}
|
|
|
47 |
if (typeof (v) == "boolean" || typeof (v) == "number" || v instanceof Boolean || v instanceof Number) {
|
|
|
48 |
return v.toString();
|
|
|
49 |
}
|
|
|
50 |
if (typeof (v) == "string" || v instanceof String) {
|
|
|
51 |
var v1 = v.replace(dojo.widget.html.stabile._sqQuotables, "\\$1");
|
|
|
52 |
v1 = v1.replace(/\n/g, "\\n");
|
|
|
53 |
v1 = v1.replace(/\r/g, "\\r");
|
|
|
54 |
return "'" + v1 + "'";
|
|
|
55 |
}
|
|
|
56 |
if (v instanceof Date) {
|
|
|
57 |
return "new Date(" + d.getFullYear + "," + d.getMonth() + "," + d.getDate() + ")";
|
|
|
58 |
}
|
|
|
59 |
var d;
|
|
|
60 |
if (v instanceof Array || v.push) {
|
|
|
61 |
if (depth >= dojo.widget.html.stabile.depthLimit) {
|
|
|
62 |
return "[ ... ]";
|
|
|
63 |
}
|
|
|
64 |
d = "[";
|
|
|
65 |
var first = true;
|
|
|
66 |
dojo.widget.html.stabile._depth++;
|
|
|
67 |
for (var i = 0; i < v.length; i++) {
|
|
|
68 |
if (first) {
|
|
|
69 |
first = false;
|
|
|
70 |
} else {
|
|
|
71 |
d += ",";
|
|
|
72 |
}
|
|
|
73 |
d += arguments.callee(v[i], showAll);
|
|
|
74 |
}
|
|
|
75 |
return d + "]";
|
|
|
76 |
}
|
|
|
77 |
if (v.constructor == Object || v.toString == describeThis) {
|
|
|
78 |
if (depth >= dojo.widget.html.stabile.depthLimit) {
|
|
|
79 |
return "{ ... }";
|
|
|
80 |
}
|
|
|
81 |
if (typeof (v.hasOwnProperty) != "function" && v.prototype) {
|
|
|
82 |
throw new Error("description: " + v + " not supported by script engine");
|
|
|
83 |
}
|
|
|
84 |
var first = true;
|
|
|
85 |
d = "{";
|
|
|
86 |
dojo.widget.html.stabile._depth++;
|
|
|
87 |
for (var key in v) {
|
|
|
88 |
if (v[key] == void (0) || typeof (v[key]) == "function") {
|
|
|
89 |
continue;
|
|
|
90 |
}
|
|
|
91 |
if (first) {
|
|
|
92 |
first = false;
|
|
|
93 |
} else {
|
|
|
94 |
d += ", ";
|
|
|
95 |
}
|
|
|
96 |
var kd = key;
|
|
|
97 |
if (!kd.match(/^[a-zA-Z_][a-zA-Z0-9_]*$/)) {
|
|
|
98 |
kd = arguments.callee(key, showAll);
|
|
|
99 |
}
|
|
|
100 |
d += kd + ": " + arguments.callee(v[key], showAll);
|
|
|
101 |
}
|
|
|
102 |
return d + "}";
|
|
|
103 |
}
|
|
|
104 |
if (showAll) {
|
|
|
105 |
if (dojo.widget.html.stabile._recur) {
|
|
|
106 |
var objectToString = Object.prototype.toString;
|
|
|
107 |
return objectToString.apply(v, []);
|
|
|
108 |
} else {
|
|
|
109 |
dojo.widget.html.stabile._recur = true;
|
|
|
110 |
return v.toString();
|
|
|
111 |
}
|
|
|
112 |
} else {
|
|
|
113 |
throw new Error("Unknown type: " + v);
|
|
|
114 |
return "'unknown'";
|
|
|
115 |
}
|
|
|
116 |
}
|
|
|
117 |
finally {
|
|
|
118 |
dojo.widget.html.stabile._depth = depth;
|
|
|
119 |
}
|
|
|
120 |
};
|
|
|
121 |
dojo.widget.html.stabile._getStorage = function () {
|
|
|
122 |
if (dojo.widget.html.stabile.dataField) {
|
|
|
123 |
return dojo.widget.html.stabile.dataField;
|
|
|
124 |
}
|
|
|
125 |
var form = document.forms._dojo_form;
|
|
|
126 |
return dojo.widget.html.stabile.dataField = form ? form.stabile : {value:""};
|
|
|
127 |
};
|
|
|
128 |
|