3 <title>The source code</title>
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
7 <body onload="prettyPrint();">
8 <pre class="prettyprint lang-js">/*!
10 * Copyright(c) 2006-2009 Ext JS, LLC
12 * http://www.extjs.com/license
20 function createConsole(){
22 var scriptPanel = new Ext.debug.ScriptsPanel();
23 var logView = new Ext.debug.LogPanel();
24 var tree = new Ext.debug.DomTree();
25 var compInspector = new Ext.debug.ComponentInspector();
26 var compInfoPanel = new Ext.debug.ComponentInfoPanel();
27 var storeInspector = new Ext.debug.StoreInspector();
28 var objInspector = new Ext.debug.ObjectInspector();
30 var tabs = new Ext.TabPanel({
33 tabPosition: 'bottom',
35 title: 'Debug Console',
37 items: [logView, scriptPanel]
39 title: 'HTML Inspector',
43 title: 'Component Inspector',
45 items: [compInspector,compInfoPanel]
47 title: 'Object Inspector',
53 items: [storeInspector]
58 id: 'x-debug-browser',
62 style: 'position:absolute;left:0;bottom:0;z-index:101',
72 Ext.EventManager.removeResizeListener(handleResize);
79 cp.render(Ext.getBody());
81 cp.resizer = new Ext.Resizable(cp.el, {
86 resizeElement : function(){
87 var box = this.proxy.getBox();
89 cp.setHeight(box.height);
94 // function handleResize(){
95 // cp.setWidth(Ext.getBody().getViewSize().width);
97 // Ext.EventManager.onWindowResize(handleResize);
101 function handleResize(){
102 var b = Ext.getBody()
103 var size = b.getViewSize();
104 if(size.height < b.dom.scrollHeight) {
107 cp.setWidth(size.width);
109 Ext.EventManager.onWindowResize(handleResize);
119 cp.logView.log.apply(cp.logView, arguments);
122 logf : function(format, arg1, arg2, etc){
123 Ext.log(String.format.apply(String, arguments));
127 if(typeof o == 'string' || typeof o == 'number' || typeof o == 'undefined' || Ext.isDate(o)){
131 }else if(typeof o != "object"){
132 Ext.log('Unknown return type');
133 }else if(Ext.isArray(o)){
134 Ext.log('['+o.join(',')+']');
138 var to = typeof o[key];
139 if(to != "function" && to != "object"){
140 b.push(String.format(" {0}: {1},\n", key, o[key]));
145 s = s.substr(0, s.length-2);
153 time : function(name){
154 name = name || "def";
155 Ext._timers[name] = new Date().getTime();
158 timeEnd : function(name, printResults){
159 var t = new Date().getTime();
160 name = name || "def";
161 var v = String.format("{0} ms", t-Ext._timers[name]);
162 Ext._timers[name] = new Date().getTime();
163 if(printResults !== false){
164 Ext.log('Timer ' + (name == "def" ? v : name + ": " + v));
173 Ext.debug.ScriptsPanel = Ext.extend(Ext.Panel, {
174 id:'x-debug-scripts',
181 style:'border-width:0 0 0 1px;',
183 initComponent : function(){
185 this.scriptField = new Ext.form.TextArea({
187 style:'border-width:0;'
190 this.trapBox = new Ext.form.Checkbox({
192 boxLabel: 'Trap Errors',
196 this.toolbar = new Ext.Toolbar([{
199 handler: this.evalScript
210 this.items = [this.toolbar, this.scriptField];
212 Ext.debug.ScriptsPanel.superclass.initComponent.call(this);
215 evalScript : function(){
216 var s = this.scriptField.getValue();
217 if(this.trapBox.getValue()){
220 Ext.dump(rt === undefined? '(no return)' : rt);
222 Ext.log(e.message || e.descript);
226 Ext.dump(rt === undefined? '(no return)' : rt);
231 this.scriptField.setValue('');
232 this.scriptField.focus();
237 Ext.debug.LogPanel = Ext.extend(Ext.Panel, {
241 style:'border-width:0 1px 0 0',
244 var markup = [ '<div style="padding:5px !important;border-bottom:1px solid #ccc;">',
245 Ext.util.Format.htmlEncode(Array.prototype.join.call(arguments, ', ')).replace(/\n/g, '<br/>').replace(/\s/g, ' '),
248 this.body.insertHtml('beforeend', markup);
249 this.body.scrollTo('top', 100000);
253 this.body.update('');
254 this.body.dom.scrollTop = 0;
258 Ext.debug.DomTree = Ext.extend(Ext.tree.TreePanel, {
268 initComponent : function(){
271 Ext.debug.DomTree.superclass.initComponent.call(this);
273 // tree related stuff
274 var styles = false, hnode;
275 var nonSpace = /^\s*$/;
276 var html = Ext.util.Format.htmlEncode;
277 var ellipsis = Ext.util.Format.ellipsis;
278 var styleRe = /\s?([a-z\-]*)\:([^;]*)(?:[;\s\n\r]*)/gi;
280 function findNode(n){
281 if(!n || n.nodeType != 1 || n == document.body || n == document){
285 while((p = p.parentNode) && p.nodeType == 1 && p.tagName.toUpperCase() != 'HTML'){
289 for(var i = 0, len = pn.length; i < len; i++){
291 cn = cn.findChild('htmlNode', pn[i]);
292 if(!cn){ // in this dialog?
297 var a = cn.ui.anchor;
298 this.getTreeEl().dom.scrollTop = Math.max(0 ,a.offsetTop-10);
299 //treeEl.dom.scrollLeft = Math.max(0 ,a.offsetLeft-10); no likey
304 function nodeTitle(n){
308 }else if(n.className){
309 s += '.'+n.className;
315 function onNodeSelect(t, n, last){
317 if(last && last.unframe){
329 reload.setDisabled(n.leaf);
330 var dom = n.htmlNode;
331 stylePanel.setTitle(nodeTitle(dom));
332 if(styles && !showAll.pressed){
333 var s = dom.style ? dom.style.cssText : '';
336 while ((m = styleRe.exec(s)) != null){
337 props[m[1].toLowerCase()] = m[2];
341 var cl = Ext.debug.cssList;
342 var s = dom.style, fly = Ext.fly(dom);
344 for(var i = 0, len = cl.length; i<len; i++){
346 var v = s[st] || fly.getStyle(st);
347 if(v != undefined && v !== null && v !== ''){
355 if((isNaN(a+10)) && v != undefined && v !== null && v !== '' && !(Ext.isGecko && a[0] == a[0].toUpperCase())){
367 stylesGrid.setSource(props);
368 stylesGrid.treeNode = n;
369 stylesGrid.view.fitColumns();
373 this.loader = new Ext.tree.TreeLoader();
374 this.loader.load = function(n, cb){
375 var isBody = n.htmlNode == document.body;
376 var cn = n.htmlNode.childNodes;
377 for(var i = 0, c; c = cn[i]; i++){
378 if(isBody && c.id == 'x-debug-browser'){
382 n.appendChild(new Ext.debug.HtmlNode(c));
383 }else if(c.nodeType == 3 && !nonSpace.test(c.nodeValue)){
384 n.appendChild(new Ext.tree.TreeNode({
385 text:'<em>' + ellipsis(html(String(c.nodeValue)), 35) + '</em>',
393 //tree.getSelectionModel().on('selectionchange', onNodeSelect, null, {buffer:250});
395 this.root = this.setRootNode(new Ext.tree.TreeNode('Ext'));
397 hnode = this.root.appendChild(new Ext.debug.HtmlNode(
398 document.getElementsByTagName('html')[0]
404 Ext.debug.ComponentNodeUI = Ext.extend(Ext.tree.TreeNodeUI,{
405 onOver : function(e){
406 Ext.debug.ComponentNodeUI.superclass.onOver.call(this);
407 var cmp = this.node.attributes.component;
408 if (cmp.el && cmp.el.mask && cmp.id !='x-debug-browser') {
409 try { // Oddly bombs on some elements in IE, gets any we care about though
416 Ext.debug.ComponentNodeUI.superclass.onOut.call(this);
417 var cmp = this.node.attributes.component;
418 if (cmp.el && cmp.el.unmask && cmp.id !='x-debug-browser') {
426 Ext.debug.ComponentInspector = Ext.extend(Ext.tree.TreePanel, {
436 initComponent : function(){
437 this.loader = new Ext.tree.TreeLoader();
438 this.bbar = new Ext.Toolbar([{
440 handler: this.refresh,
443 Ext.debug.ComponentInspector.superclass.initComponent.call(this);
445 this.root = this.setRootNode(new Ext.tree.TreeNode({
446 text: 'Ext Components',
447 component: Ext.ComponentMgr.all,
450 this.parseRootNode();
452 this.on('click', this.onClick, this);
455 createNode: function(n,c) {
456 var leaf = (c.items && c.items.length > 0);
457 return n.appendChild(new Ext.tree.TreeNode({
458 text: c.id + (c.getXType() ? ' [ ' + c.getXType() + ' ]': '' ),
460 uiProvider:Ext.debug.ComponentNodeUI,
465 parseChildItems: function(n) {
466 var cn = n.attributes.component.items;
468 for (var i = 0;i < cn.length; i++) {
470 if (c.id != this.id && c.id != this.bottomToolbar.id) {
471 var newNode = this.createNode(n,c);
473 this.parseChildItems(newNode)
480 parseRootNode: function() {
482 var cn = n.attributes.component.items;
483 for (var i = 0,c;c = cn[i];i++) {
484 if (c.id != this.id && c.id != this.bottomToolbar.id) {
486 var newNode = this.createNode(n,c);
488 this.parseChildItems(newNode);
495 onClick: function(node, e) {
496 var oi = Ext.getCmp('x-debug-objinspector');
497 oi.refreshNodes(node.attributes.component);
501 refresh: function() {
502 while (this.root.firstChild) {
503 this.root.removeChild(this.root.firstChild);
505 this.parseRootNode();
506 var ci = Ext.getCmp('x-debug-compinfo');
508 ci.message('refreshed component tree - '+Ext.ComponentMgr.all.length)
513 Ext.debug.ComponentInfoPanel = Ext.extend(Ext.Panel,{
514 id:'x-debug-compinfo',
522 style:'border-width:0 0 0 1px;',
524 initComponent: function() {
525 this.watchBox = new Ext.form.Checkbox({
526 id: 'x-debug-watchcomp',
527 boxLabel: 'Watch ComponentMgr',
529 check: function(cb, val) {
531 Ext.ComponentMgr.all.on('add', this.onAdd, this);
532 Ext.ComponentMgr.all.on('remove', this.onRemove, this);
534 Ext.ComponentMgr.all.un('add', this.onAdd, this);
535 Ext.ComponentMgr.all.un('remove', this.onRemove, this);
542 this.tbar = new Ext.Toolbar([{
548 Ext.debug.ComponentInfoPanel.superclass.initComponent.call(this);
551 onAdd: function(i, o, key) {
552 var markup = ['<div style="padding:5px !important;border-bottom:1px solid #ccc;">',
555 this.insertMarkup(markup);
558 onRemove: function(o, key) {
559 var markup = ['<div style="padding:5px !important;border-bottom:1px solid #ccc;">',
562 this.insertMarkup(markup);
565 message: function(msg) {
566 var markup = ['<div style="padding:5px !important;border-bottom:1px solid #ccc;">',
569 this.insertMarkup(markup);
571 insertMarkup: function(markup) {
572 this.body.insertHtml('beforeend', markup);
573 this.body.scrollTo('top', 100000);
576 this.body.update('');
577 this.body.dom.scrollTop = 0;
581 Ext.debug.ColumnNodeUI = Ext.extend(Ext.tree.TreeNodeUI, {
582 focus: Ext.emptyFn, // prevent odd scrolling behavior
584 renderElements : function(n, a, targetNode, bulkRender){
585 this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : '';
587 var t = n.getOwnerTree();
588 var cols = t.columns;
589 var bw = t.borderWidth;
593 '<li class="x-tree-node"><div ext:tree-node-id="',n.id,'" class="x-tree-node-el x-tree-node-leaf ', a.cls,'">',
594 '<div class="x-tree-col" style="width:',c.width-bw,'px;">',
595 '<span class="x-tree-node-indent">',this.indentMarkup,"</span>",
596 '<img src="', this.emptyIcon, '" class="x-tree-ec-icon x-tree-elbow"/>',
597 '<img src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon',(a.icon ? " x-tree-node-inline-icon" : ""),(a.iconCls ? " "+a.iconCls : ""),'" unselectable="on"/>',
598 '<a hidefocus="on" class="x-tree-node-anchor" href="',a.href ? a.href : "#",'" tabIndex="1" ',
599 a.hrefTarget ? ' target="'+a.hrefTarget+'"' : "", '>',
600 '<span unselectable="on">', n.text || (c.renderer ? c.renderer(a[c.dataIndex], n, a) : a[c.dataIndex]),"</span></a>",
602 for(var i = 1, len = cols.length; i < len; i++){
605 buf.push('<div class="x-tree-col ',(c.cls?c.cls:''),'" style="width:',c.width-bw,'px;">',
606 '<div class="x-tree-col-text">',(c.renderer ? c.renderer(a[c.dataIndex], n, a) : a[c.dataIndex]),"</div>",
610 '<div class="x-clear"></div></div>',
611 '<ul class="x-tree-node-ct" style="display:none;"></ul>',
614 if(bulkRender !== true && n.nextSibling && n.nextSibling.ui.getEl()){
615 this.wrap = Ext.DomHelper.insertHtml("beforeBegin",
616 n.nextSibling.ui.getEl(), buf.join(""));
618 this.wrap = Ext.DomHelper.insertHtml("beforeEnd", targetNode, buf.join(""));
621 this.elNode = this.wrap.childNodes[0];
622 this.ctNode = this.wrap.childNodes[1];
623 var cs = this.elNode.firstChild.childNodes;
624 this.indentNode = cs[0];
626 this.iconNode = cs[2];
628 this.textNode = cs[3].firstChild;
632 Ext.debug.ObjectInspector = Ext.extend(Ext.tree.TreePanel, {
633 id: 'x-debug-objinspector',
643 borderWidth: Ext.isBorderBox ? 0 : 2, // the combined left/right border for each cell
646 initComponent : function(){
647 this.showFunc = false;
648 this.toggleFunc = function() {
649 this.showFunc = !this.showFunc;
650 this.refreshNodes(this.currentObject);
652 this.bbar = new Ext.Toolbar([{
653 text: 'Show Functions',
656 handler: this.toggleFunc,
662 loader: new Ext.tree.TreeLoader(),
674 Ext.debug.ObjectInspector.superclass.initComponent.call(this);
676 this.root = this.setRootNode(new Ext.tree.TreeNode({
681 if (this.currentObject) {
686 refreshNodes: function(newObj) {
687 this.currentObject = newObj;
688 var node = this.root;
689 while(node.firstChild){
690 node.removeChild(node.firstChild);
695 parseNodes: function() {
696 for (var o in this.currentObject) {
697 if (!this.showFunc) {
698 if (Ext.isFunction(this.currentObject[o])) {
706 createNode: function(o) {
707 return this.root.appendChild(new Ext.tree.TreeNode({
709 value: this.currentObject[o],
710 uiProvider:Ext.debug.ColumnNodeUI,
711 iconCls: 'x-debug-node',
716 onRender : function(){
717 Ext.debug.ObjectInspector.superclass.onRender.apply(this, arguments);
718 this.headers = this.header.createChild({cls:'x-tree-headers'});
720 var cols = this.columns, c;
723 for(var i = 0, len = cols.length; i < len; i++){
725 totalWidth += c.width;
726 this.headers.createChild({
727 cls:'x-tree-hd ' + (c.cls?c.cls+'-hd':''),
729 cls:'x-tree-hd-text',
732 style:'width:'+(c.width-this.borderWidth)+'px;'
735 this.headers.createChild({cls:'x-clear'});
736 // prevent floats from wrapping when clipped
737 this.headers.setWidth(totalWidth);
738 this.innerCt.setWidth(totalWidth);
743 Ext.debug.StoreInspector = Ext.extend(Ext.tree.TreePanel, {
753 initComponent: function() {
754 this.bbar = new Ext.Toolbar([{
756 handler: this.refresh,
759 Ext.debug.StoreInspector.superclass.initComponent.call(this);
761 this.root = this.setRootNode(new Ext.tree.TreeNode({
765 this.on('click', this.onClick, this);
770 parseStores: function() {
771 var cn = Ext.StoreMgr.items;
772 for (var i = 0,c;c = cn[i];i++) {
773 this.root.appendChild({
774 text: c.storeId + ' - ' + c.totalLength + ' records',
781 onClick: function(node, e) {
782 var oi = Ext.getCmp('x-debug-objinspector');
783 oi.refreshNodes(node.attributes.component);
787 refresh: function() {
788 while (this.root.firstChild) {
789 this.root.removeChild(this.root.firstChild);
795 // highly unusual class declaration
796 Ext.debug.HtmlNode = function(){
797 var html = Ext.util.Format.htmlEncode;
798 var ellipsis = Ext.util.Format.ellipsis;
799 var nonSpace = /^\s*$/;
803 {n: 'className', v: 'class'},
804 {n: 'name', v: 'name'},
805 {n: 'type', v: 'type'},
806 {n: 'src', v: 'src'},
807 {n: 'href', v: 'href'}
810 function hasChild(n){
811 for(var i = 0, c; c = n.childNodes[i]; i++){
819 function renderNode(n, leaf){
820 var tag = n.tagName.toLowerCase();
821 var s = '<' + tag;
822 for(var i = 0, len = attrs.length; i < len; i++){
825 if(v && !nonSpace.test(v)){
826 s += ' ' + a.v + '="<i>' + html(v) +'</i>"';
829 var style = n.style ? n.style.cssText : '';
831 s += ' style="<i>' + html(style.toLowerCase()) +'</i>"';
833 if(leaf && n.childNodes.length > 0){
834 s+='><em>' + ellipsis(html(String(n.innerHTML)), 35) + '</em></'+tag+'>';
843 var HtmlNode = function(n){
844 var leaf = !hasChild(n);
846 this.tagName = n.tagName.toLowerCase();
848 text : renderNode(n, leaf),
852 HtmlNode.superclass.constructor.call(this, attr);
853 this.attributes.htmlNode = n; // for searching
855 this.on('expand', this.onExpand, this);
856 this.on('collapse', this.onCollapse, this);
861 Ext.extend(HtmlNode, Ext.tree.AsyncTreeNode, {
862 cls: 'x-tree-noicon',
863 preventHScroll: true,
864 refresh : function(highlight){
865 var leaf = !hasChild(this.htmlNode);
866 this.setText(renderNode(this.htmlNode, leaf));
868 Ext.fly(this.ui.textNode).highlight();
872 onExpand : function(){
873 if(!this.closeNode && this.parentNode){
874 this.closeNode = this.parentNode.insertBefore(new Ext.tree.TreeNode({
875 text:'</' + this.tagName + '>',
877 }), this.nextSibling);
878 }else if(this.closeNode){
879 this.closeNode.ui.show();
883 onCollapse : function(){
885 this.closeNode.ui.hide();
889 render : function(bulkRender){
890 HtmlNode.superclass.render.call(this, bulkRender);
893 highlightNode : function(){
894 //Ext.fly(this.htmlNode).highlight();
897 highlight : function(){
898 //Ext.fly(this.ui.textNode).highlight();
902 this.htmlNode.style.border = '1px solid #0000ff';
903 //this.highlightNode();
906 unframe : function(){
907 //Ext.fly(this.htmlNode).removeClass('x-debug-frame');
908 this.htmlNode.style.border = '';