Subversion Repositories Applications.papyrus

Rev

Rev 1371 | Details | Compare with Previous | Last modification | View Log | RSS feed

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