Upgrade to ExtJS 3.2.0 - Released 03/30/2010
[extjs.git] / examples / shared / code-display.js
index 1ffca7b..dc13b06 100644 (file)
 /*!
- * Ext JS Library 3.1.1
- * Copyright(c) 2006-2010 Ext JS, LLC
+ * Ext JS Library 3.2.0
+ * Copyright(c) 2006-2010 Ext JS, Inc.
  * licensing@extjs.com
  * http://www.extjs.com/license
  */
-// Create and append to the body, a Panel containing a block of code from the passed URL\r
-function createCodePanel(url, title) {\r
-       var panel = new Ext.Panel({\r
-               hideMode: 'visibility',\r
-               title: title,\r
-       width: 750,\r
-       style: {\r
-               'margin-top': '10px'\r
-       },\r
-       hideCollapseTool: true,\r
-       titleCollapse: true,\r
-       collapsible: true,\r
-       collapsed: true,\r
-               autoScroll: true,\r
-               renderTo: Ext.getBody(),\r
-               listeners: {\r
-                       render: function(p) {\r
-                               p.getUpdater().setRenderer({\r
-                                       render: Ext.isIE ? function(el, response, scripts, callback) {\r
-                                               el.update('');\r
-                                               var np = el.createChild({\r
-                                                       tag: 'pre',\r
-                                                       cls: 'code',\r
-                                                       cn: {\r
-                                                               tag: 'code'\r
-                                                       }\r
-                                               });\r
-                                               var t = response.responseText.split("\n");\r
-                                               var c = np.child('code', true);\r
-                                               for (var i = 0, l = t.length; i < l; i++) {\r
-                                                       var pre = document.createElement('pre');\r
-                                                       if (t[i].length) {\r
-                                                               pre.appendChild(document.createTextNode(t[i]));\r
-                                                               c.appendChild(pre);\r
-                                                       } else if (i < (l - 1)) {\r
-                                                               c.appendChild(document.createElement("br"));\r
-                                                       }\r
-                                                       \r
-                                               }\r
-                                       } : function(el, response, scripts, callback) {\r
-                                               el.update('');\r
-                                               el.createChild({\r
-                                                       tag: 'pre',\r
-                                                       cls: 'code',\r
-                                                       cn: {\r
-                                                               tag: 'code',\r
-                                                               html: response.responseText\r
-                                                       }\r
-                                               });\r
-                                       }\r
-                               });\r
-                       },\r
-                       beforeexpand: function(p) {\r
-                               p.load(url);\r
-                       },\r
-                       single: true\r
-               }\r
-       });\r
-}\r
-\r
-// Patch to allow XHR to local files. From hendricd: http://extjs.com/forum/member.php?u=8730\r
-Ext.apply( Ext.lib.Ajax ,\r
-{ forceActiveX:false,\r
-  createXhrObject:function(transactionId)\r
-        {\r
-            var obj={  status:{isError:false}\r
-                    , tId:transactionId}, http;\r
-            try\r
-            {\r
-               \r
-               if(Ext.isIE7 && !!this.forceActiveX){throw("IE7forceActiveX");}\r
-                \r
-               obj.conn= new XMLHttpRequest();\r
-               \r
-            }\r
-            catch(e)\r
-            {\r
-                for (var i = 0; i < this.activeX.length; ++i) {\r
-                    try\r
-                    {\r
-                        obj.conn= new ActiveXObject(this.activeX[i]);\r
-                       \r
-                        break;\r
-                    }\r
-                    catch(e) { \r
-                    }\r
-                }\r
-            }\r
-            finally\r
-            {\r
-               obj.status.isError = typeof(obj.conn) === undefined;\r
-            }  \r
-            return obj;\r
-            \r
-        },\r
-        \r
-        getHttpStatus: function(reqObj){\r
-        \r
-               var statObj = {  status:0\r
-                               ,statusText:''\r
-                               ,isError:false\r
-                               ,isLocal:false\r
-                               ,isOK:false\r
-                               ,error:null};\r
-               \r
-               try {\r
-                       if(!reqObj)throw('noobj');\r
-                       statObj.status = reqObj.status;\r
-                       \r
-                       statObj.isLocal = !reqObj.status && location.protocol == "file:" || \r
-                                          Ext.isSafari && reqObj.status === undefined;\r
-                       \r
-                       statObj.isOK = (statObj.isLocal || (statObj.status > 199 && statObj.status < 300));\r
-                       statObj.statusText = reqObj.statusText || '';\r
-                   } catch(e){ //status may not avail/valid yet (or called too early).\r
-                     } \r
-                   \r
-               return statObj; \r
-        \r
-        },\r
-        handleTransactionResponse:function(o, callback, isAbort)\r
-               {\r
-       \r
-               \r
-               callback = callback || {};\r
-               var responseObject=null;\r
-               \r
-                if(!o.status.isError){\r
-                       o.status = this.getHttpStatus(o.conn);          \r
-                       /* create and enhance the response with proper status and XMLDOM if necessary */\r
-                       responseObject = this.createResponseObject(o, callback.argument);\r
-                }\r
-               \r
-                if(o.status.isError){ /* checked again in case exception was raised - ActiveX was disabled during XML-DOM creation? */\r
-                    // And mixin everything the XHR object had to offer as well\r
-                  responseObject = Ext.applyIf(responseObject||{},this.createExceptionObject(o.tId, callback.argument, (isAbort ? isAbort : false)));\r
-                  \r
-                }\r
-               \r
-                responseObject.options = o.options;\r
-                responseObject.stat = o.status;\r
-                \r
-                if (o.status.isOK && !o.status.isError) {\r
-                       if (callback.success) {\r
-                               if (!callback.scope) {\r
-                                       callback.success(responseObject);\r
-                               }\r
-                               else {\r
-                                       callback.success.apply(callback.scope, [responseObject]);\r
-                               }\r
-                       }\r
-                 } else {\r
-\r
-                       if (callback.failure) {\r
-                               if (!callback.scope) {\r
-                                       callback.failure(responseObject);\r
-                               }\r
-                               else {\r
-                                       callback.failure.apply(callback.scope, [responseObject]);\r
-                               }\r
-                       }\r
-\r
-                }\r
-               \r
-               if(o.options.async){\r
-                       this.releaseObject(o);  \r
-                       responseObject = null;\r
-               }else{ \r
-                       this.releaseObject(o);\r
-                       return responseObject; \r
-               }\r
-                       \r
-       },\r
-       createResponseObject:function(o, callbackArg)\r
-       {\r
-           var obj = {};\r
-           var headerObj = {},headerStr='';\r
-\r
-           try{  //to catch bad encoding problems here\r
-               obj.responseText = o.conn.responseText;\r
-           }catch(e){obj.responseText ='';}\r
-\r
-           obj.responseXML = o.conn.responseXML;\r
-\r
-           try{\r
-               headerStr = o.conn.getAllResponseHeaders()||'';\r
-           } catch(e){}\r
-\r
-           if(o.status.isLocal){\r
-\r
-                  o.status.isOK = ((o.status.status = (!!obj.responseText.length)?200:404) == 200);\r
-\r
-                  if(o.status.isOK && (!obj.responseXML || obj.responseXML.childNodes.length == 0)){\r
-\r
-                       var xdoc=null;\r
-                       try{   //ActiveX may be disabled\r
-                               if(typeof(DOMParser) == 'undefined'){ \r
-                                       xdoc=new ActiveXObject("Microsoft.XMLDOM"); \r
-                                       xdoc.async="false";\r
-                                       xdoc.loadXML(obj.responseText); \r
-\r
-                               }else{ \r
-                                       try{  //Opera 9 will fail parsing non-XML content, so trap here.\r
-                                               var domParser = new DOMParser(); \r
-                                               xdoc = domParser.parseFromString(obj.responseText, 'application\/xml'); \r
-                                       }catch(ex){}\r
-                                       finally{domParser = null;}\r
-\r
-                               }\r
-                       } catch(ex){ \r
-                               o.status.isError = true; \r
-                               o.status.error = ex;\r
-\r
-                               }\r
-\r
-                       obj.responseXML = xdoc;\r
-                   }\r
-\r
-                   if(obj.responseXML){\r
-\r
-                       var parseBad = (obj.responseXML.parseError || 0) != 0 || obj.responseXML.childNodes.length == 0;\r
-                       if(!parseBad){\r
-                               headerStr = 'Content-Type: ' + (obj.responseXML.contentType || 'text\/xml') + '\n' + headerStr ;\r
-                               }                           \r
-                   }           \r
-\r
-\r
-           }   \r
-\r
-          var header = headerStr.split('\n');\r
-          for (var i = 0; i < header.length; i++) {\r
-               var delimitPos = header[i].indexOf(':');\r
-               if (delimitPos != -1) {\r
-                       headerObj[header[i].substring(0, delimitPos)] = header[i].substring(delimitPos + 2);\r
-               }\r
-           }\r
-\r
-           obj.tId = o.tId;\r
-           obj.status = o.status.status;\r
-           obj.statusText = o.status.statusText;\r
-           obj.getResponseHeader = headerObj;\r
-           obj.getAllResponseHeaders = headerStr;\r
-           obj.stat = o.status\r
-\r
-           if (typeof callbackArg !== undefined) {\r
-               obj.argument = callbackArg;\r
-           }\r
-\r
-           return obj;\r
-        },\r
-        \r
-       request : function(method, uri, cb, data, options) {\r
-                   \r
-                    options = Ext.apply({async:true,\r
-                          headers:false,\r
-                          userId:null,\r
-                          password:null,\r
-                          xmlData:null }, options||{});\r
-                                               \r
-                       var hs = options.headers;\r
-                       if(hs){\r
-                           for(var h in hs){\r
-                               if(hs.hasOwnProperty(h)){\r
-                                   this.initHeader(h, hs[h], false);\r
-                               }\r
-                           }\r
-                       }\r
-                       if(options.xmlData){\r
-                           this.initHeader('Content-Type', 'text/xml', false);\r
-                           method = 'POST';\r
-                           data = options.xmlData;\r
-                       }\r
-                                   \r
-                   return this.makeRequest(method, uri, cb, data, options);\r
-                   \r
-        },\r
-        asyncRequest:function(method, uri, callback, postData)\r
-        {\r
-            var o = this.getConnectionObject();\r
-\r
-            if (!o || o.status.isError) {\r
-                return null;\r
-            }\r
-            else {\r
-               o.options = options;\r
-                try{\r
-                       o.conn.open(method, uri, true);\r
-               } catch(ex){\r
-                       o.status.isError = true;\r
-                       o.status.error = ex;\r
-                       return Ext.apply(o,this.handleTransactionResponse(o, callback));\r
-                       \r
-               }\r
-               \r
-               \r
-               if (this.useDefaultXhrHeader) {\r
-                   if (!this.defaultHeaders['X-Requested-With']) {\r
-                       this.initHeader('X-Requested-With', this.defaultXhrHeader, true);\r
-                   }\r
-               }\r
-\r
-               if(postData && this.useDefaultHeader){\r
-                   this.initHeader('Content-Type', this.defaultPostHeader);\r
-               }\r
-\r
-                if (this.hasDefaultHeaders || this.hasHeaders) {\r
-                   this.setHeader(o);\r
-               }\r
-\r
-               this.handleReadyState(o, callback);\r
-               \r
-               try{ o.conn.send(postData || null);\r
-               } catch(ex){ \r
-                       o.status.isError=true;\r
-                       o.status.error = ex;\r
-                       return Ext.apply(o,this.handleTransactionResponse(o, callback));\r
-               }\r
-                       \r
-                                       \r
-               return o;\r
-            }\r
-        },\r
-        \r
-        makeRequest:function(method, uri, callback, postData, options)\r
-        {\r
-            var o = this.getConnectionObject();\r
-                    \r
-            if (!o || o.status.isError) {\r
-                return null;\r
-            }\r
-            else {\r
-               o.options = options;    \r
-                try{\r
-                       o.conn.open(method, uri, options.async, options.userId, options.password);\r
-               } catch(ex){\r
-                       o.status.isError = true;\r
-                       o.status.error = ex;\r
-                       var r=this.handleTransactionResponse(o, callback);\r
-                       return Ext.apply(o,r);\r
-               }\r
-\r
-               if (this.useDefaultXhrHeader) {\r
-                   if (!this.defaultHeaders['X-Requested-With']) {\r
-                       this.initHeader('X-Requested-With', this.defaultXhrHeader, true);\r
-                   }\r
-               }\r
-\r
-               if(postData && this.useDefaultHeader){\r
-                   this.initHeader('Content-Type', this.defaultPostHeader);\r
-               }\r
-\r
-                if (this.hasDefaultHeaders || this.hasHeaders) {\r
-                   this.setHeader(o);\r
-               }\r
-\r
-               if(o.options.async){ //Timers won't work here as it's a blocking call\r
-                       this.handleReadyState(o, callback);\r
-               }\r
-               \r
-               try{ o.conn.send(postData || null);\r
-               } catch(ex){ \r
-                       //Ext.apply(o,this.handleTransactionResponse(o, callback));\r
-               }\r
-                               \r
-               return options.async?o:Ext.apply(o,this.handleTransactionResponse(o, callback));\r
-            }\r
-   }});\r
-       \r
+// 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 */
\ No newline at end of file