code-display_wev8.js
9.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
/*
* Ext JS Library 2.0.2
* Copyright(c) 2006-2008, Ext JS, LLC.
* licensing@extjs.com
*
* http://extjs.com/license
*/
// Create and append to the body, a Panel containing a block of code from the passed URL
function createCodePanel(url, title) {
var panel = new Ext.Panel({
hideMode: 'visibility',
title: title,
width: 750,
style: {
'margin-top': '10px'
},
hideCollapseTool: true,
titleCollapse: true,
collapsible: true,
collapsed: true,
autoScroll: true,
renderTo: Ext.getBody(),
listeners: {
render: function(p) {
p.getUpdater().setRenderer({
render: Ext.isIE ? function(el, response, scripts, callback) {
el.update('');
var np = el.createChild({
tag: 'pre',
cls: 'code',
cn: {
tag: 'code'
}
});
var t = response.responseText.split("\n");
var c = np.child('code', true);
for (var i = 0, l = t.length; i < l; i++) {
var pre = document.createElement('pre');
if (t[i].length) {
pre.appendChild(document.createTextNode(t[i]));
c.appendChild(pre);
} else if (i < (l - 1)) {
c.appendChild(document.createElement("br"));
}
}
} : function(el, response, scripts, callback) {
el.update('');
el.createChild({
tag: 'pre',
cls: 'code',
cn: {
tag: 'code',
html: response.responseText
}
});
}
});
},
beforeexpand: function(p) {
p.load(url);
},
single: true
}
});
}
// Patch to allow XHR to local files. From hendricd: http://extjs.com/forum/member.php?u=8730
Ext.apply( Ext.lib.Ajax ,
{ forceActiveX:false,
createXhrObject:function(transactionId)
{
var obj={ status:{isError:false}
, tId:transactionId}, http;
try
{
if(Ext.isIE7 && !!this.forceActiveX){throw("IE7forceActiveX");}
obj.conn= new XMLHttpRequest();
}
catch(e)
{
for (var i = 0; i < this.activeX.length; ++i) {
try
{
obj.conn= new ActiveXObject(this.activeX[i]);
break;
}
catch(e) {
}
}
}
finally
{
obj.status.isError = typeof(obj.conn) === undefined;
}
return obj;
},
getHttpStatus: function(reqObj){
var statObj = { status:0
,statusText:''
,isError:false
,isLocal:false
,isOK:false
,error:null};
try {
if(!reqObj)throw('noobj');
statObj.status = reqObj.status;
statObj.isLocal = !reqObj.status && location.protocol == "file:" ||
Ext.isSafari && reqObj.status === undefined;
statObj.isOK = (statObj.isLocal || (statObj.status > 199 && statObj.status < 300));
statObj.statusText = reqObj.statusText || '';
} catch(e){ //status may not avail/valid yet (or called too early).
}
return statObj;
},
handleTransactionResponse:function(o, callback, isAbort)
{
callback = callback || {};
var responseObject=null;
if(!o.status.isError){
o.status = this.getHttpStatus(o.conn);
/* create and enhance the response with proper status and XMLDOM if necessary */
responseObject = this.createResponseObject(o, callback.argument);
}
if(o.status.isError){ /* checked again in case exception was raised - ActiveX was disabled during XML-DOM creation? */
// And mixin everything the XHR object had to offer as well
responseObject = Ext.applyIf(responseObject||{},this.createExceptionObject(o.tId, callback.argument, (isAbort ? isAbort : false)));
}
responseObject.options = o.options;
responseObject.stat = o.status;
if (o.status.isOK && !o.status.isError) {
if (callback.success) {
if (!callback.scope) {
callback.success(responseObject);
}
else {
callback.success.apply(callback.scope, [responseObject]);
}
}
} else {
if (callback.failure) {
if (!callback.scope) {
callback.failure(responseObject);
}
else {
callback.failure.apply(callback.scope, [responseObject]);
}
}
}
if(o.options.async){
this.releaseObject(o);
responseObject = null;
}else{
this.releaseObject(o);
return responseObject;
}
},
createResponseObject:function(o, callbackArg)
{
var obj = {};
var headerObj = {},headerStr='';
try{ //to catch bad encoding problems here
obj.responseText = o.conn.responseText;
}catch(e){obj.responseText ='';}
obj.responseXML = o.conn.responseXML;
try{
headerStr = o.conn.getAllResponseHeaders()||'';
} catch(e){}
if(o.status.isLocal){
o.status.isOK = ((o.status.status = (!!obj.responseText.length)?200:404) == 200);
if(o.status.isOK && (!obj.responseXML || obj.responseXML.childNodes.length == 0)){
var xdoc=null;
try{ //ActiveX may be disabled
if(typeof(DOMParser) == 'undefined'){
xdoc=new ActiveXObject("Microsoft.XMLDOM");
xdoc.async="false";
xdoc.loadXML(obj.responseText);
}else{
try{ //Opera 9 will fail parsing non-XML content, so trap here.
var domParser = new DOMParser();
xdoc = domParser.parseFromString(obj.responseText, 'application\/xml');
}catch(ex){}
finally{domParser = null;}
}
} catch(ex){
o.status.isError = true;
o.status.error = ex;
}
obj.responseXML = xdoc;
}
if(obj.responseXML){
var parseBad = (obj.responseXML.parseError || 0) != 0 || obj.responseXML.childNodes.length == 0;
if(!parseBad){
headerStr = 'Content-Type: ' + (obj.responseXML.contentType || 'text\/xml') + '\n' + headerStr ;
}
}
}
var header = headerStr.split('\n');
for (var i = 0; i < header.length; i++) {
var delimitPos = header[i].indexOf(':');
if (delimitPos != -1) {
headerObj[header[i].substring(0, delimitPos)] = header[i].substring(delimitPos + 2);
}
}
obj.tId = o.tId;
obj.status = o.status.status;
obj.statusText = o.status.statusText;
obj.getResponseHeader = headerObj;
obj.getAllResponseHeaders = headerStr;
obj.stat = o.status
if (typeof callbackArg !== undefined) {
obj.argument = callbackArg;
}
return obj;
},
request : function(method, uri, cb, data, options) {
options = Ext.apply({async:true,
headers:false,
userId:null,
password:null,
xmlData:null }, options||{});
var hs = options.headers;
if(hs){
for(var h in hs){
if(hs.hasOwnProperty(h)){
this.initHeader(h, hs[h], false);
}
}
}
if(options.xmlData){
this.initHeader('Content-Type', 'text/xml', false);
method = 'POST';
data = options.xmlData;
}
return this.makeRequest(method, uri, cb, data, options);
},
asyncRequest:function(method, uri, callback, postData)
{
var o = this.getConnectionObject();
if (!o || o.status.isError) {
return null;
}
else {
o.options = options;
try{
o.conn.open(method, uri, true);
} catch(ex){
o.status.isError = true;
o.status.error = ex;
return Ext.apply(o,this.handleTransactionResponse(o, callback));
}
if (this.useDefaultXhrHeader) {
if (!this.defaultHeaders['X-Requested-With']) {
this.initHeader('X-Requested-With', this.defaultXhrHeader, true);
}
}
if(postData && this.useDefaultHeader){
this.initHeader('Content-Type', this.defaultPostHeader);
}
if (this.hasDefaultHeaders || this.hasHeaders) {
this.setHeader(o);
}
this.handleReadyState(o, callback);
try{ o.conn.send(postData || null);
} catch(ex){
o.status.isError=true;
o.status.error = ex;
return Ext.apply(o,this.handleTransactionResponse(o, callback));
}
return o;
}
},
makeRequest:function(method, uri, callback, postData, options)
{
var o = this.getConnectionObject();
if (!o || o.status.isError) {
return null;
}
else {
o.options = options;
try{
o.conn.open(method, uri, options.async, options.userId, options.password);
} catch(ex){
o.status.isError = true;
o.status.error = ex;
var r=this.handleTransactionResponse(o, callback);
return Ext.apply(o,r);
}
if (this.useDefaultXhrHeader) {
if (!this.defaultHeaders['X-Requested-With']) {
this.initHeader('X-Requested-With', this.defaultXhrHeader, true);
}
}
if(postData && this.useDefaultHeader){
this.initHeader('Content-Type', this.defaultPostHeader);
}
if (this.hasDefaultHeaders || this.hasHeaders) {
this.setHeader(o);
}
if(o.options.async){ //Timers won't work here as it's a blocking call
this.handleReadyState(o, callback);
}
try{ o.conn.send(postData || null);
} catch(ex){
//Ext.apply(o,this.handleTransactionResponse(o, callback));
}
return options.async?o:Ext.apply(o,this.handleTransactionResponse(o, callback));
}
}});
Ext.lib.Ajax.forceActiveX = (document.location.protocol == 'file:');/* or other true/false mechanism */